From b7e9962585446d4160ad090b2f674e9f0ac705e9 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Tue, 3 Nov 2020 14:14:45 -0800 Subject: [PATCH] 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. --- extensions/ql-vscode/src/astViewer.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extensions/ql-vscode/src/astViewer.ts b/extensions/ql-vscode/src/astViewer.ts index acd7e9915e4..662d4b603a5 100644 --- a/extensions/ql-vscode/src/astViewer.ts +++ b/extensions/ql-vscode/src/astViewer.ts @@ -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 { +class AstViewerDataProvider extends DisposableObject implements TreeDataProvider { 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 &&