From 42a744091a2b9c3082169fab10e82c0eb311d0ba Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 18 Sep 2023 19:56:22 +0200 Subject: [PATCH] Fail textDocument/formatting when no formatter is set Currently, nil silently fails when no formatter is set. This caused me a lot of confusion as to why nothing was formatting when I accidentally misconfigured the formatter. This makes it so that we return an error instead, alerting the user that something is wrong. This could be annoying to someone who hasn't configured a formatter on purpose but still causes formatting events, either by format-on-save or muscle memory. I think this is fine, and they should turn off format-on-save or just get a formatter instead. Alternatively, someone could set `cat` as their formatter. --- crates/nil/src/handler.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/nil/src/handler.rs b/crates/nil/src/handler.rs index 6ea3540..7dea0d4 100644 --- a/crates/nil/src/handler.rs +++ b/crates/nil/src/handler.rs @@ -221,9 +221,10 @@ pub(crate) fn formatting( Ok(stdout) } - let Some(cmd) = &snap.config.formatting_command else { - return Ok(None); - }; + let cmd = + snap.config.formatting_command.as_ref().context( + "No formatter configured. Set the nil.formatting.command LSP server setting.", + )?; let (file_content, line_map) = { let vfs = snap.vfs();