Skip to content

Commit cf8d89e

Browse files
committed
Add a command to clear flycheck diagnostics
1 parent d8ddde2 commit cf8d89e

File tree

7 files changed

+64
-2
lines changed

7 files changed

+64
-2
lines changed

crates/rust-analyzer/src/lsp_ext.rs

+7
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ impl Notification for RunFlycheck {
144144
const METHOD: &'static str = "rust-analyzer/runFlycheck";
145145
}
146146

147+
pub enum ClearFlycheck {}
148+
149+
impl Notification for ClearFlycheck {
150+
type Params = ();
151+
const METHOD: &'static str = "rust-analyzer/clearFlycheck";
152+
}
153+
147154
#[derive(Deserialize, Serialize, Debug)]
148155
#[serde(rename_all = "camelCase")]
149156
pub struct RunFlycheckParams {

crates/rust-analyzer/src/main_loop.rs

+4
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,10 @@ impl GlobalState {
861861
}
862862
Ok(())
863863
})?
864+
.on::<lsp_ext::ClearFlycheck>(|this, ()| {
865+
this.diagnostics.clear_check_all();
866+
Ok(())
867+
})?
864868
.on::<lsp_ext::RunFlycheck>(|this, params| {
865869
if let Some(text_document) = params.text_document {
866870
if let Ok(vfs_path) = from_proto::vfs_path(&text_document.uri) {

docs/dev/lsp-extensions.md

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!---
2-
lsp_ext.rs hash: 1cb29d3afa36e743
2+
lsp_ext.rs hash: 45bd7985265725c5
33
44
If you need to change the above hash to make the test pass, please check if you
55
need to adjust this doc as well and ping this issue:
@@ -459,6 +459,45 @@ Note that this functionality is intended primarily to inform the end user about
459459
In particular, it's valid for the client to completely ignore this extension.
460460
Clients are discouraged from but are allowed to use the `health` status to decide if it's worth sending a request to the server.
461461

462+
### Controlling Flycheck
463+
464+
The flycheck/checkOnSave feature can be controlled via notifications sent by the client to the server.
465+
466+
**Method:** `rust-analyzer/runFlycheck`
467+
468+
**Notification:**
469+
470+
```typescript
471+
interface RunFlycheckParams {
472+
/// The text document whose cargo workspace flycheck process should be started.
473+
/// If the document is null or does not belong to a cargo workspace all flycheck processes will be started.
474+
textDocument: lc.TextDocumentIdentifier | null;
475+
}
476+
```
477+
478+
Triggers the flycheck processes.
479+
480+
481+
**Method:** `rust-analyzer/clearFlycheck`
482+
483+
**Notification:**
484+
485+
```typescript
486+
interface ClearFlycheckParams {}
487+
```
488+
489+
Clears the flycheck diagnostics.
490+
491+
**Method:** `rust-analyzer/cancelFlycheck`
492+
493+
**Notification:**
494+
495+
```typescript
496+
interface CancelFlycheckParams {}
497+
```
498+
499+
Cancels all running flycheck processes.
500+
462501
## Syntax Tree
463502

464503
**Method:** `rust-analyzer/syntaxTree`

editors/code/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@
251251
"command": "rust-analyzer.runFlycheck",
252252
"title": "Run flycheck",
253253
"category": "rust-analyzer"
254+
},
255+
{
256+
"command": "rust-analyzer.clearFlycheck",
257+
"title": "Clear flycheck diagnostics",
258+
"category": "rust-analyzer"
254259
}
255260
],
256261
"keybindings": [

editors/code/src/commands.ts

+6
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,12 @@ export function cancelFlycheck(ctx: CtxInit): Cmd {
792792
};
793793
}
794794

795+
export function clearFlycheck(ctx: CtxInit): Cmd {
796+
return async () => {
797+
await ctx.client.sendNotification(ra.clearFlycheck);
798+
};
799+
}
800+
795801
export function runFlycheck(ctx: CtxInit): Cmd {
796802
return async () => {
797803
const editor = ctx.activeRustEditor;

editors/code/src/lsp_ext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, Te
8080
);
8181

8282
export const cancelFlycheck = new lc.NotificationType0("rust-analyzer/cancelFlycheck");
83-
83+
export const clearFlycheck = new lc.NotificationType0("rust-analyzer/clearFlycheck");
8484
export const runFlycheck = new lc.NotificationType<{
8585
textDocument: lc.TextDocumentIdentifier | null;
8686
}>("rust-analyzer/runFlycheck");

editors/code/src/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function createCommands(): Record<string, CommandFactory> {
150150
moveItemUp: { enabled: commands.moveItemUp },
151151
moveItemDown: { enabled: commands.moveItemDown },
152152
cancelFlycheck: { enabled: commands.cancelFlycheck },
153+
clearFlycheck: { enabled: commands.clearFlycheck },
153154
runFlycheck: { enabled: commands.runFlycheck },
154155
ssr: { enabled: commands.ssr },
155156
serverVersion: { enabled: commands.serverVersion },

0 commit comments

Comments
 (0)