Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(language-service): add style scoped and module completion #4705

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/language-server/tests/completions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,23 @@ describe('Completions', async () => {
"script setup lang="tsx"",
"script setup lang="jsx"",
"style lang="css"",
"style lang="css" scoped",
"style lang="css" module",
"style lang="scss"",
"style lang="scss" scoped",
"style lang="scss" module",
"style lang="less"",
"style lang="less" scoped",
"style lang="less" module",
"style lang="stylus"",
"style lang="stylus" scoped",
"style lang="stylus" module",
"style lang="postcss"",
"style lang="postcss" scoped",
"style lang="postcss" module",
"style lang="sass"",
"style lang="sass" scoped",
"style lang="sass" module",
"template lang="pug"",
]
`);
Expand Down
32 changes: 22 additions & 10 deletions packages/language-service/lib/plugins/vue-sfc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,11 @@ export function create(): LanguageServicePlugin {
styleItem.kind = 17 satisfies typeof vscode.CompletionItemKind.File;
styleItem.detail = '.css';
for (const lang of styleLangs) {
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,
});
result.items.push(
getStyleCompletionItem(styleItem, lang),
getStyleCompletionItem(styleItem, lang, 'scoped'),
getStyleCompletionItem(styleItem, lang, 'module')
);
}
}

Expand Down Expand Up @@ -253,3 +248,20 @@ export function create(): LanguageServicePlugin {
}
}
}

function getStyleCompletionItem(
styleItem: vscode.CompletionItem,
lang: string,
attr?: string
): vscode.CompletionItem {
return {
...styleItem,
kind: 17 satisfies typeof vscode.CompletionItemKind.File,
detail: lang === 'postcss' ? '.css' : `.${lang}`,
label: styleItem.label + ' lang="' + lang + '"' + (attr ? ` ${attr}` : ''),
textEdit: styleItem.textEdit ? {
...styleItem.textEdit,
newText: styleItem.textEdit.newText + ' lang="' + lang + '"' + (attr ? ` ${attr}` : ''),
} : undefined
};
}