@@ -27,10 +27,7 @@ export default (
27
27
configuration : GetConfig ,
28
28
preferences : ts . UserPreferences ,
29
29
formatOptions : ts . FormatCodeSettings | undefined ,
30
- ) : void | {
31
- entries : [ ]
32
- typescriptEssentialsResponse : any
33
- } => {
30
+ ) : any => {
34
31
const _specialCommandsParts = specialCommand . split ( '?' )
35
32
specialCommand = _specialCommandsParts [ 0 ] ! as TriggerCharacterCommand
36
33
const specialCommandArg = _specialCommandsParts [ 1 ] && JSON . parse ( _specialCommandsParts [ 1 ] )
@@ -41,10 +38,7 @@ export default (
41
38
if ( specialCommand === 'emmet-completions' ) {
42
39
const leftNode = findChildContainingPosition ( ts , sourceFile , position - 1 )
43
40
if ( ! leftNode ) return
44
- return {
45
- entries : [ ] ,
46
- typescriptEssentialsResponse : getEmmetCompletions ( fileName , leftNode , sourceFile , position , languageService ) ,
47
- }
41
+ return getEmmetCompletions ( fileName , leftNode , sourceFile , position , languageService )
48
42
}
49
43
// todo rename from getTwoStepCodeActions to additionalCodeActions
50
44
if ( specialCommand === 'getTwoStepCodeActions' ) {
@@ -55,28 +49,22 @@ export default (
55
49
56
50
const extendedCodeActions = getExtendedCodeActions ( sourceFile , posEnd , languageService , undefined , undefined )
57
51
return {
58
- entries : [ ] ,
59
- typescriptEssentialsResponse : {
60
- turnArrayIntoObject : objectIntoArrayConverters ( posEnd , node , undefined ) ,
61
- moveToExistingFile : moveToExistingFile ? { } : undefined ,
62
- extendedCodeActions : extendedCodeActions ,
63
- } satisfies RequestResponseTypes [ 'getTwoStepCodeActions' ] ,
52
+ turnArrayIntoObject : objectIntoArrayConverters ( posEnd , node , undefined ) ,
53
+ moveToExistingFile : moveToExistingFile ? { } : undefined ,
54
+ extendedCodeActions : extendedCodeActions ,
64
55
}
65
56
}
66
57
if ( specialCommand === 'getExtendedCodeActionEdits' ) {
67
58
changeType < RequestOptionsTypes [ 'getExtendedCodeActionEdits' ] > ( specialCommandArg )
68
59
const { range, applyCodeActionTitle } = specialCommandArg
69
60
const posEnd = { pos : range [ 0 ] , end : range [ 1 ] }
70
- return {
71
- entries : [ ] ,
72
- typescriptEssentialsResponse : getExtendedCodeActions (
73
- sourceFile ,
74
- posEnd ,
75
- languageService ,
76
- formatOptions ,
77
- applyCodeActionTitle ,
78
- ) satisfies RequestResponseTypes [ 'getExtendedCodeActionEdits' ] ,
79
- }
61
+ return getExtendedCodeActions (
62
+ sourceFile ,
63
+ posEnd ,
64
+ languageService ,
65
+ formatOptions ,
66
+ applyCodeActionTitle ,
67
+ ) satisfies RequestResponseTypes [ 'getExtendedCodeActionEdits' ]
80
68
}
81
69
if ( specialCommand === 'twoStepCodeActionSecondStep' ) {
82
70
changeType < RequestOptionsTypes [ 'twoStepCodeActionSecondStep' ] > ( specialCommandArg )
@@ -105,42 +93,22 @@ export default (
105
93
break
106
94
}
107
95
}
108
- return {
109
- entries : [ ] ,
110
- typescriptEssentialsResponse : data ,
111
- }
96
+ return data
112
97
}
113
98
if ( specialCommand === 'getNodeAtPosition' ) {
114
99
// ensure return data is the same as for node in getNodePath
115
100
const node = findChildContainingPosition ( ts , sourceFile , position )
116
- return {
117
- entries : [ ] ,
118
- typescriptEssentialsResponse : ! node ? undefined : nodeToApiResponse ( node ) ,
119
- }
101
+ return ! node ? undefined : nodeToApiResponse ( node )
120
102
}
121
103
if ( specialCommand === 'getFullMethodSnippet' ) {
122
- return {
123
- entries : [ ] ,
124
- typescriptEssentialsResponse : constructMethodSnippet (
125
- languageService ,
126
- sourceFile ,
127
- position ,
128
- configuration ,
129
- ) satisfies RequestResponseTypes [ 'getFullMethodSnippet' ] ,
130
- }
104
+ return constructMethodSnippet ( languageService , sourceFile , position , configuration ) satisfies RequestResponseTypes [ 'getFullMethodSnippet' ]
131
105
}
132
106
if ( specialCommand === 'getSpanOfEnclosingComment' ) {
133
- return {
134
- entries : [ ] ,
135
- typescriptEssentialsResponse : languageService . getSpanOfEnclosingComment ( fileName , position , false ) ,
136
- }
107
+ return languageService . getSpanOfEnclosingComment ( fileName , position , false )
137
108
}
138
109
if ( specialCommand === 'getNodePath' ) {
139
110
const nodes = getNodePath ( sourceFile , position )
140
- return {
141
- entries : [ ] ,
142
- typescriptEssentialsResponse : nodes . map ( node => nodeToApiResponse ( node ) ) ,
143
- }
111
+ return nodes . map ( node => nodeToApiResponse ( node ) )
144
112
}
145
113
if ( specialCommand === 'getFixAllEdits' ) {
146
114
// code adopted is for asyncInSync fix for now
@@ -163,10 +131,7 @@ export default (
163
131
}
164
132
}
165
133
}
166
- return {
167
- entries : [ ] ,
168
- typescriptEssentialsResponse : edits ,
169
- } as any
134
+ return edits
170
135
}
171
136
if ( specialCommand === 'removeFunctionArgumentsTypesInSelection' ) {
172
137
changeType < RequestOptionsTypes [ 'removeFunctionArgumentsTypesInSelection' ] > ( specialCommandArg )
@@ -178,15 +143,12 @@ export default (
178
143
}
179
144
const allParams = node . parent . parent . parameters
180
145
return {
181
- entries : [ ] ,
182
- typescriptEssentialsResponse : {
183
- ranges : allParams
184
- . map ( param => {
185
- if ( ! param . type || param . name . pos > specialCommandArg . endSelection ) return
186
- return [ param . name . end , param . type . end ]
187
- } )
188
- . filter ( Boolean ) ,
189
- } ,
146
+ ranges : allParams
147
+ . map ( param => {
148
+ if ( ! param . type || param . name . pos > specialCommandArg . endSelection ) return
149
+ return [ param . name . end , param . type . end ]
150
+ } )
151
+ . filter ( Boolean ) ,
190
152
}
191
153
}
192
154
if ( specialCommand === 'getRangeOfSpecialValue' ) {
@@ -240,22 +202,16 @@ export default (
240
202
}
241
203
if ( targetNode ) {
242
204
return {
243
- entries : [ ] ,
244
- typescriptEssentialsResponse : {
245
- range : Array . isArray ( targetNode ) ? targetNode : [ targetNode . pos , targetNode . end ] ,
246
- } satisfies RequestResponseTypes [ 'getRangeOfSpecialValue' ] ,
247
- }
205
+ range : Array . isArray ( targetNode ) ? targetNode : [ targetNode . pos , targetNode . end ] ,
206
+ } satisfies RequestResponseTypes [ 'getRangeOfSpecialValue' ]
248
207
} else {
249
208
return
250
209
}
251
210
}
252
211
if ( specialCommand === 'acceptRenameWithParams' ) {
253
212
changeType < RequestOptionsTypes [ 'acceptRenameWithParams' ] > ( specialCommandArg )
254
213
overrideRequestPreferences . rename = specialCommandArg
255
- return {
256
- entries : [ ] ,
257
- typescriptEssentialsResponse : undefined ,
258
- }
214
+ return undefined
259
215
}
260
216
if ( specialCommand === 'pickAndInsertFunctionArguments' ) {
261
217
// const sourceFile = (info.languageService as ReturnType<typeof tsFull['createLanguageService']>).getProgram()!.getSourceFile(fileName)!
@@ -270,23 +226,20 @@ export default (
270
226
}
271
227
sourceFile . forEachChild ( collectNodes )
272
228
return {
273
- entries : [ ] ,
274
- typescriptEssentialsResponse : {
275
- functions : collectedNodes . map ( arr => {
276
- return [
277
- arr [ 0 ] ,
278
- [ arr [ 1 ] . pos , arr [ 1 ] . end ] ,
279
- compact (
280
- arr [ 2 ] . map ( ( { name, type } ) => {
281
- // or maybe allow?
282
- if ( ! ts . isIdentifier ( name ) ) return
283
- return [ name . text , type ?. getText ( ) ?? '' ]
284
- } ) ,
285
- ) ,
286
- ]
287
- } ) ,
288
- } satisfies RequestResponseTypes [ 'pickAndInsertFunctionArguments' ] ,
289
- }
229
+ functions : collectedNodes . map ( arr => {
230
+ return [
231
+ arr [ 0 ] ,
232
+ [ arr [ 1 ] . pos , arr [ 1 ] . end ] ,
233
+ compact (
234
+ arr [ 2 ] . map ( ( { name, type } ) => {
235
+ // or maybe allow?
236
+ if ( ! ts . isIdentifier ( name ) ) return
237
+ return [ name . text , type ?. getText ( ) ?? '' ]
238
+ } ) ,
239
+ ) ,
240
+ ]
241
+ } ) ,
242
+ } satisfies RequestResponseTypes [ 'pickAndInsertFunctionArguments' ]
290
243
}
291
244
if ( specialCommand === 'filterBySyntaxKind' ) {
292
245
const collectedNodes : RequestResponseTypes [ 'filterBySyntaxKind' ] [ 'nodesByKind' ] = { }
@@ -305,12 +258,11 @@ export default (
305
258
}
306
259
sourceFile . forEachChild ( collectNodes )
307
260
return {
308
- entries : [ ] ,
309
- typescriptEssentialsResponse : {
310
- nodesByKind : collectedNodes ,
311
- } satisfies RequestResponseTypes [ 'filterBySyntaxKind' ] ,
312
- }
261
+ nodesByKind : collectedNodes ,
262
+ } satisfies RequestResponseTypes [ 'filterBySyntaxKind' ]
313
263
}
264
+
265
+ return null
314
266
}
315
267
316
268
function changeType < T > ( arg ) : asserts arg is T { }
0 commit comments