Skip to content

Commit 53bdcac

Browse files
authored
docs(language_server): add contribute guide for oxc_language_server (#709)
1 parent 8634168 commit 53bdcac

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

.vitepress/config/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export const enConfig = defineLocaleConfig("root", {
258258
link: "/docs/contribute/transformer",
259259
},
260260
{ text: "Minifier", link: "/docs/contribute/minifier" },
261+
{ text: "Language Server", link: "/docs/contribute/language_server" },
261262
{ text: "VSCode", link: "/docs/contribute/vscode" },
262263
],
263264
},
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Language Server
3+
outline: deep
4+
---
5+
6+
This page tells you the main concept of the `oxc_language_server` and what the differences to the CLI are.
7+
If you want to learn more about the communication between the language server and the editor, the official [LSP/LSIF documentation](https://microsoft.github.io/language-server-protocol/) is a great start.
8+
The [`README.md`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_language_server/README.md) of the language server has a quick overview of the relevant specs.
9+
10+
Note: In this document we will talk a lot about "tools", this is an abstract concept of the core logic for `oxlint` and `oxfmt`.
11+
12+
## `oxc_language_server` concept of implementing tools
13+
14+
`oxc_language_server` can be used to upgrade your own script with the capability to work as a language server.
15+
The server on its own does not change your files or create suggestions. This is the responsibility of the tool.
16+
Instead, it manages the workspace folders and all the communication for loading the right configuration.
17+
To communicate with the provided tools, the server provides a [`ToolBuilder` and `Tool` trait](https://github.com/oxc-project/oxc/blob/main/crates/oxc_language_server/src/tool.rs).
18+
19+
## Difference between Language Server and CLI
20+
21+
### Editors changes the file, server communicates the changes
22+
23+
A small but important part about the communication of a file and the fix of it.
24+
The CLI Tools are writing the changes to the file system.
25+
The (oxc) language server should NEVER write to it, instead it just communicates it changes to the editor.
26+
27+
### Workspace Folders
28+
29+
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.
30+
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.
31+
You can think of a workspace URI as the same as a "current working directory" for the CLI tool.
32+
Keep in mind that a workspace folder can be added / removed by the editor.
33+
34+
### Configurations (with folders)
35+
36+
The language server can (like the CLI flags) be configured, the oxc language server follows the concept:
37+
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.
38+
39+
### Changing Configuration
40+
41+
Surprise! The user can change the language server configuration on the fly. The editor will send us the updated configuration.
42+
Currently, the server will send each tool the old and new configuration, so it can handle all kinds of stuff.
43+
Depending on the configuration the tool can restart/rebuild itself.
44+
45+
### Watch Patterns & Changing watched files
46+
47+
Your tool can tell the editor to watch for specific file (glob) patterns and notify the server, when the file is changed/created/deleted.
48+
This is mostly used for the `.ox**rc.json` configuration and the referenced files inside of it (example `extends` from `oxlint`).
49+
Depending on the configuration of the workspace and the tool, the tool may need to restart/rebuild itself again.

0 commit comments

Comments
 (0)