summary refs log tree commit diff
path: root/.vim/lua/plugins/_lsp.lua
blob: 9d98aca50c090d176e5d75846a557e70733ed20d (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- lsp config

local lsp     = require('lspconfig')
local util    = require('lspconfig.util')
local u       = require('utils')

-- https://github.com/kosayoda/nvim-lightbulb
require('nvim-lightbulb').update_lightbulb {
	sign = {
		enabled = true,
		priority = 10,
	},
	float = {
		enabled = true,
		text = '󱉵',
		win_opts = {},
	},
}

local my_attach = function(client)
	-- attach completion
	require 'completion'.on_attach(client)

	-- lsp mappings
	u.map('n', 'K',     '<cmd>lua vim.lsp.buf.hover()<cr>')
	u.map(0, 'n', '<c-]>', '<cmd>lua vim.lsp.buf.definition()<cr>')
	u.map(0, 'n', 'grr',   '<cmd>lua vim.lsp.buf.rename()<cr>')
	u.map(0, 'i', '<c-h>', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
	u.map(0, 'n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<cr>')
	u.map(0, 'n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<cr>')

	-- nnoremap <silent> gD <cmd> lua vim.lsp.buf.declaration()<CR>
	-- nnoremap <silent> gd <cmd> lua vim.lsp.buf.definition()<CR>
	-- nnoremap <silent> gT <cmd> lua vim.lsp.buf.type_definition()<CR>
	-- nnoremap <silent> gI <cmd> lua vim.lsp.buf.implementation()<CR>
	-- nnoremap <silent> gr <cmd> lua vim.lsp.buf.references()<CR>
	-- nnoremap <silent> g0 <cmd> lua vim.lsp.buf.document_symbol()<CR>
	-- nnoremap <silent> gW <cmd> lua vim.lsp.buf.workspace_symbol()<CR>
	-- nnoremap <silent> ;h <cmd> lua vim.lsp.buf.hover()<CR>
	-- nnoremap <silent> ;s <cmd> lua vim.lsp.buf.signature_help()<CR>
end

-- lsp.ccls.setup{
-- 	on_attach = my_attach,
-- }

lsp.gopls.setup{
	on_attach = my_attach,
	root_dir = util.root_pattern('go.mod', '.git'),
	-- NOTE: this is done to avoid the gopls warning about being outside gopath
	-- message_level = vim.lsp.protocol.MessageType.Error,
}

lsp.sumneko_lua.setup{
	on_attach = my_attach;
	cmd = { 'lua-language-server' };
	settings = {
		Lua = {
			runtime = {
				version = 'LuaJIT',
			},
			diagnostics = {
				globals = {'vim'},
			},
			workspace = {
				library = {
					[vim.fn.expand('$VIMRUNTIME/lua')] = true,
					[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
				}
			}
		}
	},
}

lsp.rust_analyzer.setup{
	on_attach = my_attach,
	cmd = { 'env', 'CARGO_TARGET_DIR=/tmp', 'rust-analyzer' },
}