Skip to content

在你的编辑器中集成 Biome

Biome 具有 LSP 一流支持。如果你的编辑器实现了 LSP,那么 Biome 的集成应该是无缝的。

¥Biome has LSP first-class support. If your editor implements LSP, then the integration of Biome should be seamless.

¥Use the LSP proxy

Biome 有一个名为 lsp-proxy 的命令。执行时,Biome 将产生两个进程:

¥Biome has a command called lsp-proxy. When executed, Biome will spawn two processes:

  • 执行请求操作的 daemon

    ¥a daemon that executes the requested operations;

  • 在客户端请求之间充当代理的服务器 - 编辑器 - 和服务器 - 守护进程;

    ¥a server that functions as a proxy between the requests of the client - the editor - and the server - the daemon;

如果你的编辑器能够与服务器交互并发送 JSON-RPC 请求,你只需配置编辑器并运行该命令即可。

¥If your editor is able to interact with a server and send JSON-RPC request, you only need to configure the editor run that command.

你可以检查 neo-vim biome plugin 是如何执行的。

¥You can check how the neo-vim biome plugin does it.

¥Use stdin

如果你的编辑器不支持 LSP,你可以直接使用 biome 二进制文件并使用 标准输入 调用它。

¥If your editor doesn’t support LSP, you can use the biome binary directly and call it using standard input.

以下命令可以通过标准输入调用:

¥The following commands can be called via standard input:

Biome 将向 标准输出 返回新输出(如果没有发生变化,则返回原始输出),并将诊断信息返回到 标准错误

¥Biome will return the new output (or the original output if changes haven’t occurred) to standard output and the diagnostics to standard error.

当你使用 stdin 时,你必须传递 --stdin-file-path 选项。文件 path 不需要存在于你的文件系统中,它可以是任何名称。重要的是提供正确的文件扩展名,这样 Biome 才知道如何处理你的文件。

¥When you use stdin, you must pass the --stdin-file-path option. The file path doesn’t need to exist in your file system, it can be any name. What’s important is to provide the correct file extension, so Biome knows how to treat your file.

编辑器有责任找到解析二进制文件的路径,然后在需要时调用它。二进制文件根据我们支持的架构和操作系统发送到 npm:

¥It’s the editor’s responsibility to locate the resolve the path of the binary and then call it when it’s needed. The binaries are shipped to npm based on the architectures and OS that we support:

  • @biomejs/cli-darwin-arm64

  • @biomejs/cli-darwin-x64

  • @biomejs/cli-linux-arm64

  • @biomejs/cli-linux-x64

  • @biomejs/cli-win32-arm64

  • @biomejs/cli-win32-x64

二进制名称为 biomebiome.exe,可以在库的根目录中找到,例如:@biomejs/cli-darwin-arm64/biome, @biomejs/cli-win32-x64/biome.exe.

¥The binary name is biome or biome.exe, and it can be found in the root directory of the library, e.g.: @biomejs/cli-darwin-arm64/biome, @biomejs/cli-win32-x64/biome.exe.

将守护进程与二进制文件一起使用

Section titled 将守护进程与二进制文件一起使用

¥Use the daemon with the binary

通过 CLI 使用二进制文件非常高效,尽管你无法向用户提供 logs。CLI 允许你引导守护进程,然后通过守护进程本身使用 CLI 命令。

¥Using the binary via CLI is very efficient, although you won’t be able to provide logs to your users. The CLI allows you to bootstrap a daemon and then use the CLI commands through the daemon itself.

如果要这样做,你首先需要使用 start 命令启动守护进程:

¥If order to do so, you first need to start a daemon process with the start command:

Terminal window
biome start

然后,每个命令都需要添加 --use-server 选项,例如:

¥Then, every command needs to add the --use-server options, e.g.:

Terminal window
echo "console.log('')" | biome format --use-server --stdin-file-path=dummy.js

¥Daemon logs

Biome 守护进程将日志保存在你的文件系统中。它们存储在名为 biome-logs 的文件夹中。此文件夹的路径将根据你的操作系统而变化:

¥The Biome daemon saves logs in your file system. They are stored in a folder called biome-logs. The path to this folder will vary depending on your operating system:

  • Linux:~/.cache/biome

  • Windows:C:\Users\<UserName>\AppData\Local\biomejs\biome\cache

  • macOS:/Users/<UserName>/Library/Caches/dev.biomejs.biome

对于其他操作系统,你可以在系统的临时目录中找到该文件夹​​。

¥For other operative systems, you can find the folder in the system’s temporary directory.

要获取精确路径,请执行以下命令:

¥To obtain the precise path, execute the following command:

Terminal window
biome explain daemon-logs

日志文件每小时轮换一次。你可以使用 clean 命令删除日志:

¥The log files are rotated on an hourly basis. You can remove the logs using the clean command:

Terminal window
biome clean