Skip to content

Commit 3a07fa9

Browse files
committed
Show initially open file in queries panel
1 parent b6f7755 commit 3a07fa9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

extensions/ql-vscode/src/queries-panel/queries-panel.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ export class QueriesPanel extends DisposableObject {
6060

6161
void this.revealTextEditor(changedTextEditor);
6262
});
63+
64+
// If there is an active text editor when activating the extension, we want to show it in the tree view.
65+
if (window.activeTextEditor) {
66+
// We need to wait for the data provider to load its data. Without this, we will end up in a situation
67+
// where we're trying to show an item that does not exist yet since the query discoverer has not yet
68+
// finished running.
69+
const initialEventDisposable = this.dataProvider.onDidChangeTreeData(
70+
() => {
71+
if (window.activeTextEditor && this.treeView.visible) {
72+
void this.revealTextEditor(window.activeTextEditor);
73+
}
74+
75+
// We only want to listen to this event once, so dispose of the listener to unsubscribe.
76+
initialEventDisposable.dispose();
77+
},
78+
);
79+
}
6380
}
6481

6582
private revealTextEditor(textEditor: TextEditor): void {

0 commit comments

Comments
 (0)