[nvim] native lsp

This commit is contained in:
odrling 2021-11-19 16:13:36 +01:00
parent 90649c2bbc
commit 984d8045ed
No known key found for this signature in database
GPG key ID: A0145F975F9F8B75
24 changed files with 145 additions and 32 deletions

View file

@ -283,19 +283,15 @@ function! VisualSelection(direction, extra_filter) range
let @" = l:saved_reg
endfunction
function! ConfUpdate()
CocUpdateSync
quit
endfunction
source ~/.config/nvim/coc.vim
source ~/.config/nvim/treesitter.vim
source ~/.config/nvim/lsp.vim
colorscheme space_vim_theme
" Load all plugins now.
" Plugins need to be added to runtimepath before helptags can be generated.
packloadall
" Load all of the helptags now, after plugins have been loaded.
" All messages and errors will be ignored.
silent! helptags ALL

102
.config/nvim/lsp.vim Normal file
View file

@ -0,0 +1,102 @@
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)
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 <c-x><c-o>
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', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
local lsp_installer = require("nvim-lsp-installer")
-- Register a handler that will be called for all installed servers.
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
lsp_installer.on_server_ready(function(server)
local opts = {}
-- 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)
EOF

37
.gitmodules vendored
View file

@ -57,10 +57,6 @@
[submodule ".vim/bundle/vim-unimpaired"]
path = .local/share/nvim/site/pack/vim-unimpaired/start/vim-unimpaired
url = https://github.com/tpope/vim-unimpaired.git
[submodule ".vim/bundle/coc.nvim"]
path = .local/share/nvim/site/pack/coc.nvim/start/coc.nvim
url = https://github.com/neoclide/coc.nvim.git
branch = release
[submodule ".vim/bundle/eleline.vim"]
path = .local/share/nvim/site/pack/eleline.vim/start/eleline.vim
url = https://github.com/liuchengxu/eleline.vim.git
@ -97,12 +93,27 @@
[submodule ".local/share/nvim/site/pack/nvim-treesitter/start/nvim-treesitter-textobjects"]
path = .local/share/nvim/site/pack/nvim-treesitter/start/nvim-treesitter-textobjects
url = https://github.com/nvim-treesitter/nvim-treesitter-textobjects.git
[submodule ".local/share/nvim/site/pack/git/start/neogit"]
path = .local/share/nvim/site/pack/git/start/neogit
url = https://github.com/TimUntersberger/neogit.git
[submodule ".local/share/nvim/site/pack/git/start/plenary.nvim"]
path = .local/share/nvim/site/pack/git/start/plenary.nvim
url = https://github.com/nvim-lua/plenary.nvim.git
[submodule ".local/share/nvim/site/pack/git/start/diffview.nvim"]
path = .local/share/nvim/site/pack/git/start/diffview.nvim
url = https://github.com/sindrets/diffview.nvim.git
[submodule ".local/share/nvim/site/pack/lspconfig/start/nvim-lspconfig"]
path = .local/share/nvim/site/pack/lspconfig/start/nvim-lspconfig
url = https://github.com/neovim/nvim-lspconfig.git
[submodule ".local/share/nvim/site/pack/lspconfig/start/nvim-cmp"]
path = .local/share/nvim/site/pack/lspconfig/start/nvim-cmp
url = https://github.com/hrsh7th/nvim-cmp
[submodule ".local/share/nvim/site/pack/lspconfig/start/cmp-nvim-lsp"]
path = .local/share/nvim/site/pack/lspconfig/start/cmp-nvim-lsp
url = https://github.com/hrsh7th/cmp-nvim-lsp
[submodule ".local/share/nvim/site/pack/lspconfig/start/cmp_luasnip"]
path = .local/share/nvim/site/pack/lspconfig/start/cmp_luasnip
url = https://github.com/saadparwaiz1/cmp_luasnip
[submodule ".local/share/nvim/site/pack/lspconfig/start/LuaSnip"]
path = .local/share/nvim/site/pack/lspconfig/start/LuaSnip
url = https://github.com/L3MON4D3/LuaSnip
[submodule ".local/share/nvim/site/pack/lspconfig/start/nvim-lsp-installer"]
path = .local/share/nvim/site/pack/lspconfig/start/nvim-lsp-installer
url = https://github.com/williamboman/nvim-lsp-installer
[submodule ".local/share/nvim/site/pack/space-vim-theme/start/space-vim-dark"]
path = .local/share/nvim/site/pack/space-vim-theme/start/space-vim-dark
url = https://github.com/liuchengxu/space-vim-dark.git
[submodule ".local/share/nvim/site/pack/space-vim-theme/start/space-nvim"]
path = .local/share/nvim/site/pack/space-vim-theme/start/space-nvim
url = https://github.com/Th3Whit3Wolf/space-nvim.git

