@@ -3,7 +3,7 @@ import { env, EventEmitter, ThemeColor, ThemeIcon, TreeItem } from "vscode";
33import { DisposableObject } from "../common/disposable-object" ;
44import { assertNever } from "../common/helpers-pure" ;
55import type { QueryHistoryInfo } from "./query-history-info" ;
6- import { getLanguage } from "./query-history-info" ;
6+ import { getLanguage , getQueryId } from "./query-history-info" ;
77import { QueryStatus } from "./query-status" ;
88import type { HistoryItemLabelProvider } from "./history-item-label-provider" ;
99import type { LanguageContextStore } from "../language-context-store" ;
@@ -17,6 +17,25 @@ export enum SortOrder {
1717 CountDesc = "CountDesc" ,
1818}
1919
20+ /**
21+ * Computes a stable, unique id for a query history item, suitable for use as a
22+ * `TreeItem.id`. `getQueryId` alone is not unique because a multi-query run
23+ * produces several local-query items that share the same `initialInfo.id`; for
24+ * those we also include the (per-result) output base name.
25+ */
26+ function getTreeItemId ( element : QueryHistoryInfo ) : string {
27+ switch ( element . t ) {
28+ case "local" :
29+ return `local:${ element . initialInfo . id } :${
30+ element . completedQuery ?. query . outputBaseName ?? ""
31+ } `;
32+ case "variant-analysis" :
33+ return `variant-analysis:${ getQueryId ( element ) } ` ;
34+ default :
35+ assertNever ( element ) ;
36+ }
37+ }
38+
2039/**
2140 * Tree data provider for the query history view.
2241 */
@@ -54,6 +73,22 @@ export class HistoryTreeDataProvider
5473 async getTreeItem ( element : QueryHistoryInfo ) : Promise < TreeItem > {
5574 const treeItem = new TreeItem ( this . labelProvider . getLabel ( element ) ) ;
5675
76+ // Give the tree item a stable, unique id. Without this, VS Code identifies
77+ // tree nodes by their label plus their position in the list. When multiple
78+ // history items share the same label, that positional identity is ambiguous
79+ // and makes `treeView.reveal` resolve to the wrong item (or fail outright)
80+ // when the list is re-sorted or refreshed. The default label format includes
81+ // the start time, so labels are effectively unique in practice and users are
82+ // unlikely to hit this; it mainly affects tests (and any user who customises
83+ // the label format to something non-unique).
84+ //
85+ // `getQueryId` is not guaranteed to be unique: a multi-query run produces
86+ // several local-query items that share the same `initialInfo.id`. Those
87+ // items differ by their output base name, so we include it to keep the id
88+ // unique (VS Code de-duplicates nodes that share an id, which would break
89+ // reveal/selection for all but one of them).
90+ treeItem . id = getTreeItemId ( element ) ;
91+
5792 treeItem . command = {
5893 title : "Query History Item" ,
5994 command : "codeQLQueryHistory.itemClicked" ,
0 commit comments