Skip to content

Commit

Permalink
fix: template syntax and directive values formatting not working
Browse files Browse the repository at this point in the history
close #2026
  • Loading branch information
johnsoncodehk committed Oct 22, 2022
1 parent f3f36ba commit 415a4f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
27 changes: 14 additions & 13 deletions packages/language-service/src/documentFeatures/format.ts
Expand Up @@ -243,26 +243,27 @@ export function register(context: DocumentServiceRuntimeContext) {
if (!edits.length)
return edits;

let newText = TextDocument.applyEdits(formatDocument, edits);

if (initialIndentBracket) {
let newText = TextDocument.applyEdits(formatDocument, edits);
newText = newText.substring(
newText.indexOf(initialIndentBracket[0]) + initialIndentBracket[0].length,
newText.lastIndexOf(initialIndentBracket[1]),
);
if (newText === document.getText()) {
edits = [];
}
else {
edits = [{
newText,
range: {
start: document.positionAt(0),
end: document.positionAt(document.getText().length),
},
}];
}
}

if (newText === document.getText()) {
return [];
}

return [{
range: {
start: document.positionAt(0),
end: document.positionAt(document.getText().length),
},
newText,
}];
return edits;
}
}

Expand Down
4 changes: 2 additions & 2 deletions vue-language-tools/vue-language-core/src/plugins/vue-tsx.ts
Expand Up @@ -92,7 +92,7 @@ const plugin: VueLanguagePlugin = ({ modules, vueCompilerOptions, compilerOption
}

if (sfc.template) {
fileNames.push(fileName + '.__VLS_template_format.tsx');
fileNames.push(fileName + '.__VLS_template_format.ts');
fileNames.push(fileName + '.__VLS_template_style.css');
}

Expand Down Expand Up @@ -123,7 +123,7 @@ const plugin: VueLanguagePlugin = ({ modules, vueCompilerOptions, compilerOption
embeddedFile.teleportMappings = [...tsx.teleports];
}
}
else if (suffix.match(/^\.__VLS_template_format\.tsx$/)) {
else if (suffix.match(/^\.__VLS_template_format\.ts$/)) {

embeddedFile.parentFileName = fileName + '.template.' + sfc.template?.lang;
embeddedFile.capabilities = {
Expand Down

0 comments on commit 415a4f7

Please sign in to comment.