Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extensions/ql-vscode/src/databases/ui/db-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ export class DbPanel extends DisposableObject {
"Not a selectable database item. Please select a valid item.",
);
}

// Optimistically update the UI to select the item that the user
// selected to avoid delay in the UI.
this.dataProvider.updateSelectedItem(treeViewItem);

await this.dbManager.setSelectedDbItem(treeViewItem.dbItem);
}

Expand Down
17 changes: 17 additions & 0 deletions extensions/ql-vscode/src/databases/ui/db-tree-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ export class DbTreeDataProvider
});
}

/**
* Updates the selected item and re-renders the tree.
* @param selectedItem The item to select.
*/
public updateSelectedItem(selectedItem: DbTreeViewItem): void {
// Unselect all items
for (const item of this.dbTreeItems) {
item.setAsUnselected();
}

// Select the new item
selectedItem.setAsSelected();

// Re-render the tree
this._onDidChangeTreeData.fire(undefined);
}

/**
* Called when expanding a node (including the root node).
* @param node The node to expand.
Expand Down
12 changes: 10 additions & 2 deletions extensions/ql-vscode/src/databases/ui/db-tree-view-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ export class DbTreeViewItem extends vscode.TreeItem {
if (dbItem) {
this.contextValue = getContextValue(dbItem);
if (isSelectableDbItem(dbItem) && dbItem.selected) {
// Define the resource id to drive the UI to render this item as selected.
this.resourceUri = vscode.Uri.parse(SELECTED_DB_ITEM_RESOURCE_URI);
this.setAsSelected();
}
}
}

public setAsSelected(): void {
// Define the resource id to drive the UI to render this item as selected.
this.resourceUri = vscode.Uri.parse(SELECTED_DB_ITEM_RESOURCE_URI);
}

public setAsUnselected(): void {
this.resourceUri = undefined;
}
}

function getContextValue(dbItem: DbItem): string | undefined {
Expand Down