diff --git a/after/plugin/airline.vim b/after/plugin/airline.vim index 013324c..377d079 100644 --- a/after/plugin/airline.vim +++ b/after/plugin/airline.vim @@ -7,3 +7,12 @@ let g:airline_symbols.branch = '' let g:airline_symbols.readonly = '' let g:airline_symbols.linenr = '' let g:airline_section_z = '' + +function! LspStatus() abort + let status = luaeval('require("lsp-status").status()') + return trim(status) +endfunction +call airline#parts#define_function('lsp_status', 'LspStatus') +call airline#parts#define_condition('lsp_status', 'luaeval("#vim.lsp.buf_get_clients() > 0")') +let g:airline#extensions#nvimlsp#enabled = 0 +let g:airline_section_warning = airline#section#create_right(['lsp_status']) diff --git a/init.vim b/init.vim index e4a70ac..ddd0b30 100644 --- a/init.vim +++ b/init.vim @@ -52,8 +52,9 @@ set suffixes+=.pdf set wildmenu set hidden -" set completeopt=menu,noinsert,preview -set completeopt=menuone,noinsert,noselect +"set completeopt=menu,noinsert,preview +"set completeopt=menuone,noinsert,noselect +set completeopt=menu,menuone,noselect set shortmess+=c inoremap pumvisible() ? "\" : "\u\" @@ -177,7 +178,6 @@ let g:localvimrc_sandbox=0 lua require("my-lsp") lua require("lsputils") -"lua require("conf.compe") lua require("conf.cmp") lua require("conf.trouble") " vi:foldmethod=marker sw=2 diff --git a/lua/conf/cmp.lua b/lua/conf/cmp.lua index ec04ac3..fe8b747 100644 --- a/lua/conf/cmp.lua +++ b/lua/conf/cmp.lua @@ -13,12 +13,19 @@ cmp.setup({ behavior = cmp.ConfirmBehavior.Replace, select = true, }), - [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }) + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end }, sources = { { name = 'nvim_lsp' }, - { name = 'buffer' }, - { name = 'path' }, + --{ name = 'buffer' }, + { name = 'vsnip' }, + --{ name = 'path' }, } }) local capabilities = vim.lsp.protocol.make_client_capabilities() diff --git a/lua/conf/compe.lua b/lua/conf/compe.lua deleted file mode 100644 index c430800..0000000 --- a/lua/conf/compe.lua +++ /dev/null @@ -1,72 +0,0 @@ -require'compe'.setup { - enabled = true; - autocomplete = true; - debug = false; - min_length = 1; - preselect = 'enable'; - throttle_time = 80; - source_timeout = 200; - resolve_timeout = 800; - incomplete_delay = 400; - max_abbr_width = 100; - max_kind_width = 100; - max_menu_width = 100; - documentation = { - border = { '', '' ,'', ' ', '', '', '', ' ' }, -- the border option is the same as `|help nvim_open_win|` - winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", - max_width = 120, - min_width = 60, - max_height = math.floor(vim.o.lines * 0.3), - min_height = 1, - }; - - source = { - path = true; - buffer = true; - calc = true; - nvim_lsp = true; - nvim_lua = true; - vsnip = true; - ultisnips = true; - luasnip = true; - }; -} - -local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) -end - -local check_back_space = function() - local col = vim.fn.col('.') - 1 - return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil -end - --- Use (s-)tab to: ---- move to prev/next item in completion menuone ---- jump to prev/next snippet's placeholder -_G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn['vsnip#available'](1) == 1 then - return t "(vsnip-expand-or-jump)" - elseif check_back_space() then - return t "" - else - return vim.fn['compe#complete']() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn['vsnip#jumpable'](-1) == 1 then - return t "(vsnip-jump-prev)" - else - -- If is not working in your terminal, change it to - return t "" - end -end - -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", {expr = true}) diff --git a/lua/lsputils.lua b/lua/lsputils.lua index fc1c315..765578b 100644 --- a/lua/lsputils.lua +++ b/lua/lsputils.lua @@ -1,8 +1,44 @@ -vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler -vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler -vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler -vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler -vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler -vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler -vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler -vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler +if vim.fn.has('nvim-0.5.1') == 1 then + vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler + vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler + vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler + vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler + vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler + vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler + vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler + vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler +else + local bufnr = vim.api.nvim_buf_get_number(0) + + vim.lsp.handlers['textDocument/codeAction'] = function(_, _, actions) + require('lsputil.codeAction').code_action_handler(nil, actions, nil, nil, nil) + end + + vim.lsp.handlers['textDocument/references'] = function(_, _, result) + require('lsputil.locations').references_handler(nil, result, { bufnr = bufnr }, nil) + end + + vim.lsp.handlers['textDocument/definition'] = function(_, method, result) + require('lsputil.locations').definition_handler(nil, result, { bufnr = bufnr, method = method }, nil) + end + + vim.lsp.handlers['textDocument/declaration'] = function(_, method, result) + require('lsputil.locations').declaration_handler(nil, result, { bufnr = bufnr, method = method }, nil) + end + + vim.lsp.handlers['textDocument/typeDefinition'] = function(_, method, result) + require('lsputil.locations').typeDefinition_handler(nil, result, { bufnr = bufnr, method = method }, nil) + end + + vim.lsp.handlers['textDocument/implementation'] = function(_, method, result) + require('lsputil.locations').implementation_handler(nil, result, { bufnr = bufnr, method = method }, nil) + end + + vim.lsp.handlers['textDocument/documentSymbol'] = function(_, _, result, _, bufn) + require('lsputil.symbols').document_handler(nil, result, { bufnr = bufn }, nil) + end + + vim.lsp.handlers['textDocument/symbol'] = function(_, _, result, _, bufn) + require('lsputil.symbols').workspace_handler(nil, result, { bufnr = bufn }, nil) + end + end diff --git a/lua/my-lsp.lua b/lua/my-lsp.lua index 39b6213..c4078b1 100644 --- a/lua/my-lsp.lua +++ b/lua/my-lsp.lua @@ -1,5 +1,6 @@ -local lspconfig = require('lspconfig') -local configs = require('lspconfig.configs') +local lsp_status = require('lsp-status') + +lsp_status.register_progress() -- enable snippet support local capabilities = vim.lsp.protocol.make_client_capabilities() @@ -11,6 +12,7 @@ capabilities.textDocument.completion.completionItem.resolveSupport = { 'additionalTextEdits', } } +capabilities = vim.tbl_extend('keep', capabilities or {}, lsp_status.capabilities) -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer @@ -40,6 +42,9 @@ local on_attach = function(client, bufnr) buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) buf_set_keymap('n', '', 'lua vim.lsp.diagnostic.set_loclist()', opts) buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) + + lsp_status.on_attach(client) + --require'completion'.on_attach(client, bufnr) end @@ -47,13 +52,6 @@ local lsp_installer = require("nvim-lsp-installer") lsp_installer.on_server_ready(function(server) local opts = {} - -- (optional) Customize the options passed to the server - -- if server.name == "tsserver" then - -- opts.root_dir = function() ... end - -- end - - -- This setup() function is exactly the same as lspconfig's setup function. - -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md server:setup(opts) end) @@ -61,31 +59,25 @@ metals_config = require("metals").bare_config() metals_config.init_options.statusBarProvider = "on" metals_config.settings = { showImplicitArguments = true } metals_config.on_attach = on_attach +metals_config.capabilities = capabilities vim.cmd [[augroup lsp]] vim.cmd [[au!]] vim.cmd [[au FileType scala,sbt lua require("metals").initialize_or_attach(metals_config)]] vim.cmd [[augroup end]] --- Use a loop to conveniently call 'setup' on multiple servers and --- map buffer local keybindings when the language server attaches -local servers = { "lemminx" } -for _, lsp in ipairs(servers) do - lspconfig[lsp].setup { - on_attach = on_attach, - capabilities = capabilities, - flags = { - debounce_text_changes = 150, - } - } -end - vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = false, - underline = true, - signs = true, - } + vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = false, + underline = true, + signs = true, + } +) + +vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( + vim.lsp.handlers.signature_help, { + silent = true, focusable = false + } ) vim.cmd [[autocmd CursorHoldI * silent! lua vim.lsp.buf.signature_help()]] diff --git a/packages.vim b/packages.vim index 842fc6e..164be60 100644 --- a/packages.vim +++ b/packages.vim @@ -16,7 +16,7 @@ Plug 'tpope/vim-characterize' Plug 'tpope/vim-eunuch' Plug 'tpope/vim-commentary' Plug 'tpope/vim-sleuth' - +" " motions and textobjects Plug 'kana/vim-textobj-user' Plug 'glts/vim-textobj-comment' @@ -26,18 +26,25 @@ Plug 'vim-scripts/argtextobj.vim' Plug 'mhinz/vim-signify' " LSP +Plug 'neovim/nvim-lspconfig' +Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'hrsh7th/cmp-buffer' +Plug 'hrsh7th/nvim-cmp' +Plug 'nvim-lua/plenary.nvim' +Plug 'scalameta/nvim-metals' +Plug 'hrsh7th/cmp-vsnip' +Plug 'hrsh7th/vim-vsnip' " Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'neovim/nvim-lspconfig' Plug 'williamboman/nvim-lsp-installer' Plug 'scalameta/nvim-metals' -"Plug 'hrsh7th/nvim-compe' -Plug 'hrsh7th/nvim-cmp' Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'hrsh7th/nvim-cmp' +Plug 'hrsh7th/cmp-vsnip' Plug 'hrsh7th/vim-vsnip' -Plug 'hrsh7th/vim-vsnip-integ' "Plug 'nvim-lua/completion-nvim' Plug 'nvim-treesitter/nvim-treesitter', {'branch': '0.5-compat', 'do': ':TSUpdate'} Plug 'nvim-lua/lsp-status.nvim' @@ -49,8 +56,6 @@ Plug 'folke/lsp-colors.nvim' Plug 'nvim-lua/popup.nvim' Plug 'nvim-lua/plenary.nvim' Plug 'nvim-telescope/telescope.nvim' -Plug 'L3MON4D3/LuaSnip' - Plug 'machakann/vim-highlightedyank' @@ -70,10 +75,10 @@ Plug 'tpope/vim-rails' Plug 'tpope/vim-rake' " git -"Plug 'tpope/vim-fugitive' Plug 'lambdalisue/gina.vim' Plug 'gregsexton/gitv' Plug 'gisphm/vim-gitignore' +Plug 'sjl/splice.vim' " other filetype specific plugins Plug 'jamessan/vim-gnupg'