From 9b80bee1d5f69002402cbc27959563d96d50e7e4 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Fri, 15 Apr 2022 23:21:17 -0700 Subject: [PATCH] update nvim --- nvim/init.vim | 5 +- nvim/keybindings.vim | 9 +- nvim/plugin-confs/lspconfig.lua | 142 ++++++++++++++++---------------- nvim/plugin-confs/null-ls.lua | 43 +++++----- nvim/plugin-confs/nvim-cmp.lua | 132 ++++++++++++++--------------- 5 files changed, 169 insertions(+), 162 deletions(-) diff --git a/nvim/init.vim b/nvim/init.vim index a2301b7..5177925 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -1,7 +1,7 @@ syntax enable filetype plugin on set noshowmode "disable default vim insert text at bottom -set laststatus=2 +set laststatus=3 set number set colorcolumn=80 set tw=80 @@ -79,6 +79,8 @@ if has('nvim') Plug 'nvim-lua/plenary.nvim' Plug 'nvim-lua/popup.nvim' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} + " Plug 'zbirenbaum/copilot.lua' + " Plug 'zbirenbaum/copilot-cmp' " Plug 'nvim-telescope/telescope.nvim' " Plug 'TimUntersberger/neogit' @@ -153,6 +155,7 @@ if has('nvim') source ~/.config/nvim/plugin-confs/whichkey.lua source ~/.config/nvim/plugin-confs/code_actions.lua + " source ~/.config/nvim/plugin-confs/copilot.lua source ~/.config/nvim/plugin-confs/goto-preview.lua source ~/.config/nvim/plugin-confs/lsp-kind.lua source ~/.config/nvim/plugin-confs/lsp-signature.lua diff --git a/nvim/keybindings.vim b/nvim/keybindings.vim index 948e7e9..8958aac 100644 --- a/nvim/keybindings.vim +++ b/nvim/keybindings.vim @@ -5,10 +5,10 @@ nmap :! vnoremap < >gv -" for toggling/hiding the vsplit-term +" for toggling/hiding the split-term tnoremap :FloatermToggle floatingterm tnoremap -tnoremap tt :FloatermToggle vsplit-term +tnoremap tt :FloatermToggle split-term nmap :bnext nmap :bprev @@ -91,9 +91,10 @@ nmap n :NvimTreeToggle nmap ob :FloatermNew --title=bpytop --opener=vsplit bpytop nmap od :FloatermNew --title=lazydocker --opener=vsplit lazydocker +nmap oh :FloatermNew --title=floaterm --name=split-term --opener=edit --wintype=split --position=botright --height=0.45 nmap on :FloatermNew --title=ncmpcpp --opener=vsplit ncmpcpp nmap or :FloatermNew --title=ranger --opener=vsplit ranger --cmd="cd $PWD" -nmap ot :FloatermNew --title=floaterm --name=vsplit-term --opener=edit --wintype=vsplit --position=botright --width=0.5 +nmap ot :FloatermNew --title=floaterm --name=split-term --opener=edit --wintype=vsplit --position=botright --width=0.5 nmap r :NvimTreeRefresh @@ -107,7 +108,7 @@ nmap s/ :History/ nnoremap tc :DashboardChangeColorscheme nmap to :SymbolsOutline -nmap tt :FloatermToggle vsplit-term +nmap tt :FloatermToggle split-term nmap wa :lua vim.lsp.buf.add_workspace_folder() nmap wl :lua print(vim.inspect(vim.lsp.buf.list_workspace_folders())) diff --git a/nvim/plugin-confs/lspconfig.lua b/nvim/plugin-confs/lspconfig.lua index 7c0c9b7..f73b811 100644 --- a/nvim/plugin-confs/lspconfig.lua +++ b/nvim/plugin-confs/lspconfig.lua @@ -1,4 +1,4 @@ -local opts = { noremap=true, silent=true } +local opts = { noremap = true, silent = true } vim.api.nvim_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) vim.api.nvim_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) vim.api.nvim_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) @@ -7,38 +7,38 @@ vim.api.nvim_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist() - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') - -- Mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - -- set in ~/.config/nvim/keybindings.vim - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()', opts) - -- highlighting things under cursor - -- if client.resolved_capabilities.document_highlight then - -- vim.cmd [[ - -- hi! LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow - -- hi! LspReferenceText cterm=bold ctermbg=red guibg=LightYellow - -- hi! LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow - -- augroup lsp_document_highlight - -- autocmd! * - -- autocmd! CursorHold lua vim.lsp.buf.document_highlight() - -- autocmd! CursorMoved lua vim.lsp.buf.clear_references() - -- augroup END - -- ]] - -- end + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + -- set in ~/.config/nvim/keybindings.vim + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) + -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()', opts) + -- highlighting things under cursor + -- if client.resolved_capabilities.document_highlight then + -- vim.cmd [[ + -- hi! LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow + -- hi! LspReferenceText cterm=bold ctermbg=red guibg=LightYellow + -- hi! LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow + -- augroup lsp_document_highlight + -- autocmd! * + -- autocmd! CursorHold lua vim.lsp.buf.document_highlight() + -- autocmd! CursorMoved lua vim.lsp.buf.clear_references() + -- augroup END + -- ]] + -- end end vim.cmd [[autocmd! ColorScheme * highlight NormalFloat guibg=#1f2335]] @@ -60,19 +60,19 @@ vim.cmd [[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335 -- rounded local border = { - {"╭", "FloatBorder"}, - {"─", "FloatBorder"}, - {"╮", "FloatBorder"}, - {"│", "FloatBorder"}, - {"╯", "FloatBorder"}, - {"─", "FloatBorder"}, - {"╰", "FloatBorder"}, - {"│", "FloatBorder"}, + { "╭", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╮", "FloatBorder" }, + { "│", "FloatBorder" }, + { "╯", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╰", "FloatBorder" }, + { "│", "FloatBorder" }, } -local handlers = { - ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {border = border}), - ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {border = border }), +local handlers = { + ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }), + ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = border }), } local DEFAULT_SETTINGS = { @@ -110,7 +110,7 @@ local DEFAULT_SETTINGS = { install_args = {}, }, on_attach = on_attach, - handlers=handlers, + handlers = handlers, -- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when -- debugging issues with server installations. @@ -122,36 +122,36 @@ local DEFAULT_SETTINGS = { } vim.diagnostic.config({ - virtual_text = true, - signs = true, - underline = false, - update_in_insert = false, - severity_sort = true, + virtual_text = true, + signs = true, + underline = false, + update_in_insert = false, + severity_sort = true, }) local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end function PrintDiagnostics(opts, bufnr, line_nr, client_id) - bufnr = bufnr or 0 - line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) - opts = opts or {['lnum'] = line_nr} + bufnr = bufnr or 0 + line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) + opts = opts or { ['lnum'] = line_nr } - local line_diagnostics = vim.diagnostic.get(bufnr, opts) - if vim.tbl_isempty(line_diagnostics) then return end + local line_diagnostics = vim.diagnostic.get(bufnr, opts) + if vim.tbl_isempty(line_diagnostics) then return end - local diagnostic_message = "" - for i, diagnostic in ipairs(line_diagnostics) do - diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") - print(diagnostic_message) - if i ~= #line_diagnostics then - diagnostic_message = diagnostic_message .. "\n" + local diagnostic_message = "" + for i, diagnostic in ipairs(line_diagnostics) do + diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") + print(diagnostic_message) + if i ~= #line_diagnostics then + diagnostic_message = diagnostic_message .. "\n" + end end - end - vim.api.nvim_echo({{diagnostic_message, "Normal"}}, false, {}) + vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) end -- vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]] @@ -176,13 +176,13 @@ end) -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -local servers = { 'pyright', 'bashls', 'vimls', 'yamlls', 'dockerls', 'html', 'sumneko_lua', 'dotls', 'rust_analyzer', 'clangd' } +local servers = { 'pyright', 'bashls', 'vimls', 'yamlls', 'dockerls', 'html', 'sumneko_lua', 'dotls', 'rust_analyzer', 'clangd', 'ansiblels' } for _, lsp in pairs(servers) do - require('lspconfig')[lsp].setup { - on_attach = on_attach, - flags = { - -- This will be the default in neovim 0.7+ - debounce_text_changes = 150, + require('lspconfig')[lsp].setup { + on_attach = on_attach, + flags = { + -- This will be the default in neovim 0.7+ + debounce_text_changes = 150, + } } - } end diff --git a/nvim/plugin-confs/null-ls.lua b/nvim/plugin-confs/null-ls.lua index c9bf64c..3824d85 100644 --- a/nvim/plugin-confs/null-ls.lua +++ b/nvim/plugin-confs/null-ls.lua @@ -13,35 +13,36 @@ require("null-ls").setup({ end end, sources = { - require("null-ls").builtins.completion.spell, - require("null-ls").builtins.completion.luasnip, - require("null-ls").builtins.code_actions.gitsigns, - require("null-ls").builtins.code_actions.shellcheck, - require("null-ls").builtins.diagnostics.cppcheck, - require("null-ls").builtins.diagnostics.gitlint, - require("null-ls").builtins.diagnostics.jsonlint, + null_ls.builtins.completion.spell, + null_ls.builtins.completion.luasnip, + null_ls.builtins.code_actions.gitsigns, + null_ls.builtins.code_actions.shellcheck, + null_ls.builtins.diagnostics.cppcheck, + null_ls.builtins.diagnostics.gitlint, + null_ls.builtins.diagnostics.jsonlint, -- require("null-ls").builtins.diagnostics.luacheck, - require("null-ls").builtins.diagnostics.markdownlint, - require("null-ls").builtins.diagnostics.pylint, - require("null-ls").builtins.diagnostics.pydocstyle.with({ + null_ls.builtins.diagnostics.markdownlint, + null_ls.builtins.diagnostics.pylint, + null_ls.builtins.diagnostics.pydocstyle.with({ extra_args = { "--config=$ROOT/setup.cfg" } }), - require("null-ls").builtins.diagnostics.vint, - require("null-ls").builtins.formatting.json_tool, + null_ls.builtins.diagnostics.vint, + null_ls.builtins.diagnostics.shellcheck.with({ + extra_args = { "-s", "bash", "-o", "add-default-case, check-set-e-suppressed, check-unassigned-uppercase, deprecate-which, quote-safe-variables" } + }), + null_ls.builtins.diagnostics.ansiblelint, + null_ls.builtins.formatting.json_tool, -- require("null-ls").builtins.formatting.lua_format, - require("null-ls").builtins.formatting.markdownlint, - require("null-ls").builtins.formatting.prettier, + null_ls.builtins.formatting.markdownlint, + null_ls.builtins.formatting.prettier, -- handled by lsp server -- require("null-ls").builtins.formatting.rustfmt, - require("null-ls").builtins.formatting.shfmt.with({ - filetypes = {"sh", "bash"}, + null_ls.builtins.formatting.shfmt.with({ + filetypes = { "sh", "bash" }, extra_args = { "-i", "0", "-ci", "-sr" } }), - require("null-ls").builtins.diagnostics.shellcheck.with({ - extra_args = { "-s", "bash", "-o", "check-extra-masked-returns, check-set-e-suppressed, check-unassigned-uppercase, deprecate-which, quote-safe-variables" } - }), - require("null-ls").builtins.formatting.black, - require("null-ls").builtins.formatting.isort, + null_ls.builtins.formatting.black, + null_ls.builtins.formatting.isort, }, }) diff --git a/nvim/plugin-confs/nvim-cmp.lua b/nvim/plugin-confs/nvim-cmp.lua index 32c0360..aedb035 100644 --- a/nvim/plugin-confs/nvim-cmp.lua +++ b/nvim/plugin-confs/nvim-cmp.lua @@ -1,5 +1,5 @@ -- Setup nvim-cmp. -local cmp = require'cmp' +local cmp = require 'cmp' local lspkind = require('lspkind') local capabilities = vim.lsp.protocol.make_client_capabilities() @@ -10,12 +10,12 @@ local luasnip = require 'luasnip' cmp.setup({ snippet = { - expand = function(args) - -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - end, + expand = function(args) + -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, }, capabilities = capabilities, -- mapping = { @@ -30,72 +30,74 @@ cmp.setup({ -- [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. -- }, mapping = { - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - -- [''] = function(fallback) - -- if cmp.visible() then - -- cmp.select_next_item() - -- elseif luasnip.expand_or_jumpable() then - -- luasnip.expand_or_jump() - -- else - -- fallback() - -- end - -- end, - -- [''] = function(fallback) - -- if cmp.visible() then - -- cmp.select_prev_item() - -- elseif luasnip.jumpable(-1) then - -- luasnip.jump(-1) - -- else - -- fallback() - -- end - -- end, + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + -- [''] = function(fallback) + -- if cmp.visible() then + -- cmp.select_next_item() + -- elseif luasnip.expand_or_jumpable() then + -- luasnip.expand_or_jump() + -- else + -- fallback() + -- end + -- end, + -- [''] = function(fallback) + -- if cmp.visible() then + -- cmp.select_prev_item() + -- elseif luasnip.jumpable(-1) then + -- luasnip.jump(-1) + -- else + -- fallback() + -- end + -- end, }, formatting = { - format = lspkind.cmp_format({ - mode = 'symbol', -- show only symbol annotations - maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) + format = lspkind.cmp_format({ + mode = 'symbol', -- show only symbol annotations + maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) - -- The function below will be called before any actual modifications from lspkind - -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) - -- before = function (entry, vim_item) - -- ... - -- return vim_item - -- end - }) + -- The function below will be called before any actual modifications from lspkind + -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30)) + -- before = function (entry, vim_item) + -- ... + -- return vim_item + -- end + }) }, sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - -- { name = 'vsnip' }, -- For vsnip users. - { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. + { name = "copilot", group_index = 2 }, + { name = 'nvim_lsp', group_index = 2 }, + -- { name = 'vsnip' }, -- For vsnip users. + { name = "path", group_index = 2 }, + { name = 'luasnip', group_index = 2 }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. }, { - { name = 'buffer' }, + { name = 'buffer' }, }) - }) +}) - -- Setup lspconfig. - -- local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) - -- Replace with each lsp server you've enabled. - -- require('lspconfig')['bashls'].setup { - -- capabilities = capabilities - -- } - -- Enable some language servers with the additional completion capabilities offered by nvim-cmp - local lspconfig = require('lspconfig') - local servers = { 'bashls', 'pyright', 'sqlls', 'jsonls', 'yamlls', 'vimls', 'dotls', 'dockerls' } - for _, lsp in ipairs(servers) do +-- Setup lspconfig. +-- local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +-- Replace with each lsp server you've enabled. +-- require('lspconfig')['bashls'].setup { +-- capabilities = capabilities +-- } +-- Enable some language servers with the additional completion capabilities offered by nvim-cmp +local lspconfig = require('lspconfig') +local servers = { 'bashls', 'pyright', 'sqlls', 'jsonls', 'yamlls', 'vimls', 'dotls', 'dockerls' } +for _, lsp in ipairs(servers) do lspconfig[lsp].setup { - -- on_attach = my_custom_on_attach, - capabilities = capabilities, + -- on_attach = my_custom_on_attach, + capabilities = capabilities, } - end +end