From 73f64b93127e0d297c98db2901d879ce73325c7f Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 23 Apr 2018 12:56:03 +0200 Subject: [PATCH] first cut of _proposed_ api for hierarchy of document symbols, #34968 --- src/vs/vscode.proposed.d.ts | 18 +++++++++++ src/vs/workbench/api/node/extHost.api.impl.ts | 6 ++++ .../api/node/extHostLanguageFeatures.ts | 5 ++- src/vs/workbench/api/node/extHostTypes.ts | 32 +++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index a32ee44692421..d385d7cb0755e 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -738,4 +738,22 @@ declare module 'vscode' { } //#endregion + + //#region Joh: hierarchical document symbols, https://github.com/Microsoft/vscode/issues/34968 + + export class HierarchicalSymbolInformation { + name: string; + kind: SymbolKind; + location: Location; + range: Range; + children: HierarchicalSymbolInformation[]; + + constructor(name: string, kind: SymbolKind, location: Location, range: Range); + } + + export interface DocumentSymbolProvider { + provideDocumentSymbols(document: TextDocument, token: CancellationToken): ProviderResult; + } + + //#endregion } diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index d477382fdf990..c3205e53724af 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -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, diff --git a/src/vs/workbench/api/node/extHostLanguageFeatures.ts b/src/vs/workbench/api/node/extHostLanguageFeatures.ts index 2d14359a8b128..ef8b3280235b6 100644 --- a/src/vs/workbench/api/node/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/node/extHostLanguageFeatures.ts @@ -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 { 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))); } diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index 491bbf87129bd..32a94c5d0baa6 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -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;