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

fix(language-core): auto-completion for the last line of template block #4771

Merged
merged 4 commits into from
Aug 31, 2024
Merged
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
26 changes: 25 additions & 1 deletion packages/language-core/lib/plugins/vue-template-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface Loc {
}
type Node = CompilerDOM.RootNode | CompilerDOM.TemplateChildNode | CompilerDOM.ExpressionNode | CompilerDOM.AttributeNode | CompilerDOM.DirectiveNode;

const shouldAddSuffix = /(?<=<[^>/]+)$/;

const plugin: VueLanguagePlugin = ({ modules }) => {

return {
Expand All @@ -20,14 +22,36 @@ const plugin: VueLanguagePlugin = ({ modules }) => {

const compiler = modules['@vue/compiler-dom'];

return compiler.compile(template, {
let addedSuffix = false;

// #4583
if (shouldAddSuffix.test(template)) {
template += '>';
addedSuffix = true;
}

const result = compiler.compile(template, {
...options,
comments: true,
});
// @ts-expect-error
result.__addedSuffix = addedSuffix;
return result;
}
},

updateSFCTemplate(oldResult, change) {
oldResult.code = oldResult.code.slice(0, change.start)
+ change.newText
+ oldResult.code.slice(change.end);

// @ts-expect-error
if (oldResult.__addedSuffix) {
const originalTemplate = oldResult.code.slice(0, -1); // remove added '>'
if (!shouldAddSuffix.test(originalTemplate)) {
return undefined;
}
}

const CompilerDOM = modules['@vue/compiler-dom'];

Expand Down