提交 c80fb1b7 编写于 作者: M Matt Bierner

Be more resilient when checking if we have an opened jts/ts buffer

Fixes #83338

`TextDocument` lifetime may not match that of the the user facing editors. However the JS/TS extension was assuming that it did. Introduce a `ensureHasBuffer` function that can open a buffer if vscode knows about a textdocument but no `onDidOpenTextDocument` has been fired for it yet
上级 b06513f6
......@@ -361,6 +361,19 @@ export default class BufferSyncSupport extends Disposable {
return this.syncedBuffers.has(resource);
}
public ensureHasBuffer(resource: vscode.Uri): boolean {
if (this.syncedBuffers.has(resource)) {
return true;
}
const existingDocument = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === resource.toString());
if (existingDocument) {
return this.openTextDocument(existingDocument);
}
return false;
}
public toVsCodeResource(resource: vscode.Uri): vscode.Uri {
const filepath = this.client.normalizedPath(resource);
for (const buffer of this.syncedBuffers.allBuffers) {
......@@ -385,24 +398,25 @@ export default class BufferSyncSupport extends Disposable {
}
}
public openTextDocument(document: vscode.TextDocument): void {
public openTextDocument(document: vscode.TextDocument): boolean {
if (!this.modeIds.has(document.languageId)) {
return;
return false;
}
const resource = document.uri;
const filepath = this.client.normalizedPath(resource);
if (!filepath) {
return;
return false;
}
if (this.syncedBuffers.has(resource)) {
return;
return true;
}
const syncedBuffer = new SyncedBuffer(document, filepath, this.client, this.synchronizer);
this.syncedBuffers.set(resource, syncedBuffer);
syncedBuffer.open();
this.requestDiagnostic(syncedBuffer);
return true;
}
public closeResource(resource: vscode.Uri): void {
......
......@@ -560,7 +560,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}
public toOpenedFilePath(document: vscode.TextDocument): string | undefined {
if (!this.bufferSyncSupport.handles(document.uri)) {
if (!this.bufferSyncSupport.ensureHasBuffer(document.uri)) {
console.error(`Unexpected resource ${document.uri}`);
return undefined;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册