lazyvim/lua/lazyvim/plugins
Jinfeng Guo 167d39b2be
fix(clangd): rewrite the root_dir function (#6060)
## Description

<!-- Describe the big picture of your changes to communicate to the
maintainers
  why we should accept this pull request. -->

Nvim 0.11 had some breaking changes in lsp related parts. And one of
them is that if the root_dir field of lsp config is a function, the
bufnr and a function would be passed instead of the file name in nvim
0.10. As a result, the configurations of extra.lang.clangd broke.

However, before the breaking changes of mason and mason-lspconfig, the
configurations of clangd still worked. So maybe what really broke the
configurations is mason-lspconfig, which uses a new way to enable lsp in
v2.

I rewrite the root_dir function and make it work both on 0.11 and 0.10.

It would check whether the first argument is a string to decide whether
to adapt the new interface.

To test whether it works, you can just add a plugin/clangd.lua to you
personal config with the content below:

```lua
return {
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      clangd = {
        root_dir = function(bufnr, ondir)
          local root_directory = function(fname)
            return require("lspconfig.util").root_pattern(
              "Makefile",
              "configure.ac",
              "configure.in",
              "config.h.in",
              "meson.build",
              "meson_options.txt",
              "build.ninja"
            )(fname) or require("lspconfig.util").root_pattern("compile_commands.json", "compile_flags.txt")(
              fname
            ) or require("lspconfig.util").find_git_ancestor(fname)
          end
          if type(bufnr) == "string" then
            return root_directory(bufnr)
          else
            local fname = vim.api.nvim_buf_get_name(bufnr)
            ondir(root_directory(fname))
          end
        end,
      },
    },
  },
}
```

## Checklist

- [x] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
2025-09-15 17:19:23 +02:00
..
extras fix(clangd): rewrite the root_dir function (#6060) 2025-09-15 17:19:23 +02:00
lsp refactor(lsp): cleanup lsp config 2025-09-15 16:28:46 +02:00
coding.lua fix(mini): update mini plugin references from echasnovski to nvim-mini (#6374) 2025-09-15 11:45:00 +02:00
colorscheme.lua fix(catppuccin): follow renamed integration (#6354) 2025-09-15 11:21:32 +02:00
editor.lua feat(extras): big rework of default extras 2025-02-08 15:04:46 +01:00
formatting.lua fix(conform): changes for new conform.nvim config 2024-07-20 17:14:07 +02:00
init.lua feat!: LazyVim now requires Neovim >= 0.11 See #6421 for more info 2025-09-15 10:58:22 +02:00
linting.lua fix(lint): make prepend_args opt work when default args is empty (#3828) 2024-06-27 17:31:11 +02:00
treesitter.lua feat(keymaps): dynamic which-key icons/descriptions for toggles (#4050) 2024-07-15 15:47:44 +02:00
ui.lua fix(mini): update mini plugin references from echasnovski to nvim-mini (#6374) 2025-09-15 11:45:00 +02:00
util.lua feat(snacks): added profiler keymaps 2024-12-12 13:47:29 +01:00
xtras.lua fix(neo-tree): import neo-tree Extra before edgy Extra (#5763) 2025-09-15 11:27:29 +02:00