205 lines
7.2 KiB
Lua
205 lines
7.2 KiB
Lua
-- 1. Configure CiderLSP
|
||
local nvim_lsp = require("lspconfig")
|
||
local configs = require("lspconfig.configs")
|
||
configs.ciderlsp = {
|
||
default_config = {
|
||
cmd = { "/google/bin/releases/cider/ciderlsp/ciderlsp", "--tooltag=nvim-lsp", "--noforward_sync_responses", "--enable_semantic_tokens", "--relay_mode=true", "--hub_addr=blade:languageservices-staging" ,"--enable_document_highlight"},
|
||
-- cmd = {'/google/bin/releases/cider/ciderlsp/ciderlsp', '--forward_sync_responses', '--enable_document_highlight'};
|
||
filetypes = { "c", "cpp", "java", "kotlin", "proto", "textproto", "go", "python", "bzl" },
|
||
root_dir = nvim_lsp.util.root_pattern("BUILD"),
|
||
settings = {},
|
||
},
|
||
}
|
||
|
||
local has_words_before = function()
|
||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||
end
|
||
|
||
-- 2. Configure CMP
|
||
vim.opt.completeopt = { "menu", "menuone", "noselect" }
|
||
|
||
-- Don't show the dumb matching stuff
|
||
vim.opt.shortmess:append("c")
|
||
|
||
local lspkind = require("lspkind")
|
||
lspkind.init()
|
||
|
||
local cmp = require("cmp")
|
||
|
||
cmp.setup({
|
||
mapping = {
|
||
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||
["<C-u>"] = cmp.mapping.scroll_docs(4),
|
||
["<C-e>"] = cmp.mapping.close(),
|
||
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
|
||
["<C-m>"] = cmp.mapping.confirm({ select = true }),
|
||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||
["<Tab>"] = cmp.mapping(function(fallback)
|
||
if cmp.visible() then
|
||
cmp.select_next_item()
|
||
elseif vim.fn["vsnip#available"](1) == 1 then
|
||
feedkey("<Plug>(vsnip-expand-or-jump)", "")
|
||
elseif has_words_before() then
|
||
cmp.complete()
|
||
else
|
||
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
|
||
end
|
||
end, { "i", "s" }),
|
||
|
||
["<S-Tab>"] = cmp.mapping(function()
|
||
if cmp.visible() then
|
||
cmp.select_prev_item()
|
||
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
|
||
feedkey("<Plug>(vsnip-jump-prev)", "")
|
||
end
|
||
end, { "i", "s" }),
|
||
|
||
["<Up>"] = cmp.mapping(function(fallback)
|
||
if cmp.visible() then
|
||
cmp.select_prev_item()
|
||
elseif vim.fn["vsnip#available"](1) == 1 then
|
||
feedkey("<Plug>(vsnip-jump-prev)", "")
|
||
else
|
||
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
|
||
end
|
||
end),
|
||
|
||
["<Down>"] = cmp.mapping(function(fallback)
|
||
if cmp.visible() then
|
||
cmp.select_next_item()
|
||
elseif vim.fn["vsnip#available"](1) == 1 then
|
||
feedkey("<Plug>(vsnip-expand-or-jump)", "")
|
||
else
|
||
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
|
||
end
|
||
end),
|
||
},
|
||
|
||
sources = {
|
||
{ name = "nvim_lua" },
|
||
{ name = "nvim_lsp" },
|
||
{ name = "path" },
|
||
{ name = "vim_vsnip" },
|
||
{ name = 'nvim_ciderlsp', priority = 9 },
|
||
{ name = "buffer", keyword_length = 5 },
|
||
},
|
||
|
||
sorting = {
|
||
comparators = {
|
||
cmp.config.compare.offset,
|
||
cmp.config.compare.exact,
|
||
cmp.config.compare.score,
|
||
|
||
function(entry1, entry2)
|
||
local _, entry1_under = entry1.completion_item.label:find("^_+")
|
||
local _, entry2_under = entry2.completion_item.label:find("^_+")
|
||
entry1_under = entry1_under or 0
|
||
entry2_under = entry2_under or 0
|
||
if entry1_under > entry2_under then
|
||
return false
|
||
elseif entry1_under < entry2_under then
|
||
return true
|
||
end
|
||
end,
|
||
|
||
cmp.config.compare.kind,
|
||
cmp.config.compare.sort_text,
|
||
cmp.config.compare.length,
|
||
cmp.config.compare.order,
|
||
},
|
||
},
|
||
|
||
snippet = {
|
||
expand = function(args)
|
||
vim.fn["vsnip#anonymous"](args.body)
|
||
end,
|
||
},
|
||
|
||
formatting = {
|
||
format = lspkind.cmp_format({
|
||
with_text = true,
|
||
maxwidth = 40, -- half max width
|
||
menu = {
|
||
nvim_ciderlsp = "(ﮧ)",
|
||
buffer = "[buffer]",
|
||
nvim_lsp = "[CiderLSP]",
|
||
nvim_lua = "[API]",
|
||
path = "[path]",
|
||
vim_vsnip = "[snip]",
|
||
},
|
||
}),
|
||
},
|
||
|
||
experimental = {
|
||
native_menu = false,
|
||
ghost_text = true,
|
||
},
|
||
})
|
||
|
||
vim.cmd([[
|
||
augroup CmpZsh
|
||
au!
|
||
autocmd Filetype zsh lua require'cmp'.setup.buffer { sources = { { name = "zsh" }, } }
|
||
augroup END
|
||
]])
|
||
|
||
-- 3. Set up CiderLSP
|
||
local on_attach = function(client, bufnr)
|
||
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
|
||
if vim.lsp.formatexpr then -- Neovim v0.6.0+ only.
|
||
vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr")
|
||
end
|
||
if vim.lsp.tagfunc then
|
||
vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc")
|
||
end
|
||
|
||
local opts = { noremap = true, silent = true }
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "L", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "g0", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gW", "<cmd>lua vim.lsp.buf.workspace_symbol()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>tab split | lua vim.lsp.buf.definition()<CR>", opts)
|
||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
||
-- vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) -- diagnostics controls references
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<C-g>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "i", "<C-g>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gt", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "[g", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opts)
|
||
vim.api.nvim_buf_set_keymap(bufnr, "n", "]g", "<cmd>lua vim.diagnostic.goto_next()<CR>", opts)
|
||
|
||
vim.api.nvim_command("augroup LSP")
|
||
vim.api.nvim_command("autocmd!")
|
||
if client.resolved_capabilities.document_highlight then
|
||
vim.api.nvim_command("autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()")
|
||
vim.api.nvim_command("autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()")
|
||
vim.api.nvim_command("autocmd CursorMoved <buffer> lua vim.lsp.util.buf_clear_references()")
|
||
end
|
||
vim.api.nvim_command("augroup END")
|
||
end
|
||
|
||
|
||
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||
|
||
capabilities = require('cmp_nvim_ciderlsp').update_capabilities(capabilities)
|
||
|
||
-- capabilities.textDocument.codeAction = {
|
||
-- codeActionLiteralSupport = {
|
||
-- codeActionKind = {
|
||
-- valueSet = {
|
||
-- '', 'quickfix', 'refactor', 'refactor.extract', 'refactor.inline', 'refactor.rewrite', 'source', 'source.organizeImports'
|
||
-- }
|
||
-- }
|
||
-- }
|
||
-- }
|
||
-- capabilities.textDocument.publishDiagnostics['versionSupport'] = false
|
||
|
||
nvim_lsp.ciderlsp.setup({
|
||
capabilities = capabilities,
|
||
on_attach = on_attach,
|
||
})
|