first cut of _proposed_ api for hierarchy of document symbols, #34968

This commit is contained in:
Johannes Rieken
2018-04-23 12:56:03 +02:00
parent 2bf25467ad
commit 73f64b9312
4 changed files with 60 additions and 1 deletions

View File

@@ -666,6 +666,12 @@ export function createApiFactory(
SourceBreakpoint: extHostTypes.SourceBreakpoint,
StatusBarAlignment: extHostTypes.StatusBarAlignment,
SymbolInformation: extHostTypes.SymbolInformation,
HierarchicalSymbolInformation: class extends extHostTypes.HierarchicalSymbolInformation {
constructor(name, kind, keyof, range) {
checkProposedApiEnabled(extension);
super(name, kind, keyof, range);
}
},
SymbolKind: extHostTypes.SymbolKind,
SourceControlInputBoxValidationType: extHostTypes.SourceControlInputBoxValidationType,
TextDocumentSaveReason: extHostTypes.TextDocumentSaveReason,

View File

@@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { mixin } from 'vs/base/common/objects';
import * as vscode from 'vscode';
import * as TypeConverters from 'vs/workbench/api/node/extHostTypeConverters';
import { Range, Disposable, CompletionList, SnippetString, CodeActionKind } from 'vs/workbench/api/node/extHostTypes';
import { Range, Disposable, CompletionList, SnippetString, CodeActionKind, HierarchicalSymbolInformation } from 'vs/workbench/api/node/extHostTypes';
import { ISingleEditOperation } from 'vs/editor/common/model';
import * as modes from 'vs/editor/common/modes';
import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
@@ -39,6 +39,9 @@ class OutlineAdapter {
provideDocumentSymbols(resource: URI): TPromise<SymbolInformationDto[]> {
let doc = this._documents.getDocumentData(resource).document;
return asWinJsPromise(token => this._provider.provideDocumentSymbols(doc, token)).then(value => {
if (value instanceof HierarchicalSymbolInformation) {
value = HierarchicalSymbolInformation.toFlatSymbolInformation(value);
}
if (Array.isArray(value)) {
return value.map(symbol => IdObject.mixin(TypeConverters.fromSymbolInformation(symbol)));
}

View File

@@ -876,6 +876,38 @@ export class SymbolInformation {
}
}
export class HierarchicalSymbolInformation {
name: string;
location: Location;
kind: SymbolKind;
range: Range;
children: HierarchicalSymbolInformation[];
constructor(name: string, kind: SymbolKind, location: Location, range: Range) {
this.name = name;
this.kind = kind;
this.location = location;
this.range = range;
this.children = [];
}
static toFlatSymbolInformation(info: HierarchicalSymbolInformation): SymbolInformation[] {
let result: SymbolInformation[] = [];
HierarchicalSymbolInformation._toFlatSymbolInformation(info, undefined, result);
return result;
}
private static _toFlatSymbolInformation(info: HierarchicalSymbolInformation, containerName: string, bucket: SymbolInformation[]): void {
bucket.push(new SymbolInformation(info.name, info.kind, containerName, new Location(info.location.uri, info.range)));
if (Array.isArray(info.children)) {
for (const child of info.children) {
HierarchicalSymbolInformation._toFlatSymbolInformation(child, info.name, bucket);
}
}
}
}
export class CodeAction {
title: string;