From 97d8d3d0b44ae60b9c8529e20f18543db0375017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sun, 4 Jul 2021 09:54:33 +0200 Subject: [PATCH] nvim 0.5 plugins --- .../templates/snippets/pm_dev_common.j2 | 2 + .../automatrop/roles/vim/templates/editor.j2 | 7 +- .../roles/vim/templates/pluginlist.j2 | 24 +++++- .../roles/vim/templates/plugins/base16.j2 | 9 ++ .../roles/vim/templates/plugins/devicons.j2 | 5 ++ .../roles/vim/templates/plugins/nvim_compe.j2 | 84 +++++++++++++++++++ .../vim/templates/plugins/nvim_lspconfig.j2 | 70 ++++++++++++++++ .../roles/vim/templates/plugins/supertab.j2 | 3 + .../roles/vim/templates/plugins/telescope.j2 | 39 +++++++++ .../roles/vim/templates/plugins/treesitter.j2 | 6 ++ .../roles/vim/templates/plugins/vim_lsp.j2 | 32 +++++-- .../roles/vim/templates/plugins/vsnip.j2 | 3 + 12 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 config/automatrop/roles/vim/templates/plugins/devicons.j2 create mode 100644 config/automatrop/roles/vim/templates/plugins/nvim_compe.j2 create mode 100644 config/automatrop/roles/vim/templates/plugins/nvim_lspconfig.j2 create mode 100644 config/automatrop/roles/vim/templates/plugins/telescope.j2 create mode 100644 config/automatrop/roles/vim/templates/plugins/treesitter.j2 create mode 100644 config/automatrop/roles/vim/templates/plugins/vsnip.j2 diff --git a/config/automatrop/roles/software/templates/snippets/pm_dev_common.j2 b/config/automatrop/roles/software/templates/snippets/pm_dev_common.j2 index e334359..20fbef4 100644 --- a/config/automatrop/roles/software/templates/snippets/pm_dev_common.j2 +++ b/config/automatrop/roles/software/templates/snippets/pm_dev_common.j2 @@ -9,3 +9,5 @@ universal-ctags {% if not termux %} highlight {% endif %} +{# For nvim's :Telescope live_grep #} +ripgrep diff --git a/config/automatrop/roles/vim/templates/editor.j2 b/config/automatrop/roles/vim/templates/editor.j2 index 9b1070c..9f42efb 100644 --- a/config/automatrop/roles/vim/templates/editor.j2 +++ b/config/automatrop/roles/vim/templates/editor.j2 @@ -67,10 +67,15 @@ filetype on filetype plugin on filetype indent on -set wildmode=longest,list +set wildmode=longest:full,full set wildmenu set showcmd +" Completion + +" Avoid showing message extra message when using completion +set shortmess+=c + " Close the file explorer once you select a file let g:netrw_fastbrowse = 0 diff --git a/config/automatrop/roles/vim/templates/pluginlist.j2 b/config/automatrop/roles/vim/templates/pluginlist.j2 index 1c50b41..b2f3342 100644 --- a/config/automatrop/roles/vim/templates/pluginlist.j2 +++ b/config/automatrop/roles/vim/templates/pluginlist.j2 @@ -7,13 +7,17 @@ " END PLUGIN CONFIG {{ name }} {%- endmacro -%} -" Theming +" Visuals {{ use_plugin('base16') }} {{ use_plugin('airline') }} {{ use_plugin('devicons') }} " Goto utilities +{% if variant == 'nvim' %} +{{ use_plugin('telescope') }} +{% else %} {{ use_plugin('fzf') }} +{% endif %} " Search/replace {{ use_plugin('abolish') }} @@ -31,11 +35,27 @@ {{ use_plugin('vista') }} " Language Server Client +{% if variant == 'nvim' %} +{{ use_plugin('nvim_lspconfig') }} +{% else %} {{ use_plugin('vim_lsp') }} +{% endif %} + +" Treesitter +{% if variant == 'nvim' %} +{{ use_plugin('treesitter') }} +{% endif %} + +" Snippets +{{ use_plugin('vsnip') }} " Auto-completion +{% if variant == 'nvim' %} +{{ use_plugin('nvim_compe') }} +{% else %} {{ use_plugin('deoplete') }} {{ use_plugin('supertab') }} +{% endif %} " Undo management {{ use_plugin('undotree') }} @@ -51,9 +71,11 @@ {% if 'c' in dev_stuffs or 'c++' in dev_stuffs %} {{ use_plugin('vebugger') }} {% endif %} +{# {% if 'python' in dev_stuffs and variant == 'nvim' %} {{ use_plugin('semshi') }} {% endif %} +#} {% if 'ansible' in dev_stuffs %} {{ use_plugin('ansible') }} {% endif %} diff --git a/config/automatrop/roles/vim/templates/plugins/base16.j2 b/config/automatrop/roles/vim/templates/plugins/base16.j2 index 555fb41..90e1fca 100644 --- a/config/automatrop/roles/vim/templates/plugins/base16.j2 +++ b/config/automatrop/roles/vim/templates/plugins/base16.j2 @@ -1,4 +1,13 @@ +{# +" nvim plugin doesn't support terminal colors +{% if variant == 'nvim' %} +{{ add_source('RRethy/nvim-base16') -}} +{% else %} +#} {{ add_source('chriskempson/base16-vim') -}} +{# +{% endif %} +#} colorscheme base16-default-dark " let base16colorspace=256 diff --git a/config/automatrop/roles/vim/templates/plugins/devicons.j2 b/config/automatrop/roles/vim/templates/plugins/devicons.j2 new file mode 100644 index 0000000..7b5e65f --- /dev/null +++ b/config/automatrop/roles/vim/templates/plugins/devicons.j2 @@ -0,0 +1,5 @@ +{% if variant == 'nvim' %} +{{ add_source('kyazdani42/nvim-web-devicons') -}} +{% else %} +{{ add_source('ryanoasis/vim-devicons') -}} +{% endif %} diff --git a/config/automatrop/roles/vim/templates/plugins/nvim_compe.j2 b/config/automatrop/roles/vim/templates/plugins/nvim_compe.j2 new file mode 100644 index 0000000..0c89f21 --- /dev/null +++ b/config/automatrop/roles/vim/templates/plugins/nvim_compe.j2 @@ -0,0 +1,84 @@ +{{ add_source('hrsh7th/nvim-compe') -}} +{# I'm a bit lost with all this, so this is the default recommended config, +using vim-vsnip because the proposed configuration for tab-completion uses it, so… #} +lua << EOF +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; + vsnip = true; + }; +} +EOF +set completeopt=menuone,noselect + + +inoremap compe#complete() +inoremap compe#confirm('') +inoremap compe#close('') +inoremap compe#scroll({ 'delta': +4 }) +inoremap compe#scroll({ 'delta': -4 }) + +lua << EOF +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}) +EOF diff --git a/config/automatrop/roles/vim/templates/plugins/nvim_lspconfig.j2 b/config/automatrop/roles/vim/templates/plugins/nvim_lspconfig.j2 new file mode 100644 index 0000000..790c842 --- /dev/null +++ b/config/automatrop/roles/vim/templates/plugins/nvim_lspconfig.j2 @@ -0,0 +1,70 @@ +{# LSP client for neovim ≥ 0.5 #} +{{ add_source('neovim/nvim-lspconfig') -}} +lua << EOF +local nvim_lsp = require('lspconfig') + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(client, bufnr) + + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + -- disable virtual text + virtual_text = false, + + -- show signs + signs = true, + + -- delay update diagnostics + update_in_insert = false, + } + ) + + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + --Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) +-- buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) +-- buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) +-- buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'd', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) +-- buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) + buf_set_keymap("v", "f", "lua vim.lsp.buf.range_formatting()", opts) + +end + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { +{% if 'python' in dev_stuffs %} + "pyls", +{% endif %} +} +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + + } + } +end +EOF diff --git a/config/automatrop/roles/vim/templates/plugins/supertab.j2 b/config/automatrop/roles/vim/templates/plugins/supertab.j2 index 29e9ce3..8b3abb6 100644 --- a/config/automatrop/roles/vim/templates/plugins/supertab.j2 +++ b/config/automatrop/roles/vim/templates/plugins/supertab.j2 @@ -1,4 +1,7 @@ {# Use TAB for autocompletion #} {{ add_source('ervandew/supertab') -}} +let g:SuperTabLongestEnhanced = 1 +let g:SuperTabLongestHighlight = 1 +{# TODO longest doesn't work, even when longest is set in completeopt #} let g:SuperTabDefaultCompletionType = "" " Go down when completing let g:SuperTabContextDefaultCompletionType = "" diff --git a/config/automatrop/roles/vim/templates/plugins/telescope.j2 b/config/automatrop/roles/vim/templates/plugins/telescope.j2 new file mode 100644 index 0000000..bc62da4 --- /dev/null +++ b/config/automatrop/roles/vim/templates/plugins/telescope.j2 @@ -0,0 +1,39 @@ +{{ add_source('nvim-telescope/telescope.nvim') -}} +{# Dependencies #} +{{ add_source('nvim-lua/popup.nvim') -}} +{{ add_source('nvim-lua/plenary.nvim') -}} + +noremap gF Telescope find_files +noremap gf Telescope git_files +noremap gb Telescope buffers +noremap gl Telescope current_buffer_fuzzy_find +noremap gL Telescope live_grep +noremap gT Telescope tags +noremap gt Telescope treesitter +noremap gm Telescope marks +noremap gh Telescope oldfiles +noremap gH Telescope command_history +noremap gS Telescope search_history +noremap gc Telescope commands +noremap gr Telescope lsp_references +noremap ga Telescope lsp_code_actions +vnoremap ga Telescope lsp_range_code_actions +noremap gq Telescope lsp_document_diagnostics +noremap gQ Telescope lsp_workspace_diagnostics +noremap gd Telescope lsp_definitions + +lua << EOF +require('telescope').setup{ + defaults = { + vimgrep_arguments = { + 'rg', + '--color=never', + '--no-heading', + '--with-filename', + '--line-number', + '--column', + '--smart-case' + }, + } +} +EOF diff --git a/config/automatrop/roles/vim/templates/plugins/treesitter.j2 b/config/automatrop/roles/vim/templates/plugins/treesitter.j2 new file mode 100644 index 0000000..46aeab6 --- /dev/null +++ b/config/automatrop/roles/vim/templates/plugins/treesitter.j2 @@ -0,0 +1,6 @@ +{# Allow for better syntax highlighting. Bit experimental #} +{{ add_source('nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}) -}} +{# To check if it's really working +{{ add_source('nvim-treesitter/playground') -}} +#} +{# TODO Find a way to run `:TSInstall all` non-interactively #} diff --git a/config/automatrop/roles/vim/templates/plugins/vim_lsp.j2 b/config/automatrop/roles/vim/templates/plugins/vim_lsp.j2 index b175265..dfd0d2e 100644 --- a/config/automatrop/roles/vim/templates/plugins/vim_lsp.j2 +++ b/config/automatrop/roles/vim/templates/plugins/vim_lsp.j2 @@ -4,14 +4,6 @@ " (providers are automatically detected thanks to vim-lsp-settings. " You can even install some locally using :LspInstallServer) -nnoremap gd :LspDefinition -nnoremap gD :LspDeclaration -nnoremap :LspDocumentFormat -vnoremap :LspDocumentRangeFormat -nnoremap gE :LspNextDiagnostic -nnoremap ge :LspNextError -nnoremap :LspRename - let g:lsp_signs_enabled = 1 let g:lsp_diagnostics_echo_cursor = 1 @@ -21,3 +13,27 @@ let g:lsp_signs_information = {'text': 'ℹ'} let g:lsp_signs_hint = {'text': '?'} let g:lsp_highlight_references_enabled = 1 + +function! s:on_lsp_buffer_enabled() abort + setlocal omnifunc=lsp#complete + setlocal signcolumn=yes + if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif + nmap gd (lsp-definition) + nmap gD (lsp-declaration) + nmap gr (lsp-references) + nmap gi (lsp-implementation) + nmap rn (lsp-rename) + nmap [d (lsp-previous-diagnostic) + nmap ]d (lsp-next-diagnostic) + nmap K (lsp-hover) + nmap f (lsp-document-format) + vmap f (lsp-document-range-format) + inoremap lsp#scroll(+4) + inoremap lsp#scroll(-4) +endfunction + +augroup lsp_install + au! + " call s:on_lsp_buffer_enabled only for languages that has the server registered. + autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() +augroup END diff --git a/config/automatrop/roles/vim/templates/plugins/vsnip.j2 b/config/automatrop/roles/vim/templates/plugins/vsnip.j2 new file mode 100644 index 0000000..06aa3bc --- /dev/null +++ b/config/automatrop/roles/vim/templates/plugins/vsnip.j2 @@ -0,0 +1,3 @@ +{{ add_source('hrsh7th/vim-vsnip') -}} +{{ add_source('hrsh7th/vim-vsnip-integ') -}} +{{ add_source('rafamadriz/friendly-snippets') -}}