-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlsp.lua
More file actions
249 lines (229 loc) · 8.27 KB
/
lsp.lua
File metadata and controls
249 lines (229 loc) · 8.27 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
---@type LazySpec
return {
-- Manages DAPs, language servers, linters, and formatters
-- We use mason-lspconfig for language servers, and Mason only for DAPs,
-- linters and formatters
{
"mason-org/mason.nvim",
cmd = { "Mason", "MasonInstall", "MasonUpdate" },
opts = {},
},
-- Linters and formatters ONLY. DO NOT add LSP servers or DAPs here.
-- LSPs are installed later in this file, see mason-lsp-config:setup({...})
-- DAPs are installed in "dap.lua", see mason-nvim-dap:setup({...})
{
"jay-babu/mason-null-ls.nvim",
dependencies = { "mason-org/mason.nvim", "nvimtools/none-ls.nvim" },
opts = {
ensure_installed = {
-- Formatters
"black", -- Python
"gofumpt", -- Go
"goimports-reviser", -- Go
"golines", -- Go
"latexindent", -- Latex
"prettier", -- Multiple languages
"shfmt", -- Bash/sh
"stylua", -- Lua
-- Linters
"cmakelang", -- CMake
"cmakelint", -- CMake
"mypy", -- Python
"shellcheck", -- Bash/sh
},
},
},
-- Manages (installs/removes etc.) language servers only
{
"mason-org/mason-lspconfig.nvim",
dependencies = { "mason-org/mason.nvim", "neovim/nvim-lspconfig" },
opts = {
-- LSPs that are installed by default
ensure_installed = {
"basedpyright", -- Python
"bashls", -- Bash/sh
"clangd", -- C, C++
"cmake", -- C, C++ build system
"eslint", -- JavaScript/TypeScript
"gopls", -- Go
-- "hls", -- Haskell, not needed, we use haskell-tools
-- Do not install julials via Mason
-- https://discourse.julialang.org/t/neovim-languageserver-jl-crashing-again/130273
-- "julials",
"lua_ls", -- Lua
"marksman", -- Markdown
"tombi", -- TOML
"ruff", -- Python
"rust_analyzer", -- Rust
"texlab", -- LaTeX
"tinymist", -- Typst
"ts_ls", -- JavaScript/TypeScript
"vimls", -- Vim
"yamlls", -- YAML
"zls", -- Zig
},
},
},
-- LSP (Language Server Protocol)
{
"neovim/nvim-lspconfig",
event = "LspAttach",
config = function()
local util = require("core.util")
local lsp_capabilities = vim.lsp.protocol.make_client_capabilities()
local augroup =
vim.api.nvim_create_augroup("LSP-formatting", { clear = true })
local lsp_format_on_save = util.format_on_save(augroup)
-- TODO: Migrate to the native Neovim 0.11+ LSP autocompletion
lsp_capabilities = vim.tbl_deep_extend(
"force",
lsp_capabilities,
require("cmp_nvim_lsp").default_capabilities()
)
-- Configure the servers
local servers = {
-- Servers that do not require custom settings
basedpyright = {}, -- Python
bashls = {}, -- Bash/sh
cmake = {}, -- CMake
marksman = {}, -- Markdown
ruff = {}, -- Python
tombi = {}, -- TOML
ts_ls = {}, -- JavaScript/TypeScript
vimls = {}, -- Vim script
yamlls = {}, -- YAML
zls = {}, -- Zig
-- Servers that require custom settings
-- C, C++
clangd = {
cmd = {
"clangd",
"--header-insertion=never",
"--offset-encoding=utf-16",
},
},
-- JavaScript/TypeScript
eslint = {
filetypes = {
"javascript",
"javascript.jsx",
"javascriptreact",
"svelte",
"typescript",
"typescript.tsx",
"typescriptreact",
"vue",
},
settings = {
workingDirectory = { mode = "auto" },
},
},
-- Go
gopls = {
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_markers = { "go.work", "go.mod", ".git" },
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = { unusedparams = true },
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
constantValues = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
},
},
},
},
-- Julia
julials = {
cmd = {
"julia",
"--project=@nvim-lspconfig",
"-e",
"using LanguageServer; using SymbolServer; runserver()",
},
filetypes = { "julia" },
},
-- Lua
lua_ls = {
settings = {
Lua = {
hint = { enable = true },
format = { enable = false },
},
},
},
-- Rust
rust_analyzer = {
filetypes = { "rust" },
root_markers = { "Cargo.toml" },
settings = {
["rust-analyzer"] = {
cargo = { allFeatures = true },
},
},
},
-- LaTeX
texlab = {
settings = {
texlab = {
latexindent = { modifyLineBreaks = true },
},
},
},
}
-- Iterate over LSPs and apply global defaults
for server_name, config in pairs(servers) do
config.capabilities = lsp_capabilities
config.on_attach = lsp_format_on_save
vim.lsp.config(server_name, config)
vim.lsp.enable(server_name)
end
-- Additional settings
local lsp_group =
vim.api.nvim_create_augroup("Nvim-lspconfig", { clear = true })
vim.api.nvim_create_autocmd("LspAttach", {
group = lsp_group,
callback =
---@param ev vim.api.keyset.create_autocmd.callback_args
function(ev)
-- Disable semantic token highlighting for lua_ls
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client and client.name and client.name == "lua_ls" then
client.server_capabilities.semanticTokensProvider = nil
end
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
-- Buffer-local keymaps
local keymaps = require("core.keymaps")
util.map_keys(keymaps.nvim_lspconfig, { buffer = ev.buf })
-- Inlay hints policy (buffer overrides global)
if vim.lsp.inlay_hint then
local bufnr = ev.buf
if vim.b[bufnr].inlay_hints_enabled ~= nil then
-- Buffer override wins (even if false)
vim.lsp.inlay_hint.enable(
vim.b[bufnr].inlay_hints_enabled,
{ bufnr = bufnr }
)
elseif vim.g.inlay_hints_enabled ~= nil then
-- Apply global only if explicitly set; default stays
-- untouched otherwise
vim.lsp.inlay_hint.enable(
vim.g.inlay_hints_enabled == true,
{ bufnr = bufnr }
)
end
end
end,
desc = "Keymaps nvim-lspconfig (buffer-local)",
})
end,
},
}