提交 0af1d56c 编写于 作者: M Matt Bierner

Use offical TS API for folding

Fixes #45950
上级 aee00a20
......@@ -6,28 +6,9 @@
import * as vscode from 'vscode';
import * as Proto from '../protocol';
import * as typeConverters from '../utils/typeConverters';
import { ITypeScriptServiceClient } from '../typescriptService';
// TODO: forward declarations for private TS API.
interface TextSpan {
start: number;
length: number;
}
interface OutliningSpan {
textSpan: TextSpan;
hintSpan: TextSpan;
bannerText: string;
autoCollapse: boolean;
}
interface OutliningSpansRequestArgs extends Proto.FileRequestArgs { }
interface OutliningSpansResponse extends Proto.Response {
body?: OutliningSpan[];
}
export default class TypeScriptFoldingProvider implements vscode.FoldingProvider {
public constructor(
private readonly client: ITypeScriptServiceClient
......@@ -35,10 +16,10 @@ export default class TypeScriptFoldingProvider implements vscode.FoldingProvider
async provideFoldingRanges(
document: vscode.TextDocument,
_: vscode.FoldingContext,
_context: vscode.FoldingContext,
token: vscode.CancellationToken
): Promise<vscode.FoldingRangeList | undefined> {
if (!this.client.apiVersion.has270Features()) {
if (!this.client.apiVersion.has280Features()) {
return;
}
......@@ -47,17 +28,15 @@ export default class TypeScriptFoldingProvider implements vscode.FoldingProvider
return;
}
const args: OutliningSpansRequestArgs = { file };
const response: OutliningSpansResponse = await this.client.execute('outliningSpans', args, token);
const args: Proto.FileRequestArgs = { file };
const response: Proto.OutliningSpansResponse = await this.client.execute('getOutliningSpans', args, token);
if (!response || !response.body) {
return;
}
return new vscode.FoldingRangeList(response.body.map(span => {
const start = document.positionAt(span.textSpan.start);
const end = document.positionAt(span.textSpan.start + span.textSpan.length);
return new vscode.FoldingRange(start.line, end.line);
const range = typeConverters.Range.fromTextSpan(span.textSpan);
return new vscode.FoldingRange(range.start.line, range.end.line);
}));
}
}
\ No newline at end of file
}
......@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken, Uri, Event } from 'vscode';
import * as Proto from './protocol';
import API from './utils/api';
......@@ -59,5 +58,6 @@ export interface ITypeScriptServiceClient {
execute(command: 'getEditsForRefactor', args: Proto.GetEditsForRefactorRequestArgs, token?: CancellationToken): Promise<Proto.GetEditsForRefactorResponse>;
execute(command: 'applyCodeActionCommand', args: Proto.ApplyCodeActionCommandRequestArgs, token?: CancellationToken): Promise<Proto.ApplyCodeActionCommandResponse>;
execute(command: 'organizeImports', args: Proto.OrganizeImportsRequestArgs, token?: CancellationToken): Promise<Proto.OrganizeImportsResponse>;
execute(command: 'getOutliningSpans', args: Proto.FileRequestArgs, token: CancellationToken): Promise<Proto.OutliningSpansResponse>;
execute(command: string, args: any, expectedResult: boolean | CancellationToken, token?: CancellationToken): Promise<any>;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册