Skip to content

Commit e627309

Browse files
committed
feat(language_server): support textDocument/diagnostic
1 parent 094b81c commit e627309

File tree

14 files changed

+427
-167
lines changed

14 files changed

+427
-167
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,8 @@ 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" }
294+
tower-lsp-server = { git = "https://github.com/tower-lsp-community/tower-lsp-server", rev = "27cbe421c6cdc6e9cd607abaf1ece8c060e5cd4e" }

crates/oxc_language_server/README.md

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,34 @@ 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-
| `unusedDisableDirectives` | `"allow" \| "warn"` \| "deny"` | `"allow"` | Define how directive comments like `// oxlint-disable-line` should be reported, when no errors would have been reported on that line anyway |
27-
| `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+
| `unusedDisableDirectives` | `"allow" \| "warn"` \| "deny"` | `"allow"` | Define how directive comments like `// oxlint-disable-line` should be reported, when no errors would have been reported on that line anyway |
28+
| `flags` | `Map<string, string>` | `<empty>` | Special oxc language server flags, currently only one flag key is supported: `disable_nested_config` |
29+
30+
### Flags
31+
32+
- `key: disable_nested_config`: Disabled nested configuration and searches only for `configPath`
33+
- `key: fix_kind`: default: `"safe_fix"`, possible values `"safe_fix" | "safe_fix_or_suggestion" | "dangerous_fix" | "dangerous_fix_or_suggestion" | "none" | "all"`
34+
35+
### Workspace Options without Diagnostic Provider
36+
37+
| Option Key | Value(s) | Default | Description |
38+
| ---------- | ---------------------- | ---------- | ------------------------------------------------------------------ |
39+
| `run` | `"onSave" \| "onType"` | `"onType"` | Should the server lint the files when the user is typing or saving |
40+
41+
## Diagnostics Modes
42+
43+
Depending on the client, the server will push diagnostics, or will wait for a pull request from the client.
44+
The server will prefer pull diagnostics when the client supports it and able to support [textDocument/diagnostic/refresh](#textdocumentdiagnosticrefresh).
2845

2946
## Supported LSP Specifications from Server
3047

@@ -47,11 +64,6 @@ The client can pass the workspace options like following:
4764
}
4865
```
4966

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

5769
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).
@@ -110,31 +122,39 @@ Executes a [Command](https://microsoft.github.io/language-server-protocol/specif
110122

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

113-
The server will validate the file content and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
125+
The server will cache the internal content of the text document.
126+
When the server is using [Push Mode](#diagnostics-modes),
127+
the server will validate the text document and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
114128

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

117-
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.
131+
The server will cache the internal content of the text document.
132+
When the server is using [Push Mode](#diagnostics-modes) and configuration `run` is set to `onSave`,
133+
the server will validate the text document and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
118134

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

121-
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.
137+
The server will cache the internal content of the text document.
138+
When the server is using [Push Mode](#diagnostics-modes) and configuration `run` is set to `onType`,
139+
the server will validate the text document and send a [textDocument/publishDiagnostics](#textdocumentpublishdiagnostics) request to the client.
122140

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

125143
It will remove the reference internal.
126144

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

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

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

133-
### TextDocument
152+
When the server is using the [Pull Mode](#diagnostics-modes) it will request the client sometimes to re-pull the diagnostics.
153+
This will happen when changing watched files or specific server configurations.
134154

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

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

139159
## Optional LSP Specifications from Client
140160

@@ -148,6 +168,13 @@ The server will send this request to watch for specific files. The method `works
148168

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

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

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

0 commit comments

Comments
 (0)