KScript 文档
ZH

格式化

在编辑器中

VS Code 扩展是 KScript 文件的默认格式化程序,因此格式化文档(Shift+Alt+F,或 macOS 上的 Shift+Option+F)可直接使用。要在保存时自动格式化,请将以下条目添加到你的 VS Code 设置中:

JSON
{
  "[kscript]": { "editor.formatOnSave": true },
  "[kscript-code]": { "editor.formatOnSave": true }
}

VS Code 自带一个 HTML 格式化程序,它不认识 KScript 元素或 { }。要在页面中使用 KScript 的格式化程序,请在 VS Code 询问使用哪个格式化程序时选择 KScript,或者为某个站点的工作区进行设置:

JSON
{
  "[html]": { "editor.defaultFormatter": "kylepantall.kscript" }
}

其他编辑器通过 kscript lsp(LSP textDocument/formatting 请求)获取格式化结果。在 CI 中,运行 kscript fmt --check。