Skip to content

此页面向你介绍 oxc_language_server 的主要概念,以及它与 CLI 的区别。 如果你想了解更多关于语言服务器与编辑器之间通信的内容,官方的 LSP/LSIF 文档 是一个很好的起点。 语言服务器的 README.md 提供了相关规范的快速概览。

🌐 This page tells you the main concept of the oxc_language_server and what the differences to the CLI are. If you want to learn more about the communication between the language server and the editor, the official LSP/LSIF documentation is a great start. The README.md of the language server has a quick overview of the relevant specs.

注意:在本文件中,我们将大量讨论“工具”,这是 oxlintoxfmt 核心逻辑的一个抽象概念。

🌐 Note: In this document we will talk a lot about "tools", this is an abstract concept of the core logic for oxlint and oxfmt.

oxc_language_server 工具实现概念

🌐 oxc_language_server concept of implementing tools

oxc_language_server 可用于升级你自己的脚本,使其具备作为语言服务器工作的能力。 服务器本身不会更改你的文件或生成建议,这由工具负责。 它负责管理工作区文件夹以及加载正确配置所需的所有通信。 为了与提供的工具进行通信,服务器提供了 ToolBuilderTool 特性

语言服务器与命令行接口的区别

🌐 Difference between Language Server and CLI

编辑器更改文件,服务器传达这些更改

🌐 Editors changes the file, server communicates the changes

关于文件的通信及其修复,有一个小但重要的部分。CLI 工具将更改写入文件系统。(oxc) 语言服务器绝不应该写入文件,它只会将更改传达给编辑器。

🌐 A small but important part about the communication of a file and the fix of it. The CLI Tools are writing the changes to the file system. The (oxc) language server should NEVER write to it, instead it just communicates it changes to the editor.

工作区文件夹

🌐 Workspace Folders

你知道当你在编辑器中打开一个 git 项目时吗?那就是一个工作区文件夹。LSP 有同时打开多个(git)项目的概念。每个项目都可以有自己的配置(见下一部分),但最重要的部分是每个项目都有自己的“上下文”,带有工作区 URI。你可以将工作区 URI 看作 CLI 工具的“当前工作目录”。请记住,编辑器可以添加或移除工作区文件夹。

🌐 You know when you open a git project in the editor? That is a workspace folder. The LSP has the concept of opening multiple (git) projects at the same time. Each of the projects can have its own configuration (see next part), but the most important part is the own "context" with a workspace URI. You can think of a workspace URI as the same as a "current working directory" for the CLI tool. Keep in mind that a workspace folder can be added / removed by the editor.

配置(含文件夹)

🌐 Configurations (with folders)

语言服务器可以配置(就像 CLI 标志一样),oxc 语言服务器遵循以下概念:每个工作区文件夹都可以有自己的配置。例如:Git 项目 A 使用类型感知的 lint,Git 项目 B 在自动保存时使用危险修复。

🌐 The language server can (like the CLI flags) be configured, the oxc language server follows the concept: Each workspace folder can have its own configuration. As an example: git project A uses type aware linting, git project B uses dangerous fixes on auto save.

更改配置

🌐 Changing Configuration

惊喜!用户可以随时更改语言服务器配置。编辑器会将更新后的配置发送给我们。 目前,服务器会向每个工具发送旧配置和新配置,因此它可以处理各种情况。 根据配置,工具可以重新启动或重建自身。

🌐 Surprise! The user can change the language server configuration on the fly. The editor will send us the updated configuration. Currently, the server will send each tool the old and new configuration, so it can handle all kinds of stuff. Depending on the configuration the tool can restart/rebuild itself.

查看模式与正在监视的文件变化

🌐 Watch Patterns & Changing watched files

你的工具可以告诉编辑器监视特定的文件(全局匹配)模式,并在文件被修改/创建/删除时通知服务器。这主要用于 .ox**rc.json 配置及其中引用的文件(例如来自 oxlintextends)。根据工作区和工具的配置,工具可能需要重新启动或重新构建自身。

🌐 Your tool can tell the editor to watch for specific file (glob) patterns and notify the server, when the file is changed/created/deleted. This is mostly used for the .ox**rc.json configuration and the referenced files inside of it (example extends from oxlint). Depending on the configuration of the workspace and the tool, the tool may need to restart/rebuild itself again.