mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-10 12:28:25 +00:00
nvim: Only enable the integration in the carbon repo (#7995)
This fixes an error that would happen when opening neovim in a non-git-controlled directory, where `root` is `nil` and therefore one cannot `..` it as a string.
This commit is contained in:
1 parent
309d3d63c5
commit
3056e7e318
1 file changed
+17
-5
+17
-5
@@ -19,8 +19,20 @@ function find_git_ancestor(startpath)
|
||||
end
|
||||
local root = find_git_ancestor(vim.env.PWD);
|
||||
|
||||
vim.lsp.config("carbon", {
|
||||
cmd = { root .. "/bazel-bin/toolchain/carbon", "language-server" },
|
||||
filetypes = { "carbon" },
|
||||
})
|
||||
vim.lsp.enable("carbon")
|
||||
toolchain_path = nil
|
||||
if root and vim.uv.fs_stat(root .. "/bazel/carbon_rules") then
|
||||
-- when we're in the carbon repo, use the toolchain from there
|
||||
-- (note that this won't update if one `cd`s into the carbon repo)
|
||||
toolchain_path = root .. "/bazel-bin/toolchain/carbon"
|
||||
elseif vim.fn.executable("carbon") then
|
||||
-- otherwise, check if it's on the path
|
||||
toolchain_path = "carbon"
|
||||
end
|
||||
|
||||
if toolchain_path then
|
||||
vim.lsp.config("carbon", {
|
||||
cmd = { toolchain_path, "language-server" },
|
||||
filetypes = { "carbon" },
|
||||
})
|
||||
vim.lsp.enable("carbon")
|
||||
end
|
||||
Reference in new issue
Block a user