summaryrefslogtreecommitdiff
path: root/lua/config/lsp.lua
blob: 8e71e24b26f7fcbe61804db029e1de41395f774b (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
54
55
56
57
58
59
60
vim.diagnostic.config({
	signs = true,
	underline = true,
	update_in_insert = true,
	virtual_text = true,
})

vim.lsp.enable({
	"lua-language-server",

	"nixd",

	"rust-analyzer",

	"angular-language-server",
	"biome",
	"typescript-language-server",
})

vim.lsp.inlay_hint.enable(true)

-- Enable Angular HTML Treesitter grammar when needed
vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
	pattern = { "*.component.html", "*.container.html" },
	callback = function()
		vim.bo.filetype = "htmlangular"
		vim.treesitter.start(nil, "angular")
	end,
})

vim.api.nvim_create_autocmd("LspAttach", {
	callback = function(args)
		local buffer = args.buf
		local client = vim.lsp.get_client_by_id(args.data.client_id)
		if client then
			-- Keybindings
			local map = vim.keymap.set
			local opts = { buffer = buffer }

			map("n", "<leader>cr", vim.lsp.buf.rename, opts)
			map("n", "gd", vim.lsp.buf.definition, opts)
			map("n", "gD", vim.lsp.buf.declaration, opts)
			map("n", "gI", vim.lsp.buf.implementation, opts)
			map("n", "gy", vim.lsp.buf.type_definition, opts)
			map("n", "gr", vim.lsp.buf.references, opts)

			map("n", "K", function()
				return vim.lsp.buf.hover()
			end, opts)

			map("n", "gK", function()
				return vim.lsp.buf.signature_help()
			end, opts)

			map("n", "<C-i>", function()
				return vim.lsp.buf.signature_help()
			end, opts)
		end
	end,
})