Skip to content

Commit abd25b4

Browse files
committed
safeguard doc highlight
1 parent e0de2f0 commit abd25b4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/vs/workbench/api/common/extHostLanguageFeatures.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,21 @@ class MultiDocumentHighlightAdapter {
373373

374374
constructor(
375375
private readonly _documents: ExtHostDocuments,
376-
private readonly _provider: vscode.MultiDocumentHighlightProvider
376+
private readonly _provider: vscode.MultiDocumentHighlightProvider,
377+
private readonly _logService: ILogService,
377378
) { }
378379

379380
async provideMultiDocumentHighlights(resource: URI, position: IPosition, otherResources: URI[], token: CancellationToken): Promise<languages.MultiDocumentHighlight[] | undefined> {
380-
381381
const doc = this._documents.getDocument(resource);
382-
const otherDocuments = otherResources.map(r => this._documents.getDocument(r));
382+
const otherDocuments = otherResources.map(r => {
383+
try {
384+
return this._documents.getDocument(r);
385+
} catch (err) {
386+
this._logService.error('Error: Unable to retrieve document from URI: ' + r + '. Error message: ' + err);
387+
return undefined;
388+
}
389+
}).filter(doc => doc !== undefined);
390+
383391
const pos = typeConvert.Position.to(position);
384392

385393
const value = await this._provider.provideMultiDocumentHighlights(doc, pos, otherDocuments, token);
@@ -2436,7 +2444,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
24362444
}
24372445

24382446
registerMultiDocumentHighlightProvider(extension: IExtensionDescription, selector: vscode.DocumentSelector, provider: vscode.MultiDocumentHighlightProvider): vscode.Disposable {
2439-
const handle = this._addNewAdapter(new MultiDocumentHighlightAdapter(this._documents, provider), extension);
2447+
const handle = this._addNewAdapter(new MultiDocumentHighlightAdapter(this._documents, provider, this._logService), extension);
24402448
this._proxy.$registerMultiDocumentHighlightProvider(handle, this._transformDocumentSelector(selector, extension));
24412449
return this._createDisposable(handle);
24422450
}

0 commit comments

Comments
 (0)