Skip to content

Commit 3be60c6

Browse files
committed
fix(language-core): <style> completions and html custom data completions not provided in some cases
close #4092
1 parent f1cf024 commit 3be60c6

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

packages/language-core/lib/codegen/template/context.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ const _codeFeatures = {
3131
} as VueCodeInformation,
3232
navigationAndCompletion: {
3333
navigation: true,
34+
completion: true,
35+
} as VueCodeInformation,
36+
navigationAndAdditionalCompletion: {
37+
navigation: true,
38+
completion: { isAdditional: true },
3439
} as VueCodeInformation,
3540
withoutHighlight: {
3641
semantic: { shouldHighlight: () => false },
@@ -104,6 +109,7 @@ export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCo
104109
const blockConditions: string[] = [];
105110
const usedComponentCtxVars = new Set<string>();
106111
const scopedClasses: { className: string, offset: number; }[] = [];
112+
const emptyClassOffsets: number[] = [];
107113

108114
return {
109115
slots,
@@ -114,6 +120,7 @@ export function createTemplateCodegenContext(scriptSetupBindingNames: TemplateCo
114120
blockConditions,
115121
usedComponentCtxVars,
116122
scopedClasses,
123+
emptyClassOffsets,
117124
hasSlot: false,
118125
accessExternalVariable(name: string, offset?: number) {
119126
let arr = accessExternalVariables.get(name);

packages/language-core/lib/codegen/template/element.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -549,20 +549,33 @@ function* generateReferencesForScopedCssClasses(
549549
&& prop.value
550550
) {
551551
let startOffset = prop.value.loc.start.offset;
552-
let tempClassName = '';
553-
for (const char of (prop.value.loc.source + ' ')) {
554-
if (char.trim() === '' || char === '"' || char === "'") {
555-
if (tempClassName !== '') {
556-
ctx.scopedClasses.push({ className: tempClassName, offset: startOffset });
557-
startOffset += tempClassName.length;
558-
tempClassName = '';
552+
let content = prop.value.loc.source;
553+
if (
554+
(content.startsWith(`'`) && content.endsWith(`'`))
555+
|| (content.startsWith(`"`) && content.endsWith(`"`))
556+
) {
557+
startOffset++;
558+
content = content.slice(1, -1);
559+
}
560+
if (content) {
561+
let currentClassName = '';
562+
for (const char of (content + ' ')) {
563+
if (char.trim() === '') {
564+
if (currentClassName !== '') {
565+
ctx.scopedClasses.push({ className: currentClassName, offset: startOffset });
566+
startOffset += currentClassName.length;
567+
currentClassName = '';
568+
}
569+
startOffset += char.length;
570+
}
571+
else {
572+
currentClassName += char;
559573
}
560-
startOffset += char.length;
561-
}
562-
else {
563-
tempClassName += char;
564574
}
565575
}
576+
else {
577+
ctx.emptyClassOffsets.push(startOffset);
578+
}
566579
}
567580
else if (
568581
prop.type === CompilerDOM.NodeTypes.DIRECTIVE

packages/language-core/lib/codegen/template/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
8686

8787
function* generateStyleScopedClasses(): Generator<Code> {
8888
yield `if (typeof __VLS_styleScopedClasses === 'object' && !Array.isArray(__VLS_styleScopedClasses)) {${newLine}`;
89+
for (const offset of ctx.emptyClassOffsets) {
90+
yield `__VLS_styleScopedClasses['`;
91+
yield [
92+
'',
93+
'template',
94+
offset,
95+
ctx.codeFeatures.additionalCompletion,
96+
];
97+
yield `']${endOfLine}`;
98+
}
8999
for (const { className, offset } of ctx.scopedClasses) {
90100
yield `__VLS_styleScopedClasses[`;
91101
yield [
@@ -99,7 +109,7 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
99109
className,
100110
'template',
101111
offset,
102-
ctx.codeFeatures.navigationAndCompletion,
112+
ctx.codeFeatures.navigationAndAdditionalCompletion,
103113
];
104114
yield `'`;
105115
yield [

packages/language-core/lib/utils/parseCssClassNames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { clearComments } from './parseCssVars';
22

3-
const cssClassNameReg = /(?=([\.]{1}[a-zA-Z_]+[\w\_\-]*)[\s\.\+\{\>#\:]{1})/g;
3+
const cssClassNameReg = /(?=([\.]{1}[a-zA-Z_]+[\w\_\-]*)[\s\.\,\+\{\>#\:]{1})/g;
44

55
export function* parseCssClassNames(styleContent: string) {
66
styleContent = clearComments(styleContent);

0 commit comments

Comments
 (0)