Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

references-view: removeReferenceItem hotkey implementation #237486

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/references-view/src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class Navigation {
);
}

getSelection(): readonly unknown[] {
return this._view.selection;
}

dispose(): void {
vscode.Disposable.from(...this._disposables).dispose();
}
Expand Down
11 changes: 9 additions & 2 deletions extensions/references-view/src/references/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
vscode.commands.registerCommand('references-view.findImplementations', () => findLocations('Implementations', 'vscode.executeImplementationProvider')),
// --- legacy name
vscode.commands.registerCommand('references-view.find', (...args: any[]) => vscode.commands.executeCommand('references-view.findReferences', ...args)),
vscode.commands.registerCommand('references-view.removeReferenceItem', removeReferenceItem),
vscode.commands.registerCommand('references-view.removeReferenceItem', (arg) => removeReferenceItem(tree, arg)),
vscode.commands.registerCommand('references-view.copy', copyCommand),
vscode.commands.registerCommand('references-view.copyAll', copyAllCommand),
vscode.commands.registerCommand('references-view.copyPath', copyPathCommand),
Expand Down Expand Up @@ -61,11 +61,18 @@ const copyAllCommand = async (item: ReferenceItem | FileItem | unknown) => {
}
};

function removeReferenceItem(item: FileItem | ReferenceItem | unknown) {
function removeReferenceItem(tree: SymbolsTree, item: FileItem | ReferenceItem | unknown) {
if (item instanceof FileItem) {
item.remove();
} else if (item instanceof ReferenceItem) {
item.remove();
} else if (item === undefined) {
// if item undefined, assume called from hotkey with no context, so call remove on selected items
for (const ni of tree.getSelection()) {
if (ni instanceof FileItem || ni instanceof ReferenceItem) {
ni.remove();
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions extensions/references-view/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class SymbolsTree {
getInput(): SymbolTreeInput<unknown> | undefined {
return this._input;
}
getSelection(): readonly unknown[] {
return this._navigation.getSelection();
}

async setInput(input: SymbolTreeInput<unknown>) {

Expand Down