提交 d6bfdf60 编写于 作者: M Matt Bierner

Split out some functions in ts document symbol provider

上级 824bfb0b
......@@ -5,13 +5,13 @@
'use strict';
import { DocumentSymbolProvider, SymbolInformation, SymbolKind, TextDocument, Range, Location, CancellationToken } from 'vscode';
import { DocumentSymbolProvider, SymbolInformation, SymbolKind, TextDocument, Range, Location, CancellationToken, Uri } from 'vscode';
import * as Proto from '../protocol';
import * as PConst from '../protocol.const';
import { ITypescriptServiceClient } from '../typescriptService';
let outlineTypeTable: { [kind: string]: SymbolKind } = Object.create(null);
const outlineTypeTable: { [kind: string]: SymbolKind } = Object.create(null);
outlineTypeTable[PConst.Kind.module] = SymbolKind.Module;
outlineTypeTable[PConst.Kind.class] = SymbolKind.Class;
outlineTypeTable[PConst.Kind.enum] = SymbolKind.Enum;
......@@ -44,46 +44,14 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
file: filepath
};
function convertNavBar(indent: number, foldingMap: ObjectMap<SymbolInformation>, bucket: SymbolInformation[], item: Proto.NavigationBarItem, containerLabel?: string): void {
let realIndent = indent + item.indent;
let key = `${realIndent}|${item.text}`;
if (realIndent !== 0 && !foldingMap[key]) {
let result = new SymbolInformation(item.text,
outlineTypeTable[item.kind] || SymbolKind.Variable,
containerLabel ? containerLabel : '',
new Location(resource.uri, textSpan2Range(item.spans[0])));
foldingMap[key] = result;
bucket.push(result);
}
if (item.childItems && item.childItems.length > 0) {
for (let child of item.childItems) {
convertNavBar(realIndent + 1, foldingMap, bucket, child, item.text);
}
}
}
function convertNavTree(bucket: SymbolInformation[], item: Proto.NavigationTree, containerLabel?: string): void {
let result = new SymbolInformation(item.text,
outlineTypeTable[item.kind] || SymbolKind.Variable,
containerLabel ? containerLabel : '',
new Location(resource.uri, textSpan2Range(item.spans[0]))
);
if (item.childItems && item.childItems.length > 0) {
for (let child of item.childItems) {
convertNavTree(bucket, child, result.name);
}
}
bucket.push(result);
}
if (this.client.apiVersion.has206Features()) {
return this.client.execute('navtree', args, token).then((response) => {
let result: SymbolInformation[] = [];
const result: SymbolInformation[] = [];
if (response.body) {
// The root represents the file. Ignore this when showing in the UI
let tree = response.body;
if (tree.childItems) {
tree.childItems.forEach(item => convertNavTree(result, item));
tree.childItems.forEach(item => TypeScriptDocumentSymbolProvider.convertNavTree(resource.uri, result, item));
}
}
return result;
......@@ -93,10 +61,10 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
});
} else {
return this.client.execute('navbar', args, token).then((response) => {
let result: SymbolInformation[] = [];
const result: SymbolInformation[] = [];
if (response.body) {
let foldingMap: ObjectMap<SymbolInformation> = Object.create(null);
response.body.forEach(item => convertNavBar(0, foldingMap, result, item));
response.body.forEach(item => TypeScriptDocumentSymbolProvider.convertNavBar(resource.uri, 0, foldingMap, result, item));
}
return result;
}, (err) => {
......@@ -106,4 +74,35 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP
}
}
private static convertNavBar(resource: Uri, indent: number, foldingMap: ObjectMap<SymbolInformation>, bucket: SymbolInformation[], item: Proto.NavigationBarItem, containerLabel?: string): void {
let realIndent = indent + item.indent;
let key = `${realIndent}|${item.text}`;
if (realIndent !== 0 && !foldingMap[key]) {
let result = new SymbolInformation(item.text,
outlineTypeTable[item.kind] || SymbolKind.Variable,
containerLabel ? containerLabel : '',
new Location(resource, textSpan2Range(item.spans[0])));
foldingMap[key] = result;
bucket.push(result);
}
if (item.childItems && item.childItems.length > 0) {
for (let child of item.childItems) {
TypeScriptDocumentSymbolProvider.convertNavBar(resource, realIndent + 1, foldingMap, bucket, child, item.text);
}
}
}
private static convertNavTree(resource: Uri, bucket: SymbolInformation[], item: Proto.NavigationTree, containerLabel?: string): void {
const result = new SymbolInformation(item.text,
outlineTypeTable[item.kind] || SymbolKind.Variable,
containerLabel ? containerLabel : '',
new Location(resource, textSpan2Range(item.spans[0]))
);
if (item.childItems && item.childItems.length > 0) {
for (const child of item.childItems) {
TypeScriptDocumentSymbolProvider.convertNavTree(resource, bucket, child, result.name);
}
}
bucket.push(result);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册