@@ -27,10 +27,7 @@ export default (
2727 configuration : GetConfig ,
2828 preferences : ts . UserPreferences ,
2929 formatOptions : ts . FormatCodeSettings | undefined ,
30- ) : void | {
31- entries : [ ]
32- typescriptEssentialsResponse : any
33- } => {
30+ ) : any => {
3431 const _specialCommandsParts = specialCommand . split ( '?' )
3532 specialCommand = _specialCommandsParts [ 0 ] ! as TriggerCharacterCommand
3633 const specialCommandArg = _specialCommandsParts [ 1 ] && JSON . parse ( _specialCommandsParts [ 1 ] )
@@ -41,10 +38,7 @@ export default (
4138 if ( specialCommand === 'emmet-completions' ) {
4239 const leftNode = findChildContainingPosition ( ts , sourceFile , position - 1 )
4340 if ( ! leftNode ) return
44- return {
45- entries : [ ] ,
46- typescriptEssentialsResponse : getEmmetCompletions ( fileName , leftNode , sourceFile , position , languageService ) ,
47- }
41+ return getEmmetCompletions ( fileName , leftNode , sourceFile , position , languageService )
4842 }
4943 // todo rename from getTwoStepCodeActions to additionalCodeActions
5044 if ( specialCommand === 'getTwoStepCodeActions' ) {
@@ -55,28 +49,22 @@ export default (
5549
5650 const extendedCodeActions = getExtendedCodeActions ( sourceFile , posEnd , languageService , undefined , undefined )
5751 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 ,
6455 }
6556 }
6657 if ( specialCommand === 'getExtendedCodeActionEdits' ) {
6758 changeType < RequestOptionsTypes [ 'getExtendedCodeActionEdits' ] > ( specialCommandArg )
6859 const { range, applyCodeActionTitle } = specialCommandArg
6960 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' ]
8068 }
8169 if ( specialCommand === 'twoStepCodeActionSecondStep' ) {
8270 changeType < RequestOptionsTypes [ 'twoStepCodeActionSecondStep' ] > ( specialCommandArg )
@@ -105,42 +93,22 @@ export default (
10593 break
10694 }
10795 }
108- return {
109- entries : [ ] ,
110- typescriptEssentialsResponse : data ,
111- }
96+ return data
11297 }
11398 if ( specialCommand === 'getNodeAtPosition' ) {
11499 // ensure return data is the same as for node in getNodePath
115100 const node = findChildContainingPosition ( ts , sourceFile , position )
116- return {
117- entries : [ ] ,
118- typescriptEssentialsResponse : ! node ? undefined : nodeToApiResponse ( node ) ,
119- }
101+ return ! node ? undefined : nodeToApiResponse ( node )
120102 }
121103 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' ]
131105 }
132106 if ( specialCommand === 'getSpanOfEnclosingComment' ) {
133- return {
134- entries : [ ] ,
135- typescriptEssentialsResponse : languageService . getSpanOfEnclosingComment ( fileName , position , false ) ,
136- }
107+ return languageService . getSpanOfEnclosingComment ( fileName , position , false )
137108 }
138109 if ( specialCommand === 'getNodePath' ) {
139110 const nodes = getNodePath ( sourceFile , position )
140- return {
141- entries : [ ] ,
142- typescriptEssentialsResponse : nodes . map ( node => nodeToApiResponse ( node ) ) ,
143- }
111+ return nodes . map ( node => nodeToApiResponse ( node ) )
144112 }
145113 if ( specialCommand === 'getFixAllEdits' ) {
146114 // code adopted is for asyncInSync fix for now
@@ -163,10 +131,7 @@ export default (
163131 }
164132 }
165133 }
166- return {
167- entries : [ ] ,
168- typescriptEssentialsResponse : edits ,
169- } as any
134+ return edits
170135 }
171136 if ( specialCommand === 'removeFunctionArgumentsTypesInSelection' ) {
172137 changeType < RequestOptionsTypes [ 'removeFunctionArgumentsTypesInSelection' ] > ( specialCommandArg )
@@ -178,15 +143,12 @@ export default (
178143 }
179144 const allParams = node . parent . parent . parameters
180145 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 ) ,
190152 }
191153 }
192154 if ( specialCommand === 'getRangeOfSpecialValue' ) {
@@ -240,22 +202,16 @@ export default (
240202 }
241203 if ( targetNode ) {
242204 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' ]
248207 } else {
249208 return
250209 }
251210 }
252211 if ( specialCommand === 'acceptRenameWithParams' ) {
253212 changeType < RequestOptionsTypes [ 'acceptRenameWithParams' ] > ( specialCommandArg )
254213 overrideRequestPreferences . rename = specialCommandArg
255- return {
256- entries : [ ] ,
257- typescriptEssentialsResponse : undefined ,
258- }
214+ return undefined
259215 }
260216 if ( specialCommand === 'pickAndInsertFunctionArguments' ) {
261217 // const sourceFile = (info.languageService as ReturnType<typeof tsFull['createLanguageService']>).getProgram()!.getSourceFile(fileName)!
@@ -270,23 +226,20 @@ export default (
270226 }
271227 sourceFile . forEachChild ( collectNodes )
272228 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' ]
290243 }
291244 if ( specialCommand === 'filterBySyntaxKind' ) {
292245 const collectedNodes : RequestResponseTypes [ 'filterBySyntaxKind' ] [ 'nodesByKind' ] = { }
@@ -305,12 +258,11 @@ export default (
305258 }
306259 sourceFile . forEachChild ( collectNodes )
307260 return {
308- entries : [ ] ,
309- typescriptEssentialsResponse : {
310- nodesByKind : collectedNodes ,
311- } satisfies RequestResponseTypes [ 'filterBySyntaxKind' ] ,
312- }
261+ nodesByKind : collectedNodes ,
262+ } satisfies RequestResponseTypes [ 'filterBySyntaxKind' ]
313263 }
264+
265+ return null
314266}
315267
316268function changeType < T > ( arg ) : asserts arg is T { }
0 commit comments