1
- import * as vscode from ' vscode' ;
2
- import * as fspath from ' path' ;
3
- import * as fs from 'fs' ;
4
- import * as os from 'os' ;
5
- import { activeToolchain , Cargo , Crate , getRustcVersion } from ' ./toolchain' ;
1
+ import * as vscode from " vscode" ;
2
+ import * as fspath from " path" ;
3
+ import * as fs from "fs" ;
4
+ import * as os from "os" ;
5
+ import { activeToolchain , Cargo , Crate , getRustcVersion } from " ./toolchain" ;
6
6
7
7
const debugOutput = vscode . window . createOutputChannel ( "Debug" ) ;
8
8
9
- export class RustDependenciesProvider implements vscode . TreeDataProvider < Dependency | DependencyFile > {
9
+ export class RustDependenciesProvider
10
+ implements vscode . TreeDataProvider < Dependency | DependencyFile >
11
+ {
10
12
cargo : Cargo ;
11
13
dependenciesMap : { [ id : string ] : Dependency | DependencyFile } ;
12
14
13
- constructor (
14
- private readonly workspaceRoot : string ,
15
- ) {
16
- this . cargo = new Cargo ( this . workspaceRoot || '.' , debugOutput ) ;
15
+ constructor ( private readonly workspaceRoot : string ) {
16
+ this . cargo = new Cargo ( this . workspaceRoot || "." , debugOutput ) ;
17
17
this . dependenciesMap = { } ;
18
18
}
19
19
20
- private _onDidChangeTreeData : vscode . EventEmitter < Dependency | DependencyFile | undefined | null | void > = new vscode . EventEmitter < Dependency | undefined | null | void > ( ) ;
21
-
22
- readonly onDidChangeTreeData : vscode . Event < Dependency | DependencyFile | undefined | null | void > = this . _onDidChangeTreeData . event ;
20
+ private _onDidChangeTreeData : vscode . EventEmitter <
21
+ Dependency | DependencyFile | undefined | null | void
22
+ > = new vscode . EventEmitter < Dependency | undefined | null | void > ( ) ;
23
23
24
+ readonly onDidChangeTreeData : vscode . Event <
25
+ Dependency | DependencyFile | undefined | null | void
26
+ > = this . _onDidChangeTreeData . event ;
24
27
25
28
getDependency ( filePath : string ) : Dependency | DependencyFile | undefined {
26
29
return this . dependenciesMap [ filePath . toLowerCase ( ) ] ;
@@ -34,7 +37,9 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
34
37
this . _onDidChangeTreeData . fire ( ) ;
35
38
}
36
39
37
- getParent ?( element : Dependency | DependencyFile ) : vscode . ProviderResult < Dependency | DependencyFile > {
40
+ getParent ?(
41
+ element : Dependency | DependencyFile
42
+ ) : vscode . ProviderResult < Dependency | DependencyFile > {
38
43
if ( element instanceof Dependency ) return undefined ;
39
44
return element . parent ;
40
45
}
@@ -44,39 +49,34 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
44
49
return element ;
45
50
}
46
51
47
- getChildren ( element ?: Dependency | DependencyFile ) : vscode . ProviderResult < Dependency [ ] | DependencyFile [ ] > {
52
+ getChildren (
53
+ element ?: Dependency | DependencyFile
54
+ ) : vscode . ProviderResult < Dependency [ ] | DependencyFile [ ] > {
48
55
return new Promise ( ( resolve , _reject ) => {
49
56
if ( ! this . workspaceRoot ) {
50
- void vscode . window . showInformationMessage ( ' No dependency in empty workspace' ) ;
57
+ void vscode . window . showInformationMessage ( " No dependency in empty workspace" ) ;
51
58
return Promise . resolve ( [ ] ) ;
52
59
}
53
60
54
61
if ( element ) {
55
- const files = fs . readdirSync ( element . dependencyPath ) . map ( fileName => {
62
+ const files = fs . readdirSync ( element . dependencyPath ) . map ( ( fileName ) => {
56
63
const filePath = fspath . join ( element . dependencyPath , fileName ) ;
57
- const collapsibleState = fs . lstatSync ( filePath ) . isDirectory ( ) ?
58
- vscode . TreeItemCollapsibleState . Collapsed :
59
- vscode . TreeItemCollapsibleState . None ;
60
- const dep = new DependencyFile (
61
- fileName ,
62
- filePath ,
63
- element ,
64
- collapsibleState
65
- ) ;
64
+ const collapsibleState = fs . lstatSync ( filePath ) . isDirectory ( )
65
+ ? vscode . TreeItemCollapsibleState . Collapsed
66
+ : vscode . TreeItemCollapsibleState . None ;
67
+ const dep = new DependencyFile ( fileName , filePath , element , collapsibleState ) ;
66
68
this . dependenciesMap [ dep . dependencyPath . toLowerCase ( ) ] = dep ;
67
69
return dep ;
68
70
} ) ;
69
- return resolve (
70
- files
71
- ) ;
71
+ return resolve ( files ) ;
72
72
} else {
73
73
return resolve ( this . getRootDependencies ( ) ) ;
74
74
}
75
75
} ) ;
76
76
}
77
77
78
78
private async getRootDependencies ( ) : Promise < Dependency [ ] > {
79
- const registryDir = fspath . join ( os . homedir ( ) , ' .cargo' , ' registry' , ' src' ) ;
79
+ const registryDir = fspath . join ( os . homedir ( ) , " .cargo" , " registry" , " src" ) ;
80
80
const basePath = fspath . join ( registryDir , fs . readdirSync ( registryDir ) [ 0 ] ) ;
81
81
const deps = await this . getDepsInCartoTree ( basePath ) ;
82
82
const stdlib = await this . getStdLib ( ) ;
@@ -87,7 +87,17 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
87
87
private async getStdLib ( ) : Promise < Dependency > {
88
88
const toolchain = await activeToolchain ( ) ;
89
89
const rustVersion = await getRustcVersion ( os . homedir ( ) ) ;
90
- const stdlibPath = fspath . join ( os . homedir ( ) , '.rustup' , 'toolchains' , toolchain , 'lib' , 'rustlib' , 'src' , 'rust' , 'library' ) ;
90
+ const stdlibPath = fspath . join (
91
+ os . homedir ( ) ,
92
+ ".rustup" ,
93
+ "toolchains" ,
94
+ toolchain ,
95
+ "lib" ,
96
+ "rustlib" ,
97
+ "src" ,
98
+ "rust" ,
99
+ "library"
100
+ ) ;
91
101
const stdlib = new Dependency (
92
102
"stdlib" ,
93
103
rustVersion ,
@@ -110,7 +120,7 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
110
120
) ;
111
121
} ;
112
122
113
- const deps = crates . map ( crate => {
123
+ const deps = crates . map ( ( crate ) => {
114
124
const dep = toDep ( crate . name , crate . version ) ;
115
125
this . dependenciesMap [ dep . dependencyPath . toLowerCase ( ) ] = dep ;
116
126
return dep ;
@@ -119,7 +129,6 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
119
129
}
120
130
}
121
131
122
-
123
132
export class Dependency extends vscode . TreeItem {
124
133
constructor (
125
134
public readonly label : string ,
@@ -135,7 +144,6 @@ export class Dependency extends vscode.TreeItem {
135
144
}
136
145
137
146
export class DependencyFile extends vscode . TreeItem {
138
-
139
147
constructor (
140
148
readonly label : string ,
141
149
readonly dependencyPath : string ,
@@ -146,9 +154,13 @@ export class DependencyFile extends vscode.TreeItem {
146
154
const isDir = fs . lstatSync ( this . dependencyPath ) . isDirectory ( ) ;
147
155
this . id = this . dependencyPath . toLowerCase ( ) ;
148
156
if ( ! isDir ) {
149
- this . command = { command : 'rust-analyzer.openFile' , title : "Open File" , arguments : [ vscode . Uri . file ( this . dependencyPath ) ] , } ;
157
+ this . command = {
158
+ command : "rust-analyzer.openFile" ,
159
+ title : "Open File" ,
160
+ arguments : [ vscode . Uri . file ( this . dependencyPath ) ] ,
161
+ } ;
150
162
}
151
163
}
152
164
}
153
165
154
- export type DependencyId = { id : string } ;
166
+ export type DependencyId = { id : string } ;
0 commit comments