Skip to content

Commit f1314ef

Browse files
committed
feat(language-service): strip ="" for boolean props completion edits (#5888)
1 parent 5f2d2db commit f1314ef

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/language-server/tests/completions.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,31 @@ test('Auto import', async () => {
615615
`);
616616
});
617617

618+
test('Boolean props', async () => {
619+
await requestCompletionItemToVueServer(
620+
'fixture.vue',
621+
'vue',
622+
`
623+
<template>
624+
<Comp :f| />
625+
</template>
626+
627+
<script setup lang="ts">
628+
declare function Comp(props: { foo: boolean }): void;
629+
</script>
630+
`,
631+
':foo',
632+
);
633+
});
634+
618635
test('Directives', async () => {
619636
await requestCompletionItemToVueServer('fixture.vue', 'vue', `<template><div v-ht|></div></template>`, 'v-html');
620637
await requestCompletionItemToVueServer('fixture.vue', 'vue', `<template><div v-cl|></div></template>`, 'v-cloak');
621638
await requestCompletionItemToVueServer('fixture.vue', 'vue', `<template><div v-el|></div></template>`, 'v-else');
622639
await requestCompletionItemToVueServer('fixture.vue', 'vue', `<template><div v-p|></div></template>`, 'v-pre');
623640
});
624641

625-
test('Directive Modifiers', async () => {
642+
test('Directive modifiers', async () => {
626643
expect(
627644
(await requestCompletionListToVueServer(
628645
'fixture.vue',

packages/language-service/lib/plugins/vue-template.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@ export function create(
765765
const name = attrNameCasing === AttrNameCasing.Camel ? prop.name : hyphenateAttr(prop.name);
766766
return name === labelName;
767767
});
768+
const isBoolean = propMeta2?.type === 'boolean' || propMeta2?.type.startsWith('boolean ');
769+
768770
if (addPlainAttrs) {
769771
attributes.push({
770772
name: labelName,
@@ -775,12 +777,14 @@ export function create(
775777
attributes.push({
776778
name: V_BIND_SHORTHAND + labelName,
777779
description: propMeta2 && createDescription(propMeta2),
780+
valueSet: isBoolean ? 'v' : undefined,
778781
});
779782
}
780783
if (addVBinds) {
781784
attributes.push({
782785
name: DIRECTIVE_V_BIND + labelName,
783786
description: propMeta2 && createDescription(propMeta2),
787+
valueSet: isBoolean ? 'v' : undefined,
784788
});
785789
}
786790
}

0 commit comments

Comments
 (0)