-
Notifications
You must be signed in to change notification settings - Fork 12
/
init.lua
146 lines (138 loc) · 5.42 KB
/
init.lua
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
local servers = {}
if nixCats('neonixdev') then
servers.lua_ls = {
Lua = {
formatters = {
ignoreComments = true,
},
signatureHelp = { enabled = true },
diagnostics = {
globals = { 'nixCats' },
disable = { 'missing-fields' },
},
},
telemetry = { enabled = false },
filetypes = { 'lua' },
}
if require('nixCatsUtils').isNixCats then
servers.nixd = {
nixd = {
nixpkgs = {
-- nixd requires some configuration in flake based configs.
-- luckily, the nixCats plugin is here to pass whatever we need!
expr = [[import (builtins.getFlake "]] .. nixCats.extra("nixdExtras.nixpkgs") .. [[") { } ]],
},
formatting = {
command = { "nixfmt" }
},
diagnostic = {
suppress = {
"sema-escaping-with"
}
}
}
}
-- If you integrated with your system flake,
-- you should pass inputs.self as nixdExtras.flake-path
-- that way it will ALWAYS work, regardless
-- of where your config actually was.
-- otherwise flake-path could be an absolute path to your system flake, or nil or false
if nixCats.extra("nixdExtras.flake-path") then
local flakePath = nixCats.extra("nixdExtras.flake-path")
if nixCats.extra("nixdExtras.systemCFGname") then
-- (builtins.getFlake "<path_to_system_flake>").nixosConfigurations."<name>".options
servers.nixd.nixd.options.nixos = {
expr = [[(builtins.getFlake "]] .. flakePath .. [[").nixosConfigurations."]] ..
nixCats.extra("nixdExtras.systemCFGname") .. [[".options]]
}
end
if nixCats.extra("nixdExtras.homeCFGname") then
-- (builtins.getFlake "<path_to_system_flake>").homeConfigurations."<name>".options
servers.nixd.nixd.options["home-manager"] = {
expr = [[(builtins.getFlake "]] .. flakePath .. [[").homeConfigurations."]]
.. nixCats.extra("nixdExtras.homeCFGname") .. [[".options]]
}
end
end
else
servers.rnix = {}
servers.nil_ls = {}
end
end
if nixCats('go') then
servers.gopls = {}
end
-- This is this flake's version of what kickstarter has set up for mason handlers.
-- This is a convenience function that calls lspconfig on the lsps we downloaded via nix
-- This will not download your lsp. Nix does that.
-- Add any additional override configuration in the following tables. They will be passed to
-- the `settings` field of the server config. You must look up that documentation yourself.
-- All of them are listed in https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
--
-- If you want to override the default filetypes that your language server will attach to you can
-- define the property 'filetypes' to the map in question.
-- You may do the same thing with cmd
-- servers.clangd = {},
-- servers.gopls = {},
-- servers.pyright = {},
-- servers.rust_analyzer = {},
-- servers.tsserver = {},
-- servers.html = { filetypes = { 'html', 'twig', 'hbs'} },
if not require('nixCatsUtils').isNixCats and nixCats('lspDebugMode') then
vim.lsp.set_log_level("debug")
end
-- If you were to comment out this autocommand
-- and instead pass the on attach function directly to
-- nvim-lspconfig, it would do the same thing.
-- come to think of it, it might be better because then lspconfig doesnt have to be called before lsp attach?
-- but you would still end up triggering on a FileType event anyway, so, it makes little difference.
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('nixCats-lsp-attach', { clear = true }),
callback = function(event)
require('myLuaConf.LSPs.caps-on_attach').on_attach(vim.lsp.get_client_by_id(event.data.client_id), event.buf)
end
})
require('lze').load {
{
"nvim-lspconfig",
for_cat = "general.always",
event = "FileType",
load = (require('nixCatsUtils').isNixCats and vim.cmd.packadd) or function(name)
vim.cmd.packadd(name)
vim.cmd.packadd("mason.nvim")
vim.cmd.packadd("mason-lspconfig.nvim")
end,
after = function(plugin)
if require('nixCatsUtils').isNixCats then
for server_name, cfg in pairs(servers) do
require('lspconfig')[server_name].setup({
capabilities = require('myLuaConf.LSPs.caps-on_attach').get_capabilities(server_name),
-- this line is interchangeable with the above LspAttach autocommand
-- on_attach = require('myLuaConf.LSPs.caps-on_attach').on_attach,
settings = cfg,
filetypes = (cfg or {}).filetypes,
cmd = (cfg or {}).cmd,
root_pattern = (cfg or {}).root_pattern,
})
end
else
require('mason').setup()
local mason_lspconfig = require 'mason-lspconfig'
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
}
mason_lspconfig.setup_handlers {
function(server_name)
require('lspconfig')[server_name].setup {
capabilities = require('myLuaConf.LSPs.caps-on_attach').get_capabilities(server_name),
-- this line is interchangeable with the above LspAttach autocommand
-- on_attach = require('myLuaConf.LSPs.caps-on_attach').on_attach,
settings = servers[server_name],
filetypes = (servers[server_name] or {}).filetypes,
}
end,
}
end
end,
}
}