summary refs log tree commit diff
path: root/.vim/lua/plugins/_lsp.lua
blob: 780f70357c2254e5a3f73adc90f4792f23e804cf (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
79
-- lsp config

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

-- 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
	nnoremap { 'K', function() vim.lsp.buf.hover() end }
	nnoremap { '<C-]>', function() vim.lsp.buf.definition() end }
	nnoremap { 'grr',   function() vim.lsp.buf.rename() end }
	nnoremap { '<c-h>', function() vim.lsp.buf.signature_help() end }
	nnoremap { ']d', function() vim.lsp.diagnostic.goto_next() end }
	nnoremap { '[d', function() vim.lsp.diagnostic.goto_prev() end }

	-- 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' },
}