diff options
| author | bruno-ortiz <brunortiz11@gmail.com> | 2022-02-25 22:37:09 -0300 |
|---|---|---|
| committer | Bruno Ortiz <brunortiz11@gmail.com> | 2023-05-02 10:48:38 -0300 |
| commit | 77a4bfd34f2d251482aca8e8da10634f34552e3b (patch) | |
| tree | 3585eff856c3f174faa4e16871d970c3b5513104 | |
| parent | 68aa20bb8add41a2996c857235f554e11cde71aa (diff) | |
| download | rust-77a4bfd34f2d251482aca8e8da10634f34552e3b.tar.gz rust-77a4bfd34f2d251482aca8e8da10634f34552e3b.zip | |
fixing linting problemas
| -rw-r--r-- | editors/code/src/dependencies_provider.ts | 262 |
1 files changed, 131 insertions, 131 deletions
diff --git a/editors/code/src/dependencies_provider.ts b/editors/code/src/dependencies_provider.ts index 1b9ab897350..2df5ef61111 100644 --- a/editors/code/src/dependencies_provider.ts +++ b/editors/code/src/dependencies_provider.ts @@ -7,148 +7,148 @@ import { activeToolchain, Cargo, Crate, getRustcVersion } from './toolchain'; const debugOutput = vscode.window.createOutputChannel("Debug"); export class RustDependenciesProvider implements vscode.TreeDataProvider<Dependency | DependencyFile>{ - cargo: Cargo; - dependenciesMap: { [id: string]: Dependency | DependencyFile }; - - constructor( - private readonly workspaceRoot: string, - ) { - this.cargo = new Cargo(this.workspaceRoot || '.', debugOutput); - this.dependenciesMap = {}; - } - - private _onDidChangeTreeData: vscode.EventEmitter<Dependency | DependencyFile | undefined | null | void> = new vscode.EventEmitter<Dependency | undefined | null | void>(); - - readonly onDidChangeTreeData: vscode.Event<Dependency | DependencyFile | undefined | null | void> = this._onDidChangeTreeData.event; - - - getDependency(filePath: string): Dependency | DependencyFile | undefined { - return this.dependenciesMap[filePath.toLowerCase()]; - } - - contains(filePath: string): boolean { - return filePath.toLowerCase() in this.dependenciesMap; - } - - refresh(): void { - this._onDidChangeTreeData.fire(); - } - - getParent?(element: Dependency | DependencyFile): vscode.ProviderResult<Dependency | DependencyFile> { - if (element instanceof Dependency) return undefined; - return element.parent; - } - - getTreeItem(element: Dependency | DependencyFile): vscode.TreeItem | Thenable<vscode.TreeItem> { - if (element.id! in this.dependenciesMap) return this.dependenciesMap[element.id!]; - return element; - } - - getChildren(element?: Dependency | DependencyFile): vscode.ProviderResult<Dependency[] | DependencyFile[]> { - return new Promise((resolve, _reject) => { - if (!this.workspaceRoot) { - void vscode.window.showInformationMessage('No dependency in empty workspace'); - return Promise.resolve([]); - } - - if (element) { - const files = fs.readdirSync(element.dependencyPath).map(fileName => { - const filePath = fspath.join(element.dependencyPath, fileName); - const collapsibleState = fs.lstatSync(filePath).isDirectory() ? - vscode.TreeItemCollapsibleState.Collapsed : - vscode.TreeItemCollapsibleState.None; - const dep = new DependencyFile( - fileName, - filePath, - element, - collapsibleState - ); - this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep; - return dep; + cargo: Cargo; + dependenciesMap: { [id: string]: Dependency | DependencyFile }; + + constructor( + private readonly workspaceRoot: string, + ) { + this.cargo = new Cargo(this.workspaceRoot || '.', debugOutput); + this.dependenciesMap = {}; + } + + private _onDidChangeTreeData: vscode.EventEmitter<Dependency | DependencyFile | undefined | null | void> = new vscode.EventEmitter<Dependency | undefined | null | void>(); + + readonly onDidChangeTreeData: vscode.Event<Dependency | DependencyFile | undefined | null | void> = this._onDidChangeTreeData.event; + + + getDependency(filePath: string): Dependency | DependencyFile | undefined { + return this.dependenciesMap[filePath.toLowerCase()]; + } + + contains(filePath: string): boolean { + return filePath.toLowerCase() in this.dependenciesMap; + } + + refresh(): void { + this._onDidChangeTreeData.fire(); + } + + getParent?(element: Dependency | DependencyFile): vscode.ProviderResult<Dependency | DependencyFile> { + if (element instanceof Dependency) return undefined; + return element.parent; + } + + getTreeItem(element: Dependency | DependencyFile): vscode.TreeItem | Thenable<vscode.TreeItem> { + if (element.id! in this.dependenciesMap) return this.dependenciesMap[element.id!]; + return element; + } + + getChildren(element?: Dependency | DependencyFile): vscode.ProviderResult<Dependency[] | DependencyFile[]> { + return new Promise((resolve, _reject) => { + if (!this.workspaceRoot) { + void vscode.window.showInformationMessage('No dependency in empty workspace'); + return Promise.resolve([]); + } + + if (element) { + const files = fs.readdirSync(element.dependencyPath).map(fileName => { + const filePath = fspath.join(element.dependencyPath, fileName); + const collapsibleState = fs.lstatSync(filePath).isDirectory() ? + vscode.TreeItemCollapsibleState.Collapsed : + vscode.TreeItemCollapsibleState.None; + const dep = new DependencyFile( + fileName, + filePath, + element, + collapsibleState + ); + this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep; + return dep; + }); + return resolve( + files + ); + } else { + return resolve(this.getRootDependencies()); + } }); - return resolve( - files + } + + private async getRootDependencies(): Promise<Dependency[]> { + const registryDir = fspath.join(os.homedir(), '.cargo', 'registry', 'src'); + const basePath = fspath.join(registryDir, fs.readdirSync(registryDir)[0]); + const deps = await this.getDepsInCartoTree(basePath); + const stdlib = await this.getStdLib(); + this.dependenciesMap[stdlib.dependencyPath.toLowerCase()] = stdlib; + return [stdlib].concat(deps); + } + + private async getStdLib(): Promise<Dependency> { + const toolchain = await activeToolchain(); + const rustVersion = await getRustcVersion(os.homedir()); + const stdlibPath = fspath.join(os.homedir(), '.rustup', 'toolchains', toolchain, 'lib', 'rustlib', 'src', 'rust', 'library'); + const stdlib = new Dependency( + "stdlib", + rustVersion, + stdlibPath, + vscode.TreeItemCollapsibleState.Collapsed ); - } else { - return resolve(this.getRootDependencies()); - } - }); - } - - private async getRootDependencies(): Promise<Dependency[]> { - const registryDir = fspath.join(os.homedir(), '.cargo', 'registry', 'src'); - const basePath = fspath.join(registryDir, fs.readdirSync(registryDir)[0]); - const deps = await this.getDepsInCartoTree(basePath); - const stdlib = await this.getStdLib(); - this.dependenciesMap[stdlib.dependencyPath.toLowerCase()] = stdlib; - return [stdlib].concat(deps); - } - - private async getStdLib(): Promise<Dependency> { - const toolchain = await activeToolchain(); - const rustVersion = await getRustcVersion(os.homedir()); - const stdlibPath = fspath.join(os.homedir(), '.rustup', 'toolchains', toolchain, 'lib', 'rustlib', 'src', 'rust', 'library'); - const stdlib = new Dependency( - "stdlib", - rustVersion, - stdlibPath, - vscode.TreeItemCollapsibleState.Collapsed - ); - - return stdlib; - } - - private async getDepsInCartoTree(basePath: string): Promise<Dependency[]> { - const crates: Crate[] = await this.cargo.crates(); - const toDep = (moduleName: string, version: string): Dependency => { - const cratePath = fspath.join(basePath, `${moduleName}-${version}`); - return new Dependency( - moduleName, - version, - cratePath, - vscode.TreeItemCollapsibleState.Collapsed - ); - }; - - const deps = crates.map(crate => { - const dep = toDep(crate.name, crate.version); - this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep; - return dep; - }); - return deps; - } + + return stdlib; + } + + private async getDepsInCartoTree(basePath: string): Promise<Dependency[]> { + const crates: Crate[] = await this.cargo.crates(); + const toDep = (moduleName: string, version: string): Dependency => { + const cratePath = fspath.join(basePath, `${moduleName}-${version}`); + return new Dependency( + moduleName, + version, + cratePath, + vscode.TreeItemCollapsibleState.Collapsed + ); + }; + + const deps = crates.map(crate => { + const dep = toDep(crate.name, crate.version); + this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep; + return dep; + }); + return deps; + } } export class Dependency extends vscode.TreeItem { - constructor( - public readonly label: string, - private version: string, - readonly dependencyPath: string, - public readonly collapsibleState: vscode.TreeItemCollapsibleState - ) { - super(label, collapsibleState); - this.tooltip = `${this.label}-${this.version}`; - this.description = this.version; - this.resourceUri = vscode.Uri.file(dependencyPath); - } + constructor( + public readonly label: string, + private version: string, + readonly dependencyPath: string, + public readonly collapsibleState: vscode.TreeItemCollapsibleState + ) { + super(label, collapsibleState); + this.tooltip = `${this.label}-${this.version}`; + this.description = this.version; + this.resourceUri = vscode.Uri.file(dependencyPath); + } } export class DependencyFile extends vscode.TreeItem { - constructor( - readonly label: string, - readonly dependencyPath: string, - readonly parent: Dependency | DependencyFile, - public readonly collapsibleState: vscode.TreeItemCollapsibleState - ) { - super(vscode.Uri.file(dependencyPath), collapsibleState); - const isDir = fs.lstatSync(this.dependencyPath).isDirectory(); - this.id = this.dependencyPath.toLowerCase(); - if (!isDir) { - this.command = { command: 'rust-analyzer.openFile', title: "Open File", arguments: [vscode.Uri.file(this.dependencyPath)], }; + constructor( + readonly label: string, + readonly dependencyPath: string, + readonly parent: Dependency | DependencyFile, + public readonly collapsibleState: vscode.TreeItemCollapsibleState + ) { + super(vscode.Uri.file(dependencyPath), collapsibleState); + const isDir = fs.lstatSync(this.dependencyPath).isDirectory(); + this.id = this.dependencyPath.toLowerCase(); + if (!isDir) { + this.command = { command: 'rust-analyzer.openFile', title: "Open File", arguments: [vscode.Uri.file(this.dependencyPath)], }; + } } - } } export type DependencyId = { id: string }; \ No newline at end of file |
