Fix async problem with jupyter book viewlet loading (#7591)

* Fix async problem with jupyter book viewlet

* PR Feedback
This commit is contained in:
Chris LaFreniere
2019-10-09 16:06:32 -07:00
committed by GitHub
parent 22774f28c0
commit 5a1183a457
2 changed files with 18 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ import { BookTreeItem } from './bookTreeItem';
import * as nls from 'vscode-nls';
import { isEditorTitleFree } from '../common/utils';
import { BookModel } from './bookModel';
import { Deferred } from '../common/promise';
const localize = nls.loadMessageBundle();
@@ -24,6 +25,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
private _resource: string;
private _extensionContext: vscode.ExtensionContext;
private prompter: IPrompter;
private _initializeDeferred: Deferred<void> = new Deferred<void>();
// For testing
private _errorMessage: string;
@@ -38,14 +40,14 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
this._extensionContext = extensionContext;
this.books = [];
this.initialize(workspaceFolders.map(a => a.uri.fsPath));
vscode.commands.executeCommand('setContext', 'untitledBooks', openAsUntitled);
this.viewId = view;
this.prompter = new CodeAdapter();
}
private async initialize(bookPaths: string[]): Promise<any> {
return Promise.all(bookPaths.map(async (bookPath) => {
private async initialize(bookPaths: string[]): Promise<void> {
await vscode.commands.executeCommand('setContext', 'untitledBooks', this._openAsUntitled);
await Promise.all(bookPaths.map(async (bookPath) => {
let book: BookModel = new BookModel(bookPath, this._openAsUntitled, this._extensionContext);
await book.initializeContents();
this.books.push(book);
@@ -53,13 +55,16 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
this.currentBook = book;
}
}));
this._initializeDeferred.resolve();
}
public get onReadAllTOCFiles(): vscode.Event<void> {
return this._onReadAllTOCFiles.event;
}
public get initialized(): Promise<void> {
return this._initializeDeferred.promise;
}
async openBook(bookPath: string, urlToOpen?: string): Promise<void> {
try {