Repository navigation
bug: Selection formatting doesn't work as expected with fallback LSP #63
Description
Activity
- changed the title
[-]bug: [/-][+]bug: Selection formatting doesn't work as expected with fallback LSP[/+]on Sep 19, 2023 - added a commit that references this issue
on Sep 19, 2023 Thanks for the report! There was indeed a bug with range formatting and LSP. Should be fixed!
Reacted by Jędrzej OrbikThat was an extremely fast fix! Thank you :)
Hmm if I test it locally i still get the unexpected behavior on
<leader>f- whole file is being formatted instead of just the selection. Could you please check that?Using the repro steps
nvim -u repro.lua test.cpp- Vjj to highlight the first three lines
<leader>f
The first three lines get de-indented, and the rest of the file is unaffected.
Can you double check that you're on the most recent version of conform? And if your process is different, could you give me exact repro steps for the problem?
Oh, right. I'm sorry for not being specific. My steps are:
nvim -u repro.lua test.cpp- jjVj to select lines 3-4.
<leader>f
As the result not only lines 3-4 are being formatted but all lines starting from the 3rd line. Besides the visual selection stays active.
Ah, this is just the behavior of the LSP server. It's likely formatting the entirety of the main function because you have part of it selected. There's not much we can do about that, since it's just how range formatting works for clangd. You can verify that this is just the built-in LSP behavior by changing the mapping to call
vim.lsp.buf.format({ async = true })instead.Reacted by Jędrzej OrbikOh, and if you want to not be in visual mode after the formatting, you can add this line after the call to
format()(again, this would also be necessary forvim.lsp.buf.format)vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<ESC>", true, true, true), "n", true)
Reacted by Syakhisk Al-AzmiYou are right, sorry for the confusion and thank you for your patience! I'll tweak it with the command above :)
Neovim version (nvim -v)
NVIM v0.8.3
Operating system/version
MacOS 13.5.2
Output of :ConformInfo
Log file: /Users/Jedrzej/.local/state/nvim/conform.log
Formatters for this buffer:
LSP: clangd
Other formatters:
Describe the bug
I tried following this example to set up the formatting of selection: #40
The selection formatting with
require("conform").format({ async = true, lsp_fallback = true })doesn't work as expected with LSP fallback formatting clangd - the whole file is being formatted instead of just the selection and the visual mode stays active. The formatting of the selection works fine though with the other solution:Formatuser command suggested in the same post.Steps To Reproduce
Expected Behavior
In both cases the selection formatting works as expected as suggested in the post #40
Minimal example file
Minimal init.lua
Additional context
I tried fixing the issue but am not versatile in neovim API. If there is an easy workaround that would help too! The problem is that even setting something like:
results in the unexpected behavior with selection formatting, but if I manually type
:Formateverything works as expected.