Skip to content

Commit 416882d

Browse files
committed
fix(language-service): ignore html wrapAttributes format settings for vue document
close #3987
1 parent d6f2519 commit 416882d

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

Diff for: packages/language-service/lib/plugins/vue-sfc.ts

+22-23
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,29 @@ export function create(): LanguageServicePlugin {
2323
sfcDataProvider ??= html.newHTMLDataProvider('vue', loadLanguageBlocks(context.env.locale ?? 'en'));
2424
return [sfcDataProvider];
2525
},
26+
async getFormattingOptions(document, options, context) {
27+
return await worker(document, async vueCode => {
28+
29+
const formatSettings = await context.env.getConfiguration?.<html.HTMLFormatConfiguration>('html.format') ?? {};
30+
const blockTypes = ['template', 'script', 'style'];
31+
32+
for (const customBlock of vueCode.sfc.customBlocks) {
33+
blockTypes.push(customBlock.type);
34+
}
35+
36+
return {
37+
...options,
38+
...formatSettings,
39+
wrapAttributes: 'auto',
40+
unformatted: '',
41+
contentUnformatted: blockTypes.join(','),
42+
endWithNewline: options.insertFinalNewline ? true
43+
: options.trimFinalNewlines ? false
44+
: document.getText().endsWith('\n'),
45+
};
46+
}) ?? {};
47+
},
2648
}).create(context);
27-
const htmlLanguageService: html.LanguageService = htmlPlugin.provide['html/languageService']();
2849

2950
return {
3051

@@ -148,28 +169,6 @@ export function create(): LanguageServicePlugin {
148169
return result;
149170
});
150171
},
151-
152-
provideDocumentFormattingEdits(document, range, options) {
153-
return worker(document, async vueCode => {
154-
155-
const formatSettings = await context.env.getConfiguration?.<html.HTMLFormatConfiguration>('html.format') ?? {};
156-
const blockTypes = ['template', 'script', 'style'];
157-
158-
for (const customBlock of vueCode.sfc.customBlocks) {
159-
blockTypes.push(customBlock.type);
160-
}
161-
162-
return htmlLanguageService.format(document, range, {
163-
...options,
164-
...formatSettings,
165-
unformatted: '',
166-
contentUnformatted: blockTypes.join(','),
167-
endWithNewline: options.insertFinalNewline ? true
168-
: options.trimFinalNewlines ? false
169-
: document.getText().endsWith('\n'),
170-
});
171-
});
172-
},
173172
};
174173

175174
function worker<T>(document: TextDocument, callback: (vueSourceFile: vue.VueGeneratedCode) => T) {

Diff for: packages/language-service/tests/format/3987.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineFormatTest } from '../utils/format';
2+
3+
defineFormatTest({
4+
title: '#' + __filename.split('.')[0],
5+
languageId: 'vue',
6+
input: `
7+
<style lang="scss"
8+
scoped>
9+
.wrapper {
10+
display: block;
11+
}
12+
</style>
13+
`.trim(),
14+
output: `
15+
<style lang="scss" scoped>
16+
.wrapper {
17+
display: block;
18+
}
19+
</style>
20+
`.trim(),
21+
settings: {
22+
'html.format.wrapAttributes': 'force-aligned',
23+
},
24+
});

0 commit comments

Comments
 (0)