From 3ba66bf24fece8df19314ee50320f25656998390 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 9 May 2022 15:52:52 -0700 Subject: [PATCH] Use explicit empty authority for JS/TS resources (#149125) Fixes #149123 10c8c1c2cce90256dc84597034c18b391a8b189f made sure we sync over the authority of in-memory resources over to TS Server. However if a resource does not have an authority, this resulted in a url with `scheme//path` instead of `scheme/authority/path` TS would then normalize the uri to `scheme/path`, resulting in us considering this a new resource This fix adds an explicit empty authority that we use in this case instead --- .../src/typescriptServiceClient.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extensions/typescript-language-features/src/typescriptServiceClient.ts b/extensions/typescript-language-features/src/typescriptServiceClient.ts index 9df101d76dd..306dd8570eb 100644 --- a/extensions/typescript-language-features/src/typescriptServiceClient.ts +++ b/extensions/typescript-language-features/src/typescriptServiceClient.ts @@ -95,6 +95,7 @@ namespace ServerState { export default class TypeScriptServiceClient extends Disposable implements ITypeScriptServiceClient { private readonly pathSeparator: string; + private readonly emptyAuthority = 'ts-nul-authority'; private readonly inMemoryResourcePrefix = '^'; private readonly workspaceState: vscode.Memento; @@ -676,7 +677,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType { return this.inMemoryResourcePrefix + '/' + resource.scheme - + '/' + resource.authority + + '/' + (resource.authority || this.emptyAuthority) + (resource.path.startsWith('/') ? resource.path : '/' + resource.path) + (resource.fragment ? '#' + resource.fragment : ''); } @@ -724,9 +725,9 @@ export default class TypeScriptServiceClient extends Disposable implements IType } if (filepath.startsWith(this.inMemoryResourcePrefix)) { - const parts = filepath.match(/^\^\/([^\/]+)\/(.+)$/); + const parts = filepath.match(/^\^\/([^\/]+)\/([^\/]*)\/(.+)$/); if (parts) { - const resource = vscode.Uri.parse(parts[1] + '://' + parts[2]); + const resource = vscode.Uri.parse(parts[1] + '://' + (parts[2] === this.emptyAuthority ? '' : parts[2]) + '/' + parts[3]); return this.bufferSyncSupport.toVsCodeResource(resource); } }