nix: Vim LSP plugins

This commit is contained in:
Geoffrey Frogeye 2023-10-31 23:48:01 +01:00
parent e6f25d9fac
commit 39294e4b90
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
9 changed files with 85 additions and 173 deletions

View file

@ -16,16 +16,6 @@
" Theme
source ~/.config/vim/theme.vim
" Language Server Client
{% if variant == 'nvim' %}
{{ use_plugin('nvim_lspconfig') }}
{{ use_plugin('lightbulb') }}
{{ use_plugin('lspkind') }}
{{ use_plugin('lsp_signature') }}
{% else %}
{{ use_plugin('vim_lsp') }}
{% endif %}
" Treesitter
{% if variant == 'nvim' %}
{{ use_plugin('treesitter') }}

View file

@ -1,3 +0,0 @@
{# Shows a lightbulb whenever a codeAction is available under the cursor #}
{{ add_source('kosayoda/nvim-lightbulb') -}}
autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()

View file

@ -1,8 +0,0 @@
{# Show argument documentation when typing a function #}
{{ add_source('ray-x/lsp_signature.nvim') -}}
lua << EOF
require'lsp_signature'.on_attach({
hint_enable = false,
})
EOF

View file

@ -1,6 +0,0 @@
{# Add icons to LSP completions #}
{{ add_source('onsails/lspkind-nvim') -}}
lua << EOF
require('lspkind').init()
EOF

View file

@ -1,70 +0,0 @@
{# LSP client for neovim ≥ 0.5 #}
{{ add_source('neovim/nvim-lspconfig') -}}
lua << EOF
local nvim_lsp = require('lspconfig')
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[e', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']e', vim.diagnostic.goto_next, opts)
-- vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
-- 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)
-- Enable completion triggered by <c-x><c-o>
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
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
-- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-S-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
-- vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
-- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = {
{% if 'ansible' in dev_stuffs %}
"ansiblels",
{% endif %}
{% if 'nix' in dev_stuffs %}
"rnix",
{% endif %}
{% if 'perl' in dev_stuffs %}
"perlls",
{% endif %}
{% if 'python' in dev_stuffs %}
"pylsp",
{% endif %}
{% if 'php' in dev_stuffs %}
"phpactor", -- Install this one manually https://phpactor.readthedocs.io/en/master/usage/standalone.html#global-installation
{% endif %}
{% if 'sql' in dev_stuffs %}
"sqlls",
{% endif %}
}
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
EOF

View file

@ -1,39 +0,0 @@
{# LSP client for Vim8 and neovim #}
{{ add_source('prabirshrestha/vim-lsp') -}}
{{ add_source('mattn/vim-lsp-settings') -}}
" (providers are automatically detected thanks to vim-lsp-settings.
" You can even install some locally using :LspInstallServer)
let g:lsp_signs_enabled = 1
let g:lsp_diagnostics_echo_cursor = 1
let g:lsp_signs_error = {'text': '✗'}
let g:lsp_signs_warning = {'text': '‼'}
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 <buffer> gd <plug>(lsp-definition)
nmap <buffer> gD <plug>(lsp-declaration)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> <space>rn <plug>(lsp-rename)
nmap <buffer> [d <plug>(lsp-previous-diagnostic)
nmap <buffer> ]d <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
nmap <buffer> <space>f <plug>(lsp-document-format)
vmap <buffer> <space>f <plug>(lsp-document-range-format)
inoremap <buffer> <expr><c-f> lsp#scroll(+4)
inoremap <buffer> <expr><c-d> 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