Skip to content

Commit

Permalink
feat(language-service): support auto-complete for more preprocessing …
Browse files Browse the repository at this point in the history
…languages
  • Loading branch information
johnsoncodehk committed Jul 4, 2024
1 parent 614aed7 commit 00e2fd2
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions packages/language-service/lib/plugins/vue-sfc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,50 @@ export function create(): LanguageServicePlugin {
}
result.items = result.items.filter(item => item.label !== '!DOCTYPE' && item.label !== 'Custom Blocks');
for (const scriptItem of result.items.filter(item => item.label === 'script' || item.label === 'script setup')) {
scriptItem.kind = 17 satisfies typeof vscode.CompletionItemKind.File;
scriptItem.detail = '.js';
for (const lang of ['ts', 'tsx', 'jsx']) {
result.items.push({
...scriptItem,
detail: `.${lang}`,
kind: 17 satisfies typeof vscode.CompletionItemKind.File,
label: scriptItem.label + ' lang="' + lang + '"',
textEdit: scriptItem.textEdit ? {
...scriptItem.textEdit,
newText: scriptItem.textEdit.newText + ' lang="' + lang + '"',
} : undefined,
});
}
}
const styleItem = result.items.find(item => item.label === 'style');
if (styleItem) {
styleItem.kind = 17 satisfies typeof vscode.CompletionItemKind.File;
styleItem.detail = '.css';
for (const lang of ['css', 'scss', 'less', 'postcss']) {
result.items.push({
...styleItem,
kind: 17 satisfies typeof vscode.CompletionItemKind.File,
detail: lang === 'postcss' ? '.css' : `.${lang}`,
label: styleItem.label + ' lang="' + lang + '"',
textEdit: styleItem.textEdit ? {
...styleItem.textEdit,
newText: styleItem.textEdit.newText + ' lang="' + lang + '"',
} : undefined,
});
}
}
const templateItem = result.items.find(item => item.label === 'template');
if (templateItem) {
templateItem.kind = 17 satisfies typeof vscode.CompletionItemKind.File;
templateItem.detail = '.html';
result.items.push({
...scriptItem,
label: scriptItem.label + ' lang="ts"',
textEdit: scriptItem.textEdit ? {
...scriptItem.textEdit,
newText: scriptItem.textEdit.newText + ' lang="ts"',
...templateItem,
kind: 17 satisfies typeof vscode.CompletionItemKind.File,
detail: '.pug',
label: templateItem.label + ' lang="pug"',
textEdit: templateItem.textEdit ? {
...templateItem.textEdit,
newText: templateItem.textEdit.newText + ' lang="pug"',
} : undefined,
});
}
Expand Down

0 comments on commit 00e2fd2

Please sign in to comment.