-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlsp.lua
More file actions
208 lines (180 loc) · 7.01 KB
/
Copy pathlsp.lua
File metadata and controls
208 lines (180 loc) · 7.01 KB
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
return {
{
"williamboman/mason.nvim", -- manage LSP servers, DAP servers, linters, and formatters through a single interface
lazy = false,
opts = {
ui = {
border = "rounded",
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗",
},
},
},
},
{
"williamboman/mason-lspconfig.nvim", -- install LSP servers
lazy = false,
opts = {
automatic_installation = true,
ensure_installed = { "lua_ls", "ts_ls", "eslint", "html", "tailwindcss", "ansiblels", "ruby_lsp" },
},
},
{
"jay-babu/mason-null-ls.nvim", -- install formatters & linters
lazy = false,
opts = {
automatic_installation = true,
ensure_installed = {
"prettier", -- prettier formatter
"stylua", -- lua formatter
"rubocop", -- ruby formatter
},
},
},
{
"neovim/nvim-lspconfig", -- configure LSP servers
lazy = false,
config = function()
local opts = { noremap = true, silent = true }
vim.lsp.commands["rubyLsp.openFile"] = function(command)
local arguments = command.arguments[1]
local uri = arguments[1]
local line = arguments[2] or 0
-- Convert LSP URI to file path
local filepath = vim.uri_to_fname(uri)
-- Open the file
vim.cmd("edit " .. filepath)
-- Move to specified line
if line > 0 then
vim.api.nvim_win_set_cursor(0, {line, 0})
end
end
vim.lsp.commands["rubyLsp.runTest"] = function()
require("neotest").run.run()
end
vim.lsp.commands["rubyLsp.runTestInTerminal"] = function()
local neotest = require("neotest")
neotest.output_panel.clear()
neotest.run.run()
neotest.output_panel.open()
end
vim.lsp.commands["rubyLsp.debugTest"] = function()
local neotest = require("neotest")
neotest.output_panel.clear()
neotest.run.run({ strategy = "tmux" })
end
local on_attach = function(client, bufnr)
opts.buffer = bufnr
vim.lsp.inlay_hint.enable()
-- Enable CodeLens
if client.server_capabilities.codeLensProvider then
vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, {
buffer = bufnr,
callback = function()
vim.lsp.codelens.refresh()
end,
})
-- Initial refresh
vim.lsp.codelens.refresh()
end
-- Add key mappings for CodeLens actions
opts.desc = "Run CodeLens action"
vim.keymap.set('n', '<leader>c', vim.lsp.codelens.run, opts)
-- opts.desc = "Show documentation for what is under cursor"
-- vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
-- opts.desc = "Show line diagnostics"
-- vim.keymap.set("n", "<C-W>d", vim.diagnostic.open_float, opts)
-- opts.desc = "Go to previous diagnostic"
-- vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
-- opts.desc = "Go to next diagnostic"
-- vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
opts.desc = "Go to definition"
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
-- Default keymaps: https://neovim.io/doc/user/lsp.html#_global-defaults
-- "grn" is mapped in Normal mode to rename all references to the symbol under the cursor (vim.lsp.buf.rename)
-- "gra" is mapped in Normal and Visual mode to select code action available at the current cursor position (vim.lsp.buf.code_action)
-- "grr" is mapped in Normal mode to list all the references to the symbol under the cursor in the quickfix window (vim.lsp.buf.references)
-- "gri" is mapped in Normal mode to list all the implementations for the symbol under the cursor in the quickfix window (vim.lsp.buf.implementation)
-- "gO" is mapped in Normal mode to list all symbols in the current buffer in the location-list (vim.lsp.buf.document_symbol)
-- CTRL-S is mapped in Insert mode to show signature information about the symbol under the cursor in a floating window (vim.lsp.buf.signature_help)
opts.desc = "Show available code actions"
vim.keymap.set("n", "<leader>a", vim.lsp.buf.code_action, opts)
opts.desc = "Format source code"
vim.keymap.set("n", "F", function()
vim.lsp.buf.format({ async = true })
end, opts)
end
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local border = {
{ "┌", "FloatBorder" },
{ "─", "FloatBorder" },
{ "┐", "FloatBorder" },
{ "│", "FloatBorder" },
{ "┘", "FloatBorder" },
{ "─", "FloatBorder" },
{ "└", "FloatBorder" },
{ "│", "FloatBorder" },
}
-- setup borders in the diagnostic window.
vim.diagnostic.config({
float = {
border = border,
},
})
-- only show diagnostics in the current line
vim.diagnostic.config({ virtual_text = { current_line = true } })
-- add the border on hover and on signature help popup window
local handlers = {
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }),
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = border }),
}
-- change the Diagnostic symbols in the sign column (gutter)
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
local lsps = {"lua_ls", "ts_ls", "html", "tailwindcss", "ansiblels", "ruby_lsp"}
for _, lsp in pairs(lsps) do
vim.lsp.config(lsp, {
capabilities = capabilities,
on_attach = on_attach,
handlers = handlers,
})
end
end,
vim.keymap.set("n", "<leader>d", function()
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
end, { desc = "Toggle diagnostics" })
},
{
"nvimtools/none-ls.nvim", -- configure formatters & linters
dependencies = {
"davidmh/cspell.nvim",
},
lazy = false,
config = function()
local null_ls = require("null-ls")
local null_ls_utils = require("null-ls.utils")
local cspell = require('cspell')
local formatting = null_ls.builtins.formatting -- to setup formatters
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
local hover = null_ls.builtins.hover -- to setup hovers
null_ls.setup({
root_dir = null_ls_utils.root_pattern(".null-ls-root", "Makefile", ".git", "package.json"),
sources = {
formatting.stylua,
formatting.prettier,
formatting.rubocop,
diagnostics.rubocop,
diagnostics.ltrs,
cspell.diagnostics,
cspell.code_actions,
hover.printenv,
},
})
end,
},
}