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.
This commit is contained in:
Andrew Eisenberg
2020-11-03 14:14:45 -08:00
parent b2b1021207
commit 2953c15e5e

View File

@@ -8,6 +8,7 @@ import {
TreeItem,
TreeView,
TextEditorSelectionChangeEvent,
TextEditorSelectionChangeKind,
Location,
Range
} from 'vscode';
@@ -33,7 +34,7 @@ export interface ChildAstItem extends AstItem {
parent: ChildAstItem | AstItem;
}
class AstViewerDataProvider extends DisposableObject implements TreeDataProvider<AstItem> {
class AstViewerDataProvider extends DisposableObject implements TreeDataProvider<AstItem> {
public roots: AstItem[] = [];
public db: DatabaseItem | undefined;
@@ -47,9 +48,9 @@ class AstViewerDataProvider extends DisposableObject implements TreeDataProvide
super();
this.push(
commandRunner('codeQLAstViewer.gotoCode',
async (item: AstItem) => {
await showLocation(item.fileLocation);
})
async (item: AstItem) => {
await showLocation(item.fileLocation);
})
);
}
@@ -160,6 +161,11 @@ export class AstViewer extends DisposableObject {
return;
}
// Avoid recursive tree-source code updates.
if (e.kind === TextEditorSelectionChangeKind.Command) {
return;
}
if (
this.treeView.visible &&
e.textEditor.document.uri.fsPath === this.currentFile &&