File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
extensions/typescript-language-features/src Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,20 @@ class SyncedBuffer {
191
191
}
192
192
193
193
private getProjectRootPath ( resource : vscode . Uri ) : string | undefined {
194
- const workspaceRoot = this . client . getWorkspaceRootForResource ( resource ) ;
194
+ let workspaceRoot = this . client . getWorkspaceRootForResource ( resource ) ;
195
+
196
+ // If we didn't find a real workspace, we still want to try sending along a workspace folder
197
+ // to prevent TS from loading projects from outside of any workspace.
198
+ // Just pick the highest level one on the same FS even though the file is outside of it
199
+ if ( ! workspaceRoot && vscode . workspace . workspaceFolders ) {
200
+ for ( const root of Array . from ( vscode . workspace . workspaceFolders ) . sort ( ( a , b ) => a . uri . path . length - b . uri . path . length ) ) {
201
+ if ( root . uri . scheme === resource . scheme && root . uri . authority === resource . authority ) {
202
+ workspaceRoot = root . uri ;
203
+ break ;
204
+ }
205
+ }
206
+ }
207
+
195
208
if ( workspaceRoot ) {
196
209
const tsRoot = this . client . toTsFilePath ( workspaceRoot ) ;
197
210
return tsRoot ?. startsWith ( inMemoryResourcePrefix ) ? undefined : tsRoot ;
Original file line number Diff line number Diff line change @@ -836,9 +836,10 @@ export default class TypeScriptServiceClient extends Disposable implements IType
836
836
}
837
837
}
838
838
839
- for ( const root of roots . sort ( ( a , b ) => a . uri . fsPath . length - b . uri . fsPath . length ) ) {
839
+ // Find the highest level workspace folder that contains the file
840
+ for ( const root of roots . sort ( ( a , b ) => a . uri . path . length - b . uri . path . length ) ) {
840
841
if ( root . uri . scheme === resource . scheme && root . uri . authority === resource . authority ) {
841
- if ( resource . fsPath . startsWith ( root . uri . fsPath + path . sep ) ) {
842
+ if ( resource . path . startsWith ( root . uri . path + '/' ) ) {
842
843
return root . uri ;
843
844
}
844
845
}
You can’t perform that action at this time.
0 commit comments