summaryrefslogtreecommitdiff
path: root/dot_config/nvim/lua/plugins/lsp/init.lua
blob: 76b01b10192cac46d201fc19d94d6f8f0a4e82b4 (plain) (blame)
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
-- lsp options + runtime bindings
-- technically I could do some tree transforms, but that's a pain and I haven't done fennel stuff yet
-- + I'm not sure how feasible fennel stuff is in bootstrap-phase
-- anyway this is here to be in front of everything, so you can edit the settings you actually care about
local gopts = function(plist)
	return {
		clangd = {},
		clojure_lsp = {
			root_dir = plist('project.clj', 'deps.edn', 'bb.edn', 'build.boot', 'shadow-cljs.edn', '.git'),
		},
		denols = {
			autostart = false,
			root_dir = plist('deno.json', 'deno.jsonc'),
		},
		gopls = {},
		ltex  = {},
		lua_ls = {},
		tsserver = {
			autostart = false,
			root_dir = plist('tsconfig.json', 'package.json'),
		},
		zls = {},
	}
end

local attach = require 'plugins.lsp.attach'
local caps   = require 'plugins.lsp.capabilities'

return {
	{
		'neovim/nvim-lspconfig',
		config = function(_, opts)
			for k, v in pairs(opts) do
				v.on_attach = v.on_attach or attach
				if type(caps) == 'table' then
					v.capabilities = v.capabilities or caps
				end
				local s = require 'lspconfig'[k]
				local c = v.cmd or s.document_config.default_config.cmd
				if vim.fn.executable(c[1]) ~= 0 then
					s.setup(v)
				end
			end
		end,
		opts = function()
			local plist = function(...)
				local p = require 'lspconfig.util'.root_pattern(...)
				return function(f) return p(f) end
			end
			return gopts(plist)
		end
	},
}