-
Notifications
You must be signed in to change notification settings - Fork 172
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
Auto detect formatter when client did not specify it #723
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, the server should always set it's defaults internally if nothing is received.
Can you please sign the CLA?
lib/ruby_lsp/executor.rb
Outdated
@@ -421,7 +421,7 @@ def initialize_request(options) | |||
end | |||
|
|||
formatter = options.dig(:initializationOptions, :formatter) | |||
@store.formatter = if formatter == "auto" | |||
@store.formatter = if formatter == "auto" || formatter == '' || formatter.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any scenario where formatter would be an empty string instead of nil
?
I don't believe there would be. If it can only be nil
, let's move this up instead and do
formatter = options.dig(:initializationOptions, :formatter) || "auto"
I have signed the CLA! |
@asok there's a minor linting issue to address. |
Thanks for the contribution! CI is failing, but it's unrelated to these changes. |
Motivation
I was playing with ruby-lsp and Emacs client eglot and I noticed that formatting of the buffer is not working. It seems that the client is not passing the "auto" formatter in the
initializationOptions
.I'm very green to lsp so I don't quite understand everything. But when following this thread I've read that the server should apply defaults by itself:
Implementation
Assume by default that the formatter should be auto detected if the initialization option is missing.
Automated Tests
No automated tests yet since I'm opening a draft pull request in order to find out if it's the right way to proceed.
Manual Tests
~/.emacs.d/init.el
file with contents:eglot
command in Emacseglot-format-buffer
command in Emacs, you should see the error message "Unknown formatter: " in the minibufferruby-lsp
gemeglot-reconnect
command in Emacseglot-format-buffer
command in Emacs, you should not see the error