Skip to content

Commit 67a0be8

Browse files
committed
Add followCursor setting for Imports/Exports views (resolve #1788)
1 parent 98aa962 commit 67a0be8

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/vscode-knip/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@
287287
"type": "boolean",
288288
"default": true,
289289
"description": "Enable imports view"
290+
},
291+
"knip.imports.followCursor": {
292+
"type": "boolean",
293+
"default": true,
294+
"description": "Reveal and select the import matching the editor cursor position. Disable to keep the view in sync without it taking focus, e.g. when moved out of the Explorer."
290295
}
291296
}
292297
},
@@ -302,6 +307,11 @@
302307
"default": true,
303308
"description": "Enable exports view"
304309
},
310+
"knip.exports.followCursor": {
311+
"type": "boolean",
312+
"default": true,
313+
"description": "Reveal and select the export matching the editor cursor position. Disable to keep the view in sync without it taking focus, e.g. when moved out of the Explorer."
314+
},
305315
"knip.exports.contention.enabled": {
306316
"type": "boolean",
307317
"default": true,

packages/vscode-knip/src/tree-view-base.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const isGlobLike = specifier => specifier.includes('*');
2525

2626
/** @implements {vscode.TreeDataProvider<TreeViewItem>} */
2727
export class BaseTreeViewProvider {
28-
constructor() {
28+
/** @param {string} configSection */
29+
constructor(configSection) {
30+
this.configSection = configSection;
2931
this._onDidChangeTreeData = new vscode.EventEmitter();
3032
this.onDidChangeTreeData = this._onDidChangeTreeData.event;
3133
this.currentUri = undefined;
@@ -129,6 +131,7 @@ export class BaseTreeViewProvider {
129131
/** @param {vscode.Position} position */
130132
async revealItemAtCursor(position) {
131133
if (!this.file || !this.treeView) return;
134+
if (!vscode.workspace.getConfiguration('knip').get(`${this.configSection}.followCursor`, true)) return;
132135

133136
try {
134137
const items = this._rootItems ?? [];

packages/vscode-knip/src/tree-view-exports.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const CONTENTION_TOOLTIPS = {
1616
* @extends {BaseTreeViewProvider}
1717
*/
1818
export class ExportsTreeViewProvider extends BaseTreeViewProvider {
19+
constructor() {
20+
super('exports');
21+
}
22+
1923
/** @param {import('knip/session').File} fileNode */
2024
getFileItems(fileNode) {
2125
const isDeferChildren = fileNode.exports.length > 9;

packages/vscode-knip/src/tree-view-imports.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { BaseTreeViewProvider, toTree } from './tree-view-base.js';
66
* @extends {BaseTreeViewProvider}
77
*/
88
export class ImportsTreeViewProvider extends BaseTreeViewProvider {
9+
constructor() {
10+
super('imports');
11+
}
12+
913
/** @param {import('knip/session').File} fileNode */
1014
getFileItems(fileNode) {
1115
if (fileNode.internalImports.length === 0) return [this.createMessageItem('(none)')];

0 commit comments

Comments
 (0)