Skip to content

Commit c619d5e

Browse files
committed
Make clangd and ciderlsp exclusive
Current setup is fine for now because I only work in C++, but if I add more LSPs I'll want some root_dir = get_root_dir_fn_excluding_google3() sort of function
1 parent db49cea commit c619d5e

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

init.lua

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,46 @@ vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper win
177177
vim.keymap.set('n', '<leader>fs', '<cmd>:w<CR>', { desc = '[F]ile [S]ave' })
178178
vim.keymap.set('n', '<leader>qq', '<cmd>:q<CR>', { desc = '[Q]uit [Q]uit' })
179179

180+
local is_google3 = function(fname)
181+
local citc_results = vim.fs.find('.citc', { upward = true, path = fname })
182+
if #citc_results ~= 0 then
183+
return vim.fs.dirname(citc_results[1])
184+
else
185+
return nil
186+
end
187+
end
188+
189+
-- TODO: Shove google-specific config elsewhere.
190+
vim.lsp.config('ciderlsp', {
191+
cmd = { '/google/bin/releases/cider/ciderlsp/ciderlsp', '--tooltag=nvim-lsp', '--noforward_sync_responses' },
192+
filetypes = { 'c', 'cpp', 'cc', 'java', 'kotlin', 'objc', 'proto', 'textpb', 'go', 'python', 'bzl', 'typescript' },
193+
-- root_markers = { '.citc' },
194+
root_dir = function(bufnr, on_dir)
195+
local citc_dir = is_google3(vim.api.nvim_buf_get_name(bufnr))
196+
if citc_dir then
197+
on_dir(citc_dir)
198+
end
199+
end,
200+
})
201+
vim.lsp.enable 'ciderlsp'
202+
180203
-- clangd is set up differently than all of the other LSPs due to
181204
-- https://github.com/mason-org/mason.nvim/issues/1578?
182205
vim.lsp.config('clangd', {
183206
cmd = { 'clangd', '--background-index', '--limit-references=1000', '--limit-results=1000' },
184207
root_markers = { '.clangd', 'compile_commands.json' },
208+
root_dir = function(bufnr, on_dir)
209+
local fname = vim.api.nvim_buf_get_name(bufnr)
210+
if is_google3(fname) then
211+
return
212+
end
213+
local root_markers = { '.clangd', 'compile_commands.json' }
214+
local root_dirs = vim.fs.find(root_markers, { upward = true, path = fname })
215+
if #root_dirs == 0 then
216+
on_dir(vim.fs.dirname(fname))
217+
end
218+
on_dir(vim.fs.dirname(root_dirs[1]))
219+
end,
185220
filetypes = { 'c', 'cpp', 'cc' },
186221
})
187222
vim.lsp.enable 'clangd'
@@ -755,15 +790,6 @@ require('lazy').setup({
755790
-- So, we create new capabilities with blink.cmp, and then broadcast that to the servers.
756791
local capabilities = require('blink.cmp').get_lsp_capabilities()
757792

758-
-- Enable the following language servers
759-
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
760-
--
761-
-- Add any additional override configuration in the following tables. Available keys are:
762-
-- - cmd (table): Override the default command used to start the server
763-
-- - filetypes (table): Override the default list of associated filetypes for the server
764-
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
765-
-- - settings (table): Override the default settings passed when initializing the server.
766-
-- For example, to see the options for `lua_ls`, you could go to: https://lals.github.io/wiki/settings/
767793
local servers = {
768794
-- pyright = {},
769795
rust_analyzer = {},
@@ -979,11 +1005,7 @@ require('lazy').setup({
9791005
-- - sr)' - [S]urround [R]eplace [)] [']
9801006
require('mini.surround').setup()
9811007

982-
-- Simple and easy statusline.
983-
-- You could remove this setup call if you don't like it,
984-
-- and try some other statusline plugin
9851008
local statusline = require 'mini.statusline'
986-
-- set use_icons to true if you have a Nerd Font
9871009
statusline.setup { use_icons = vim.g.have_nerd_font }
9881010

9891011
-- You can configure sections in the statusline by overriding their
@@ -1071,6 +1093,3 @@ require('lazy').setup({
10711093
},
10721094
},
10731095
})
1074-
1075-
-- The line beneath this is called `modeline`. See `:help modeline`
1076-
-- vim: ts=2 sts=2 sw=2 et

0 commit comments

Comments
 (0)