@ -1 +1 @@
Subproject commit f896744feec260fb196d38bba23308080c04192c
Subproject commit ea643b97ab08e571a543f4bd89cd3170f3f288e2

@ -1 +0,0 @@
Subproject commit 595e60210f7d0c9e5a21672428bae8c3f518a3b9

@ -1 +0,0 @@
Subproject commit e0ffb1cb7c5ea9e693e5ee5ee3ce1e5f78916ed6

@ -1 +0,0 @@
Subproject commit 06000011b9a8b1f2f843489c32afdb487e163c14

@ -1 +0,0 @@
Subproject commit 15c3cb9e6311dc1a875eacb9fc8df69ca48d7402

@ -0,0 +1 @@
Subproject commit f400b978b1dbca96e9e190b7009c415c09b8924c

@ -0,0 +1 @@
Subproject commit 134117299ff9e34adde30a735cd8ca9cf8f3db81

@ -0,0 +1 @@
Subproject commit 16832bb50e760223a403ffa3042859845dd9ef9d

@ -0,0 +1 @@
Subproject commit 1c7f73aa4ad2ca1d25ea57ba5ab4e43df85d3479

@ -0,0 +1 @@
Subproject commit 4f8cafab7f518f033036c611e6954dc22f7dc336

@ -0,0 +1 @@
Subproject commit 6c47af495cb30c12e58c87f829c5daa65958cc67

@ -1 +1 @@
Subproject commit 7241ddaff43e38ffbe9b163ca42b30114ae56757
Subproject commit 190bcc8d56c0b4c5047492d17b1615c6e89139af

@ -1 +1 @@
Subproject commit 531b5d4b808960fbcd5419a52c15f7753d074e2e
Subproject commit 31cfd4221b2729a7d4e60a6f1bb506b17af60e87

@ -1 +1 @@
Subproject commit deb887b3f49d66654d9faa9778e8949fe0d80bc3
Subproject commit 787a7a8d4444e58467d6b3d4b88a497e7d494643

@ -0,0 +1 @@
Subproject commit 9c4f5857acf51aa6d4924f3f2ccabb079799e7f6

@ -0,0 +1 @@
Subproject commit d24c6c27b49c1ab49416a47d96979481281f53b5

@ -1 +1 @@
Subproject commit 349340debb34f6302931f0eb7139b2c11dfdf427
Subproject commit 627308e30639be3e2d5402808ce18690557e8292

@ -1 +1 @@
Subproject commit e8b1be581b88de524fc62cd24265d602f8caac19
Subproject commit 7a48f9ff0ef5f21447b2354ee52dc18b5567e05c

@ -1 +1 @@
Subproject commit ce31cd1d2f4e8eee9fd91325e4599f15cb9566fd
Subproject commit 4d4aa5fe553a47ef5c5c6d0a97bb487fdfda2d5b

@ -1 +1 @@
Subproject commit f51a26d3710629d031806305b6c8727189cd1935
Subproject commit aeb933272e72617f7c4d35e1f003be16836b948d

@ -1 +1 @@
Subproject commit aee3455e19686ce84225752de678a9725866248b
Subproject commit e4006d68cd4f390efef935bc09be0ce3bd022e72