mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
support more external use in API
Signed-off-by: Shi Chen <chenshi@microsoft.com>
This commit is contained in:
parent
33b1980f6f
commit
90e6cb4a40
|
@ -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 };
|
||||
}
|
||||
|
|
|
@ -6,32 +6,41 @@
|
|||
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>('ms-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 {
|
||||
|
||||
/**
|
||||
* Set the contents of the references viewlet.
|
||||
*
|
||||
* Set the contents of the references viewlet.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* A symbol tree input is the entry point for populating the references viewlet.
|
||||
* Inputs must be anchored at a code location, they must have a title, and they
|
||||
* Inputs must be anchored at a code location, they must have a title, and they
|
||||
* must resolve to a model.
|
||||
*/
|
||||
export interface SymbolTreeInput<T> {
|
||||
|
@ -54,17 +63,17 @@ export interface SymbolTreeInput<T> {
|
|||
readonly location: vscode.Location;
|
||||
|
||||
/**
|
||||
* Resolve this input to a model that contains the actual data. When there are no result
|
||||
* Resolve this input to a model that contains the actual data. When there are no result
|
||||
* than `undefined` or `null` should be returned.
|
||||
*/
|
||||
resolve(): vscode.ProviderResult<SymbolTreeModel<T>>;
|
||||
|
||||
/**
|
||||
* This function is called when re-running from history. The symbols tree has tracked
|
||||
* the original location of this input and that is now passed to this input. The
|
||||
* the original location of this input and that is now passed to this input. The
|
||||
* implementation of this function should return a clone where the `location`-property
|
||||
* uses the provided `location`
|
||||
*
|
||||
*
|
||||
* @param location The location at which the new input should be anchored.
|
||||
* @returns A new input which location is anchored at the position.
|
||||
*/
|
||||
|
@ -94,7 +103,7 @@ export interface SymbolTreeModel<T> {
|
|||
navigation?: SymbolItemNavigation<T>;
|
||||
|
||||
/**
|
||||
* Optional support for editor highlights. WHen implemented, the editor will highlight
|
||||
* Optional support for editor highlights. WHen implemented, the editor will highlight
|
||||
* symbol ranges in the source code.
|
||||
*/
|
||||
highlights?: SymbolItemEditorHighlights<T>;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue