back to more conventinal api proposal, #34968

This commit is contained in:
Johannes Rieken
2018-06-05 17:05:13 +02:00
parent fa95a20cee
commit 9a86a83b50
6 changed files with 40 additions and 66 deletions

View File

@@ -708,15 +708,9 @@ export function createApiFactory(
StatusBarAlignment: extHostTypes.StatusBarAlignment,
SymbolInformation: extHostTypes.SymbolInformation,
SymbolInformation2: class extends extHostTypes.SymbolInformation2 {
constructor(name, detail, kind, range, location) {
constructor(name, kind, containerName, location) {
checkProposedApiEnabled(extension);
super(name, detail, kind, range, location);
}
},
Hierarchy: class <T> extends extHostTypes.Hierarchy<T> {
constructor(parent: T) {
checkProposedApiEnabled(extension);
super(parent);
super(name, kind, containerName, location);
}
},
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, SymbolInformation, Hierarchy, SymbolInformation2 } from 'vs/workbench/api/node/extHostTypes';
import { Range, Disposable, CompletionList, SnippetString, CodeActionKind, SymbolInformation, 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 Hierarchy)) {
if (!(probe instanceof SymbolInformation2)) {
value = OutlineAdapter._asSymbolHierarchy(<SymbolInformation[]>value);
}
return (<Hierarchy<SymbolInformation2>[]>value).map(typeConvert.HierarchicalSymbolInformation.from);
return (<SymbolInformation2[]>value).map(typeConvert.SymbolInformation2.from);
});
}
private static _asSymbolHierarchy(info: SymbolInformation[]): vscode.Hierarchy<SymbolInformation2>[] {
private static _asSymbolHierarchy(info: SymbolInformation[]): vscode.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,12 +61,12 @@ class OutlineAdapter {
}
return res;
});
let res: Hierarchy<SymbolInformation2>[] = [];
let parentStack: Hierarchy<SymbolInformation2>[] = [];
let res: SymbolInformation2[] = [];
let parentStack: SymbolInformation2[] = [];
for (let i = 0; i < info.length; i++) {
let element = new Hierarchy(new SymbolInformation2(info[i].name, '', info[i].kind, info[i].location.range, info[i].location));
element.parent.containerName = info[i].containerName;
element.parent.location = info[i].location; // todo@joh make this proper
let element = new SymbolInformation2(info[i].name, info[i].kind, '', info[i].location);
element.containerName = info[i].containerName;
element.location = info[i].location; // todo@joh make this proper
while (true) {
if (parentStack.length === 0) {
@@ -75,7 +75,7 @@ class OutlineAdapter {
break;
}
let parent = parentStack[parentStack.length - 1];
if (parent.parent.range.contains(element.parent.range) && !parent.parent.range.isEqual(element.parent.range)) {
if (parent.definingRange.contains(element.definingRange) && !parent.definingRange.isEqual(element.definingRange)) {
parent.children.push(element);
parentStack.push(element);
break;

View File

@@ -374,31 +374,30 @@ export namespace SymbolInformation {
}
}
export namespace HierarchicalSymbolInformation {
export function from(info: vscode.Hierarchy<vscode.SymbolInformation2>): modes.SymbolInformation {
export namespace SymbolInformation2 {
export function from(info: vscode.SymbolInformation2): modes.SymbolInformation {
let result: modes.SymbolInformation = {
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),
containerName: info.parent.containerName
name: info.name,
detail: undefined,
location: location.from(info.location),
definingRange: Range.from(info.definingRange),
kind: SymbolKind.from(info.kind),
containerName: info.containerName
};
if (info.children) {
result.children = info.children.map(from);
}
return result;
}
export function to(info: modes.SymbolInformation): types.Hierarchy<vscode.SymbolInformation2> {
let result = new types.Hierarchy<vscode.SymbolInformation2>(new types.SymbolInformation2(
export function to(info: modes.SymbolInformation): vscode.SymbolInformation2 {
let result = new types.SymbolInformation2(
info.name,
info.detail,
SymbolKind.to(info.kind),
Range.to(info.definingRange),
info.containerName,
location.to(info.location),
));
);
if (info.children) {
result.children = info.children.map(to);
result.children = info.children.map(to) as any;
}
return result;
}

View File

@@ -882,25 +882,15 @@ export class SymbolInformation {
}
export class SymbolInformation2 extends SymbolInformation {
definingRange: Range;
children: SymbolInformation2[];
constructor(name: string, kind: SymbolKind, containerName: string, location: Location) {
super(name, kind, containerName, 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 = [];
this.definingRange = location.range;
}
}
export enum CodeActionTrigger {
@@ -1927,4 +1917,4 @@ export enum CommentThreadCollapsibleState {
* Determines an item is expanded
*/
Expanded = 1
}
}