explore Hierarchy<T> idea, #34968

This commit is contained in:
Johannes Rieken
2018-05-17 10:40:08 +02:00
parent 72e6a7d66e
commit 49323b3798
6 changed files with 72 additions and 56 deletions

View File

@@ -700,10 +700,16 @@ export function createApiFactory(
SourceBreakpoint: extHostTypes.SourceBreakpoint,
StatusBarAlignment: extHostTypes.StatusBarAlignment,
SymbolInformation: extHostTypes.SymbolInformation,
HierarchicalSymbolInformation: class extends extHostTypes.HierarchicalSymbolInformation {
constructor(name, detail, kind, keyof, range) {
SymbolInformation2: class extends extHostTypes.SymbolInformation2 {
constructor(name, detail, kind, range, location) {
checkProposedApiEnabled(extension);
super(name, detail, kind, keyof, range);
super(name, detail, kind, range, location);
}
},
Hierarchy: class <T> extends extHostTypes.Hierarchy<T> {
constructor(parent: T) {
checkProposedApiEnabled(extension);
super(parent);
}
},
SymbolKind: extHostTypes.SymbolKind,

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 typeConvert from 'vs/workbench/api/node/extHostTypeConverters';
import { Range, Disposable, CompletionList, SnippetString, CodeActionKind, HierarchicalSymbolInformation, SymbolInformation } from 'vs/workbench/api/node/extHostTypes';
import { Range, Disposable, CompletionList, SnippetString, CodeActionKind, SymbolInformation, Hierarchy, SymbolInformation2 } 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';
@@ -44,14 +44,14 @@ class OutlineAdapter {
return undefined;
}
let [probe] = value;
if (!(probe instanceof HierarchicalSymbolInformation)) {
value = OutlineAdapter._asSymbolTree(<SymbolInformation[]>value);
if (!(probe instanceof Hierarchy)) {
value = OutlineAdapter._asSymbolHierarchy(<SymbolInformation[]>value);
}
return (<HierarchicalSymbolInformation[]>value).map(typeConvert.HierarchicalSymbolInformation.from);
return (<Hierarchy<SymbolInformation2>[]>value).map(typeConvert.HierarchicalSymbolInformation.from);
});
}
private static _asSymbolTree(info: SymbolInformation[]): vscode.HierarchicalSymbolInformation[] {
private static _asSymbolHierarchy(info: SymbolInformation[]): vscode.Hierarchy<SymbolInformation2>[] {
// first sort by start (and end) and then loop over all elements
// and build a tree based on containment.
info = info.slice(0).sort((a, b) => {
@@ -61,10 +61,10 @@ class OutlineAdapter {
}
return res;
});
let res: HierarchicalSymbolInformation[] = [];
let parentStack: HierarchicalSymbolInformation[] = [];
let res: Hierarchy<SymbolInformation2>[] = [];
let parentStack: Hierarchy<SymbolInformation2>[] = [];
for (let i = 0; i < info.length; i++) {
let element = new HierarchicalSymbolInformation(info[i].name, '', info[i].kind, info[i].location, info[i].location.range);
let element = new Hierarchy(new SymbolInformation2(info[i].name, '', info[i].kind, info[i].location.range, info[i].location));
while (true) {
if (parentStack.length === 0) {
parentStack.push(element);
@@ -72,7 +72,7 @@ class OutlineAdapter {
break;
}
let parent = parentStack[parentStack.length - 1];
if (parent.range.contains(element.range)) {
if (parent.parent.range.contains(element.parent.range)) {
parent.children.push(element);
parentStack.push(element);
break;

View File

@@ -364,27 +364,27 @@ export namespace SymbolInformation {
}
export namespace HierarchicalSymbolInformation {
export function from(info: vscode.HierarchicalSymbolInformation): modes.SymbolInformation {
export function from(info: vscode.Hierarchy<vscode.SymbolInformation2>): modes.SymbolInformation {
let result: modes.SymbolInformation = {
name: info.name,
detail: info.detail,
location: location.from(info.location),
definingRange: Range.from(info.range),
kind: SymbolKind.from(info.kind)
name: info.parent.name,
detail: info.parent.detail,
location: location.from(info.parent.location),
definingRange: Range.from(info.parent.range),
kind: SymbolKind.from(info.parent.kind)
};
if (info.children) {
result.children = info.children.map(from);
}
return result;
}
export function to(info: modes.SymbolInformation): types.HierarchicalSymbolInformation {
let result = new types.HierarchicalSymbolInformation(
export function to(info: modes.SymbolInformation): types.Hierarchy<vscode.SymbolInformation2> {
let result = new types.Hierarchy<vscode.SymbolInformation2>(new types.SymbolInformation2(
info.name,
info.detail,
SymbolKind.to(info.kind),
Range.to(info.definingRange),
location.to(info.location),
Range.to(info.definingRange)
);
));
if (info.children) {
result.children = info.children.map(to);
}

View File

@@ -876,19 +876,24 @@ export class SymbolInformation {
}
}
export class HierarchicalSymbolInformation {
name: string;
location: Location;
detail: string;
kind: SymbolKind;
range: Range;
children: HierarchicalSymbolInformation[];
export class SymbolInformation2 extends SymbolInformation {
constructor(name: string, detail: string, kind: SymbolKind, location: Location, range: Range) {
this.name = name;
this.kind = kind;
this.location = location;
detail: string;
range: Range;
constructor(name: string, detail: string, kind: SymbolKind, range: Range, location: Location) {
super(name, kind, undefined, location);
this.detail = detail;
this.range = range;
}
}
export class Hierarchy<T> {
parent: T;
children: Hierarchy<T>[];
constructor(parent: T) {
this.parent = parent;
this.children = [];
}
}