summaryrefslogtreecommitdiff
path: root/.config/nvim/after/plugin/lsp.lua
blob: 12e1025f89fa02e31bc827c70757cd6d3ffa1a72 (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
local conf = require('lspconfig')

conf.clangd.setup {}
conf.gopls.setup {}
conf.rust_analyzer.setup {}
conf.lua_ls.setup {
	settings = {
		Lua = {
			runtime = {
				version = 'LuaJIT',
			},
			diagnostics = {
				globals = {
					'vim',
					'require',
				},
			},
			workspace = {
				library = vim.api.nvim_get_runtime_file('', true),
			},
			telemetry = {
				enable = false,
			},
		},
	},
}

vim.api.nvim_create_autocmd('LspAttach', {
	group = vim.api.nvim_create_augroup('MangoLspConfig', {}),
	callback = function(ev)
		local function remap(mode, map, fn)
			vim.keymap.set(mode, map, fn, { buffer = ev.buf })
		end

		vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
		remap('n', 'K', vim.lsp.buf.hover)
		remap('n', 'gd', vim.lsp.buf.definition)
		remap('n', 'gi', vim.lsp.buf.implementation)
		remap('n', 'gr', vim.lsp.buf.rename)
		remap('n', 'gt', vim.lsp.buf.type_definition)
		remap('n', 'g=', function() vim.lsp.buf.format { async = true } end)
		remap('n', ']d', vim.diagnostic.goto_prev)
		remap('n', '[d', vim.diagnostic.goto_next)
		remap('n', '<leader>la', vim.lsp.buf.code_action)
	end,
})