From 77cb4a8d7c3dcac52dab56f3005bde5310f74095 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 17 Feb 2022 13:05:42 +0000 Subject: Using neovim lsp support (for python initialy) --- README.md | 7 +++++-- init.vim | 2 +- lsc.vim | 27 --------------------------- lsp.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ vimrc | 7 +++++-- 5 files changed, 61 insertions(+), 32 deletions(-) delete mode 100644 lsc.vim create mode 100644 lsp.lua diff --git a/README.md b/README.md index fb4da3f..8383f44 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,10 @@ Managed by [vim-plug](https://github.com/junegunn/vim-plug). -A few things require nvim 0.5.0 or later, but (hopefully) won't load if not possible. +A few things require nvim at a specific version: + + - nvim 0.5.0 or later: Scala LSP (metals), telescope, autocompleten + - nvim 0.6.1 or later: LSP support For further information on installed plugins: @@ -21,7 +24,7 @@ If you're not using vim 8; create a `.vimrc` with: This can be also be used to customise your local vim configuration without having uncommitted changes in your repository. -In case of Neovim, you can link the provided `init.vim` into `~/.config/nvim/init.vim`. +In case of neovim, you can link the provided `init.vim` into `~/.config/nvim/init.vim`. Then it is recommended you run: diff --git a/init.vim b/init.vim index 480385f..434b892 100644 --- a/init.vim +++ b/init.vim @@ -6,7 +6,7 @@ source ~/.vimrc " for LSC support " " general -source ~/.vim/lsc.vim +source ~/.vim/lsp.lua " scala and metals source ~/.vim/metals.vim diff --git a/lsc.vim b/lsc.vim deleted file mode 100644 index 5c6abd8..0000000 --- a/lsc.vim +++ /dev/null @@ -1,27 +0,0 @@ -" vim-lsc configuation -" -" req: -" - python-lsp-server -" - pylsp-mypy -" - python-lsp-black -" -" ensure yapf and autopep8 is not installed so black works -" -let g:lsc_server_commands = { - \ 'python': { - \ 'command': 'pylsp', - \ 'suppress_stderr': 0, - \ 'workspace_config': { - \ 'pylsp.plugins.pylsp_mypy.enabled': 1, - \ 'pylsp.plugins.pylsp_mypy.live_mode': 0 - \ } - \ }, - \ 'haskell' : { - \ 'command': 'haskell-language-server-wrapper --lsp', - \ 'suppress_stderr': 1 - \ } - \ } - -let g:lsc_auto_map = {'defaults': v:true, 'FindImplementations': ''} -let g:lsc_preview_split_direction = "below" - diff --git a/lsp.lua b/lsp.lua new file mode 100644 index 0000000..10d5471 --- /dev/null +++ b/lsp.lua @@ -0,0 +1,50 @@ +-- for nvim lsp support + +-- Mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap=true, silent=true } +vim.api.nvim_set_keymap('n', 'd', 'lua vim.diagnostic.open_float()', opts) +vim.api.nvim_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) +vim.api.nvim_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) +vim.api.nvim_set_keymap('n', 'da', 'lua 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 + 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 + vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gsh', 'lua vim.lsp.buf.signature_help()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'F', 'lua vim.lsp.buf.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 = { 'pylsp' } +for _, lsp in pairs(servers) do + require('lspconfig')[lsp].setup { + on_attach = on_attach, + flags = { + -- This will be the default in neovim 0.7+ + debounce_text_changes = 150, + }, + settings = { + pylsp = { + plugins = { + pylsp_mypy = { + enabled = true, + live_move = false + } + } + } + } + } +end diff --git a/vimrc b/vimrc index 4659c59..f8eb9e9 100644 --- a/vimrc +++ b/vimrc @@ -58,13 +58,11 @@ Plug 'plasticboy/vim-markdown' Plug 'vimwiki/vimwiki' " language support -Plug 'natebosch/vim-lsc' Plug 'samsaga2/vim-z80' Plug 'tomtom/tcomment_vim' Plug 'https://tildegit.org/sloum/gemini-vim-syntax.git' Plug 'neovimhaskell/haskell-vim' -" nvim 0.5.0 or later if has('nvim-0.5') " general lua Plug 'nvim-lua/popup.nvim' @@ -81,6 +79,11 @@ if has('nvim-0.5') Plug 'hrsh7th/vim-vsnip' end +if has('nvim-0.6.1') + " lsp + Plug 'neovim/nvim-lspconfig' +end + call plug#end() " crystaline conf -- cgit v1.2.3