Skip to content

Commit 31b80ef

Browse files
authored
Use constant for selected db item resource uri (#1908)
1 parent 3234f0a commit 31b80ef

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

extensions/ql-vscode/src/databases/ui/db-selection-decoration-provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
ProviderResult,
66
Uri,
77
} from "vscode";
8+
import { SELECTED_DB_ITEM_RESOURCE_URI } from "./db-tree-view-item";
89

910
export class DbSelectionDecorationProvider implements FileDecorationProvider {
1011
provideFileDecoration(
1112
uri: Uri,
1213
_token: CancellationToken,
1314
): ProviderResult<FileDecoration> {
14-
if (uri?.query === "selected=true") {
15+
if (uri.toString(true) === SELECTED_DB_ITEM_RESOURCE_URI) {
1516
return {
1617
badge: "✓",
1718
tooltip: "Currently selected",

extensions/ql-vscode/src/databases/ui/db-tree-view-item.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
RootRemoteDbItem,
1313
} from "../db-item";
1414

15+
export const SELECTED_DB_ITEM_RESOURCE_URI = "codeql://databases?selected=true";
16+
1517
/**
1618
* Represents an item in the database tree view. This item could be
1719
* representing an actual database item or a warning.
@@ -33,7 +35,7 @@ export class DbTreeViewItem extends vscode.TreeItem {
3335
if (dbItem && isSelectableDbItem(dbItem)) {
3436
if (dbItem.selected) {
3537
// Define the resource id to drive the UI to render this item as selected.
36-
this.resourceUri = vscode.Uri.parse("codeql://databases?selected=true");
38+
this.resourceUri = vscode.Uri.parse(SELECTED_DB_ITEM_RESOURCE_URI);
3739
} else {
3840
// Define a context value to drive the UI to show an action to select the item.
3941
this.contextValue = "selectableDbItem";

extensions/ql-vscode/src/vscode-tests/minimal-workspace/databases/db-panel.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
DbListKind,
1414
LocalDatabaseDbItem,
1515
} from "../../../databases/db-item";
16-
import { DbTreeViewItem } from "../../../databases/ui/db-tree-view-item";
16+
import {
17+
DbTreeViewItem,
18+
SELECTED_DB_ITEM_RESOURCE_URI,
19+
} from "../../../databases/ui/db-tree-view-item";
1720
import { ExtensionApp } from "../../../common/vscode/vscode-app";
1821
import { createMockExtensionContext } from "../../factories/extension-context";
1922
import { createDbConfig } from "../../factories/db-config-factories";
@@ -831,8 +834,8 @@ describe("db panel", () => {
831834

832835
function isTreeViewItemSelected(treeViewItem: DbTreeViewItem) {
833836
return (
834-
treeViewItem.resourceUri?.query === "selected=true" &&
835-
treeViewItem.contextValue === undefined
837+
treeViewItem.resourceUri?.toString(true) ===
838+
SELECTED_DB_ITEM_RESOURCE_URI && treeViewItem.contextValue === undefined
836839
);
837840
}
838841
});

0 commit comments

Comments
 (0)