From 67df627f0a5552a6fc2751a98e4edfb3c62397d5 Mon Sep 17 00:00:00 2001 From: erw7 Date: Wed, 5 Feb 2020 17:19:29 +0900 Subject: clangd: fix root_dir problem #114 - On Windows an error occurred (#113). - On non-Windows, it was always the directory where the file located. Since 638dad178311e the following error occurs when opening a C source file on Windows: E5108: Error executing lua shared.lua:427: root_dir: expected directory, got C:\msys64\home\erw7\src\github.com\neovim\neovim\src\nvim\tui\tui.c On Windows, the following result does not seem to be `nil`. vim.loop.fs_stat('C:\\Windows\\System32\\notepad.exe\\.') fix #113 --- lua/nvim_lsp/clangd.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/nvim_lsp/clangd.lua b/lua/nvim_lsp/clangd.lua index 34207e5a..8c9855df 100644 --- a/lua/nvim_lsp/clangd.lua +++ b/lua/nvim_lsp/clangd.lua @@ -2,11 +2,14 @@ local configs = require 'nvim_lsp/configs' local util = require 'nvim_lsp/util' local lsp = vim.lsp +local root_pattern = util.root_pattern("compile_commands.json", "compile_flags.txt", ".git") configs.clangd = { default_config = util.utf8_config { cmd = {"clangd", "--background-index"}; filetypes = {"c", "cpp", "objc", "objcpp"}; - root_dir = util.root_pattern("compile_commands.json", "compile_flags.txt", ".git", "."); + root_dir = function(fname) + return root_pattern(fname) or util.path.dirname(fname) + end; log_level = lsp.protocol.MessageType.Warning; settings = {}; }; @@ -23,7 +26,7 @@ clangd relies on a [JSON compilation database](https://clang.llvm.org/docs/JSONC as compile_commands.json or, for simpler projects, a compile_flags.txt. ]]; default_config = { - root_dir = [[root_pattern("compile_commands.json", "compile_flags.txt", ".git") or cwd]]; + root_dir = [[root_pattern("compile_commands.json", "compile_flags.txt", ".git") or dirname]]; on_init = [[function to handle changing offsetEncoding]]; capabilities = [[default capabilities, with offsetEncoding utf-8]]; }; -- cgit v1.2.3-70-g09d2