@@ -174,15 +174,21 @@ export function create(): LanguageServicePlugin {
174
174
} ,
175
175
176
176
async provideCompletionItems ( document , position , context , token ) {
177
- const result = await htmlPluginInstance . provideCompletionItems ?.( document , position , context , token )
177
+ const result = await htmlPluginInstance . provideCompletionItems ?.( document , position , context , token ) ;
178
178
if ( ! result ) {
179
179
return ;
180
180
}
181
- result . items = [
182
- ...result . items . filter ( item => item . label !== '!DOCTYPE' && item . label !== 'Custom Blocks' ) ,
183
- createCompletionItemWithTs ( result . items . find ( item => item . label === 'script' ) ! ) ,
184
- createCompletionItemWithTs ( result . items . find ( item => item . label === 'script setup' ) ! ) ,
185
- ]
181
+ result . items = result . items . filter ( item => item . label !== '!DOCTYPE' && item . label !== 'Custom Blocks' ) ;
182
+ for ( const scriptItem of result . items . filter ( item => item . label === 'script' || item . label === 'script setup' ) ) {
183
+ result . items . push ( {
184
+ ...scriptItem ,
185
+ label : scriptItem . label + ' lang="ts"' ,
186
+ textEdit : scriptItem . textEdit ? {
187
+ ...scriptItem . textEdit ,
188
+ newText : scriptItem . textEdit . newText + ' lang="ts"' ,
189
+ } : undefined ,
190
+ } ) ;
191
+ }
186
192
return result ;
187
193
} ,
188
194
} ;
@@ -198,14 +204,3 @@ export function create(): LanguageServicePlugin {
198
204
}
199
205
}
200
206
}
201
-
202
- function createCompletionItemWithTs ( base : vscode . CompletionItem ) : vscode . CompletionItem {
203
- return {
204
- ...base ,
205
- label : base . label + ' lang="ts"' ,
206
- textEdit : {
207
- ...base . textEdit ! ,
208
- newText : base . textEdit ! . newText + ' lang="ts"' ,
209
- }
210
- } ;
211
- }
0 commit comments