-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
Allow disabling the formattingProvider #3283
Comments
UpdateRejecting requests with Therefore a potential solution should be to not propagate the format server capability in the first place. |
:o what... is this? I have never seen something where people try to stitch together multiple language servers. Is that even a thing?? I'm a little unclear what the behaviour you expect is. I think it's correct for a server to respond with an error if it gets a request it can't handle. I don't object to having a "none" option for formatting provider, though. |
Slightly offtopic but
I'm not sure if there are many places where it would make sense to have multiple servers for a single file, but I think it's technically possible and supported by clients. In is no 1:1 mapping from filetype to server in the client configuration, but each server typically is defined with a list of file types. For example having a spell checker and linter for markdown files or commit messages, or having a more general purpose language server (e.g. yaml syntax) combined with a more specific solution (e.g. AWS CoudFormation).
If I configure two servers and both can format the file, I'd say the behavior is not defined.
Correct, but ...
There are /**
* The server provides document formatting.
*/
documentFormattingProvider?: boolean | DocumentFormattingOptions And my assumption would be if there are two language servers defined for a file, but only one of them provides document formatting, then there is no conflict and formatting should work as expected. Long story shortIgnoring the background, ideally if the server is configured with |
I think the lsp library automatically determines them based on whether you have a handler for the corresponding functionality. So I think it might just work out if there is no formatting handler at all. |
This is the bit I don't understand. What is a "conflict"? I think there's some implicit model here where you can enable multiple servers, and then you expect them to advertise their capabilities very precisely (?) so that if you want to take an action you just look for the unique server that exposes that capability (?) and then send the request to that one (?). Or you send it to all of them, but you expect them to just ignore it if they don't handle it? I really don't know what the model is here, which makes it hard to know what to do... |
Might be the case. But it should also be possible to explicitly define them (like
My assumption would be that the client is smart enough to not send a formatting request to a server that states there is no formatting provider in it's capabilities. But it's just guessing at this point. Here seems to be a good starting point to see if that's the case for CoC. |
I mean you certainly can, I just mean that our library setup does that. |
I did some further investigation and had some progress. Yes, in case the language server responds initialization with
Also if there is a second language server that does support formatting, formatting will work with the second LS and ignore the first. Since I mentioned It might be tricky (or not possible?) to get access to the configuration before the server is initialized. On first glance it doesn't seem to be as easy as grabbing the current config and setting the value to |
Sorry, I think I haven't communicated it properly. HLS uses the |
Nope, your explanation was clear and I understood it. I would also assume that's the case 😌 I did my testing mostly with purescript-language-server since the project is easy to work with, there already exists an explicit For haskell-language-server one option could be to explicitly define the capabilities but another would be to filter out formatting handlers (if the assumption is correct). |
This is supported already, just not in an obvious way. To disable the formatter capability, you need to disable all the plugins that carry a EDIT: oh well, this won't work, as we register the request handlers unconditionally and then only run the ones that are enabled. Some work needed to fix that |
Is there any update to this? |
I'm confused about why formatting has anything to do with the responsibilities of HLS. All I ever want is for my "format document" command in vscode to do exactly the same thing that running the formatting program would do on the command line, and it never does. I'm perpetually frustrated that either because the formatter I need isn't supported, or HLS is for some reason invoking it differently. I just want HLS to back off and stop interfering on this. |
@chris-martin please weigh in on #411 |
This plugin is what my organization recommends for setting up our formatter: https://marketplace.visualstudio.com/items?itemName=SteefH.external-formatters I haven't been able to use it because HLS's formatter seems to take precedence over what I need to be using. |
The minimal thing I need is just to be able to set formattingProvider = null |
Workaround for using an external Install the jkillian.custom-local-formatters extension. Add the following to {
"[haskell]": {
"editor.defaultFormatter": "jkillian.custom-local-formatters"
},
"customLocalFormatters.formatters": [
{
"command": "fourmolu --stdin-input-file ${file}",
"languages": ["haskell"]
}
]
} |
I've had issues with the formatting capabilities of HLS, specifically using I found a way to stop sending formatting requests to HLS in neovim and instead use something like I added the vim.keymap.set(
'n',
'<space>lf',
function()
vim.lsp.buf.format {
async = true,
filter = function(client) return client.name ~= "haskell-tools.nvim" end
}
end,
{ noremap = true, silent = true, buffer = bufnr }
) In my case I am using the haskell-tools.nvim plugin that registers a custom hls intance, thus the |
The filter workaround is nice. but we can easily disable the formatting directly from the lsp config. inside the hls's set
that's all, I do the same with tsserver, I use biome instead for formatting. I hope it helped anyone who was trying to disable it. |
Is your enhancement request related to a problem? Please describe.
Disabling the
formattingProvider
configuration does not seem possible. There is a handful of options but it can't be disabled.The current implementation reacts formatting requests and then figures out there is plugin available. It will then result in an error
Options
https://github.com/haskell/haskell-language-server/blob/aee737237c7f4542bddc7ab31a2bdd7ee0cab48d/docs/configuration.md#language-specific-server-options
Why would one want to disable the formattingProvider?
Followup of #3282
In order to configure a separate generic language server (https://github.com/iamcco/diagnostic-languageserver) to deal with formatting, Haskell language server should not "catch" the formatting requests. Instead it has to be possible to disable formatting without completely disabling the language server.
Another possibility would be - this is a bit made up - that people could have arbitrary reasons to to configure no "formattingProvider", e.g. they have configured "format on save" or they often press the format shortcut out of habit, but don't want formatting to happen temporarily for a specific or Haskell projects in general.
Describe the solution you'd like
Either
""
or"none"
should be handled in a way where the language server behaves as if the formatting handler wouldn't be implemented.Maybe it is as simple as this...
Additional context
There is a test that defines how
"none"
is handled. It succeeds forMethodNotFound
but also""No plugin enabled for STextDocumentFormatting""
what is shown above. But this is not the wanted behavior since from the LSP client's perspective the request was handled.haskell-language-server/test/functional/Format.hs
Line 54 in b378de2
The text was updated successfully, but these errors were encountered: