Skip to content

Commit 771f995

Browse files
committed
feat(language_server): support textDocument/diagnostic
1 parent db0b099 commit 771f995

File tree

15 files changed

+437
-178
lines changed

15 files changed

+437
-178
lines changed

Cargo.lock

Lines changed: 45 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,7 @@ overflow-checks = true # Catch arithmetic overflow errors
287287
[profile.dev-no-debug-assertions]
288288
inherits = "dev"
289289
debug-assertions = false
290+
291+
[patch.crates-io]
292+
# this patch has the fix for `WorkspaceClientCapabilities`, see tower-lsp-community/tower-lsp-server#50
293+
lsp-types = { git = "https://github.com/tower-lsp-community/lsp-types", rev = "7332122ee5572c3f2c247b37cd1af77289b2e1c8" }

crates/oxc_language_server/README.md

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,33 @@ This crate provides an [LSP](https://microsoft.github.io/language-server-protoco
1414
- `quickfix`
1515
- `source.fixAll.oxc`, behaves the same as `quickfix` only used when the `CodeActionContext#only` contains
1616
`source.fixAll.oxc`.
17+
- [Diagnostic Provider](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics)
18+
- Only when [Diagnostics Refresh](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic_refresh) is supported by your client
1719

1820
## Workspace Options
1921

2022
These options can be passed with [initialize](#initialize), [workspace/didChangeConfiguration](#workspace/didChangeConfiguration) and [workspace/configuration](#workspace/configuration).
2123

22-
| Option Key | Value(s) | Default | Description |
23-
| ------------ | ---------------------- | ---------- | ---------------------------------------------------------------------------------------------------- |
24-
| `run` | `"onSave" \| "onType"` | `"onType"` | Should the server lint the files when the user is typing or saving |
25-
| `configPath` | `<string>` \| `null` | `null` | Path to a oxlint configuration file, passing a string will disable nested configuration |
26-
| `flags` | `Map<string, string>` | `<empty>` | Special oxc language server flags, currently only one flag key is supported: `disable_nested_config` |
24+
| Option Key | Value(s) | Default | Description |
25+
| ------------ | --------------------- | --------- | ---------------------------------------------------------------------------------------------------- |
26+
| `configPath` | `<string>` \| `null` | `null` | Path to a oxlint configuration file, passing a string will disable nested configuration |
27+
| `flags` | `Map<string, string>` | `<empty>` | Special oxc language server flags, currently only one flag key is supported: `disable_nested_config` |
28+
29+
### Flags
30+
31+
- `key: disable_nested_config`: Disabled nested configuration and searches only for `configPath`
32+
- `key: fix_kind`: default: `"safe_fix"`, possible values `"safe_fix" | "safe_fix_or_suggestion" | "dangerous_fix" | "dangerous_fix_or_suggestion" | "none" | "all"`
33+
34+
### Workspace Options without Diagnostic Provider
35+
36+
| Option Key | Value(s) | Default | Description |
37+
| ---------- | ---------------------- | ---------- | ------------------------------------------------------------------ |
38+
| `run` | `"onSave" \| "onType"` | `"onType"` | Should the server lint the files when the user is typing or saving |
39+
40+
## Diagnostics Modes
41+
42+
Depending on the client, the server will push diagnostics, or will wait for a pull request from the client.
43+
The server will prefer pull diagnostics when the client supports it and able to support [textDocument/diagnostic/refresh](#textdocumentdiagnosticrefresh).
2744

2845
## Supported LSP Specifications from Server
2946

@@ -45,11 +62,6 @@ The client can pass the workspace options like following:
4562
}
4663
```
4764

48-
#### Flags
49-
50-
- `key: disable_nested_config`: Disabled nested configuration and searches only for `configPath`
51-
- `key: fix_kind`: default: `"safe_fix"`, possible values `"safe_fix" | "safe_fix_or_suggestion" | "dangerous_fix" | "dangerous_fix_or_suggestion" | "none" | "all"`
52-
5365
### [initialized](https://microsoft.github.io/language-server-protocol/specification#initialized)
5466

5567
When the client did not pass the workspace configuration in [initialize](#initialize), the server will request the configuration for every workspace with [workspace/configuration](#workspaceconfiguration).
@@ -107,31 +119,39 @@ Executes a [Command](https://microsoft.github.io/language-server-protocol/specif
107119

108120
#### [textDocument/didOpen](https://microsoft.github.io/language-server-protocol/specification#textDocument_didOpen)
109121

110-
The server will validate the file content and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
122+
The server will cache the internal content of the text document.
123+
When the server is using [Push Mode](#diagnostics-modes),
124+
the server will validate the text document and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
111125

112126
#### [textDocument/didSave](https://microsoft.github.io/language-server-protocol/specification#textDocument_didSave)
113127

114-
When the configuration `run` is set to `onSave`, the server will validate the file content and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
128+
The server will cache the internal content of the text document.
129+
When the server is using [Push Mode](#diagnostics-modes) and configuration `run` is set to `onSave`,
130+
the server will validate the text document and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
115131

116132
#### [textDocument/didChange](https://microsoft.github.io/language-server-protocol/specification#textDocument_didChange)
117133

118-
When the configuration `run` is set to `onType`, the server will validate the file content and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
134+
The server will cache the internal content of the text document.
135+
When the server is using [Push Mode](#diagnostics-modes) and configuration `run` is set to `onType`,
136+
the server will validate the text document and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
119137

120138
#### [textDocument/didClose](https://microsoft.github.io/language-server-protocol/specification#textDocument_didClose)
121139

122140
It will remove the reference internal.
123141

124-
#### [textDocument/codeAction](https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction)
142+
#### [textDocument/diagnostics](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_diagnostic)
125143

126-
Returns a list of [CodeAction](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction)
144+
Should only be used when the server is using the [Pull Mode](#diagnostics-modes) for diagnostics.
145+
The server will lint the file and report the diagnostics back to the client.
127146

128-
## Expected LSP Specification from Client
147+
#### [textDocument/diagnostic/refresh](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic_refresh)
129148

130-
### TextDocument
149+
When the server is using the [Pull Mode](#diagnostics-modes) it will request the client sometimes to re-pull the diagnostics.
150+
This will happened when the changing watched files or changing specific server configurations.
131151

132-
#### [textDocument/publishDiagnostics](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics)
152+
#### [textDocument/codeAction](https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction)
133153

134-
Returns a [PublishDiagnostic object](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#publishDiagnosticsParams)
154+
Returns a list of [CodeAction](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction)
135155

136156
## Optional LSP Specifications from Client
137157

@@ -145,6 +165,13 @@ The server will send this request to watch for specific files. The method `works
145165

146166
The server will send this request to stop watching for specific files. The `id` will match from [client/registerCapability](#clientregistercapability).
147167

168+
### TextDocument
169+
170+
#### [textDocument/publishDiagnostics](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics)
171+
172+
When the server is using [Push Mode](#diagnostics-modes) it will lint the file [onOpen](#textdocumentdidopen) and [onChange](#textdocumentdidchange) or [onSave](#textdocumentdidsave]
173+
(depending on the configuration the client passed).
174+
148175
### Workspace
149176

150177
#### [workspace/configuration](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration)

0 commit comments

Comments
 (0)