mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-21 02:50:21 +00:00
fixing linting problemas
This commit is contained in:
parent
f8215dd426
commit
ee54c6558d
1 changed files with 36 additions and 30 deletions
|
@ -5,13 +5,15 @@ import { CtxInit } from "./ctx";
|
||||||
import * as ra from "./lsp_ext";
|
import * as ra from "./lsp_ext";
|
||||||
import { FetchDependencyGraphResult } from "./lsp_ext";
|
import { FetchDependencyGraphResult } from "./lsp_ext";
|
||||||
|
|
||||||
export class RustDependenciesProvider
|
|
||||||
implements vscode.TreeDataProvider<Dependency | DependencyFile> {
|
|
||||||
dependenciesMap: { [id: string]: Dependency | DependencyFile };
|
|
||||||
ctx: CtxInit;
|
|
||||||
|
|
||||||
constructor(private readonly workspaceRoot: string, ctx: CtxInit) {
|
|
||||||
this.dependenciesMap = {};
|
export class RustDependenciesProvider implements vscode.TreeDataProvider<Dependency | DependencyFile>{
|
||||||
|
|
||||||
|
dependenciesMap: { [id: string]: Dependency | DependencyFile };ctx: CtxInit;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly workspaceRoot: string,ctx: CtxInit) {
|
||||||
|
this.dependenciesMap = {};
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,25 +49,31 @@ export class RustDependenciesProvider
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
getChildren(
|
getChildren(element?: Dependency | DependencyFile): vscode.ProviderResult<Dependency[] | DependencyFile[]> {
|
||||||
element?: Dependency | DependencyFile
|
|
||||||
): vscode.ProviderResult<Dependency[] | DependencyFile[]> {
|
|
||||||
return new Promise((resolve, _reject) => {
|
return new Promise((resolve, _reject) => {
|
||||||
if (!this.workspaceRoot) {
|
if (!this.workspaceRoot) {
|
||||||
void vscode.window.showInformationMessage("No dependency in empty workspace");
|
void vscode.window.showInformationMessage("No dependency in empty workspace");
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
const files = fs.readdirSync(element.dependencyPath).map((fileName) => {
|
const files = fs.readdirSync(element.dependencyPath).map((fileName) => {
|
||||||
const filePath = fspath.join(element.dependencyPath, fileName);
|
const filePath = fspath.join(element.dependencyPath, fileName);
|
||||||
const collapsibleState = fs.lstatSync(filePath).isDirectory()
|
const collapsibleState = fs.lstatSync(filePath).isDirectory()
|
||||||
? vscode.TreeItemCollapsibleState.Collapsed
|
? vscode.TreeItemCollapsibleState.Collapsed
|
||||||
: vscode.TreeItemCollapsibleState.None;
|
:vscode.TreeItemCollapsibleState.None;
|
||||||
const dep = new DependencyFile(fileName, filePath, element, collapsibleState);
|
const dep = new DependencyFile(
|
||||||
|
fileName,
|
||||||
|
filePath,
|
||||||
|
element,
|
||||||
|
collapsibleState);
|
||||||
|
|
||||||
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
|
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
|
||||||
return dep;
|
return dep;
|
||||||
});
|
});
|
||||||
return resolve(files);
|
return resolve(
|
||||||
|
files
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return resolve(this.getRootDependencies());
|
return resolve(this.getRootDependencies());
|
||||||
}
|
}
|
||||||
|
@ -75,25 +83,24 @@ export class RustDependenciesProvider
|
||||||
private async getRootDependencies(): Promise<Dependency[]> {
|
private async getRootDependencies(): Promise<Dependency[]> {
|
||||||
const dependenciesResult: FetchDependencyGraphResult = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
|
const dependenciesResult: FetchDependencyGraphResult = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
|
||||||
const crates = dependenciesResult.crates;
|
const crates = dependenciesResult.crates;
|
||||||
|
|
||||||
const deps = crates.map((crate) => {
|
const deps = crates.map((crate) => {
|
||||||
const dep = this.toDep(crate.name, crate.version, crate.path);
|
const dep = this.toDep(crate.name, crate.version, crate.path);
|
||||||
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
|
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
|
||||||
this.dependenciesMap[stdlib.dependencyPath.toLowerCase()] = stdlib;
|
this.dependenciesMap[stdlib.dependencyPath.toLowerCase()] = stdlib;
|
||||||
return dep;
|
return dep;
|
||||||
});
|
});
|
||||||
return deps;
|
return deps;
|
||||||
}
|
}
|
||||||
|
|
||||||
private toDep(moduleName: string, version: string, path: string): Dependency {
|
private toDep(moduleName: string, version: string, path: string): Dependency {
|
||||||
// const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
|
//const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
|
||||||
return new Dependency(
|
return new Dependency(
|
||||||
moduleName,
|
moduleName,
|
||||||
version,
|
version,
|
||||||
path,
|
path,
|
||||||
vscode.TreeItemCollapsibleState.Collapsed
|
vscode.TreeItemCollapsibleState.Collapsed
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Dependency extends vscode.TreeItem {
|
export class Dependency extends vscode.TreeItem {
|
||||||
|
@ -111,6 +118,7 @@ export class Dependency extends vscode.TreeItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DependencyFile extends vscode.TreeItem {
|
export class DependencyFile extends vscode.TreeItem {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly label: string,
|
readonly label: string,
|
||||||
readonly dependencyPath: string,
|
readonly dependencyPath: string,
|
||||||
|
@ -121,13 +129,11 @@ export class DependencyFile extends vscode.TreeItem {
|
||||||
const isDir = fs.lstatSync(this.dependencyPath).isDirectory();
|
const isDir = fs.lstatSync(this.dependencyPath).isDirectory();
|
||||||
this.id = this.dependencyPath.toLowerCase();
|
this.id = this.dependencyPath.toLowerCase();
|
||||||
if (!isDir) {
|
if (!isDir) {
|
||||||
this.command = {
|
this.command = { command: "vscode.open",
|
||||||
command: "vscode.open",
|
|
||||||
title: "Open File",
|
title: "Open File",
|
||||||
arguments: [vscode.Uri.file(this.dependencyPath)],
|
arguments: [vscode.Uri.file(this.dependencyPath)],
|
||||||
};
|
};
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DependencyId = { id: string };
|
export type DependencyId = { id: string };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue