Chapter 07

VSCode / Zed / JetBrains 插件

IDE 内装 Biome 后,保存即格式化、修复建议、import 整理全由 LSP 无缝完成——CLI 和编辑器输出永远一致。

7.1 Biome 与 LSP

Biome 本体自带 Language Server Protocol(LSP)实现——biome lsp-proxy。各 IDE 的 Biome 插件其实是薄薄一层"LSP 客户端",真正做事的是同一个 Biome 二进制。这意味着:

7.2 VSCode

安装

Marketplace 搜索 Biome(发布者 biomejs,id: biomejs.biome)。或:

code --install-extension biomejs.biome

项目级 .vscode/settings.json

{
  // 1. 默认 formatter 设为 Biome
  "editor.defaultFormatter": "biomejs.biome",

  // 2. 保存时自动 format
  "editor.formatOnSave": true,

  // 3. 保存时自动修复 + 整理 import
  "editor.codeActionsOnSave": {
    "quickfix.biome": "explicit",
    "source.organizeImports.biome": "explicit"
  },

  // 4. 可选:按语言强制 formatter
  "[javascript]": { "editor.defaultFormatter": "biomejs.biome" },
  "[typescript]": { "editor.defaultFormatter": "biomejs.biome" },
  "[typescriptreact]": { "editor.defaultFormatter": "biomejs.biome" },
  "[json]": { "editor.defaultFormatter": "biomejs.biome" },
  "[jsonc]": { "editor.defaultFormatter": "biomejs.biome" }
}
共享给团队

.vscode/settings.json.vscode/extensions.json(推荐插件列表)一同提交。克隆仓库的人打开项目时 VSCode 会提示安装 Biome 插件——零配置上手。

排错清单

7.3 Zed

Zed 从 0.140+ 原生支持 Biome,不需要单独插件,只要项目根有 biome.json 就会自动启动 LSP。

~/.config/zed/settings.json

{
  "format_on_save": "on",
  "formatter": { "language_server": { "name": "biome" } },
  "code_actions_on_format": {
    "source.organizeImports.biome": true,
    "source.fixAll.biome": true
  }
}

7.4 JetBrains(WebStorm / IntelliJ)

安装官方插件 Biome(JetBrains Marketplace):

  1. Preferences → Languages & Frameworks → Biome
  2. 选择 Automatic Biome configuration(自动找 node_modules/.bin/biome
  3. 勾选 Run format on saveApply safe fixes on save
  4. 在 Prettier 设置页关闭 "On save",避免两个 formatter 打架

7.5 Neovim / Helix

-- nvim-lspconfig
require('lspconfig').biome.setup({
  cmd = { 'biome', 'lsp-proxy' }
})

-- null-ls / conform.nvim 亦支持 biome formatter

Helix 0.mouse:

# languages.toml
[[language]]
name = "typescript"
formatter = { command = "biome", args = ["format", "--stdin-file-path=file.ts"] }
auto-format = true

7.6 与 Copilot/AI 助手共存

AI 生成的代码风格经常与项目不符——Biome 会在保存时把它们"同化"。推荐的工作流:

  1. 让 AI 写完代码粘贴
  2. Ctrl+S(保存触发 source.fixAll.biome + format)
  3. 再看 diff——风格统一、import 也排好了

7.7 IDE 与 CI 行为一致性验证

偶尔会有"本地 IDE 没报错、CI 却挂"的问题。排查清单:

  1. CI 用的 Biome 版本与 @biomejs/biome devDep 是否一致
  2. IDE 插件是否指向了项目本地二进制(而不是全局安装的老版本)
  3. 是否漏提交了 biome.json 的最新修改
  4. biome rage 命令能导出 IDE 当前 LSP 状态,用来报 issue 或自检

小结

Biome 的"IDE 体验"靠内置 LSP 实现——VSCode、Zed、JetBrains、Neovim 都只是不同客户端。配置三件套:默认 formatter、formatOnSave、codeActionsOnSave。做对这三条,团队里每个人的代码风格就都由 biome.json 唯一决定了。下一章把它塞进 CI。