-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12_lsp.lua
231 lines (206 loc) · 8.48 KB
/
12_lsp.lua
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
local lsp_config = require('lspconfig')
local navic = require("nvim-navic")
-- vim.lsp.set_log_level("debug")
vim.diagnostic.config({
virtual_text = true,
signs = true,
underline = false,
update_in_insert = false,
severity_sort = false,
float = false
})
local on_attach = function(client, bufnr)
if client.server_capabilities.documentSymbolProvider then
navic.attach(client, bufnr)
end
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
local opts = { noremap=true, silent=true }
buf_set_keymap('n', 'gA', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
-- buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
-- buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
-- buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
-- buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
-- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
-- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
-- buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
end
-- vim.lsp.inlay_hint.enable(true)
-- local on_attach = function(client, bufnr)
-- local opts = { noremap=true, silent=true }
-- -- buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
-- -- buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
-- -- buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
-- -- buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
-- -- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
-- -- buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
-- -- buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
-- -- buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
-- -- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
-- -- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
-- -- buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
-- -- require "lsp_signature".on_attach({
-- -- bind = true,
-- -- hint_prefix = "🔸",
-- -- max_width = 70,
-- -- extra_trigger_chars = {","},
-- -- handler_opts = {
-- -- border = "shadow"
-- -- }
-- -- })
-- -- vim.lsp.inlay_hint.enable(bufnr)
-- end
-- go development
lsp_config.gopls.setup {
on_attach = on_attach
}
-- ruby development
lsp_config.rubocop.setup {
on_attach = on_attach,
cmd = { "bundle", "exec", "rubocop", "--lsp" }
}
lsp_config.solargraph.setup {
on_attach = on_attach,
settings = {
useBunlder = true,
solargraph = {
diagnostics = false,
}
}
}
-- vim development
lsp_config.vimls.setup({
on_attach = on_attach,
})
-- nvim development
require("neodev").setup({
on_attach = on_attach,
})
-- lua development
lsp_config.lua_ls.setup({
on_attach = on_attach,
on_init = function(client)
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path..'/.luarc.json') or vim.loop.fs_stat(path..'/.luarc.jsonc') then
return
end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
settings = {
Lua = {}
}
})
-- rust development
lsp_config.rust_analyzer.setup {
cmd = { "rust-analyzer" },
filetypes = { "rust" },
on_attach = on_attach,
root_dir = lsp_config.util.root_pattern("Cargo.toml", "rust-project.json"),
settings = {
["rust-analyzer"] = {
assist = {
importMergeBehavior = "last",
importPrefix = "by_self",
},
cargo = {
loadOutDirsFromCheck = true
},
procMacro = {
enable = true
},
}
}
}
-- ~ ray-x/go.nvim
--
-- Example:
-- goimport='goimports', -- goimport command
-- gofmt = 'gofmt', --gofmt cmd,
-- max_line_len = 120, -- max line length in goline format
-- tag_transform = false, -- tag_transfer check gomodifytags for details
-- test_template = '', -- default to testify if not set; g:go_nvim_tests_template check gotests for details
-- test_template_dir = '', -- default to nil if not set; g:go_nvim_tests_template_dir check gotests for details
-- comment_placeholder = '' , -- comment_placeholder your cool placeholder
-- verbose = false, -- output loginf in messages
-- lsp_cfg = true, -- true: apply go.nvim non-default gopls setup
-- lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt
-- lsp_on_attach = true, -- if a on_attach function provided: attach on_attach function to gopls
-- -- true: will use go.nvim on_attach if true
-- -- nil/false do nothing
-- gopls_cmd = nil,
-- lsp_diag_hdlr = false, -- hook lsp diag handler
-- dap_debug = false, -- set to true to enable dap
-- dap_debug_keymap = true, -- set keymaps for debugger
-- dap_debug_gui = true, -- set to true to enable dap gui, highly recommand
-- dap_debug_vt = true, -- set to true to enable dap virtual text
require('go').setup({
goimports = 'gopls', -- if set to 'gopls' will use golsp format
gofmt = 'gopls', -- if set to gopls will use golsp format
lsp_cfg = false,
-- lsp_on_attach = true,
-- on_attach = on_attach,
})
-- hover events
require("hover").setup {
init = function()
-- Require providers
require("hover.providers.lsp")
-- require('hover.providers.gh')
-- require('hover.providers.gh_user')
-- require('hover.providers.jira')
-- require('hover.providers.man')
-- require('hover.providers.dictionary')
end,
preview_opts = {
-- border = 'none'
-- border = 'shadow'
border = 'solid'
},
-- Whether the contents of a currently open hover window should be moved
-- to a :h preview-window when pressing the hover keymap.
preview_window = false,
title = false,
mouse_providers = {
'LSP'
},
mouse_delay = 1000
}
-- Setup hover keymaps
vim.keymap.set("n", "K", require("hover").hover, {desc = "hover.nvim"})
-- vim.keymap.set("n", "gK", require("hover").hover_select, {desc = "hover.nvim (select)"})
-- vim.keymap.set("n", "<C-p>", function() require("hover").hover_switch("previous") end, {desc = "hover.nvim (previous source)"})
-- vim.keymap.set("n", "<C-n>", function() require("hover").hover_switch("next") end, {desc = "hover.nvim (next source)"})
-- Mouse hover support
vim.keymap.set('n', '<MouseMove>', require('hover').hover_mouse, { desc = "hover.nvim (mouse)" })
vim.o.mousemoveevent = true
-- lsp code actions
vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler
vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler
vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler
vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler
vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler
vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler
vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler
vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler