1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-22 02:55:39 +03:00

Fail textDocument/formatting when no formatter is set (#108)

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.
This commit is contained in:
Nilstrieb 2023-09-23 18:03:37 +02:00 committed by GitHub
parent 4775e34c30
commit 510bc6e9b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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