Skip to content

Commit a3f5d24

Browse files
authored
Merge pull request microsoft#152008 from CsCherrYY/cs-reference-view-api
Support switching to/from custom views in reference-view API
2 parents 53e89be + 11b6d00 commit a3f5d24

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

extensions/references-view/src/extension.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ export function activate(context: vscode.ExtensionContext): SymbolTree {
2222
tree.setInput(input);
2323
}
2424

25-
return { setInput };
25+
function getInput(): SymbolTreeInput<unknown> | undefined {
26+
return tree.getInput();
27+
}
28+
29+
return { setInput, getInput };
2630
}

extensions/references-view/src/references-view.d.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
import * as vscode from 'vscode';
77

88
/**
9-
* This interface describes the shape for the references viewlet API. It consists
10-
* of a single `setInput` function which must be called with a full implementation
11-
* of the `SymbolTreeInput`-interface. To acquire this API use the default mechanics, e.g:
9+
* This interface describes the shape for the references viewlet API. It includes
10+
* a single `setInput` function which must be called with a full implementation
11+
* of the `SymbolTreeInput`-interface. You can also use `getInput` function to
12+
* get the current `SymbolTreeInput`. To acquire this API use the default mechanics, e.g:
1213
*
1314
* ```ts
1415
* // get references viewlet API
1516
* const api = await vscode.extensions.getExtension<SymbolTree>('vscode.references-view').activate();
1617
*
1718
* // instantiate and set input which updates the view
1819
* const myInput: SymbolTreeInput<MyItems> = ...
19-
* api.setInput(myInput)
20+
* api.setInput(myInput);
21+
* const currentInput = api.getInput();
2022
* ```
2123
*/
2224
export interface SymbolTree {
@@ -27,6 +29,13 @@ export interface SymbolTree {
2729
* @param input A symbol tree input object
2830
*/
2931
setInput(input: SymbolTreeInput<unknown>): void;
32+
33+
/**
34+
* Get the contents of the references viewlet.
35+
*
36+
* @returns The current symbol tree input object
37+
*/
38+
getInput(): SymbolTreeInput<unknown> | undefined;
3039
}
3140

3241
/**

extensions/references-view/src/types/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
1919
}
2020
}
2121

22-
function setTypeHierarchyDirection(value: TypeHierarchyDirection, anchor: TypeItem | unknown) {
22+
function setTypeHierarchyDirection(value: TypeHierarchyDirection, anchor: TypeItem | vscode.Location | unknown) {
2323
direction.value = value;
2424

2525
let newInput: TypesTreeInput | undefined;
2626
const oldInput = tree.getInput();
2727
if (anchor instanceof TypeItem) {
2828
newInput = new TypesTreeInput(new vscode.Location(anchor.item.uri, anchor.item.selectionRange.start), direction.value);
29+
} else if (anchor instanceof vscode.Location) {
30+
newInput = new TypesTreeInput(anchor, direction.value);
2931
} else if (oldInput instanceof TypesTreeInput) {
3032
newInput = new TypesTreeInput(oldInput.location, direction.value);
3133
}
@@ -36,8 +38,8 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
3638

3739
context.subscriptions.push(
3840
vscode.commands.registerCommand('references-view.showTypeHierarchy', showTypeHierarchy),
39-
vscode.commands.registerCommand('references-view.showSupertypes', (item: TypeItem | unknown) => setTypeHierarchyDirection(TypeHierarchyDirection.Supertypes, item)),
40-
vscode.commands.registerCommand('references-view.showSubtypes', (item: TypeItem | unknown) => setTypeHierarchyDirection(TypeHierarchyDirection.Subtypes, item)),
41+
vscode.commands.registerCommand('references-view.showSupertypes', (item: TypeItem | vscode.Location | unknown) => setTypeHierarchyDirection(TypeHierarchyDirection.Supertypes, item)),
42+
vscode.commands.registerCommand('references-view.showSubtypes', (item: TypeItem | vscode.Location | unknown) => setTypeHierarchyDirection(TypeHierarchyDirection.Subtypes, item)),
4143
vscode.commands.registerCommand('references-view.removeTypeItem', removeTypeItem)
4244
);
4345
}

0 commit comments

Comments
 (0)