mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
first cut of _proposed_ api for hierarchy of document symbols, #34968
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user