Comments (9)
I created a badly formatted shell script and tried to :Format
it with some logging added on the previously mentioned lines. Here's what I got:
-- client.request call
{
bufnr = 1,
handler = <function 1>,
method = "textDocument/formatting",
params = {
options = {
insertSpaces = true,
tabSize = 2
},
textDocument = {
uri = "file:///home/mange/Projects/dotfiles/foo.sh"
}
}
}
-- _handler being called with
{
ctx = {
bufnr = 1,
client_id = 1,
method = "textDocument/formatting",
params = {
options = {
insertSpaces = true,
tabSize = 2
},
textDocument = {
uri = "file:///home/mange/Projects/dotfiles/foo.sh"
}
}
},
err = {
code = -32601,
message = "Unhandled method textDocument/formatting",
<metatable> = {
__tostring = <function 1>
}
}
}
I have two LSPs for shells: bashls
and null-ls
. bashls
does not handle formatting, so the error makes sense. However, I would expect the handler and formatting to be called again for null-ls
, but there's only this one call.
I then tried disabling bashls
and restarted so only null-ls
was attached. If I run :Format
now nothing is logged at all.
By stepping through all the conditionals I figured out that the problem was that M.buffers
were empty.
β¦aaaand, here we are. Turns out I set up on_attach
on all LSP servers but null-ls
, since it was placed in a different section much further down and I forgot to check it.
So another one one the pile; misconfiguration in the PEBKAC module. π
from lsp-format.nvim.
π
Yes the behavior changed, but I consider it a bug that this worked before.
To be used for formatting, each LSP now needs to be attached individually.
Before it used all servers once it was called for one server on the buffer.
from lsp-format.nvim.
I went to my checked out package and jumped between different versions.
It broke completely on v2.3.0, same symptoms as listed in description.
The version before it, v2.2.3 still works, but only when formatting a saved changed buffer. Running :Format
on an unchanged buffer does nothing. Seems this is a separate problem.
from lsp-format.nvim.
can you make a minimal init.lua
file that reproduces this?
from lsp-format.nvim.
I just tried installing for the first time and formatting using this plugin is not working for me either. Using nvim 0.7 stable, though.
from lsp-format.nvim.
Also confirm that this PR broke :Format
: https://github.com/lukas-reineke/lsp-format.nvim/pull/33/files. If you've got any debug statements I can try adding to help, happy to tell you the result. I don't have time to make a minimal repro, sorry.
from lsp-format.nvim.
Alright, let's try to add some logging to debug then.
The first obvious ones are here
lsp-format.nvim/lua/lsp-format/init.lua
Line 166 in 2fcb2c9
And here
lsp-format.nvim/lua/lsp-format/init.lua
Line 124 in 2fcb2c9
from lsp-format.nvim.
I figured it out, at least for me. What has changed is the behaviour when LSP on_attach is not properly configured. The fix is to properly attach lsp-format to your LSPs. (FWIW, the requirement to do careful configuration didn't jump out at me, and I just blindly copy/pasted the default config, go and all π)
Specifically, if an LSP is missing the require("lsp-format").on_attach(client)
requirement, as mine was, then on commit db45b37
autoformat will not work (and perhaps never did). :Format
will, though.
The commit that "broke" :Format
is actually 4ba2f95f78af8b2d4d99c8ebe32074c529101b32
(I bisected). And this makes sense, considering that commit says "Don't format with client if on_attach
was not called for that client"
Thanks for your time @lukas-reineke, appreciate the debug help (and the plugin!)
from lsp-format.nvim.
I consider it a bug that this worked before
Me too :). Thanks again.
from lsp-format.nvim.
Related Issues (20)
- Can you give us a clearer example of how to use the on_attach function? HOT 1
- Enable/disable per buffer HOT 2
- support sync save for global HOT 1
- [Question] Unable to format python with black formatter HOT 4
- Can you add autocommand event? HOT 3
- Setting up without messing up previous settings? HOT 1
- [Feature Request] Dont add the format to undo HOT 2
- messes up files when writing into multiple files at once with multiple formating lsp providers HOT 3
- My BufWritePost/BufWritePre are being triggered twice HOT 1
- Don't format if file path matches glob HOT 2
- fix failing workflows
- [Feature Request] Format code in range
- Enabling eslint HOT 5
- Does lsp-format supports `shfmt` & `stylua` ? HOT 1
- Format on auto save HOT 1
- Format-on-save doesn't work, but calling `:lua vim.lsp.buf.format()` does HOT 1
- `lsp-format.nvim` changes the buffer when write to file twice during a short time of period
- `vim.lsp.buf.format()` formats, but `:Format` does not HOT 5
- If two files are edited and saved at the same time (:wa), the contents of one file will be overwritten by the contents of the other HOT 12
- Infinite loop of formatting HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lsp-format.nvim.