@@ -167,10 +167,15 @@ export function create(): LanguageServicePlugin {
167
167
return ;
168
168
}
169
169
result . items = result . items . filter ( item => item . label !== '!DOCTYPE' && item . label !== 'Custom Blocks' ) ;
170
- for ( const scriptItem of result . items . filter ( item => item . label === 'script' || item . label === 'script setup' ) ) {
170
+
171
+ const tags = sfcDataProvider ?. provideTags ( ) ;
172
+
173
+ const scriptLangs = getLangs ( 'script' ) ;
174
+ const scriptItems = result . items . filter ( item => item . label === 'script' || item . label === 'script setup' ) ;
175
+ for ( const scriptItem of scriptItems ) {
171
176
scriptItem . kind = 17 satisfies typeof vscode . CompletionItemKind . File ;
172
177
scriptItem . detail = '.js' ;
173
- for ( const lang of [ 'ts' , 'tsx' , 'jsx' ] ) {
178
+ for ( const lang of scriptLangs ) {
174
179
result . items . push ( {
175
180
...scriptItem ,
176
181
detail : `.${ lang } ` ,
@@ -183,11 +188,13 @@ export function create(): LanguageServicePlugin {
183
188
} ) ;
184
189
}
185
190
}
191
+
192
+ const styleLangs = getLangs ( 'style' ) ;
186
193
const styleItem = result . items . find ( item => item . label === 'style' ) ;
187
194
if ( styleItem ) {
188
195
styleItem . kind = 17 satisfies typeof vscode . CompletionItemKind . File ;
189
196
styleItem . detail = '.css' ;
190
- for ( const lang of [ 'css' , 'scss' , 'less' , 'postcss' ] ) {
197
+ for ( const lang of styleLangs ) {
191
198
result . items . push ( {
192
199
...styleItem ,
193
200
kind : 17 satisfies typeof vscode . CompletionItemKind . File ,
@@ -200,22 +207,36 @@ export function create(): LanguageServicePlugin {
200
207
} ) ;
201
208
}
202
209
}
210
+
211
+ const templateLangs = getLangs ( 'template' ) ;
203
212
const templateItem = result . items . find ( item => item . label === 'template' ) ;
204
213
if ( templateItem ) {
205
214
templateItem . kind = 17 satisfies typeof vscode . CompletionItemKind . File ;
206
215
templateItem . detail = '.html' ;
207
- result . items . push ( {
208
- ...templateItem ,
209
- kind : 17 satisfies typeof vscode . CompletionItemKind . File ,
210
- detail : '.pug' ,
211
- label : templateItem . label + ' lang="pug"' ,
212
- textEdit : templateItem . textEdit ? {
213
- ...templateItem . textEdit ,
214
- newText : templateItem . textEdit . newText + ' lang="pug"' ,
215
- } : undefined ,
216
- } ) ;
216
+ for ( const lang of templateLangs ) {
217
+ if ( lang === 'html' ) {
218
+ continue ;
219
+ }
220
+ result . items . push ( {
221
+ ...templateItem ,
222
+ kind : 17 satisfies typeof vscode . CompletionItemKind . File ,
223
+ detail : `.${ lang } ` ,
224
+ label : templateItem . label + ' lang="' + lang + '"' ,
225
+ textEdit : templateItem . textEdit ? {
226
+ ...templateItem . textEdit ,
227
+ newText : templateItem . textEdit . newText + ' lang="' + lang + '"' ,
228
+ } : undefined ,
229
+ } ) ;
230
+ }
217
231
}
218
232
return result ;
233
+
234
+ function getLangs ( label : string ) {
235
+ return tags
236
+ ?. find ( tag => tag . name === label ) ?. attributes
237
+ . find ( attr => attr . name === 'lang' ) ?. values
238
+ ?. map ( ( { name } ) => name ) ?? [ ] ;
239
+ }
219
240
} ,
220
241
} ;
221
242
} ,
0 commit comments