diff options
| author | kylo252 <59826753+kylo252@users.noreply.github.com> | 2022-04-10 06:59:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-09 21:59:09 -0700 |
| commit | 1b4142e9cdd565d29511c20a3d64e7cfa20f2241 (patch) | |
| tree | 86a01793556e8f89aafcac69967bf4961b1ce75b /lua | |
| parent | docs: update server_configurations.md (diff) | |
| download | nvim-lspconfig-1b4142e9cdd565d29511c20a3d64e7cfa20f2241.tar nvim-lspconfig-1b4142e9cdd565d29511c20a3d64e7cfa20f2241.tar.gz nvim-lspconfig-1b4142e9cdd565d29511c20a3d64e7cfa20f2241.tar.bz2 nvim-lspconfig-1b4142e9cdd565d29511c20a3d64e7cfa20f2241.tar.lz nvim-lspconfig-1b4142e9cdd565d29511c20a3d64e7cfa20f2241.tar.xz nvim-lspconfig-1b4142e9cdd565d29511c20a3d64e7cfa20f2241.tar.zst nvim-lspconfig-1b4142e9cdd565d29511c20a3d64e7cfa20f2241.zip | |
fix(clangd): update root-markers (#1826)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/server_configurations/clangd.lua | 30 | ||||
| -rw-r--r-- | lua/lspconfig/server_configurations/cmake.lua | 5 |
2 files changed, 26 insertions, 9 deletions
diff --git a/lua/lspconfig/server_configurations/clangd.lua b/lua/lspconfig/server_configurations/clangd.lua index be9e5629..4e0f2d7f 100644 --- a/lua/lspconfig/server_configurations/clangd.lua +++ b/lua/lspconfig/server_configurations/clangd.lua @@ -21,7 +21,14 @@ local function switch_source_header(bufnr) end end -local root_pattern = util.root_pattern('compile_commands.json', 'compile_flags.txt', '.git') +local root_files = { + '.clangd', + '.clang-tidy', + '.clang-format', + 'compile_commands.json', + 'compile_flags.txt', + 'configure.ac', -- AutoTools +} local default_capabilities = vim.tbl_deep_extend( 'force', @@ -41,8 +48,7 @@ return { cmd = { 'clangd' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, root_dir = function(fname) - local filename = util.path.is_absolute(fname) and fname or util.path.join(vim.loop.cwd(), fname) - return root_pattern(filename) + return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) end, single_file_support = true, capabilities = default_capabilities, @@ -59,14 +65,22 @@ return { description = [[ https://clangd.llvm.org/installation.html -**NOTE:** Clang >= 9 is recommended! See [this issue for more](https://github.com/neovim/nvim-lsp/issues/23). +**NOTE:** Clang >= 11 is recommended! See [this issue for more](https://github.com/neovim/nvim-lsp/issues/23). -clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) specified -as compile_commands.json or, for simpler projects, a compile_flags.txt. -For details on how to automatically generate one using CMake look [here](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html). Alternatively, you can use [Bear](https://github.com/rizsotto/Bear). +clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) specified as compile_commands.json, see https://clangd.llvm.org/installation#compile_commandsjson ]], default_config = { - root_dir = [[root_pattern("compile_commands.json", "compile_flags.txt", ".git") or dirname]], + root_dir = [[ + root_pattern( + '.clangd', + '.clang-tidy', + '.clang-format', + 'compile_commands.json', + 'compile_flags.txt', + 'configure.ac', + '.git' + ) + ]], capabilities = [[default capabilities, with offsetEncoding utf-8]], }, }, diff --git a/lua/lspconfig/server_configurations/cmake.lua b/lua/lspconfig/server_configurations/cmake.lua index 3591c03c..a82263fb 100644 --- a/lua/lspconfig/server_configurations/cmake.lua +++ b/lua/lspconfig/server_configurations/cmake.lua @@ -1,10 +1,13 @@ local util = require 'lspconfig.util' +local root_files = { 'CMakeLists.txt', 'cmake' } return { default_config = { cmd = { 'cmake-language-server' }, filetypes = { 'cmake' }, - root_dir = util.root_pattern('.git', 'compile_commands.json', 'build'), + root_dir = function(fname) + return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) + end, single_file_support = true, init_options = { buildDirectory = 'build', |
