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:
Matt Bierner
2019-02-08 18:06:08 -08:00
parent 9ee6077373
commit f1afe72087
3 changed files with 46 additions and 77 deletions

View File

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