mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
wire up WorkspaceSymbolProvider
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user