Add await to refresh book method (#14236)

* add await to refresh book method

* change name of method

* Reload tree view

* address pr comments

* adding finally on finally
This commit is contained in:
Barbara Valdez
2021-02-11 21:57:53 -08:00
committed by GitHub
parent b5479d0246
commit 75cda19504

View File

@@ -93,7 +93,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
setFileWatcher(book: BookModel): void {
fs.watchFile(book.tableOfContentsPath, async (curr, prev) => {
if (curr.mtime > prev.mtime) {
this.fireBookRefresh(book);
await this.initializeBookContents(book);
}
});
}
@@ -223,14 +223,18 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
await this.bookTocManager.recovery();
vscode.window.showErrorMessage(loc.editBookError(updateBook.book.contentPath, e instanceof Error ? e.message : e));
} finally {
this.fireBookRefresh(targetBook);
if (sourceBook) {
// refresh source book model to pick up latest changes
this.fireBookRefresh(sourceBook);
}
// even if it fails, we still need to watch the toc file again.
if (sourceBook) {
this.setFileWatcher(sourceBook);
try {
await targetBook.initializeContents();
if (sourceBook && sourceBook.bookPath !== targetBook.bookPath) {
// refresh source book model to pick up latest changes
await sourceBook.initializeContents();
}
} finally {
this._onDidChangeTreeData.fire(undefined);
// even if it fails, we still need to watch the toc file again.
if (sourceBook) {
this.setFileWatcher(sourceBook);
}
}
}
}
@@ -262,7 +266,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
if (curr.mtime > prev.mtime) {
let book = this.books.find(book => book.bookPath === bookPath);
if (book) {
this.fireBookRefresh(book);
await this.initializeBookContents(book);
}
}
});
@@ -293,7 +297,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
}
@debounce(1500)
async fireBookRefresh(book: BookModel): Promise<void> {
async initializeBookContents(book: BookModel): Promise<void> {
await book.initializeContents().then(() => {
this._onDidChangeTreeData.fire(undefined);
});