Skip to content

Commit

Permalink
Fail textDocument/formatting when no formatter is set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Noratrieb committed Sep 23, 2023
1 parent 4775e34 commit 42a7440
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/nil/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 42a7440

Please sign in to comment.