Skip to content

lsp_as_default_formatter not work #235

@BBboy01

Description

@BBboy01

Neovim version (nvim -v)

v0.11.5

Operating system/version

macOS Tahoe 26.1

Expected behaviour

Apply lsp formatter result

Actual behaviour

do nothing

Output of :checkhealth guard

==============================================================================
guard:                                                                    1 ⚠️

Executable check ~
- ✅ OK npx found
- ✅ OK stylua found
- ✅ OK gofumpt found
- ✅ OK shfmt found
- ✅ OK shellcheck found
- ✅ OK rustfmt found
- ✅ OK fish_indent found
- ⚠️ WARNING It seems that mason.nvim is installed,in which case checkhealth may be inaccurate. Please add your mason bin path to PATH to avoid potential issues.

Settings ~
- ✅ OK fmt_on_save: false
- ✅ OK lsp_as_default_formatter: true
- ✅ OK save_on_fmt: false

Tools registered for current buffer (bufnr 2) ~
- ✅ OK Current buffer has filetype toml:
- 1 formatter autocmds attached
- 0 linter autocmds attached
- formatters:
- {
    fn = <function 1>
  }

How to reproduce the issue

open a toml file

add taplo as lsp

:lua Guard fmt

I noticed the formatted code already generated but not applied success

vim.lsp.util.apply_text_edits = function(text_edits, _, offset_encoding)
-- the target buffer must be buf, we apply it to our scratch buffer
n_edits = n_edits - 1
vim.tbl_map(function(edit)
edit.range.start.line = edit.range.start.line - line_offset
edit.range['end'].line = edit.range['end'].line - line_offset
end, text_edits)
apply(text_edits, scratch, offset_encoding)
if n_edits == 0 then
vim.lsp.util.apply_text_edits = apply
local lines = api.nvim_buf_get_lines(scratch, 0, -1, false)
api.nvim_command('silent! bwipe! ' .. scratch)
coroutine.resume(co, table.concat(lines, '\n'))
end
end

After commenting out this code, formatter apply success

Are you sure this is a min repro?

  • I understand that if my repro step is too complicated (e.g. here is my 1k+ line config and please help me), developers might not be able to help.
  • I can confirm that my reproduction step only involves vim.opt.rtp and configuration themselves

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions