forked from scalameta/nvim-metals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvim-lsp.vim
128 lines (112 loc) · 5.35 KB
/
nvim-lsp.vim
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
" These settings are a work in progress for using https://scalameta.org/metals
" with the built-in LSP support of Nvim. They are also meant to serve as an
" example of what a setup can look like. They aren't necessarily meant to be
" copied verbatim, but rather referenced, improved, tweaked, etc.
" They assume that you have the following plugins installed for the listed
" reasons. Also ensure that you have Nvim nightly installed. The latest stable
" release does not yet have built-in LSP support.
"
" - https://github.com/neovim/nvim-lsp
" (automated installation and basic setup info)
" - https://github.com/haorenW1025/completion-nvim
" (completions much like your familiar to with other LSP clients)
" - https://github.com/haorenW1025/diagnostic-nvim
" (a bit more sensible diagnostic than what ships by default)
"=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
"-----------------------------------------------------------------------------
" nvim-lsp Mappings
"-----------------------------------------------------------------------------
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> gs <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> <leader>rn <cmd>lua vim.lsp.buf.rename()<CR>
nnoremap <silent> <leader>f <cmd>lua vim.lsp.buf.formatting()<CR>
"-----------------------------------------------------------------------------
" nvim-lsp Settings
"-----------------------------------------------------------------------------
" If you just use the latest stable version, then this setting isn't necessary
let g:metals_server_version = '0.9.0+18-27d4652a-SNAPSHOT'
" This is needed to enable completions
autocmd FileType scala setlocal omnifunc=v:lua.vim.lsp.omnifunc
" Edit these to your liking. I use them to show in the signcolumn
" rather than showing E and W
let g:LspDiagnosticsErrorSign = '✘'
let g:LspDiagnosticsWarningSign = ''
"-----------------------------------------------------------------------------
" lua callbacks
"-----------------------------------------------------------------------------
:lua << EOF
local nvim_lsp = require'nvim_lsp'
local metals = require'metals'
local M = {}
M.on_attach = function()
require'diagnostic'.on_attach()
require'completion'.on_attach()
end
nvim_lsp.metals.setup{
on_attach = M.on_attach;
root_dir = metals.root_pattern("build.sbt", "build.sc");
init_options = {
-- If you set this, make sure to have the `metals#status()` function
-- in your statusline, or you won't see any status messages
statusBarProvider = "on";
};
callbacks = {
["textDocument/hover"] = metals.hover_wrap;
["metals/status"] = metals.metals_status;
};
}
EOF
"-----------------------------------------------------------------------------
" completion-nvim settings
"-----------------------------------------------------------------------------
" Use <Tab> and <S-Tab> to navigate through popup menu
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
"-----------------------------------------------------------------------------
" diagnostic-nvim settings
"-----------------------------------------------------------------------------
" This is disabled by default. I'm still unsure if I like this on
let g:diagnostic_enable_virtual_text = 1
" Again edit this to your liking
let g:diagnostic_virtual_text_prefix = ' '
nnoremap <silent> [c :NextDiagnostic<CR>
nnoremap <silent> ]c :PrevDiagnostic<CR>
nnoremap <silent> go :OpenDiagnostic<CR>
"-----------------------------------------------------------------------------
" statusline function examples
"-----------------------------------------------------------------------------
" I set there here to reuse what I may have already set for the LSP
" diagnostic signs in my signcolumn, if not use defaults
let s:LspStatusLineErrorSign = get(g:, 'LspDiagnosticsErrorSign', 'E')
let s:LspStatusWarningSign = get(g:, 'LspDiagnosticsWarningSign', 'W')
" An examle that I use to show a sign plus count of errors in my statusline
function! LspErrors() abort
let errorCount = luaeval('vim.lsp.util.buf_diagnostics_count("Error")')
if (errorCount > 0)
return s:LspStatusDiagnosticErrorSign . errorCount
else
return ''
endif
endfunction
" An examle that I use to show a sign plus count of warnings in my statusline
function! LspWarnings() abort
let warningCount = luaeval('vim.lsp.util.buf_diagnostics_count("Warning")')
if (warningCount > 0)
return s:LspStatusDiagnosticWarningSign . warningCount
else
return ''
endif
endfunction
"-----------------------------------------------------------------------------
" Helpful general settings, I recommend making sure these are set
"-----------------------------------------------------------------------------
" Set completeopt to have a better completion experience
set completeopt=menuone,noinsert,noselect
" Avoid showing message extra message when using completion
set shortmess+=c
" always show signcolumns
set signcolumn=yes