From 96a5151f7a2a71fd4289fdf2873ccca50bcdb995 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 21 Oct 2019 18:26:32 -0700 Subject: [PATCH] Workaround for TS not being able to handle interactive playground resource with query parameters in uri Fixes #81059 Fixes #82419 The interactive playground generates uris that have query paramters. This causes the TS Server to crash. The workaround here is make sure the file paths we give to TS Server don't have query paramters but the ones we work with locally do --- .../src/features/bufferSyncSupport.ts | 10 ++++++++++ .../src/typescriptServiceClient.ts | 12 +++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts index f06e5a9304c..8d51a63215b 100644 --- a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts +++ b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts @@ -356,6 +356,16 @@ export default class BufferSyncSupport extends Disposable { return this.syncedBuffers.has(resource); } + public toVsCodeResource(resource: vscode.Uri): vscode.Uri { + const filepath = this.client.normalizedPath(resource); + for (const buffer of this.syncedBuffers.allBuffers) { + if (buffer.filepath === filepath) { + return buffer.resource; + } + } + return resource; + } + public toResource(filePath: string): vscode.Uri { const buffer = this.syncedBuffers.getForPath(filePath); if (buffer) { diff --git a/extensions/typescript-language-features/src/typescriptServiceClient.ts b/extensions/typescript-language-features/src/typescriptServiceClient.ts index b4047c58c8a..02757b61b3d 100644 --- a/extensions/typescript-language-features/src/typescriptServiceClient.ts +++ b/extensions/typescript-language-features/src/typescriptServiceClient.ts @@ -91,7 +91,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType private lastStart: number; private numberRestarts: number; private isRestarting: boolean = false; - private loadingIndicator = new ServerInitializingIndicator(); + private readonly loadingIndicator = new ServerInitializingIndicator(); public readonly telemetryReporter: TelemetryReporter; @@ -545,7 +545,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType if (resource.scheme === fileSchemes.walkThroughSnippet || resource.scheme === fileSchemes.untitled) { const dirName = path.dirname(resource.path); const fileName = this.inMemoryResourcePrefix + path.basename(resource.path); - return resource.with({ path: path.posix.join(dirName, fileName) }).toString(true); + return resource.with({ path: path.posix.join(dirName, fileName), query: '' }).toString(true); } if (resource.scheme !== fileSchemes.file) { @@ -585,10 +585,12 @@ export default class TypeScriptServiceClient extends Disposable implements IType const dirName = path.dirname(resource.path); const fileName = path.basename(resource.path); if (fileName.startsWith(this.inMemoryResourcePrefix)) { - resource = resource.with({ path: path.posix.join(dirName, fileName.slice(this.inMemoryResourcePrefix.length)) }); + resource = resource.with({ + path: path.posix.join(dirName, fileName.slice(this.inMemoryResourcePrefix.length)) + }); } } - return resource; + return this.bufferSyncSupport.toVsCodeResource(resource); } return this.bufferSyncSupport.toResource(filepath); @@ -715,7 +717,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType } case 'projectsUpdatedInBackground': const body = (event as Proto.ProjectsUpdatedInBackgroundEvent).body; - const resources = body.openFiles.map(vscode.Uri.file); + const resources = body.openFiles.map(file => this.toResource(file)); this.bufferSyncSupport.getErr(resources); break;