Move work specific LSP config
This commit is contained in:
124
vim/.vim/lua/config/lsp-google.lua
Normal file
124
vim/.vim/lua/config/lsp-google.lua
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
local use_google = require("utils").use_google
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.setup(capabilities)
|
||||||
|
if use_google() then
|
||||||
|
local lspconfig = require("lspconfig")
|
||||||
|
local configs = require("lspconfig.configs")
|
||||||
|
configs.ciderlsp = {
|
||||||
|
default_config = {
|
||||||
|
cmd = {
|
||||||
|
"/google/bin/releases/cider/ciderlsp/ciderlsp",
|
||||||
|
"--tooltag=nvim-lsp",
|
||||||
|
"--forward_sync_responses",
|
||||||
|
},
|
||||||
|
offset_encoding = "utf-8",
|
||||||
|
filetypes = {
|
||||||
|
"c",
|
||||||
|
"cpp",
|
||||||
|
"java",
|
||||||
|
"kotlin",
|
||||||
|
"objc",
|
||||||
|
"proto",
|
||||||
|
"textproto",
|
||||||
|
"go",
|
||||||
|
"python",
|
||||||
|
"bzl",
|
||||||
|
"typescript",
|
||||||
|
},
|
||||||
|
root_dir = lspconfig.util.root_pattern("google3/*BUILD"),
|
||||||
|
settings = {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
configs.analysislsp = {
|
||||||
|
default_config = {
|
||||||
|
cmd = {
|
||||||
|
"/google/bin/users/lerm/glint-ale/analysis_lsp/server",
|
||||||
|
"--lint_on_save=false",
|
||||||
|
"--max_qps=10",
|
||||||
|
},
|
||||||
|
offset_encoding = "utf-8",
|
||||||
|
filetypes = {
|
||||||
|
"c",
|
||||||
|
"cpp",
|
||||||
|
"java",
|
||||||
|
"kotlin",
|
||||||
|
"objc",
|
||||||
|
"proto",
|
||||||
|
"textproto",
|
||||||
|
"go",
|
||||||
|
"python",
|
||||||
|
"bzl",
|
||||||
|
"markdown",
|
||||||
|
"typescript",
|
||||||
|
"javascript",
|
||||||
|
},
|
||||||
|
root_dir = lspconfig.util.root_pattern("google3/*BUILD"),
|
||||||
|
settings = {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local my_on_attach = function(client, bufnr)
|
||||||
|
require("lualine").refresh()
|
||||||
|
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
|
||||||
|
|
||||||
|
lsp_status.on_attach(client)
|
||||||
|
end
|
||||||
|
|
||||||
|
local cider_on_attach = function(client, bufnr)
|
||||||
|
my_on_attach(client, bufnr)
|
||||||
|
vim.b["is_cider_lsp_attached"] = "no"
|
||||||
|
end
|
||||||
|
|
||||||
|
local cider_lsp_handlers = {
|
||||||
|
["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||||
|
underline = true,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
local notify = require("notify")
|
||||||
|
cider_lsp_handlers["$/syncResponse"] = function(_, result, ctx)
|
||||||
|
-- is_cider_lsp_attached has been setup via on_init, but hasn't received
|
||||||
|
-- sync response yet.
|
||||||
|
local first_fire = vim.b["is_cider_lsp_attached"] == "no"
|
||||||
|
vim.b["is_cider_lsp_attached"] = "yes"
|
||||||
|
if first_fire then
|
||||||
|
notify("CiderLSP attached", "info", { timeout = 500 })
|
||||||
|
require("lualine").refresh()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
cider_lsp_handlers["window/showMessage"] = function(_, result, ctx)
|
||||||
|
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||||
|
local lvl = ({ "ERROR", "WARN", "INFO", "DEBUG" })[result.type]
|
||||||
|
notify({ result.message }, lvl, {
|
||||||
|
title = "LSP | " .. client.name,
|
||||||
|
timeout = 1000,
|
||||||
|
keep = function()
|
||||||
|
return lvl == "ERROR" or lvl == "WARN"
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
capabilities = require("cmp_nvim_ciderlsp").update_capabilities(capabilities)
|
||||||
|
capabilities.workspace.codeLens = { refreshSupport = true }
|
||||||
|
capabilities.workspace.diagnostics = { refreshSupport = true }
|
||||||
|
|
||||||
|
lspconfig.ciderlsp.setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = cider_on_attach,
|
||||||
|
handlers = cider_lsp_handlers,
|
||||||
|
})
|
||||||
|
lspconfig.analysislsp.setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
@ -16,14 +16,16 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"tzachar/cmp-tabnine",
|
"Exafunction/codeium.vim",
|
||||||
build = "./install.sh",
|
|
||||||
event = "InsertEnter",
|
event = "InsertEnter",
|
||||||
cond = not use_google(),
|
cond = not use_google(),
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"onsails/lspkind.nvim",
|
"onsails/lspkind.nvim",
|
||||||
"hrsh7th/nvim-cmp",
|
"hrsh7th/nvim-cmp",
|
||||||
},
|
},
|
||||||
|
config = function()
|
||||||
|
require("codeium").setup({})
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"hrsh7th/nvim-cmp",
|
"hrsh7th/nvim-cmp",
|
||||||
@ -50,7 +52,7 @@ return {
|
|||||||
|
|
||||||
local cmp = require("cmp")
|
local cmp = require("cmp")
|
||||||
|
|
||||||
local conditionalSources = cmp.config.sources({
|
local conditionalSources = {
|
||||||
{ name = "nvim_lsp", priority = 8 },
|
{ name = "nvim_lsp", priority = 8 },
|
||||||
{ name = "treesitter", priority = 7 },
|
{ name = "treesitter", priority = 7 },
|
||||||
{ name = "nvim_lsp_signature_help" },
|
{ name = "nvim_lsp_signature_help" },
|
||||||
@ -63,7 +65,7 @@ return {
|
|||||||
{ name = "spell" },
|
{ name = "spell" },
|
||||||
-- { name = "buffer", option = { keyword_pattern = [[\k\+]] }, priority = 1 },
|
-- { name = "buffer", option = { keyword_pattern = [[\k\+]] }, priority = 1 },
|
||||||
-- { name = "buffer-lines" },
|
-- { name = "buffer-lines" },
|
||||||
})
|
}
|
||||||
|
|
||||||
if use_google() then
|
if use_google() then
|
||||||
table.insert(conditionalSources, { name = "analysislsp", priority = 5 })
|
table.insert(conditionalSources, { name = "analysislsp", priority = 5 })
|
||||||
@ -136,7 +138,7 @@ return {
|
|||||||
},
|
},
|
||||||
|
|
||||||
preselect = cmp.PreselectMode.None,
|
preselect = cmp.PreselectMode.None,
|
||||||
sources = conditionalSources,
|
sources = cmp.config.sources(conditionalSources),
|
||||||
|
|
||||||
sorting = {
|
sorting = {
|
||||||
comparators = {
|
comparators = {
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
local use_google = require("utils").use_google
|
local use_google = require("utils").use_google
|
||||||
|
|
||||||
|
local deps = {
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
|
"nvim-lua/lsp-status.nvim",
|
||||||
|
"VonHeikemen/lsp-zero.nvim",
|
||||||
|
"rcarriga/nvim-notify",
|
||||||
|
"ray-x/go.nvim",
|
||||||
|
"ray-x/guihua.lua",
|
||||||
|
}
|
||||||
|
|
||||||
|
if not use_google() then
|
||||||
|
table.insert(deps, "Exafunction/codeium.nvim")
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
dependencies = {
|
dependencies = deps,
|
||||||
"hrsh7th/nvim-cmp",
|
|
||||||
"nvim-lua/lsp-status.nvim",
|
|
||||||
"VonHeikemen/lsp-zero.nvim",
|
|
||||||
"rcarriga/nvim-notify",
|
|
||||||
"ray-x/go.nvim",
|
|
||||||
"ray-x/guihua.lua",
|
|
||||||
},
|
|
||||||
keys = {
|
keys = {
|
||||||
{ "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>" },
|
{ "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>" },
|
||||||
{ "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>" },
|
{ "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>" },
|
||||||
@ -29,73 +35,12 @@ return {
|
|||||||
{ "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", mode = "v" },
|
{ "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", mode = "v" },
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local use_google = require("utils").use_google
|
|
||||||
local notify = require("notify")
|
|
||||||
|
|
||||||
local lspconfig = require("lspconfig")
|
|
||||||
local configs = require("lspconfig.configs")
|
|
||||||
local lsp_status = require("lsp-status")
|
local lsp_status = require("lsp-status")
|
||||||
lsp_status.register_progress()
|
lsp_status.register_progress()
|
||||||
|
|
||||||
vim.opt.spell = true
|
vim.opt.spell = true
|
||||||
vim.opt.spelllang = { "en_us" }
|
vim.opt.spelllang = { "en_us" }
|
||||||
|
|
||||||
if use_google() then
|
|
||||||
configs.ciderlsp = {
|
|
||||||
default_config = {
|
|
||||||
cmd = {
|
|
||||||
"/google/bin/releases/cider/ciderlsp/ciderlsp",
|
|
||||||
"--tooltag=nvim-lsp",
|
|
||||||
"--forward_sync_responses",
|
|
||||||
},
|
|
||||||
offset_encoding = "utf-8",
|
|
||||||
filetypes = {
|
|
||||||
"c",
|
|
||||||
"cpp",
|
|
||||||
"java",
|
|
||||||
"kotlin",
|
|
||||||
"objc",
|
|
||||||
"proto",
|
|
||||||
"textproto",
|
|
||||||
"go",
|
|
||||||
"python",
|
|
||||||
"bzl",
|
|
||||||
"typescript",
|
|
||||||
},
|
|
||||||
root_dir = lspconfig.util.root_pattern("google3/*BUILD"),
|
|
||||||
settings = {},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
configs.analysislsp = {
|
|
||||||
default_config = {
|
|
||||||
cmd = {
|
|
||||||
"/google/bin/users/lerm/glint-ale/analysis_lsp/server",
|
|
||||||
"--lint_on_save=false",
|
|
||||||
"--max_qps=10",
|
|
||||||
},
|
|
||||||
offset_encoding = "utf-8",
|
|
||||||
filetypes = {
|
|
||||||
"c",
|
|
||||||
"cpp",
|
|
||||||
"java",
|
|
||||||
"kotlin",
|
|
||||||
"objc",
|
|
||||||
"proto",
|
|
||||||
"textproto",
|
|
||||||
"go",
|
|
||||||
"python",
|
|
||||||
"bzl",
|
|
||||||
"markdown",
|
|
||||||
"typescript",
|
|
||||||
"javascript",
|
|
||||||
},
|
|
||||||
root_dir = lspconfig.util.root_pattern("google3/*BUILD"),
|
|
||||||
settings = {},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
local capabilities =
|
local capabilities =
|
||||||
require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||||
capabilities["codeLens"] = { dynamicRegistration = false }
|
capabilities["codeLens"] = { dynamicRegistration = false }
|
||||||
@ -115,90 +60,22 @@ return {
|
|||||||
|
|
||||||
capabilities = vim.tbl_extend("keep", capabilities or {}, lsp_status.capabilities)
|
capabilities = vim.tbl_extend("keep", capabilities or {}, lsp_status.capabilities)
|
||||||
|
|
||||||
local my_on_attach = function(client, bufnr)
|
require("config.lsp-google").setup(capabilities)
|
||||||
require("lualine").refresh()
|
|
||||||
|
|
||||||
-- vim.api.nvim_command("augroup LSP")
|
-- Golang
|
||||||
-- vim.api.nvim_command("autocmd!")
|
require("go").setup({
|
||||||
-- if client.server_capabilities.documentFormattingProvider then
|
lsp_cfg = {
|
||||||
-- 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")
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
lsp_status.on_attach(client)
|
|
||||||
end
|
|
||||||
|
|
||||||
if use_google() then
|
|
||||||
local cider_on_attach = function(client, bufnr)
|
|
||||||
my_on_attach(client, bufnr)
|
|
||||||
vim.b["is_cider_lsp_attached"] = "no"
|
|
||||||
end
|
|
||||||
|
|
||||||
local cider_lsp_handlers = {
|
|
||||||
["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
|
||||||
underline = true,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
|
|
||||||
cider_lsp_handlers["$/syncResponse"] = function(_, result, ctx)
|
|
||||||
-- is_cider_lsp_attached has been setup via on_init, but hasn't received
|
|
||||||
-- sync response yet.
|
|
||||||
local first_fire = vim.b["is_cider_lsp_attached"] == "no"
|
|
||||||
vim.b["is_cider_lsp_attached"] = "yes"
|
|
||||||
if first_fire then
|
|
||||||
notify("CiderLSP attached", "info", { timeout = 500 })
|
|
||||||
require("lualine").refresh()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
cider_lsp_handlers["window/showMessage"] = function(_, result, ctx)
|
|
||||||
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
|
||||||
local lvl = ({ "ERROR", "WARN", "INFO", "DEBUG" })[result.type]
|
|
||||||
notify({ result.message }, lvl, {
|
|
||||||
title = "LSP | " .. client.name,
|
|
||||||
timeout = 1000,
|
|
||||||
keep = function()
|
|
||||||
return lvl == "ERROR" or lvl == "WARN"
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
capabilities = require("cmp_nvim_ciderlsp").update_capabilities(capabilities)
|
|
||||||
capabilities.workspace.codeLens = { refreshSupport = true }
|
|
||||||
capabilities.workspace.diagnostics = { refreshSupport = true }
|
|
||||||
|
|
||||||
require("go").setup({
|
|
||||||
lsp_cfg = {
|
|
||||||
capabilities = capabilities,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {})
|
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
|
||||||
pattern = "*.go",
|
|
||||||
callback = function()
|
|
||||||
require("go.format").goimport()
|
|
||||||
end,
|
|
||||||
group = format_sync_grp,
|
|
||||||
})
|
|
||||||
|
|
||||||
lspconfig.ciderlsp.setup({
|
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = cider_on_attach,
|
},
|
||||||
handlers = cider_lsp_handlers,
|
})
|
||||||
})
|
local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {})
|
||||||
lspconfig.analysislsp.setup({
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
capabilities = capabilities,
|
pattern = "*.go",
|
||||||
})
|
callback = function()
|
||||||
end
|
require("go.format").goimport()
|
||||||
|
end,
|
||||||
|
group = format_sync_grp,
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user