Skip to content

Commit 90e6cb4

Browse files
committed
support more external use in API
Signed-off-by: Shi Chen <[email protected]>
1 parent 33b1980 commit 90e6cb4

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
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: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,41 @@
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:
12-
*
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:
13+
*
1314
* ```ts
1415
* // get references viewlet API
1516
* const api = await vscode.extensions.getExtension<SymbolTree>('ms-vscode.references-view').activate();
16-
*
17+
*
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 {
2325

2426
/**
25-
* Set the contents of the references viewlet.
26-
*
27+
* Set the contents of the references viewlet.
28+
*
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
/**
3342
* A symbol tree input is the entry point for populating the references viewlet.
34-
* Inputs must be anchored at a code location, they must have a title, and they
43+
* Inputs must be anchored at a code location, they must have a title, and they
3544
* must resolve to a model.
3645
*/
3746
export interface SymbolTreeInput<T> {
@@ -54,17 +63,17 @@ export interface SymbolTreeInput<T> {
5463
readonly location: vscode.Location;
5564

5665
/**
57-
* Resolve this input to a model that contains the actual data. When there are no result
66+
* Resolve this input to a model that contains the actual data. When there are no result
5867
* than `undefined` or `null` should be returned.
5968
*/
6069
resolve(): vscode.ProviderResult<SymbolTreeModel<T>>;
6170

6271
/**
6372
* This function is called when re-running from history. The symbols tree has tracked
64-
* the original location of this input and that is now passed to this input. The
73+
* the original location of this input and that is now passed to this input. The
6574
* implementation of this function should return a clone where the `location`-property
6675
* uses the provided `location`
67-
*
76+
*
6877
* @param location The location at which the new input should be anchored.
6978
* @returns A new input which location is anchored at the position.
7079
*/
@@ -94,7 +103,7 @@ export interface SymbolTreeModel<T> {
94103
navigation?: SymbolItemNavigation<T>;
95104

96105
/**
97-
* Optional support for editor highlights. WHen implemented, the editor will highlight
106+
* Optional support for editor highlights. WHen implemented, the editor will highlight
98107
* symbol ranges in the source code.
99108
*/
100109
highlights?: SymbolItemEditorHighlights<T>;

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)