Add a command to clear flycheck diagnostics

This commit is contained in:
Lukas Wirth 2022-12-17 23:43:26 +01:00
parent d8ddde27f9
commit cf8d89e46b
7 changed files with 64 additions and 2 deletions

View file

@ -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 {

View file

@ -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) {

View file

@ -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`

View file

@ -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": [

View file

@ -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;

View file

@ -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");

View file

@ -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 },