Check if globalState has the persisted editors before attempting to load
This commit is contained in:
Prashanth 2018-03-23 17:05:56 -07:00 коммит произвёл GitHub
Родитель f32c50ce0a
Коммит 095352f0c8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 19 добавлений и 15 удалений

Просмотреть файл

@ -88,24 +88,28 @@ export class CosmosEditorManager {
private async loadPersistedEditor(documentUri: vscode.Uri, tree: AzureTreeDataProvider): Promise<string> {
const persistedEditors = this._globalState.get(this._persistedEditorsKey);
//Based on the documentUri, split just the appropriate key's value on '/'
const editorFilePath = Object.keys(persistedEditors).find((label) => path.relative(documentUri.fsPath, label) === '');
if (editorFilePath) {
const editorNode: IAzureNode | undefined = await tree.findNode(persistedEditors[editorFilePath]);
let editor: ICosmosEditor;
if (editorNode) {
if (editorNode.treeItem instanceof MongoCollectionTreeItem) {
editor = new MongoCollectionNodeEditor(<IAzureParentNode<MongoCollectionTreeItem>>editorNode);
} else if (editorNode.treeItem instanceof DocDBDocumentTreeItem) {
editor = new DocDBDocumentNodeEditor(<IAzureNode<DocDBDocumentTreeItem>>editorNode);
} else if (editorNode.treeItem instanceof MongoDocumentTreeItem) {
editor = new MongoDocumentNodeEditor(<IAzureNode<MongoDocumentTreeItem>>editorNode);
if (persistedEditors) {
const editorFilePath = Object.keys(persistedEditors).find((label) => path.relative(documentUri.fsPath, label) === '');
if (editorFilePath) {
const editorNode: IAzureNode | undefined = await tree.findNode(persistedEditors[editorFilePath]);
let editor: ICosmosEditor;
if (editorNode) {
if (editorNode.treeItem instanceof MongoCollectionTreeItem) {
editor = new MongoCollectionNodeEditor(<IAzureParentNode<MongoCollectionTreeItem>>editorNode);
} else if (editorNode.treeItem instanceof DocDBDocumentTreeItem) {
editor = new DocDBDocumentNodeEditor(<IAzureNode<DocDBDocumentTreeItem>>editorNode);
} else if (editorNode.treeItem instanceof MongoDocumentTreeItem) {
editor = new MongoDocumentNodeEditor(<IAzureNode<MongoDocumentTreeItem>>editorNode);
}
this.fileMap[editorFilePath] = editor;
} else {
throw new Error("Failed to find entity on the tree. Please check the explorer to confirm that the entity exists, and that permissions are intact.");
}
this.fileMap[editorFilePath] = editor;
} else {
throw new Error("Failed to find entity on the tree. Please check the explorer to confirm that the entity exists, and that permissions are intact.");
}
return editorFilePath;
} else {
return undefined;
}
return editorFilePath;
}
public async onDidSaveTextDocument(context: IActionContext, globalState: vscode.Memento, doc: vscode.TextDocument, tree: AzureTreeDataProvider): Promise<void> {