Skip to content

bug: ConformInfo may not display the correct LSP formatters #877

Description

@shyun3

Neovim version (nvim -v)

NVIM v0.12.2

Operating system/version

WSL Ubuntu 24.04.3

Read debugging tips

Add the debug logs

  • I have set log_level = vim.log.levels.DEBUG and pasted the log contents below.

Log file

I don't think this is relevant for this issue.

Describe the bug

If only LSP formatters are being used, :ConformInfo might list something like the following:

Formatters for this buffer:
LSP: server1, server2

The listed servers might be incorrect if some are taken out by using the filter option.

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

  1. nvim -u repro.lua test.lua
  2. Wait for LSP servers to be installed by Mason
  3. :ConformInfo
  4. Formatters for this buffer shows both lua_ls and stylua

Expected Behavior

Only stylua should be shown as a formatter, as lua_ls has been filtered out in the repro.lua

Minimal example file

-- test.lua

File is empty but should be Lua.

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    "stevearc/conform.nvim",
    config = function()
      require("conform").setup({
        log_level = vim.log.levels.DEBUG,
        formatters_by_ft = {
          lua = {
            filter = function(client)
              return client.name ~= "lua_ls"
            end,
          },
        },
      })
    end,
  },
  -- add any other plugins here
  "neovim/nvim-lspconfig",
  {
    "mason-org/mason.nvim",
    opts = {},
  },
  {
    "mason-org/mason-lspconfig.nvim",
    opts = {
      ensure_installed = { "lua_ls", "stylua" },
    },
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

Looks like :ConformInfo gathers the LSP clients here:

local lsp_clients = lsp_format.get_format_clients({ bufnr = vim.api.nvim_get_current_buf() })

This does not pass any filter fields that the user specified in their setup options.

However, the format command may merge filetype options:

merge_default_opts(
opts,
get_opts_from_filetype(opts.bufnr) or {},
{ allow_filetype_opts = true }
)

So, the actual formatting may filter out certain LSP servers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions