mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 19:59:37 +00:00
Remove old navtree call
This API has been replaced with navbar. The code related to navbar is not being tested and a very small number of users are using < 2.1 in their workspaces
This commit is contained in:
@@ -7,10 +7,8 @@ import * as vscode from 'vscode';
|
||||
import * as Proto from '../protocol';
|
||||
import * as PConst from '../protocol.const';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import API from '../utils/api';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
|
||||
|
||||
const getSymbolKind = (kind: string): vscode.SymbolKind => {
|
||||
switch (kind) {
|
||||
case PConst.Kind.module: return vscode.SymbolKind.Module;
|
||||
@@ -33,7 +31,8 @@ const getSymbolKind = (kind: string): vscode.SymbolKind => {
|
||||
|
||||
class TypeScriptDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
|
||||
public constructor(
|
||||
private readonly client: ITypeScriptServiceClient) { }
|
||||
private readonly client: ITypeScriptServiceClient
|
||||
) { }
|
||||
|
||||
public async provideDocumentSymbols(resource: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[] | vscode.SymbolInformation[]> {
|
||||
const filepath = this.client.toPath(resource.uri);
|
||||
@@ -45,23 +44,13 @@ class TypeScriptDocumentSymbolProvider implements vscode.DocumentSymbolProvider
|
||||
};
|
||||
|
||||
try {
|
||||
if (this.client.apiVersion.gte(API.v206)) {
|
||||
const response = await this.client.execute('navtree', args, token);
|
||||
if (response.body) {
|
||||
// The root represents the file. Ignore this when showing in the UI
|
||||
const tree = response.body;
|
||||
if (tree.childItems) {
|
||||
const result = new Array<vscode.DocumentSymbol>();
|
||||
tree.childItems.forEach(item => TypeScriptDocumentSymbolProvider.convertNavTree(resource.uri, result, item));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const response = await this.client.execute('navbar', args, token);
|
||||
if (response.body) {
|
||||
const result = new Array<vscode.SymbolInformation>();
|
||||
const foldingMap: ObjectMap<vscode.SymbolInformation> = Object.create(null);
|
||||
response.body.forEach(item => TypeScriptDocumentSymbolProvider.convertNavBar(resource.uri, 0, foldingMap, result as vscode.SymbolInformation[], item));
|
||||
const response = await this.client.execute('navtree', args, token);
|
||||
if (response.body) {
|
||||
// The root represents the file. Ignore this when showing in the UI
|
||||
const tree = response.body;
|
||||
if (tree.childItems) {
|
||||
const result = new Array<vscode.DocumentSymbol>();
|
||||
tree.childItems.forEach(item => TypeScriptDocumentSymbolProvider.convertNavTree(resource.uri, result, item));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -71,24 +60,6 @@ class TypeScriptDocumentSymbolProvider implements vscode.DocumentSymbolProvider
|
||||
}
|
||||
}
|
||||
|
||||
private static convertNavBar(resource: vscode.Uri, indent: number, foldingMap: ObjectMap<vscode.SymbolInformation>, bucket: vscode.SymbolInformation[], item: Proto.NavigationBarItem, containerLabel?: string): void {
|
||||
const realIndent = indent + item.indent;
|
||||
const key = `${realIndent}|${item.text}`;
|
||||
if (realIndent !== 0 && !foldingMap[key] && TypeScriptDocumentSymbolProvider.shouldInclueEntry(item)) {
|
||||
const result = new vscode.SymbolInformation(item.text,
|
||||
getSymbolKind(item.kind),
|
||||
containerLabel ? containerLabel : '',
|
||||
typeConverters.Location.fromTextSpan(resource, item.spans[0]));
|
||||
foldingMap[key] = result;
|
||||
bucket.push(result);
|
||||
}
|
||||
if (item.childItems && item.childItems.length > 0) {
|
||||
for (const child of item.childItems) {
|
||||
TypeScriptDocumentSymbolProvider.convertNavBar(resource, realIndent + 1, foldingMap, bucket, child, item.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static convertNavTree(resource: vscode.Uri, bucket: vscode.DocumentSymbol[], item: Proto.NavigationTree): boolean {
|
||||
const symbolInfo = new vscode.DocumentSymbol(
|
||||
item.text,
|
||||
|
||||
@@ -60,7 +60,6 @@ export interface ITypeScriptServiceClient {
|
||||
execute(command: 'typeDefinition', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise<Proto.TypeDefinitionResponse>;
|
||||
execute(command: 'references', args: Proto.FileLocationRequestArgs, token?: CancellationToken): Promise<Proto.ReferencesResponse>;
|
||||
execute(command: 'navto', args: Proto.NavtoRequestArgs, token?: CancellationToken): Promise<Proto.NavtoResponse>;
|
||||
execute(command: 'navbar', args: Proto.FileRequestArgs, token?: CancellationToken): Promise<Proto.NavBarResponse>;
|
||||
execute(command: 'format', args: Proto.FormatRequestArgs, token?: CancellationToken): Promise<Proto.FormatResponse>;
|
||||
execute(command: 'formatonkey', args: Proto.FormatOnKeyRequestArgs, token?: CancellationToken): Promise<Proto.FormatResponse>;
|
||||
execute(command: 'rename', args: Proto.RenameRequestArgs, token?: CancellationToken): Promise<Proto.RenameResponse>;
|
||||
|
||||
Reference in New Issue
Block a user