diff --git a/vim/.vim/lua/plugins/lsp.lua b/vim/.vim/lua/plugins/lsp.lua index ebe4958..3254bf1 100644 --- a/vim/.vim/lua/plugins/lsp.lua +++ b/vim/.vim/lua/plugins/lsp.lua @@ -1,219 +1,197 @@ return { - { - "neovim/nvim-lspconfig", - -- event = "VimEnter", - dependencies = { - "hrsh7th/nvim-cmp", - "nvim-lua/lsp-status.nvim", - "VonHeikemen/lsp-zero.nvim", - "rcarriga/nvim-notify", - }, - keys = { - { "rn", "lua vim.lsp.buf.rename()" }, - { "ca", "lua vim.lsp.buf.code_action()" }, - { "L", "lua vim.lsp.buf.hover()" }, - { "g0", "lua vim.lsp.buf.document_symbol()" }, - { "gW", "lua vim.lsp.buf.workspace_symbol()" }, - { "gd", "lua vim.lsp.buf.definition()" }, - { "gD", "tab split | lua vim.lsp.buf.definition()" }, - { "gi", "lua vim.lsp.buf.implementation()" }, - { "gI", "lua vim.lsp.buf.implementation()" }, - { "gR", "lua vim.lsp.buf.references()" }, - { "", "lua vim.lsp.buf.signature_help()" }, - { "gt", "lua vim.lsp.buf.type_definition()" }, - { "", "lua vim.lsp.buf.signature_help()", mode = "i" }, - { "ca", "lua vim.lsp.buf.code_action()", mode = "v" }, - }, - config = function() - local use_google = require("utils").use_google - local notify = require("notify") + { + "neovim/nvim-lspconfig", + -- event = "VimEnter", + dependencies = { + "hrsh7th/nvim-cmp", + "nvim-lua/lsp-status.nvim", + "VonHeikemen/lsp-zero.nvim", + "rcarriga/nvim-notify", + }, + keys = { + { "rn", "lua vim.lsp.buf.rename()" }, + { "ca", "lua vim.lsp.buf.code_action()" }, + { "L", "lua vim.lsp.buf.hover()" }, + { "g0", "lua vim.lsp.buf.document_symbol()" }, + { "gW", "lua vim.lsp.buf.workspace_symbol()" }, + { "gd", "lua vim.lsp.buf.definition()" }, + { "gD", "tab split | lua vim.lsp.buf.definition()" }, + { "gi", "lua vim.lsp.buf.implementation()" }, + { "gI", "lua vim.lsp.buf.implementation()" }, + { "gR", "lua vim.lsp.buf.references()" }, + { "", "lua vim.lsp.buf.signature_help()" }, + { "gt", "lua vim.lsp.buf.type_definition()" }, + { "", "lua vim.lsp.buf.signature_help()", mode = "i" }, + { "ca", "lua vim.lsp.buf.code_action()", mode = "v" }, + }, + 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") - lsp_status.register_progress() + local lspconfig = require("lspconfig") + local configs = require("lspconfig.configs") + local lsp_status = require("lsp-status") + lsp_status.register_progress() - -- CiderLSP - vim.opt.completeopt = { "menu", "menuone", "noselect" } - -- Don't show the dumb matching stuff - vim.opt.shortmess:append("c") + -- CiderLSP + vim.opt.completeopt = { "menu", "menuone", "noselect" } + -- Don't show the dumb matching stuff + vim.opt.shortmess:append("c") - vim.opt.spell = true - vim.opt.spelllang = { "en_us" } - vim.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 + vim.opt.spell = true + vim.opt.spelllang = { "en_us" } + vim.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 - configs.ast_grep = { - default_config = { - cmd = { "sg", "lsp" }, - offset_encoding = "utf-8", - filetypes = { - "c", - "cpp", - "java", - "kotlin", - "objc", - "proto", - "textproto", - "go", - "python", - "bzl", - "typescript", - }, - single_file_support = true, - root_dir = lspconfig.util.root_pattern("BUILD", ".git", "sgconfig.yml"), - }, - } + if use_google() then + configs.ciderlsp = { + default_config = { + cmd = { + "/google/bin/releases/cider/ciderlsp/ciderlsp", + "--tooltag=nvim-cmp", + "--forward_sync_responses", + }, + offset_encoding = "utf-8", + filetypes = { + "c", + "cpp", + "java", + "kotlin", + "objc", + "proto", + "textproto", + "go", + "python", + "bzl", + "typescript", + }, + -- required for proto generated files jump + root_dir = function(fname) + return string.match(fname, "(/google/src/cloud/[%w_-]+/[%w_-]+/google3/).+$") + end, + settings = {}, + }, + } - if use_google() then - configs.ciderlsp = { - default_config = { - cmd = { - "/google/bin/releases/cider/ciderlsp/ciderlsp", - "--tooltag=nvim-cmp", - "--forward_sync_responses", - }, - offset_encoding = "utf-8", - filetypes = { - "c", - "cpp", - "java", - "kotlin", - "objc", - "proto", - "textproto", - "go", - "python", - "bzl", - "typescript", - }, - -- required for proto generated files jump - root_dir = function(fname) - return string.match(fname, "(/google/src/cloud/[%w_-]+/[%w_-]+/google3/).+$") - end, - 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 = function(fname) + return string.match(fname, "(/google/src/cloud/[%w_-]+/[%w_-]+/google3/).+$") + end, + settings = {}, + }, + } + end - 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 = function(fname) - return string.match(fname, "(/google/src/cloud/[%w_-]+/[%w_-]+/google3/).+$") - end, - settings = {}, - }, - } - end + local capabilities = + require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + capabilities["codeLens"] = { dynamicRegistration = false } + capabilities.textDocument.publishDiagnostics = { + relatedInformation = true, + versionSupport = false, + tagSupport = { + valueSet = { + 1, + 2, + }, + }, + codeDescriptionSupport = true, + dataSupport = true, + layeredDiagnostics = true, + } - local capabilities = - require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) - capabilities["codeLens"] = { dynamicRegistration = false } - capabilities.textDocument.publishDiagnostics = { - relatedInformation = true, - versionSupport = false, - tagSupport = { - valueSet = { - 1, - 2, - }, - }, - codeDescriptionSupport = true, - dataSupport = true, - layeredDiagnostics = true, - } + 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("lualine").refresh() - local my_on_attach = function(client, bufnr) - require("lualine").refresh() + vim.api.nvim_command("autocmd CursorHold lua vim.lsp.buf.document_highlight()") + vim.api.nvim_command("autocmd CursorHoldI lua vim.lsp.buf.document_highlight()") + vim.api.nvim_command("autocmd CursorMoved lua vim.lsp.util.buf_clear_references()") - vim.api.nvim_command("autocmd CursorHold lua vim.lsp.buf.document_highlight()") - vim.api.nvim_command("autocmd CursorHoldI lua vim.lsp.buf.document_highlight()") - vim.api.nvim_command("autocmd CursorMoved lua vim.lsp.util.buf_clear_references()") + 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 - 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 - 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 - 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, + }), + } - 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["$/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 + capabilities = require("cmp_nvim_ciderlsp").update_capabilities(capabilities) + capabilities.workspace.codeLens = { refreshSupport = true } + capabilities.workspace.diagnostics = { refreshSupport = true } - capabilities = require("cmp_nvim_ciderlsp").update_capabilities(capabilities) - capabilities.workspace.codeLens = { refreshSupport = true } - capabilities.workspace.diagnostics = { refreshSupport = true } + lspconfig.analysislsp.setup({ + capabilities = capabilities, + }) - lspconfig.analysislsp.setup({ - capabilities = capabilities, - }) - - lspconfig.ciderlsp.setup({ - capabilities = capabilities, - on_attach = cider_on_attach, - handlers = cider_lsp_handlers, - }) - end - end, - }, + lspconfig.ciderlsp.setup({ + capabilities = capabilities, + on_attach = cider_on_attach, + handlers = cider_lsp_handlers, + }) + end + end, + }, }