Unnamed repository; edit this file 'description' to name the repository.
Add a command to clear flycheck diagnostics
Lukas Wirth 2022-12-18
parent d8ddde2 · commit cf8d89e
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs7
-rw-r--r--crates/rust-analyzer/src/main_loop.rs4
-rw-r--r--docs/dev/lsp-extensions.md41
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/commands.ts6
-rw-r--r--editors/code/src/lsp_ext.ts2
-rw-r--r--editors/code/src/main.ts1
7 files changed, 64 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index f03b8398c1..65620b4209 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -144,6 +144,13 @@ impl Notification for RunFlycheck {
const METHOD: &'static str = "rust-analyzer/runFlycheck";
}
+pub enum ClearFlycheck {}
+
+impl Notification for ClearFlycheck {
+ type Params = ();
+ const METHOD: &'static str = "rust-analyzer/clearFlycheck";
+}
+
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RunFlycheckParams {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index add999504d..47776f734b 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -861,6 +861,10 @@ impl GlobalState {
}
Ok(())
})?
+ .on::<lsp_ext::ClearFlycheck>(|this, ()| {
+ this.diagnostics.clear_check_all();
+ Ok(())
+ })?
.on::<lsp_ext::RunFlycheck>(|this, params| {
if let Some(text_document) = params.text_document {
if let Ok(vfs_path) = from_proto::vfs_path(&text_document.uri) {
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 308a92bebe..1bbb4c2323 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,5 +1,5 @@
<!---
-lsp_ext.rs hash: 1cb29d3afa36e743
+lsp_ext.rs hash: 45bd7985265725c5
If you need to change the above hash to make the test pass, please check if you
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
In particular, it's valid for the client to completely ignore this extension.
Clients are discouraged from but are allowed to use the `health` status to decide if it's worth sending a request to the server.
+### Controlling Flycheck
+
+The flycheck/checkOnSave feature can be controlled via notifications sent by the client to the server.
+
+**Method:** `rust-analyzer/runFlycheck`
+
+**Notification:**
+
+```typescript
+interface RunFlycheckParams {
+ /// The text document whose cargo workspace flycheck process should be started.
+ /// If the document is null or does not belong to a cargo workspace all flycheck processes will be started.
+ textDocument: lc.TextDocumentIdentifier | null;
+}
+```
+
+Triggers the flycheck processes.
+
+
+**Method:** `rust-analyzer/clearFlycheck`
+
+**Notification:**
+
+```typescript
+interface ClearFlycheckParams {}
+```
+
+Clears the flycheck diagnostics.
+
+**Method:** `rust-analyzer/cancelFlycheck`
+
+**Notification:**
+
+```typescript
+interface CancelFlycheckParams {}
+```
+
+Cancels all running flycheck processes.
+
## Syntax Tree
**Method:** `rust-analyzer/syntaxTree`
diff --git a/editors/code/package.json b/editors/code/package.json
index bfaad1edce..f9b0e28dad 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -251,6 +251,11 @@
"command": "rust-analyzer.runFlycheck",
"title": "Run flycheck",
"category": "rust-analyzer"
+ },
+ {
+ "command": "rust-analyzer.clearFlycheck",
+ "title": "Clear flycheck diagnostics",
+ "category": "rust-analyzer"
}
],
"keybindings": [
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 283771f270..cb4e13e2c6 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -792,6 +792,12 @@ export function cancelFlycheck(ctx: CtxInit): Cmd {
};
}
+export function clearFlycheck(ctx: CtxInit): Cmd {
+ return async () => {
+ await ctx.client.sendNotification(ra.clearFlycheck);
+ };
+}
+
export function runFlycheck(ctx: CtxInit): Cmd {
return async () => {
const editor = ctx.activeRustEditor;
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index 6f63084108..29349cc20f 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -80,7 +80,7 @@ export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, Te
);
export const cancelFlycheck = new lc.NotificationType0("rust-analyzer/cancelFlycheck");
-
+export const clearFlycheck = new lc.NotificationType0("rust-analyzer/clearFlycheck");
export const runFlycheck = new lc.NotificationType<{
textDocument: lc.TextDocumentIdentifier | null;
}>("rust-analyzer/runFlycheck");
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index c5fc44b4f9..9a9667b2cd 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -150,6 +150,7 @@ function createCommands(): Record<string, CommandFactory> {
moveItemUp: { enabled: commands.moveItemUp },
moveItemDown: { enabled: commands.moveItemDown },
cancelFlycheck: { enabled: commands.cancelFlycheck },
+ clearFlycheck: { enabled: commands.clearFlycheck },
runFlycheck: { enabled: commands.runFlycheck },
ssr: { enabled: commands.ssr },
serverVersion: { enabled: commands.serverVersion },