Skip to content

Commit 2953c15

Browse files
committed
Avoid recursive selection changes in ast viewer
This will prevent selections jumping around when an ast entry is selected and its child has the same source location as the current selection.
1 parent b2b1021 commit 2953c15

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

extensions/ql-vscode/src/astViewer.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
TreeItem,
99
TreeView,
1010
TextEditorSelectionChangeEvent,
11+
TextEditorSelectionChangeKind,
1112
Location,
1213
Range
1314
} from 'vscode';
@@ -33,7 +34,7 @@ export interface ChildAstItem extends AstItem {
3334
parent: ChildAstItem | AstItem;
3435
}
3536

36-
class AstViewerDataProvider extends DisposableObject implements TreeDataProvider<AstItem> {
37+
class AstViewerDataProvider extends DisposableObject implements TreeDataProvider<AstItem> {
3738

3839
public roots: AstItem[] = [];
3940
public db: DatabaseItem | undefined;
@@ -47,9 +48,9 @@ class AstViewerDataProvider extends DisposableObject implements TreeDataProvide
4748
super();
4849
this.push(
4950
commandRunner('codeQLAstViewer.gotoCode',
50-
async (item: AstItem) => {
51-
await showLocation(item.fileLocation);
52-
})
51+
async (item: AstItem) => {
52+
await showLocation(item.fileLocation);
53+
})
5354
);
5455
}
5556

@@ -160,6 +161,11 @@ export class AstViewer extends DisposableObject {
160161
return;
161162
}
162163

164+
// Avoid recursive tree-source code updates.
165+
if (e.kind === TextEditorSelectionChangeKind.Command) {
166+
return;
167+
}
168+
163169
if (
164170
this.treeView.visible &&
165171
e.textEditor.document.uri.fsPath === this.currentFile &&

0 commit comments

Comments
 (0)