summary refs log tree commit diff
path: root/.vim/lua/plugins/_lsp.lua
diff options
context:
space:
mode:
Diffstat (limited to '.vim/lua/plugins/_lsp.lua')
-rw-r--r--.vim/lua/plugins/_lsp.lua78
1 files changed, 78 insertions, 0 deletions
diff --git a/.vim/lua/plugins/_lsp.lua b/.vim/lua/plugins/_lsp.lua
new file mode 100644
index 0000000..9d98aca
--- /dev/null
+++ b/.vim/lua/plugins/_lsp.lua
@@ -0,0 +1,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' },
+}