提交 de5800af 编写于 作者: J Johannes Rieken

wire up WorkspaceSymbolProvider

上级 e62cfe97
......@@ -1737,6 +1737,16 @@ declare namespace vscode {
*/
location: Location;
/**
* Creates a new symbol information object.
*
* @param name The name of the symbol.
* @param kind The kind of the symbol.
* @param containerName The name of the symbol containing the symbol.
* @param location The the location of the symbol.
*/
constructor(name: string, kind: SymbolKind, containerName: string, location: Location);
/**
* Creates a new symbol information object.
*
......@@ -1774,7 +1784,9 @@ declare namespace vscode {
/**
* Project-wide search for a symbol matching the given query string. It is up to the provider
* how to search given the query string, like substring, indexOf etc.
* how to search given the query string, like substring, indexOf etc. To improve performance implementors can
* skip the [location](#SymbolInformation.location) of symbols and implement `resolveWorkspaceSymbol` to do that
* later.
*
* @param query A non-empty query string.
* @param token A cancellation token.
......@@ -1782,6 +1794,20 @@ declare namespace vscode {
* signaled by returning `undefined`, `null`, or an empty array.
*/
provideWorkspaceSymbols(query: string, token: CancellationToken): SymbolInformation[] | Thenable<SymbolInformation[]>;
/**
* Given a symbol fill in its [location](#SymbolInformation.location). This method is called whenever a symbol
* is selected in the UI. Providers can implement this method and return incomplete symbols from
* [`provideWorkspaceSymbols`](#WorkspaceSymbolProvider.provideWorkspaceSymbols) which often helps to improve
* performance.
*
* @param symbol The symbol that is to be resolved. Guaranteed to be an instance of an object returned from an
* earlier call to `provideWorkspaceSymbols`.
* @param token A cancellation token.
* @return The resolved symbol or a thenable that resolves to that. When no result is returned,
* the given `symbol` is used.
*/
resolveWorkspaceSymbol?: (symbol: SymbolInformation, token: CancellationToken) => SymbolInformation | Thenable<SymbolInformation>;
}
/**
......@@ -3710,9 +3736,9 @@ declare namespace vscode {
/**
* Register a workspace symbol provider.
*
* Multiple providers can be registered for a language. In that case providers are asked in
* parallel and the results are merged. A failing provider (rejected promise or exception) will
* not cause a failure of the whole operation.
* Multiple providers can be registered. In that case providers are asked in parallel and
* the results are merged. A failing provider (rejected promise or exception) will not cause
* a failure of the whole operation.
*
* @param provider A workspace symbol provider.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
......
......@@ -394,24 +394,49 @@ class OnTypeFormattingAdapter {
}
}
interface MyWorkspaceSymbol extends IWorkspaceSymbol {
idx: number;
}
class NavigateTypeAdapter implements IWorkspaceSymbolProvider {
private _provider: vscode.WorkspaceSymbolProvider;
private _cache: vscode.SymbolInformation[];
constructor(provider: vscode.WorkspaceSymbolProvider) {
this._provider = provider;
}
provideWorkspaceSymbols(search: string): TPromise<IWorkspaceSymbol[]> {
this._cache = [];
return asWinJsPromise(token => this._provider.provideWorkspaceSymbols(search, token)).then(value => {
if (Array.isArray(value)) {
return value.map(TypeConverters.fromSymbolInformation);
this._cache = value;
return value.map((item, idx) => {
const result = <MyWorkspaceSymbol>TypeConverters.fromSymbolInformation(item);
result.idx = idx;
return result;
});
}
});
}
resolveWorkspaceSymbol(item: IWorkspaceSymbol): TPromise<IWorkspaceSymbol> {
return TPromise.as(item);
if (typeof this._provider.resolveWorkspaceSymbol !== 'function') {
return;
}
const idx = (<MyWorkspaceSymbol>item).idx;
if(typeof idx !== 'number') {
return;
}
return asWinJsPromise(token => this._provider.resolveWorkspaceSymbol(this._cache[idx], token)).then(value => {
return value && TypeConverters.fromSymbolInformation(value);
});
}
}
......
......@@ -194,18 +194,18 @@ export function fromSymbolInformation(info: vscode.SymbolInformation): IWorkspac
return <IWorkspaceSymbol>{
name: info.name,
type: types.SymbolKind[info.kind || types.SymbolKind.Property].toLowerCase(),
range: fromRange(info.location.range),
resource: info.location.uri,
containerName: info.containerName
containerName: info.containerName,
range: info.location && fromRange(info.location.range),
resource: info.location && info.location.uri,
};
}
export function toSymbolInformation(bearing: IWorkspaceSymbol): types.SymbolInformation {
return new types.SymbolInformation(bearing.name,
types.SymbolKind[bearing.type.charAt(0).toUpperCase() + bearing.type.substr(1)],
toRange(bearing.range),
bearing.resource,
bearing.containerName);
bearing.containerName,
new types.Location(bearing.resource, toRange(bearing.range))
);
}
......
......@@ -628,11 +628,22 @@ export class SymbolInformation {
kind: SymbolKind;
containerName: string;
constructor(name: string, kind: SymbolKind, range: Range, uri?: URI, containerName?: string) {
constructor(name: string, kind: SymbolKind, containerName: string, location: Location);
constructor(name: string, kind: SymbolKind, range: Range, uri?: URI, containerName?: string);
constructor(name: string, kind: SymbolKind, rangeOrContainer: string | Range, locationOrUri?: Location | URI, containerName?: string) {
this.name = name;
this.kind = kind;
this.location = new Location(uri, range);
this.containerName = containerName;
if (typeof rangeOrContainer === 'string') {
this.containerName = rangeOrContainer;
}
if (locationOrUri instanceof Location) {
this.location = locationOrUri;
} else if(locationOrUri instanceof URI && rangeOrContainer instanceof Range) {
this.location = new Location(locationOrUri, rangeOrContainer);
}
}
toJSON(): any {
......
......@@ -47,7 +47,7 @@ class SymbolEntry extends EditorQuickOpenEntry {
public getDescription(): string {
let result = this._bearing.containerName;
if (!result) {
if (!result && this._bearing.resource) {
result = labels.getPathLabel(this._bearing.resource, this._contextService);
}
return result;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册