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
This commit is contained in:
Matt Bierner
2019-10-21 18:26:32 -07:00
parent ed53e86205
commit 96a5151f7a
2 changed files with 17 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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;