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

Support switching to/from custom views in reference-view API #152008

Merged
merged 2 commits into from
Aug 19, 2022
Merged
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
6 changes: 5 additions & 1 deletion extensions/references-view/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ export function activate(context: vscode.ExtensionContext): SymbolTree {
tree.setInput(input);
}

return { setInput };
function getInput(): SymbolTreeInput<unknown> | undefined {
return tree.getInput();
}

return { setInput, getInput };
}
17 changes: 13 additions & 4 deletions extensions/references-view/src/references-view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
import * as vscode from 'vscode';

/**
* This interface describes the shape for the references viewlet API. It consists
* of a single `setInput` function which must be called with a full implementation
* of the `SymbolTreeInput`-interface. To acquire this API use the default mechanics, e.g:
* This interface describes the shape for the references viewlet API. It includes
* a single `setInput` function which must be called with a full implementation
* of the `SymbolTreeInput`-interface. You can also use `getInput` function to
* get the current `SymbolTreeInput`. To acquire this API use the default mechanics, e.g:
*
* ```ts
* // get references viewlet API
* const api = await vscode.extensions.getExtension<SymbolTree>('vscode.references-view').activate();
*
* // instantiate and set input which updates the view
* const myInput: SymbolTreeInput<MyItems> = ...
* api.setInput(myInput)
* api.setInput(myInput);
* const currentInput = api.getInput();
* ```
*/
export interface SymbolTree {
Expand All @@ -27,6 +29,13 @@ export interface SymbolTree {
* @param input A symbol tree input object
*/
setInput(input: SymbolTreeInput<unknown>): void;

/**
* Get the contents of the references viewlet.
*
* @returns The current symbol tree input object
*/
getInput(): SymbolTreeInput<unknown> | undefined;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions extensions/references-view/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
}
}

function setTypeHierarchyDirection(value: TypeHierarchyDirection, anchor: TypeItem | unknown) {
function setTypeHierarchyDirection(value: TypeHierarchyDirection, anchor: TypeItem | vscode.Location | unknown) {
direction.value = value;

let newInput: TypesTreeInput | undefined;
const oldInput = tree.getInput();
if (anchor instanceof TypeItem) {
newInput = new TypesTreeInput(new vscode.Location(anchor.item.uri, anchor.item.selectionRange.start), direction.value);
} else if (anchor instanceof vscode.Location) {
newInput = new TypesTreeInput(anchor, direction.value);
} else if (oldInput instanceof TypesTreeInput) {
newInput = new TypesTreeInput(oldInput.location, direction.value);
}
Expand All @@ -36,8 +38,8 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v

context.subscriptions.push(
vscode.commands.registerCommand('references-view.showTypeHierarchy', showTypeHierarchy),
vscode.commands.registerCommand('references-view.showSupertypes', (item: TypeItem | unknown) => setTypeHierarchyDirection(TypeHierarchyDirection.Supertypes, item)),
vscode.commands.registerCommand('references-view.showSubtypes', (item: TypeItem | unknown) => setTypeHierarchyDirection(TypeHierarchyDirection.Subtypes, item)),
vscode.commands.registerCommand('references-view.showSupertypes', (item: TypeItem | vscode.Location | unknown) => setTypeHierarchyDirection(TypeHierarchyDirection.Supertypes, item)),
vscode.commands.registerCommand('references-view.showSubtypes', (item: TypeItem | vscode.Location | unknown) => setTypeHierarchyDirection(TypeHierarchyDirection.Subtypes, item)),
vscode.commands.registerCommand('references-view.removeTypeItem', removeTypeItem)
);
}
Expand Down