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 When not using nix you will of course be responsible for downloading mason
9 using something else.
10
11 It functions the same as what kickstart.nvim does for its mason setup.
12 However, when loaded via Nix,
13 it skips mason and enables them with default configs provided by nvim-lspconfig.
14
15 The following assumes that you have nvim-lspconfig loaded as a startup plugin
16
17
18 local servers = {}
19 if nixCats('neonixdev') then
20
21
22
23
24 vim.api.nvim_create_autocmd('FileType', {
25 group = vim.api.nvim_create_augroup('nixCats-lazydev', { clear = true }),
26 pattern = { 'lua' },
27 callback = function(event)
28
29 vim.cmd.packadd('lazydev.nvim')
30 require('lazydev').setup({
31 library = {
32
33
34
35
36 { path = require('nixCats').nixCatsPath .. '/lua', words = { "nixCats" } },
37 },
38 })
39 end
40 })
41
42
43
44
45
46
47 servers.lua_ls = {
48 settings = {
49 Lua = {
50 formatters = {
51 ignoreComments = true,
52 },
53 signatureHelp = { enabled = true },
54 diagnostics = {
55 globals = { 'nixCats' },
56 disable = { 'missing-fields' },
57 },
58 },
59 telemetry = { enabled = false },
60 },
61 filetypes = { 'lua' },
62 }
63 if require('nixCatsUtils').isNixCats then
64
65
66
67
68
69 servers.nixd = {
70 settings = {
71 nixd = {
72 nixpkgs = {
73
74
75 expr = nixCats.extra("nixdExtras.nixpkgs") or [[import <nixpkgs> {}]],
76 },
77 options = {
78
79
80
81
82 nixos = {
83
84 expr = nixCats.extra("nixdExtras.nixos_options")
85 },
86
87
88
89 ["home-manager"] = {
90
91 expr = nixCats.extra("nixdExtras.home_manager_options")
92 }
93 },
94 formatting = {
95 command = { "nixfmt" }
96 },
97 diagnostic = {
98 suppress = {
99 "sema-escaping-with"
100 }
101 }
102 }
103 }
104 }
105 else
106 servers.rnix = {}
107 servers.nil_ls = {}
108 end
109
110 end
111
112 if not require('nixCatsUtils').isNixCats and nixCats('lspDebugMode') then
113 vim.lsp.set_log_level("debug")
114 end
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 local function on_attach(_, bufnr)
137
138
139
140 local nmap = function(keys, func, desc)
141 if desc then
142 desc = 'LSP: ' .. desc
143 end
144
145 vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
146 end
147
148 nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
149 nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
150
151 nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
152 nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
153 nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
154 nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
155 nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
156 nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
157
158
159 nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
160 nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
161
162
163 nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
164 nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
165 nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
166 nmap('<leader>wl', function()
167 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
168 end, '[W]orkspace [L]ist Folders')
169
170
171 vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
172 vim.lsp.buf.format()
173 end, { desc = 'Format current buffer with LSP' })
174
175 end
176 vim.api.nvim_create_autocmd('LspAttach', {
177 group = vim.api.nvim_create_augroup('nixCats-lsp-attach', { clear = true }),
178 callback = function(event)
179 on_attach(vim.lsp.get_client_by_id(event.data.client_id), event.buf)
180 end
181 })
182
183
184 local capabilities = vim.lsp.protocol.make_client_capabilities()
185 capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
186 vim.lsp.config('*', { capabilities = capabilities })
187
188
189
190 if require('nixCatsUtils').isNixCats then
191 for server_name, cfg in pairs(servers) do
192
193
194 vim.lsp.config(server_name, cfg)
195 vim.lsp.enable(server_name)
196 end
197
198 else
199 require('mason').setup()
200 local mason_lspconfig = require 'mason-lspconfig'
201 mason_lspconfig.setup {
202 ensure_installed = vim.tbl_keys(servers),
203 }
204 mason_lspconfig.setup_handlers {
205 function(server_name)
206 local server = servers[server_name] or {}
207 vim.lsp.config(server_name, server)
208 vim.lsp.enable(server_name)
209 end,
210 }
211 end
212
213 =================================================================================
214 vim:tw=78:ts=8:ft=help:norl: