This repository was archived by the owner on Nov 18, 2022. It is now read-only.
File tree 1 file changed +9
-1
lines changed
1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -10,26 +10,34 @@ export function nearestParentWorkspace(
10
10
filePath : string ,
11
11
) : WorkspaceFolder {
12
12
13
+ // check that the workspace folder already contains the "Cargo.toml"
13
14
const workspaceRoot = path . parse ( curWorkspace . uri . fsPath ) . dir ;
14
15
const rootManifest = path . join ( workspaceRoot , 'Cargo.toml' ) ;
15
16
if ( fs . existsSync ( rootManifest ) ) {
16
17
return curWorkspace ;
17
18
}
18
19
20
+ // algorithm that will strip one folder at a time and check if that folder contains "Cargo.toml"
19
21
let current = filePath ;
20
-
21
22
while ( true ) {
22
23
const old = current ;
23
24
current = path . dirname ( current ) ;
25
+
26
+ // break in case there is a bug that could result in a busy loop
24
27
if ( old === current ) {
25
28
break ;
26
29
}
30
+
31
+ // break in case the strip folder has not changed
27
32
if ( workspaceRoot === path . parse ( current ) . dir ) {
28
33
break ;
29
34
}
30
35
36
+ // check if "Cargo.toml" is present in the parent folder
31
37
const cargoPath = path . join ( current , 'Cargo.toml' ) ;
32
38
if ( fs . existsSync ( cargoPath ) ) {
39
+
40
+ // ghetto change the uri on Workspace folder to make vscode think it's located elsewhere
33
41
return { ...curWorkspace , uri : Uri . parse ( current ) } ;
34
42
}
35
43
}
You can’t perform that action at this time.
0 commit comments