Skip to content

Commit 97f441f

Browse files
committed
feat: update formatting for mpx json
1 parent bdaeb12 commit 97f441f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/language-core/src/plugins/mpx-sfc-json.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ const plugin: MpxLanguagePlugin = () => {
2121
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
2222
const json = /json_(js|json)/.test(embeddedFile.id) ? sfc.json : undefined
2323
if (json) {
24-
embeddedFile.content.push([json.content, json.name, 0, allCodeFeatures])
24+
let content = json.content
25+
if (content.startsWith('\n')) {
26+
content = content.slice(1)
27+
}
28+
embeddedFile.content.push([content, json.name, 1, allCodeFeatures])
2529
}
2630
},
2731
}

packages/language-service/src/plugins/mpx-sfc-json-json.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ export function create(): LanguageServicePlugin {
77
// mpx script-json json 语法模块允许注释和尾随逗号
88
return { comments: 'ignore', trailingCommas: 'ignore' }
99
},
10+
getFormattingOptions: async (_document, options, context) => {
11+
return {
12+
...options,
13+
...(await context.env.getConfiguration?.('json.format')),
14+
// 最后一行换行避免和 </script> 标签同一行
15+
insertFinalNewline: true,
16+
}
17+
},
1018
})
1119

1220
return base

0 commit comments

Comments
 (0)