nvim: Extend lsp for nvim lua development

Added new functionality to lsp: hovering, go-to definition, referencing,
implementations, etc accessible through the usual hotkeys.

Added commands to invoke LspHover and temporarily disable lsp for the
current buffer (is re-enabled on re-entering the buffer, e.g. with
:e<cr>)

Added tjdevries extended lua lsp implementation containing functionality
for the nvim api itself (especially useful for `vim.api`, `vim.fn`).
This commit is contained in:
Marty Oehme 2020-10-09 22:11:06 +02:00
parent 4dd80b7fe1
commit 2ad1389329
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 38 additions and 11 deletions

View file

@ -80,6 +80,8 @@ Plug 'reedes/vim-textobj-sentence'
Plug 'junegunn/goyo.vim', { 'for': ['pandoc', 'markdown', 'txt'], 'on': 'Goyo' } " provide distraction free writing
Plug 'junegunn/limelight.vim', { 'for': ['pandoc', 'markdown', 'txt'], 'on': 'Goyo' } " provide even distraction free-er writing (lowlight paragraphs)
" Language Integration
Plug 'tjdevries/nlua.nvim' " lua lsp integration
Plug 'euclidianAce/BetterLua.vim' " better syntax highlighting for lua
Plug 'sheerun/vim-polyglot' " syntax plugins for almost every language
Plug 'stephpy/vim-yaml'
Plug 'mhartington/nvim-typescript', {'for': 'typescript','do': './install.sh'}

View file

@ -0,0 +1,31 @@
local on_attach = function(client, bufnr)
-- Keybindings for LSPs
-- Note these are in on_attach so that they don't override bindings in a non-LSP setting
vim.fn.nvim_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.implementation()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "<c-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "1gD", "<cmd>lua vim.lsp.buf.type_definition()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "g0", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", {noremap = true, silent = true})
vim.fn.nvim_set_keymap("n", "gW", "<cmd>lua vim.lsp.buf.workspace_symbol()<CR>", {noremap = true, silent = true})
end
require'nvim_lsp'.pyls.setup{on_attach=on_attach}
require'nvim_lsp'.vimls.setup{on_attach=on_attach}
require'nvim_lsp'.bashls.setup{on_attach=on_attach}
require'nvim_lsp'.gopls.setup{on_attach=on_attach}
require'nvim_lsp'.texlab.setup{on_attach=on_attach}
-- To get builtin LSP running, do something like:
-- NOTE: This replaces the calls where you would have before done `require('nvim_lsp').sumneko_lua.setup()`
require('nlua.lsp.nvim').setup(require('nvim_lsp'), {
on_attach = on_attach,
-- Include globals you want to tell the LSP are real :)
globals = {
-- Colorbuddy
"Color", "c", "Group", "g", "s",
}
})

View file

@ -1,12 +1,6 @@
lua << END
command! LspHover lua vim.lsp.buf.hover()<CR>
command! LspDisable lua vim.lsp.stop_client(vim.lsp.get_active_clients())<CR>
require'nvim_lsp'.pyls.setup{}
require'nvim_lsp'.vimls.setup{}
require'nvim_lsp'.bashls.setup{}
require'nvim_lsp'.gopls.setup{}
require'nvim_lsp'.texlab.setup{}
-- requires manual `:LspInstall sumneko_lua`
require'nvim_lsp'.sumneko_lua.setup{}
END
" actual LSP config takes place in lua ('lua/lsp')
lua require("nvim-lspconfig")
setlocal omnifunc=v:lua.vim.lsp.omnifunc