aboutsummaryrefslogtreecommitdiff
path: root/metals.vim
blob: 8141ff933671f412116160a2a0f6e47b25dec13f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
" nvim-metals settings
"
:lua << EOF
  metals_config = require'metals'.bare_config()
  metals_config.init_options.statusBarProvider = "on"
  metals_config.settings = {
     showImplicitArguments = true,
     excludedPackages = {
       "akka.actor.typed.javadsl",
       "com.github.swagger.akka.javadsl"
     }
  }
EOF

" nvim-lsp mappings for metals
"
function! MetalsMapKeys() abort
    nnoremap <buffer> <C-]>       <cmd>lua vim.lsp.buf.definition()<CR>
    nnoremap <buffer> K           <cmd>lua vim.lsp.buf.hover()<CR>
    nnoremap <buffer> gi          <cmd>lua vim.lsp.buf.implementation()<CR>
    nnoremap <buffer> gr          <cmd>lua vim.lsp.buf.references()<CR>
    nnoremap <buffer> gds         <cmd>lua vim.lsp.buf.document_symbol()<CR>
    nnoremap <buffer> gws         <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
    nnoremap <buffer> gsh         <cmd>lua vim.lsp.buf.signature_help()<CR>
    nnoremap <buffer> <leader>rn  <cmd>lua vim.lsp.buf.rename()<CR>
    nnoremap <buffer> <leader>F   <cmd>lua vim.lsp.buf.formatting()<CR>
    nnoremap <buffer> <leader>ca  <cmd>lua vim.lsp.buf.code_action()<CR>
    nnoremap <buffer> <leader>aw  <cmd>lua vim.diagnostic.setqflist({severity = "W"})<CR>
    nnoremap <buffer> <leader>a   <cmd>lua vim.diagnostic.setqflist()<CR>

    " diagnostic navigation
    nnoremap <buffer> <leader>d   <cmd>lua vim.diagnostic.open_float(0, {scope = "line"})<CR>
    nnoremap <buffer> <leader>da  <cmd>lua vim.diagnostic.setloclist()<CR>
    nnoremap <buffer> <leader>dn  <cmd>lua vim.diagnostic.goto_next()<CR>
    nnoremap <buffer> <leader>dp  <cmd>lua vim.diagnostic.goto_prev()<CR>
endfunction

augroup lsp
    au!
    au FileType scala,sbt lua require('metals').initialize_or_attach(metals_config)
augroup end

" Helpful general settings
"
autocmd FileType scala setlocal omnifunc=v:lua.vim.lsp.omnifunc
autocmd FileType scala call MetalsMapKeys()
autocmd BufWritePre *.scala,*.sc,*.sbt :lua vim.lsp.buf.formatting_seq_sync()
autocmd BufNewFile,BufRead *.sc set filetype=scala