6
6
import * as vscode from 'vscode' ;
7
7
8
8
import * as Proto from '../protocol' ;
9
+ import * as typeConverters from '../utils/typeConverters' ;
9
10
import { ITypeScriptServiceClient } from '../typescriptService' ;
10
11
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
-
31
12
export default class TypeScriptFoldingProvider implements vscode . FoldingProvider {
32
13
public constructor (
33
14
private readonly client : ITypeScriptServiceClient
34
15
) { }
35
16
36
17
async provideFoldingRanges (
37
18
document : vscode . TextDocument ,
38
- _ : vscode . FoldingContext ,
19
+ _context : vscode . FoldingContext ,
39
20
token : vscode . CancellationToken
40
21
) : Promise < vscode . FoldingRangeList | undefined > {
41
- if ( ! this . client . apiVersion . has270Features ( ) ) {
22
+ if ( ! this . client . apiVersion . has280Features ( ) ) {
42
23
return ;
43
24
}
44
25
@@ -47,17 +28,15 @@ export default class TypeScriptFoldingProvider implements vscode.FoldingProvider
47
28
return ;
48
29
}
49
30
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 ) ;
52
33
if ( ! response || ! response . body ) {
53
34
return ;
54
35
}
55
36
56
37
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 ) ;
61
40
} ) ) ;
62
41
}
63
- }
42
+ }
0 commit comments