vim-files
/
lsp.lua
249 строк · 10.1 Кб
1require('nvim-config-loader').add_pack {
2lsp = {
3vim_plug_bundle = {
4-- 'nvim-treesitter/playground',
5-- " 'neovim/nvim-lsp'
6-- " 'ray-x/lsp_signature.nvim'
7-- " 'folke/lsp-colors.nvim'
8'neovim/nvim-lspconfig',
9'onsails/lspkind.nvim',
10'RishabhRD/popfix',
11'RishabhRD/nvim-lsputils',
12'zeioth/garbage-day.nvim', -- stop inactive lsp servers
13},
14setup = function()
15local lsp_config = require('lspconfig')
16local navic = require("nvim-navic")
17
18-- vim.lsp.set_log_level("debug")
19
20vim.diagnostic.config({
21virtual_text = true,
22signs = true,
23underline = false,
24update_in_insert = false,
25severity_sort = false,
26float = false
27})
28
29local on_attach = function(client, bufnr)
30if client.server_capabilities.documentSymbolProvider then
31navic.attach(client, bufnr)
32end
33
34local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
35local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
36local opts = { noremap=true, silent=true }
37
38buf_set_keymap('n', 'gA', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
39
40-- buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
41-- buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
42-- buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
43-- buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
44-- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
45-- buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
46-- buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
47-- buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
48-- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
49-- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
50-- buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
51end
52
53-- vim.lsp.inlay_hint.enable(true)
54
55-- local on_attach = function(client, bufnr)
56
57-- local opts = { noremap=true, silent=true }
58
59-- -- buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
60-- -- buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
61-- -- buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
62-- -- buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
63-- -- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
64-- -- buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
65-- -- buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
66-- -- buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
67-- -- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
68-- -- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
69-- -- buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
70
71-- -- require "lsp_signature".on_attach({
72-- -- bind = true,
73-- -- hint_prefix = "🔸",
74-- -- max_width = 70,
75-- -- extra_trigger_chars = {","},
76-- -- handler_opts = {
77-- -- border = "shadow"
78-- -- }
79-- -- })
80
81-- -- vim.lsp.inlay_hint.enable(bufnr)
82-- end
83
84-- go development
85lsp_config.gopls.setup {
86on_attach = on_attach
87}
88
89-- ruby development
90
91lsp_config.rubocop.setup {
92on_attach = on_attach,
93cmd = { "bundle", "exec", "rubocop", "--lsp" }
94}
95
96lsp_config.solargraph.setup {
97on_attach = on_attach,
98settings = {
99useBunlder = true,
100solargraph = {
101diagnostics = false,
102}
103}
104}
105
106-- vim development
107lsp_config.vimls.setup({
108on_attach = on_attach,
109})
110
111-- nvim development
112require("neodev").setup({
113on_attach = on_attach,
114})
115
116-- lua development
117lsp_config.lua_ls.setup({
118on_attach = on_attach,
119on_init = function(client)
120local path = client.workspace_folders[1].name
121if vim.loop.fs_stat(path..'/.luarc.json') or vim.loop.fs_stat(path..'/.luarc.jsonc') then
122return
123end
124
125client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
126runtime = {
127-- Tell the language server which version of Lua you're using
128-- (most likely LuaJIT in the case of Neovim)
129version = 'LuaJIT'
130},
131-- Make the server aware of Neovim runtime files
132workspace = {
133checkThirdParty = false,
134library = {
135vim.env.VIMRUNTIME
136-- Depending on the usage, you might want to add additional paths here.
137-- "${3rd}/luv/library"
138-- "${3rd}/busted/library",
139}
140-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
141-- library = vim.api.nvim_get_runtime_file("", true)
142}
143})
144end,
145settings = {
146Lua = {}
147}
148})
149
150-- rust development
151lsp_config.rust_analyzer.setup {
152cmd = { "rust-analyzer" },
153filetypes = { "rust" },
154on_attach = on_attach,
155root_dir = lsp_config.util.root_pattern("Cargo.toml", "rust-project.json"),
156settings = {
157["rust-analyzer"] = {
158assist = {
159importMergeBehavior = "last",
160importPrefix = "by_self",
161},
162cargo = {
163loadOutDirsFromCheck = true
164},
165procMacro = {
166enable = true
167},
168}
169}
170}
171
172-- ~ ray-x/go.nvim
173--
174-- Example:
175-- goimport='goimports', -- goimport command
176-- gofmt = 'gofmt', --gofmt cmd,
177-- max_line_len = 120, -- max line length in goline format
178-- tag_transform = false, -- tag_transfer check gomodifytags for details
179-- test_template = '', -- default to testify if not set; g:go_nvim_tests_template check gotests for details
180-- test_template_dir = '', -- default to nil if not set; g:go_nvim_tests_template_dir check gotests for details
181-- comment_placeholder = '' , -- comment_placeholder your cool placeholder
182-- verbose = false, -- output loginf in messages
183-- lsp_cfg = true, -- true: apply go.nvim non-default gopls setup
184-- lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt
185-- lsp_on_attach = true, -- if a on_attach function provided: attach on_attach function to gopls
186-- -- true: will use go.nvim on_attach if true
187-- -- nil/false do nothing
188-- gopls_cmd = nil,
189-- lsp_diag_hdlr = false, -- hook lsp diag handler
190-- dap_debug = false, -- set to true to enable dap
191-- dap_debug_keymap = true, -- set keymaps for debugger
192-- dap_debug_gui = true, -- set to true to enable dap gui, highly recommand
193-- dap_debug_vt = true, -- set to true to enable dap virtual text
194require('go').setup({
195goimports = 'gopls', -- if set to 'gopls' will use golsp format
196gofmt = 'gopls', -- if set to gopls will use golsp format
197lsp_cfg = false,
198-- lsp_on_attach = true,
199-- on_attach = on_attach,
200})
201
202-- hover events
203require("hover").setup {
204init = function()
205-- Require providers
206require("hover.providers.lsp")
207-- require('hover.providers.gh')
208-- require('hover.providers.gh_user')
209-- require('hover.providers.jira')
210-- require('hover.providers.man')
211-- require('hover.providers.dictionary')
212end,
213preview_opts = {
214-- border = 'none'
215-- border = 'shadow'
216border = 'solid'
217},
218-- Whether the contents of a currently open hover window should be moved
219-- to a :h preview-window when pressing the hover keymap.
220preview_window = false,
221title = false,
222mouse_providers = {
223'LSP'
224},
225mouse_delay = 1000
226}
227
228-- Setup hover keymaps
229vim.keymap.set("n", "K", require("hover").hover, {desc = "hover.nvim"})
230vim.keymap.set("n", "gK", require("hover").hover_select, {desc = "hover.nvim (select)"})
231vim.keymap.set("n", "<C-p>", function() require("hover").hover_switch("previous") end, {desc = "hover.nvim (previous source)"})
232vim.keymap.set("n", "<C-n>", function() require("hover").hover_switch("next") end, {desc = "hover.nvim (next source)"})
233
234-- Mouse hover support
235vim.keymap.set('n', '<MouseMove>', require('hover').hover_mouse, { desc = "hover.nvim (mouse)" })
236vim.o.mousemoveevent = true
237
238-- lsp code actions
239vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler
240vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler
241vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler
242vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler
243vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler
244vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler
245vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler
246vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler
247end
248}
249}
250