diff options
| author | erw7 <erw7.github@gmail.com> | 2020-03-01 20:27:19 +0900 |
|---|---|---|
| committer | erw7 <erw7.github@gmail.com> | 2020-03-01 20:27:19 +0900 |
| commit | dc1c93f459577d2c04cedda212d303129de2c804 (patch) | |
| tree | 5d10467d335929006bdd7533079f3312c911fa4d /lua | |
| parent | [docgen] Update README.md (diff) | |
| download | nvim-lspconfig-dc1c93f459577d2c04cedda212d303129de2c804.tar nvim-lspconfig-dc1c93f459577d2c04cedda212d303129de2c804.tar.gz nvim-lspconfig-dc1c93f459577d2c04cedda212d303129de2c804.tar.bz2 nvim-lspconfig-dc1c93f459577d2c04cedda212d303129de2c804.tar.lz nvim-lspconfig-dc1c93f459577d2c04cedda212d303129de2c804.tar.xz nvim-lspconfig-dc1c93f459577d2c04cedda212d303129de2c804.tar.zst nvim-lspconfig-dc1c93f459577d2c04cedda212d303129de2c804.zip | |
Fix problems when relative paths are passed
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim_lsp/clangd.lua | 4 | ||||
| -rw-r--r-- | lua/nvim_lsp/util.lua | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lua/nvim_lsp/clangd.lua b/lua/nvim_lsp/clangd.lua index 59649f8e..34389721 100644 --- a/lua/nvim_lsp/clangd.lua +++ b/lua/nvim_lsp/clangd.lua @@ -7,7 +7,9 @@ configs.clangd = { cmd = {"clangd", "--background-index"}; filetypes = {"c", "cpp", "objc", "objcpp"}; root_dir = function(fname) - return root_pattern(fname) or util.path.dirname(fname) + local filename = util.path.is_absolute(fname) and fname + or util.path.join(vim.loop.cwd(), fname) + return root_pattern(filename) or util.path.dirname(filename) end; }; -- commands = {}; diff --git a/lua/nvim_lsp/util.lua b/lua/nvim_lsp/util.lua index 433bcab2..82767905 100644 --- a/lua/nvim_lsp/util.lua +++ b/lua/nvim_lsp/util.lua @@ -128,6 +128,14 @@ M.path = (function() end end + local function is_absolute(filename) + if is_windows then + return filename:match("^%a:") or filename:match("^\\\\") + else + return filename:match("^/") + end + end + local dirname do local strip_dir_pat = path_sep.."([^"..path_sep.."]+)$" @@ -195,6 +203,7 @@ M.path = (function() return { is_dir = is_dir; is_file = is_file; + is_absolute = is_absolute; exists = exists; sep = path_sep; dirname = dirname; |
