Skip to content

Commit 0af1d56

Browse files
committed
Use offical TS API for folding
Fixes #45950
1 parent aee00a2 commit 0af1d56

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

extensions/typescript/src/features/folderingProvider.ts

+8-29
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,20 @@
66
import * as vscode from 'vscode';
77

88
import * as Proto from '../protocol';
9+
import * as typeConverters from '../utils/typeConverters';
910
import { ITypeScriptServiceClient } from '../typescriptService';
1011

11-
// TODO: forward declarations for private TS API.
12-
13-
interface TextSpan {
14-
start: number;
15-
length: number;
16-
}
17-
18-
interface OutliningSpan {
19-
textSpan: TextSpan;
20-
hintSpan: TextSpan;
21-
bannerText: string;
22-
autoCollapse: boolean;
23-
}
24-
25-
interface OutliningSpansRequestArgs extends Proto.FileRequestArgs { }
26-
27-
interface OutliningSpansResponse extends Proto.Response {
28-
body?: OutliningSpan[];
29-
}
30-
3112
export default class TypeScriptFoldingProvider implements vscode.FoldingProvider {
3213
public constructor(
3314
private readonly client: ITypeScriptServiceClient
3415
) { }
3516

3617
async provideFoldingRanges(
3718
document: vscode.TextDocument,
38-
_: vscode.FoldingContext,
19+
_context: vscode.FoldingContext,
3920
token: vscode.CancellationToken
4021
): Promise<vscode.FoldingRangeList | undefined> {
41-
if (!this.client.apiVersion.has270Features()) {
22+
if (!this.client.apiVersion.has280Features()) {
4223
return;
4324
}
4425

@@ -47,17 +28,15 @@ export default class TypeScriptFoldingProvider implements vscode.FoldingProvider
4728
return;
4829
}
4930

50-
const args: OutliningSpansRequestArgs = { file };
51-
const response: OutliningSpansResponse = await this.client.execute('outliningSpans', args, token);
31+
const args: Proto.FileRequestArgs = { file };
32+
const response: Proto.OutliningSpansResponse = await this.client.execute('getOutliningSpans', args, token);
5233
if (!response || !response.body) {
5334
return;
5435
}
5536

5637
return new vscode.FoldingRangeList(response.body.map(span => {
57-
const start = document.positionAt(span.textSpan.start);
58-
const end = document.positionAt(span.textSpan.start + span.textSpan.length);
59-
60-
return new vscode.FoldingRange(start.line, end.line);
38+
const range = typeConverters.Range.fromTextSpan(span.textSpan);
39+
return new vscode.FoldingRange(range.start.line, range.end.line);
6140
}));
6241
}
63-
}
42+
}

extensions/typescript/src/typescriptService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
76
import { CancellationToken, Uri, Event } from 'vscode';
87
import * as Proto from './protocol';
98
import API from './utils/api';
@@ -59,5 +58,6 @@ export interface ITypeScriptServiceClient {
5958
execute(command: 'getEditsForRefactor', args: Proto.GetEditsForRefactorRequestArgs, token?: CancellationToken): Promise<Proto.GetEditsForRefactorResponse>;
6059
execute(command: 'applyCodeActionCommand', args: Proto.ApplyCodeActionCommandRequestArgs, token?: CancellationToken): Promise<Proto.ApplyCodeActionCommandResponse>;
6160
execute(command: 'organizeImports', args: Proto.OrganizeImportsRequestArgs, token?: CancellationToken): Promise<Proto.OrganizeImportsResponse>;
61+
execute(command: 'getOutliningSpans', args: Proto.FileRequestArgs, token: CancellationToken): Promise<Proto.OutliningSpansResponse>;
6262
execute(command: string, args: any, expectedResult: boolean | CancellationToken, token?: CancellationToken): Promise<any>;
6363
}

0 commit comments

Comments
 (0)