Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit bd681e5

Browse files
committed
show editor highlights
1 parent 373d723 commit bd681e5

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/calls/editorHighlights.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { Call } from './model';
8+
import { TreeObject } from './provider';
9+
10+
export class EditorHighlights {
11+
12+
private readonly _decorationType = vscode.window.createTextEditorDecorationType({
13+
backgroundColor: new vscode.ThemeColor('editor.findMatchHighlightBackground'),
14+
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
15+
overviewRulerLane: vscode.OverviewRulerLane.Center,
16+
overviewRulerColor: new vscode.ThemeColor('editor.findMatchHighlightBackground'),
17+
});
18+
19+
constructor(readonly view: vscode.TreeView<TreeObject>) { }
20+
21+
show() {
22+
const { activeTextEditor: editor } = vscode.window;
23+
if (!editor) {
24+
return;
25+
}
26+
const [sel] = this.view.selection;
27+
if (!(sel instanceof Call)) {
28+
return
29+
}
30+
const call = sel;
31+
32+
if (call.locations) {
33+
const ranges: vscode.Range[] = [];
34+
for (const loc of call.locations) {
35+
if (loc.uri.toString() === editor.document.uri.toString()) {
36+
ranges.push(loc.range);
37+
}
38+
}
39+
editor.setDecorations(this._decorationType, ranges);
40+
}
41+
}
42+
43+
hide() {
44+
const { activeTextEditor: editor } = vscode.window;
45+
if (editor) {
46+
editor.setDecorations(this._decorationType, []);
47+
}
48+
}
49+
50+
refresh() {
51+
this.hide();
52+
this.show();
53+
}
54+
}

src/calls/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ import * as vscode from 'vscode';
77
import { CallsDirection, CallsModel, Call } from './model';
88
import { DataProvider } from './provider';
99
import { History, HistoryItem } from './history';
10+
import { EditorHighlights } from './editorHighlights';
1011

1112
export function register(disposables: vscode.Disposable[]) {
1213

1314
const viewId = 'calls-view.tree';
1415
const history = new History();
1516
const provider = new DataProvider(history);
16-
1717
const view = vscode.window.createTreeView(viewId, { treeDataProvider: provider });
1818

19+
// highlight management
20+
const highlights = new EditorHighlights(view);
21+
vscode.window.onDidChangeActiveTextEditor(() => view.visible && highlights.refresh(), undefined, disposables);
22+
view.onDidChangeVisibility(e => e.visible ? highlights.show() : highlights.hide(), undefined, disposables);
23+
view.onDidChangeSelection(() => highlights.refresh(), undefined, disposables);
24+
1925
let callsDirection = CallsDirection.Outgoing;
2026
vscode.commands.executeCommand('setContext', 'calls-view.mode', 'showOutgoing');
2127

@@ -72,6 +78,7 @@ export function register(disposables: vscode.Disposable[]) {
7278

7379
const clearCommand = () => {
7480
updateModel(undefined);
81+
highlights.hide();
7582
if (history.items.length === 0) {
7683
view.message = `To populate this view, open an editor and run the 'Show Call Hierarchy'-command.`;
7784
} else {

src/calls/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const enum CallsDirection {
1212

1313
export class Call {
1414

15-
constructor(readonly item: vscode.CallHierarchyItem, readonly parent: Call | undefined, readonly location: vscode.Location[] | undefined) { }
15+
constructor(readonly item: vscode.CallHierarchyItem, readonly parent: Call | undefined, readonly locations: vscode.Location[] | undefined) { }
1616
}
1717

1818
export class CallsModel {

0 commit comments

Comments
 (0)