mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-15 02:48:30 -05:00
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:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user