Skip to content

Commit

Permalink
fix(language-core): auto-completion for the last line of template blo…
Browse files Browse the repository at this point in the history
…ck (#4771)
  • Loading branch information
zhiyuanzmj authored Aug 31, 2024
1 parent 4fae9dd commit 87a804a
Showing 1 changed file with 25 additions and 1 deletion.
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

0 comments on commit 87a804a

Please sign in to comment.