@@ -5,13 +5,15 @@ import { CtxInit } from "./ctx";
5
5
import * as ra from "./lsp_ext" ;
6
6
import { FetchDependencyGraphResult } from "./lsp_ext" ;
7
7
8
- export class RustDependenciesProvider
9
- implements vscode . TreeDataProvider < Dependency | DependencyFile > {
10
- dependenciesMap : { [ id : string ] : Dependency | DependencyFile } ;
11
- ctx : CtxInit ;
12
8
13
- constructor ( private readonly workspaceRoot : string , ctx : CtxInit ) {
14
- this . dependenciesMap = { } ;
9
+
10
+ export class RustDependenciesProvider implements vscode . TreeDataProvider < Dependency | DependencyFile > {
11
+
12
+ dependenciesMap : { [ id : string ] : Dependency | DependencyFile } ; ctx : CtxInit ;
13
+
14
+ constructor (
15
+ private readonly workspaceRoot : string , ctx : CtxInit ) {
16
+ this . dependenciesMap = { } ;
15
17
this . ctx = ctx ;
16
18
}
17
19
@@ -47,25 +49,31 @@ export class RustDependenciesProvider
47
49
return element ;
48
50
}
49
51
50
- getChildren (
51
- element ?: Dependency | DependencyFile
52
- ) : vscode . ProviderResult < Dependency [ ] | DependencyFile [ ] > {
52
+ getChildren ( element ?: Dependency | DependencyFile ) : vscode . ProviderResult < Dependency [ ] | DependencyFile [ ] > {
53
53
return new Promise ( ( resolve , _reject ) => {
54
54
if ( ! this . workspaceRoot ) {
55
55
void vscode . window . showInformationMessage ( "No dependency in empty workspace" ) ;
56
56
return Promise . resolve ( [ ] ) ;
57
57
}
58
+
58
59
if ( element ) {
59
60
const files = fs . readdirSync ( element . dependencyPath ) . map ( ( fileName ) => {
60
61
const filePath = fspath . join ( element . dependencyPath , fileName ) ;
61
62
const collapsibleState = fs . lstatSync ( filePath ) . isDirectory ( )
62
63
? vscode . TreeItemCollapsibleState . Collapsed
63
- : vscode . TreeItemCollapsibleState . None ;
64
- const dep = new DependencyFile ( fileName , filePath , element , collapsibleState ) ;
64
+ :vscode . TreeItemCollapsibleState . None ;
65
+ const dep = new DependencyFile (
66
+ fileName ,
67
+ filePath ,
68
+ element ,
69
+ collapsibleState ) ;
70
+
65
71
this . dependenciesMap [ dep . dependencyPath . toLowerCase ( ) ] = dep ;
66
72
return dep ;
67
73
} ) ;
68
- return resolve ( files ) ;
74
+ return resolve (
75
+ files
76
+ ) ;
69
77
} else {
70
78
return resolve ( this . getRootDependencies ( ) ) ;
71
79
}
@@ -75,25 +83,24 @@ export class RustDependenciesProvider
75
83
private async getRootDependencies ( ) : Promise < Dependency [ ] > {
76
84
const dependenciesResult : FetchDependencyGraphResult = await this . ctx . client . sendRequest ( ra . fetchDependencyGraph , { } ) ;
77
85
const crates = dependenciesResult . crates ;
78
-
79
86
const deps = crates . map ( ( crate ) => {
80
- const dep = this . toDep ( crate . name , crate . version , crate . path ) ;
87
+ const dep = this . toDep ( crate . name , crate . version , crate . path ) ;
81
88
this . dependenciesMap [ dep . dependencyPath . toLowerCase ( ) ] = dep ;
82
- this . dependenciesMap [ stdlib . dependencyPath . toLowerCase ( ) ] = stdlib ;
83
- return dep ;
89
+ this . dependenciesMap [ stdlib . dependencyPath . toLowerCase ( ) ] = stdlib ;
90
+ return dep ;
84
91
} ) ;
85
92
return deps ;
86
93
}
87
94
88
- private toDep ( moduleName : string , version : string , path : string ) : Dependency {
89
- // const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
90
- return new Dependency (
91
- moduleName ,
92
- version ,
93
- path ,
94
- vscode . TreeItemCollapsibleState . Collapsed
95
- ) ;
96
- }
95
+ private toDep ( moduleName : string , version : string , path : string ) : Dependency {
96
+ // const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
97
+ return new Dependency (
98
+ moduleName ,
99
+ version ,
100
+ path ,
101
+ vscode . TreeItemCollapsibleState . Collapsed
102
+ ) ;
103
+ }
97
104
}
98
105
99
106
export class Dependency extends vscode . TreeItem {
@@ -111,6 +118,7 @@ export class Dependency extends vscode.TreeItem {
111
118
}
112
119
113
120
export class DependencyFile extends vscode . TreeItem {
121
+
114
122
constructor (
115
123
readonly label : string ,
116
124
readonly dependencyPath : string ,
@@ -121,13 +129,11 @@ export class DependencyFile extends vscode.TreeItem {
121
129
const isDir = fs . lstatSync ( this . dependencyPath ) . isDirectory ( ) ;
122
130
this . id = this . dependencyPath . toLowerCase ( ) ;
123
131
if ( ! isDir ) {
124
- this . command = {
125
- command : "vscode.open" ,
132
+ this . command = { command : "vscode.open" ,
126
133
title : "Open File" ,
127
134
arguments : [ vscode . Uri . file ( this . dependencyPath ) ] ,
128
- } ;
129
- }
130
- }
135
+ } ;
136
+ } }
131
137
}
132
138
133
139
export type DependencyId = { id : string } ;
0 commit comments