mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
Add getDocument helper method
Many places in `extHostLanguageFeatures` were calling `getDocumentData` without checking if the result is undefined. Add an `getDocument` that cannot return undefined values and instead throws an error if there is no document
This commit is contained in:
@@ -67,6 +67,14 @@ export class ExtHostDocuments implements ExtHostDocumentsShape {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public getDocument(resource: vscode.Uri): vscode.TextDocument {
|
||||
const data = this.getDocumentData(resource);
|
||||
if (!data || !data.document) {
|
||||
throw new Error('Unable to retrieve document from URI');
|
||||
}
|
||||
return data.document;
|
||||
}
|
||||
|
||||
public ensureDocumentData(uri: URI): Promise<ExtHostDocumentData> {
|
||||
|
||||
let cached = this._documentsAndEditors.getDocument(uri.toString());
|
||||
|
||||
Reference in New Issue
Block a user