这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@Noratrieb
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
@Noratrieb Noratrieb 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.

2 participants