1 =================================================================================
2 MASON AND LSPCONFIG nixCats.LSPs
3 nixCats.LSPs.mason
4
5 This is a method you may use to make sure mason only tries to download stuff
6 when you did not install neovim via nixCats
7
8 It functions the same as what kickstart.nvim does for its mason setup.
9 However, when loaded via nix,
10 it skips mason and passes them straight to nvim-lspconfig
11
12 When installing via pckr, install mason via pckr. Then wherever you set up
13 mason, do this.
14 The stuff added to servers table is what is passed to lspconfig/mason
15
16
17 if nixCats('neonixdev') then
18
19
20
21
22 vim.api.nvim_create_autocmd('FileType', {
23 group = vim.api.nvim_create_augroup('nixCats-lazydev', { clear = true }),
24 pattern = { 'lua' },
25 callback = function(event)
26
27 vim.cmd.packadd('lazydev.nvim')
28 require('lazydev').setup({
29 library = {
30
31
32
33
34 { path = require('nixCats').nixCatsPath .. '/lua', words = { "nixCats" } },
35 },
36 })
37 end
38 })
39
40
41
42
43
44
45 servers.lua_ls = {
46 Lua = {
47 formatters = {
48 ignoreComments = true,
49 },
50 signatureHelp = { enabled = true },
51 diagnostics = {
52 globals = { 'nixCats' },
53 disable = { 'missing-fields' },
54 },
55 },
56 telemetry = { enabled = false },
57 filetypes = { 'lua' },
58 }
59 if require('nixCatsUtils').isNixCats then
60 servers.nixd = {
61 nixd = {
62 nixpkgs = {
63
64
65
66 expr = [[import (builtins.getFlake "]] .. nixCats.extra("nixdExtras.nixpkgs") .. [[") { } ]],
67 },
68 formatting = {
69 command = { "nixfmt" }
70 },
71 diagnostic = {
72 suppress = {
73 "sema-escaping-with"
74 }
75 }
76 }
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90 if nixCats.extra("nixdExtras.flake-path") then
91 local flakePath = nixCats.extra("nixdExtras.flake-path")
92 if nixCats.extra("nixdExtras.systemCFGname") then
93
94 servers.nixd.nixd.options.nixos = {
95 expr = [[(builtins.getFlake "]] .. flakePath .. [[").nixosConfigurations."]] ..
96 nixCats.extra("nixdExtras.systemCFGname") .. [[".options]]
97 }
98 end
99 if nixCats.extra("nixdExtras.homeCFGname") then
100
101 servers.nixd.nixd.options["home-manager"] = {
102 expr = [[(builtins.getFlake "]] .. flakePath .. [[").homeConfigurations."]]
103 .. nixCats.extra("nixdExtras.homeCFGname") .. [[".options]]
104 }
105 end
106 end
107 else
108 servers.rnix = {}
109 servers.nil_ls = {}
110 end
111
112 end
113
114 if not require('nixCatsUtils').isNixCats and nixCats('lspDebugMode') then
115 vim.lsp.set_log_level("debug")
116 end
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 vim.api.nvim_create_autocmd('LspAttach', {
142 group = vim.api.nvim_create_augroup('nixCats-lsp-attach', { clear = true }),
143 callback = function(event)
144 require('myLuaConf.LSPs.caps-on_attach').on_attach(vim.lsp.get_client_by_id(event.data.client_id), event.buf)
145 end
146 })
147 if require('nixCatsUtils').isNixCats then
148 for server_name, cfg in pairs(servers) do
149 require('lspconfig')[server_name].setup({
150 capabilities = require('myLuaConf.LSPs.caps-on_attach').get_capabilities(server_name),
151
152
153 settings = cfg,
154 filetypes = (cfg or {}).filetypes,
155 cmd = (cfg or {}).cmd,
156 root_pattern = (cfg or {}).root_pattern,
157 })
158 end
159
160 else
161 require('mason').setup()
162 local mason_lspconfig = require 'mason-lspconfig'
163 mason_lspconfig.setup {
164 ensure_installed = vim.tbl_keys(servers),
165 }
166 mason_lspconfig.setup_handlers {
167 function(server_name)
168 require('lspconfig')[server_name].setup {
169 capabilities = require('myLuaConf.LSPs.caps-on_attach').get_capabilities(server_name),
170
171
172 settings = servers[server_name],
173 filetypes = (servers[server_name] or {}).filetypes,
174 }
175 end,
176 }
177 end
178
179 ---------------------------------------------------------------------------------
180 nixCats.LSPs.caps-on_attach
181
182 The above snippet mentions another file at the end.
183
184 caps-on_attach.lua or 'myLuaConf.LSPs.caps-on_attach'
185
186 It is simply a file containing the function we want to run on lsp attach, and a
187 function to return our completion capabilities object.
188
189 It looks like this:
190
191
192 local M = {}
193 function M.on_attach(_, bufnr)
194
195
196
197 local nmap = function(keys, func, desc)
198 if desc then
199 desc = 'LSP: ' .. desc
200 end
201
202 vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
203 end
204
205 nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
206 nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
207
208 nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
209 nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
210 nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
211 nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
212 nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
213 nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
214
215
216 nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
217 nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
218
219
220 nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
221 nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
222 nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
223 nmap('<leader>wl', function()
224 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
225 end, '[W]orkspace [L]ist Folders')
226
227
228 vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
229 vim.lsp.buf.format()
230 end, { desc = 'Format current buffer with LSP' })
231
232 end
233
234 function M.get_capabilities(server_name)
235
236
237
238
239
240 local capabilities = vim.lsp.protocol.make_client_capabilities()
241 capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
242 capabilities.textDocument.completion.completionItem.snippetSupport = true
243 return capabilities
244 end
245 return M
246
247
248
249 =================================================================================
250 vim:tw=78:ts=8:ft=help:norl: