Auto merge of #13792 - Veykril:flycheck, r=Veykril
Add a command to clear flycheck diagnostics And document the flycheck notifications
This commit is contained in:
commit
9ed1829f1f
@ -1125,11 +1125,8 @@ pub fn rustfmt(&self) -> RustfmtConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flycheck(&self) -> Option<FlycheckConfig> {
|
||||
if !self.data.checkOnSave_enable {
|
||||
return None;
|
||||
}
|
||||
let flycheck_config = match &self.data.checkOnSave_overrideCommand {
|
||||
pub fn flycheck(&self) -> FlycheckConfig {
|
||||
match &self.data.checkOnSave_overrideCommand {
|
||||
Some(args) if !args.is_empty() => {
|
||||
let mut args = args.clone();
|
||||
let command = args.remove(0);
|
||||
@ -1183,8 +1180,11 @@ pub fn flycheck(&self) -> Option<FlycheckConfig> {
|
||||
extra_args: self.data.checkOnSave_extraArgs.clone(),
|
||||
extra_env: self.check_on_save_extra_env(),
|
||||
},
|
||||
};
|
||||
Some(flycheck_config)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_on_save(&self) -> bool {
|
||||
self.data.checkOnSave_enable
|
||||
}
|
||||
|
||||
pub fn runnables(&self) -> RunnablesConfig {
|
||||
|
@ -132,9 +132,8 @@ pub struct ExpandedMacro {
|
||||
|
||||
pub enum CancelFlycheck {}
|
||||
|
||||
impl Request for CancelFlycheck {
|
||||
impl Notification for CancelFlycheck {
|
||||
type Params = ();
|
||||
type Result = ();
|
||||
const METHOD: &'static str = "rust-analyzer/cancelFlycheck";
|
||||
}
|
||||
|
||||
@ -145,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 {
|
||||
|
@ -581,10 +581,7 @@ fn handle_flycheck_msg(&mut self, message: flycheck::Message) {
|
||||
// When we're running multiple flychecks, we have to include a disambiguator in
|
||||
// the title, or the editor complains. Note that this is a user-facing string.
|
||||
let title = if self.flycheck.len() == 1 {
|
||||
match self.config.flycheck() {
|
||||
Some(config) => format!("{}", config),
|
||||
None => "cargo check".to_string(),
|
||||
}
|
||||
format!("{}", self.config.flycheck())
|
||||
} else {
|
||||
format!("cargo check (#{})", id + 1)
|
||||
};
|
||||
@ -593,7 +590,7 @@ fn handle_flycheck_msg(&mut self, message: flycheck::Message) {
|
||||
state,
|
||||
message,
|
||||
None,
|
||||
Some(format!("rust-analyzer/checkOnSave/{}", id)),
|
||||
Some(format!("rust-analyzer/flycheck/{}", id)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -638,7 +635,6 @@ fn on_request(&mut self, req: Request) {
|
||||
.on_sync_mut::<lsp_ext::ReloadWorkspace>(handlers::handle_workspace_reload)
|
||||
.on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)
|
||||
.on_sync_mut::<lsp_ext::ShuffleCrateGraph>(handlers::handle_shuffle_crate_graph)
|
||||
.on_sync_mut::<lsp_ext::CancelFlycheck>(handlers::handle_cancel_flycheck)
|
||||
.on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)
|
||||
.on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)
|
||||
.on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)
|
||||
@ -796,7 +792,7 @@ fn run_flycheck(this: &mut GlobalState, vfs_path: VfsPath) -> bool {
|
||||
})?
|
||||
.on::<lsp_types::notification::WorkDoneProgressCancel>(|this, params| {
|
||||
if let lsp_types::NumberOrString::String(s) = ¶ms.token {
|
||||
if let Some(id) = s.strip_prefix("rust-analyzer/checkOnSave/") {
|
||||
if let Some(id) = s.strip_prefix("rust-analyzer/flycheck/") {
|
||||
if let Ok(id) = u32::from_str_radix(id, 10) {
|
||||
if let Some(flycheck) = this.flycheck.get(id as usize) {
|
||||
flycheck.cancel();
|
||||
@ -825,6 +821,7 @@ fn run_flycheck(this: &mut GlobalState, vfs_path: VfsPath) -> bool {
|
||||
}
|
||||
Ok(())
|
||||
})?
|
||||
.on::<lsp_ext::CancelFlycheck>(handlers::handle_cancel_flycheck)?
|
||||
.on::<lsp_types::notification::DidChangeTextDocument>(|this, params| {
|
||||
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
||||
match this.mem_docs.get_mut(&path) {
|
||||
@ -864,6 +861,10 @@ fn run_flycheck(this: &mut GlobalState, vfs_path: VfsPath) -> bool {
|
||||
}
|
||||
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) {
|
||||
@ -888,14 +889,14 @@ fn run_flycheck(this: &mut GlobalState, vfs_path: VfsPath) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
if run_flycheck(this, vfs_path) {
|
||||
if !this.config.check_on_save() || run_flycheck(this, vfs_path) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// No specific flycheck was triggered, so let's trigger all of them.
|
||||
for flycheck in this.flycheck.iter() {
|
||||
flycheck.restart();
|
||||
} else if this.config.check_on_save() {
|
||||
// No specific flycheck was triggered, so let's trigger all of them.
|
||||
for flycheck in this.flycheck.iter() {
|
||||
flycheck.restart();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})?
|
||||
|
@ -449,15 +449,7 @@ fn fetch_build_data_error(&self) -> Result<(), String> {
|
||||
|
||||
fn reload_flycheck(&mut self) {
|
||||
let _p = profile::span("GlobalState::reload_flycheck");
|
||||
let config = match self.config.flycheck() {
|
||||
Some(it) => it,
|
||||
None => {
|
||||
self.flycheck = Arc::new([]);
|
||||
self.diagnostics.clear_check_all();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let config = self.config.flycheck();
|
||||
let sender = self.flycheck_sender.clone();
|
||||
let invocation_strategy = match config {
|
||||
FlycheckConfig::CargoCommand { .. } => flycheck::InvocationStrategy::PerWorkspace,
|
||||
|
@ -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`
|
||||
|
@ -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": [
|
||||
|
@ -788,7 +788,13 @@ export function openDocs(ctx: CtxInit): Cmd {
|
||||
|
||||
export function cancelFlycheck(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
await ctx.client.sendRequest(ra.cancelFlycheck);
|
||||
await ctx.client.sendNotification(ra.cancelFlycheck);
|
||||
};
|
||||
}
|
||||
|
||||
export function clearFlycheck(ctx: CtxInit): Cmd {
|
||||
return async () => {
|
||||
await ctx.client.sendNotification(ra.clearFlycheck);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, Te
|
||||
"rust-analyzer/relatedTests"
|
||||
);
|
||||
|
||||
export const cancelFlycheck = new lc.RequestType0<void, void>("rust-analyzer/cancelFlycheck");
|
||||
|
||||
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");
|
||||
|
@ -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 },
|
||||
|
Loading…
Reference in New Issue
Block a user