Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail textDocument/formatting when no formatter is set #108

Merged
merged 1 commit into from
Sep 23, 2023
Merged

Fail textDocument/formatting when no formatter is set #108

merged 1 commit into from
Sep 23, 2023

Conversation

Nilstrieb
Copy link
Contributor

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.

image

[Error - 8:02:06 PM] Request textDocument/formatting failed.
Message: No formatter configured. Set the nil.formatting.command LSP server setting.
Code: -32603

@oxalica
Copy link
Owner

oxalica commented Sep 22, 2023

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.

That's reasonable. Thanks!

Comment on lines 224 to 226
let Some(cmd) = &snap.config.formatting_command else {
return Ok(None);
bail!("No formatter configured. Set the nil.formatting.command LSP server setting.");
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this can be:

Suggested change
let Some(cmd) = &snap.config.formatting_command else {
return Ok(None);
bail!("No formatter configured. Set the nil.formatting.command LSP server setting.");
};
let cmd = snap
.config
.formatting_command
.as_ref()
.context("No formatter configured. Set the nil.formatting.command LSP server setting.")?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! It still prints the useful message with context:

[Error - 3:18:09 PM] Request textDocument/formatting failed.
  Message: No formatter configured. Set the nil.formatting.command LSP server setting.
  Code: -32603 

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.
@oxalica oxalica merged commit 510bc6e into oxalica:main Sep 23, 2023
10 checks passed
@Nilstrieb Nilstrieb deleted the fail-fmt branch September 23, 2023 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants