From 9ad923900317a45d216e62626c6ef32672771ee6 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 3 Dec 2021 07:57:20 +0000 Subject: Using nvim-metals --- init.vim | 7 +++++++ lsc-local.vim | 22 ---------------------- lsc.vim | 21 +++++++++++++++++++++ metals.vim | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vimrc | 1 + 5 files changed, 86 insertions(+), 22 deletions(-) delete mode 100644 lsc-local.vim create mode 100644 lsc.vim create mode 100644 metals.vim diff --git a/init.vim b/init.vim index 0115f46..69eee22 100644 --- a/init.vim +++ b/init.vim @@ -3,3 +3,10 @@ let &packpath = &runtimepath source ~/.vimrc +" for LSC support +" +" general +source ~/.vim/lsc.vim +" +" scala and metals +source ~/.vim/metals.vim diff --git a/lsc-local.vim b/lsc-local.vim deleted file mode 100644 index 3b614ce..0000000 --- a/lsc-local.vim +++ /dev/null @@ -1,22 +0,0 @@ -" -" Exampke of local configuration -" -let g:lsc_server_commands = { - \ 'python': { - \ 'command': 'pyls', - \ 'message_hooks': { - \ 'initialize': { - \ 'initializationOptions': { - \ "pyls.plugins.pydocstyle.enabled": 1, - \ "pyls.plugins.epyls_mypy.enabled": 1, - \ "pyls.plugins.epyls_mypy.live_mode": 0 - \ } - \ } - \ } - \ }, - \ 'scala' : 'metals-vim', - \ 'haskell' : 'haskell-language-server-wrapper --lsp' - \ } - -" for mill build.sc -autocmd BufNewFile,BufRead *.sc set filetype=scala diff --git a/lsc.vim b/lsc.vim new file mode 100644 index 0000000..9b5d9c7 --- /dev/null +++ b/lsc.vim @@ -0,0 +1,21 @@ +" vim-lsc configuation +" +let g:lsc_server_commands = { + \ 'python': { + \ 'command': 'pyls', + \ 'message_hooks': { + \ 'initialize': { + \ 'initializationOptions': { + \ "pyls.plugins.pydocstyle.enabled": 1, + \ "pyls.plugins.epyls_mypy.enabled": 1, + \ "pyls.plugins.epyls_mypy.live_mode": 0 + \ } + \ } + \ } + \ }, + \ 'haskell' : 'haskell-language-server-wrapper --lsp' + \ } + +autocmd BufNewFile,BufRead *.sc set filetype=scala + + diff --git a/metals.vim b/metals.vim new file mode 100644 index 0000000..ddb7aca --- /dev/null +++ b/metals.vim @@ -0,0 +1,57 @@ +" nvim-lsp Mappings +" +nnoremap lua vim.lsp.buf.definition() +nnoremap K lua vim.lsp.buf.hover() +nnoremap gi lua vim.lsp.buf.implementation() +nnoremap gr lua vim.lsp.buf.references() +nnoremap gds lua vim.lsp.buf.document_symbol() +nnoremap gws lua vim.lsp.buf.workspace_symbol() +nnoremap rn lua vim.lsp.buf.rename() +nnoremap F lua vim.lsp.buf.formatting() +nnoremap ca lua vim.lsp.buf.code_action() +nnoremap ws lua require'metals'.worksheet_hover() +nnoremap a lua require'metals'.open_all_diagnostics() +nnoremap d lua vim.lsp.diagnostic.set_loclist() +nnoremap [c lua vim.lsp.diagnostic.goto_prev { wrap = false } +nnoremap ]c lua vim.lsp.diagnostic.goto_next { wrap = false } + +" nvim-lsp Settings +" +" using latest stable +" let g:metals_server_version = '0.9.8+10-334e402e-SNAPSHOT' + +" nvim-metals +" +:lua << EOF + metals_config = require'metals'.bare_config() + metals_config.settings = { + showImplicitArguments = true, + excludedPackages = { + "akka.actor.typed.javadsl", + "com.github.swagger.akka.javadsl" + } + } + + metals_config.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( + vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = { + prefix = '', + } + } + ) +EOF + +if has('nvim-0.5') + augroup lsp + au! + au FileType scala,sbt lua require('metals').initialize_or_attach(metals_config) + augroup end +endif + +" Helpful general settings +" +autocmd FileType scala setlocal omnifunc=v:lua.vim.lsp.omnifunc + +" Set completeopt to have a better completion experience +set completeopt=menuone,noinsert,noselect + diff --git a/vimrc b/vimrc index 23432af..8852748 100644 --- a/vimrc +++ b/vimrc @@ -68,6 +68,7 @@ Plug 'neovimhaskell/haskell-vim' if has('nvim-0.5') Plug 'nvim-lua/popup.nvim' Plug 'nvim-lua/plenary.nvim' + Plug 'scalameta/nvim-metals' Plug 'nvim-telescope/telescope.nvim' end -- cgit v1.2.3