diff --git a/config/.config/nvim/spell/en.utf-8.add b/config/.config/nvim/spell/en.utf-8.add index 3e18ebf..c21c839 100644 --- a/config/.config/nvim/spell/en.utf-8.add +++ b/config/.config/nvim/spell/en.utf-8.add @@ -1 +1,2 @@ private +handlePackageIntent diff --git a/config/.config/nvim/spell/en.utf-8.add.spl b/config/.config/nvim/spell/en.utf-8.add.spl index 06085bc..947c57a 100644 Binary files a/config/.config/nvim/spell/en.utf-8.add.spl and b/config/.config/nvim/spell/en.utf-8.add.spl differ diff --git a/vim/.vim/lua/cmp.lua b/vim/.vim/lua/cmp.lua new file mode 100644 index 0000000..e69de29 diff --git a/vim/.vim/lua/diagnostics.lua b/vim/.vim/lua/diagnostics.lua index 1541d8c..a5b315f 100644 --- a/vim/.vim/lua/diagnostics.lua +++ b/vim/.vim/lua/diagnostics.lua @@ -4,38 +4,14 @@ require("trouble").setup({ height = 10, -- height of the trouble list when position is top or bottom width = 50, -- width of the list when position is left or right icons = true, -- use devicons for filenames - -- mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist" mode = "document_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist" - fold_open = "", -- icon used for open folds - fold_closed = "", -- icon used for closed folds + -- fold_open = "", -- icon used for open folds + -- fold_closed = "", -- icon used for closed folds group = true, -- group results by file padding = true, -- add an extra new line on top of the list - action_keys = { -- key mappings for actions in the trouble list - -- map to {} to remove a mapping, for example: - -- close = {}, - close = "q", -- close the list - cancel = "", -- cancel the preview and get back to your last window / buffer / cursor - refresh = "r", -- manually refresh - jump = { "", "" }, -- jump to the diagnostic or open / close folds - open_split = { "" }, -- open buffer in new split - open_vsplit = { "" }, -- open buffer in new vsplit - open_tab = { "" }, -- open buffer in new tab - jump_close = { "o" }, -- jump to the diagnostic and close the list - toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode - toggle_preview = "P", -- toggle auto_preview - hover = "L", -- opens a small popup with the full multiline message - preview = "p", -- preview the diagnostic location - close_folds = { "zM", "zm" }, -- close all folds - open_folds = { "zR", "zr" }, -- open all folds - toggle_fold = { "zA", "za" }, -- toggle fold of current file - previous = "k", -- preview item - next = "j", -- next item - }, indent_lines = true, -- add an indent guide below the fold icons auto_open = false, -- automatically open the list when you have diagnostics auto_close = true, -- automatically close the list when you have no diagnostics - auto_preview = true, -- automatically preview the location of the diagnostic. to close preview and go back to last window - auto_fold = false, -- automatically fold a file trouble list at creation auto_jump = { "lsp_definitions" }, -- for the given modes, automatically jump if there is only a single result signs = { -- icons / text used for a diagnostic @@ -58,3 +34,5 @@ vim.api.nvim_set_keymap("n", "xl", "Trouble loclist", opts) vim.api.nvim_set_keymap("n", "xq", "Trouble quickfix", opts) vim.api.nvim_set_keymap("n", "[g", "lua vim.diagnostic.goto_prev()", opts) vim.api.nvim_set_keymap("n", "]g", "lua vim.diagnostic.goto_next()", opts) + +vim.cmd [[autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]] diff --git a/vim/.vim/lua/lsp.lua b/vim/.vim/lua/lsp.lua index e99dda7..d750fd6 100644 --- a/vim/.vim/lua/lsp.lua +++ b/vim/.vim/lua/lsp.lua @@ -1,7 +1,4 @@ --- 1. Configure CiderLSP local use_google = require("utils").use_google -local lspconfig = require("lspconfig") -local configs = require("lspconfig.configs") local notify = require 'notify' require("mason").setup() @@ -12,16 +9,142 @@ require("mason-lspconfig").setup({ local lsp = require('lsp-zero') lsp.preset('manual-setup') -local rust_lsp = lsp.build_options('rust_analyzer', {}) - lsp.nvim_workspace() lsp.setup() +-- Initialize rust_analyzer with rust-tools +local rust_lsp = lsp.build_options('rust_analyzer', {}) +require('rust-tools').setup({server = rust_lsp}) + +local lspconfig = require("lspconfig") +local configs = require("lspconfig.configs") +if use_google() then + configs.ciderlsp = { + default_config = { + cmd = { "/google/bin/releases/cider/ciderlsp/ciderlsp", "--tooltag=nvim-cmp", "--forward_sync_responses" }, + filetypes = { "c", "cpp", "java", "kotlin", "objc", "proto", "textproto", "go", "python", "bzl" }, + root_dir = lspconfig.util.root_pattern("BUILD"), + settings = {}, + }, + } + + configs.analysislsp = { + default_config = { + cmd = { '/google/bin/users/lerm/glint-ale/analysis_lsp/server', '--lint_on_save=false', '--max_qps=10', }, + filetypes = { "c", "cpp", "java", "kotlin", "objc", "proto", "textproto", "go", "python", "bzl" }, + root_dir = lspconfig.util.root_pattern('BUILD'), + settings = {}, + }, + } +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["workspace/diagnostic/refresh"] = function(_, result, ctx) + notify('result:'..result, 'info', {timeout=900}) + notify('ctx:'..ctx, 'info', {timeout=900}) +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 + +local lsp_status = require('lsp-status') + +-- 3. Set up CiderLSP +local on_attach = function(client, bufnr) + vim.b['is_cider_lsp_attached'] = 'no' + 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 + + if client.server_capabilities.document_highlight then + 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()") + end + + lsp_status.on_attach(client, bufnr) +end + +local opts = { noremap = true, silent = true } +vim.api.nvim_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) +vim.api.nvim_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", opts) +vim.api.nvim_set_keymap("n", "L", "lua vim.lsp.buf.hover()", opts) +vim.api.nvim_set_keymap("n", "g0", "lua vim.lsp.buf.document_symbol()", opts) +vim.api.nvim_set_keymap("n", "gW", "lua vim.lsp.buf.workspace_symbol()", opts) +vim.api.nvim_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) +vim.api.nvim_set_keymap("n", "gD", "tab split | lua vim.lsp.buf.definition()", opts) +-- vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) +vim.api.nvim_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) +vim.api.nvim_set_keymap("n", "grf", "lua vim.lsp.buf.references()", opts) -- diagnostics controls references +vim.api.nvim_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) +vim.api.nvim_set_keymap("i", "", "lua vim.lsp.buf.signature_help()", opts) + +vim.api.nvim_set_keymap("n", "gt", "lua vim.lsp.buf.type_definition()", opts) + + +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 +} + +lsp_status.register_progress() +capabilities = vim.tbl_extend('keep', capabilities or {}, lsp_status.capabilities) + local runtime_path = vim.split(package.path, ";") table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") lspconfig.sumneko_lua.setup({ + capabilities = capabilities, + on_attach = on_attach, settings = { Lua = { runtime = { @@ -46,35 +169,32 @@ lspconfig.sumneko_lua.setup({ }, }) --- Initialize rust_analyzer with rust-tools -require('rust-tools').setup({server = rust_lsp}) if use_google() then - configs.ciderlsp = { - default_config = { - cmd = { "/google/bin/releases/cider/ciderlsp/ciderlsp", "--tooltag=nvim-cmp", "--forward_sync_responses" }, - -- cmd = {'/google/bin/releases/cider/ciderlsp/ciderlsp', '--forward_sync_responses', '--enable_document_highlight'}; - filetypes = { "c", "cpp", "java", "kotlin", "objc", "proto", "textproto", "go", "python", "bzl" }, - root_dir = lspconfig.util.root_pattern("BUILD"), - settings = {}, - }, - } + 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 = on_attach, + handlers = cider_lsp_handlers, + }) + lspconfig.analysislsp.setup({ + capabilities = capabilities, + }) end +local lspkind = require("lspkind") +lspkind.init() +local cmp = require("cmp") + 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") +local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) +end -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline({ '/', '?' }, { @@ -114,8 +234,10 @@ local conditionalSources = { }, } +local use_google = require("utils").use_google if use_google() then table.insert(conditionalSources, { name = 'nvim_ciderlsp', priority = 9 }) + table.insert(conditionalSources, { name = 'analysislsp', priority = 9 }) end cmp.setup({ @@ -170,28 +292,7 @@ cmp.setup({ sources = conditionalSources, 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, - }, + comparators = { }, }, snippet = { @@ -205,12 +306,12 @@ cmp.setup({ with_text = true, maxwidth = 40, -- half max width menu = { - -- nvim_ciderlsp = "[]", nvim_ciderlsp = "", buffer = "", nvim_lsp = "[CiderLSP]", nvim_lua = "[API]", path = "[path]", + tmux = "[TMUX]", vim_vsnip = "[snip]", }, }), @@ -229,105 +330,3 @@ autocmd Filetype zsh lua require'cmp'.setup.buffer { sources = { { name = "zsh" augroup 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["workspace/diagnostic/refresh"] = function(_, result, ctx) - notify('result:'..result, 'info', {timeout=900}) - notify('ctx:'..ctx, 'info', {timeout=900}) -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 - --- 3. Set up CiderLSP -local on_attach = function(client, bufnr) - vim.b['is_cider_lsp_attached'] = 'no' - 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 - - if client.server_capabilities.document_highlight then - 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()") - end -end - -local opts = { noremap = true, silent = true } -vim.api.nvim_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) -vim.api.nvim_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", opts) -vim.api.nvim_set_keymap("n", "L", "lua vim.lsp.buf.hover()", opts) -vim.api.nvim_set_keymap("n", "g0", "lua vim.lsp.buf.document_symbol()", opts) -vim.api.nvim_set_keymap("n", "gW", "lua vim.lsp.buf.workspace_symbol()", opts) -vim.api.nvim_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) -vim.api.nvim_set_keymap("n", "gD", "tab split | lua vim.lsp.buf.definition()", opts) --- vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) -vim.api.nvim_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) -vim.api.nvim_set_keymap("n", "grf", "lua vim.lsp.buf.references()", opts) -- diagnostics controls references -vim.api.nvim_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) -vim.api.nvim_set_keymap("i", "", "lua vim.lsp.buf.signature_help()", opts) - -vim.api.nvim_set_keymap("n", "gt", "lua vim.lsp.buf.type_definition()", opts) - - -local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) -capabilities['codeLens'] = {dynamicRegistration=false} --- capabilities.workspace.codeLens = {refreshSupport=true} --- capabilities.workspace.diagnostics = {refreshSupport=true} -capabilities.textDocument.publishDiagnostics={ - relatedInformation=true, - versionSupport=false, - tagSupport={ - valueSet={ - 1, - 2 - } - }, - codeDescriptionSupport=true, - dataSupport=true, - --layeredDiagnostics=true -} -if use_google() then - capabilities = require('cmp_nvim_ciderlsp').update_capabilities(capabilities) - lspconfig.ciderlsp.setup({ - capabilities = capabilities, - on_attach = on_attach, - handlers = cider_lsp_handlers, - }) -end diff --git a/vim/.vim/lua/lualine_config.lua b/vim/.vim/lua/lualine_config.lua index 8d3813b..f3fad73 100644 --- a/vim/.vim/lua/lualine_config.lua +++ b/vim/.vim/lua/lualine_config.lua @@ -5,9 +5,6 @@ local split = function (inputstr, sep) end return t end -local function getWords() - return tostring(vim.fn.wordcount().words) -end local function getCitc() local fname = vim.api.nvim_buf_get_name(0) if string.find(fname, '/google/src/cloud/', 1, true) then @@ -15,7 +12,7 @@ local function getCitc() return parts[5] end end -function isCiderLspAttached() +local function isCiderLspAttached() if vim.b['is_cider_lsp_attached'] then if vim.b['is_cider_lsp_attached'] == 'yes' then return '✓' @@ -26,6 +23,7 @@ function isCiderLspAttached() return '' end end + local function getLightbulb() return require('nvim-lightbulb').get_status_text() end @@ -56,7 +54,7 @@ require('lualine').setup { sections = { lualine_a = {'mode'}, lualine_b = {'branch', 'diff', getCitc, isCiderLspAttached}, - lualine_c = {'filename', {"aerial", depth=-1}, getLightbulb}, + lualine_c = {'filename', 'lsp_progress', getLightbulb}, lualine_x = { { 'diagnostics', sources = {"nvim_lsp"}, symbols = {error = ' ', warn = ' ', info = ' ', hint = ' '} }, 'encoding', @@ -69,7 +67,7 @@ require('lualine').setup { lualine_a = {{'tabs', mode = 1}}, -- lualine_b = {'branch'}, -- lualine_c = {'filename'}, - lualine_x = { + lualine_c = { { 'diagnostics', sources = {"nvim_lsp", "nvim_workspace_diagnostic"}, symbols = {error = ' ', warn = ' ', info = ' ', hint = ' '} }, }, -- lualine_y = { getLGTMs } diff --git a/vim/.vim/lua/null_lsp.lua b/vim/.vim/lua/null_lsp.lua new file mode 100644 index 0000000..b6a3879 --- /dev/null +++ b/vim/.vim/lua/null_lsp.lua @@ -0,0 +1,25 @@ +local null_ls = require("null-ls") + +local sources = { + -- Catch insensitive, inconsiderate writing. + null_ls.builtins.diagnostics.alex, + + -- buildifier is a tool for formatting and linting bazel BUILD, WORKSPACE, and .bzl files. + null_ls.builtins.diagnostics.buildifier, + + -- Codespell finds common misspellings in text files. + -- null_ls.builtins.diagnostics.codespell, + -- null_ls.builtins.diagnostics.cspell, null_ls.builtins.code_actions.cspell, + + -- An English prose linter. Can fix some issues via code actions. + null_ls.builtins.code_actions.proselint, + + -- Reformats Java source code according to Google Java Style. + null_ls.builtins.formatting.google_java_format + +} + + +null_ls.setup({ + sources = sources, +}) diff --git a/vim/.vim/lua/plugins.lua b/vim/.vim/lua/plugins.lua index b0bfd15..cc8fef4 100644 --- a/vim/.vim/lua/plugins.lua +++ b/vim/.vim/lua/plugins.lua @@ -13,8 +13,6 @@ autocmd BufWritePost plugins.lua source | PackerCompile augroup end ]]) - - require('packer').startup(function(use) -- Packer can manage itself use 'wbthomason/packer.nvim' @@ -73,6 +71,10 @@ require('packer').startup(function(use) "williamboman/mason-lspconfig.nvim", 'VonHeikemen/lsp-zero.nvim', } + use { + 'jose-elias-alvarez/null-ls.nvim', + config = [[ require("null_lsp") ]] + } use 'simrat39/rust-tools.nvim' use 'folke/trouble.nvim' @@ -100,7 +102,10 @@ require('packer').startup(function(use) end } + use { + -- 'sso://googler@user/lerm/glint-ale', + -- 'dense-analysis/ale', 'sso://googler@user/vintharas/telescope-codesearch.nvim', disable = not use_google(), } @@ -121,6 +126,7 @@ require('packer').startup(function(use) config = [[ require("critique").setup() ]] } + use 'nvim-lua/lsp-status.nvim' use { 'nvim-lualine/lualine.nvim', config = [[ require("lualine_config") ]] @@ -202,9 +208,12 @@ end) -- CiderLSP vim.opt.completeopt = { "menu", "menuone", "noselect" } +-- Don't show the dumb matching stuff +vim.opt.shortmess:append("c") require('lspconfig') require("lsp") + require("diagnostics") require("treesitter") require("telescope_config") diff --git a/vim/.vim/lua/utils.lua b/vim/.vim/lua/utils.lua index 978b6e9..8bf07c7 100644 --- a/vim/.vim/lua/utils.lua +++ b/vim/.vim/lua/utils.lua @@ -22,7 +22,7 @@ function M.dump(o) local s = '{ ' for k,v in pairs(o) do if type(k) ~= 'number' then k = '"'..k..'"' end - s = s .. '['..k..'] = ' .. dump(v) .. ',' + s = s .. '['..k..'] = ' .. M.dump(v) .. ',' end return s .. '} ' else