Neovim add lsp keybindings
This commit is contained in:
parent
e86d81eb32
commit
ea8debd6d9
|
@ -1,39 +1,78 @@
|
||||||
local lsp_installer = require("nvim-lsp-installer")
|
local lsp_installer = require("nvim-lsp-installer")
|
||||||
|
|
||||||
|
local buf_map_keys = function(server_name, bufnr)
|
||||||
|
local function buf_set_keymap(...)
|
||||||
|
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
local keymapOpts = {noremap = true, silent = true}
|
||||||
|
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', keymapOpts)
|
||||||
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>wa',
|
||||||
|
'<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>wr',
|
||||||
|
'<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>wl',
|
||||||
|
'<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>D',
|
||||||
|
'<cmd>lua vim.lsp.buf.type_definition()<CR>', keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>e',
|
||||||
|
'<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>q',
|
||||||
|
'<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', keymapOpts)
|
||||||
|
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>',
|
||||||
|
keymapOpts)
|
||||||
|
end
|
||||||
|
|
||||||
-- Register a handler that will be called for all installed servers.
|
-- Register a handler that will be called for all installed servers.
|
||||||
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
|
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
|
||||||
lsp_installer.on_server_ready(function(server)
|
lsp_installer.on_server_ready(function(server)
|
||||||
local opts = {}
|
local opts = {}
|
||||||
print(server.name)
|
|
||||||
|
|
||||||
-- (optional) Customize the options passed to the server
|
-- Lua specific settings
|
||||||
if server.name == "sumneko_lua" then
|
if server_name == "sumneko_lua" then
|
||||||
local runtime_path = vim.split(package.path, ';')
|
local runtime_path = vim.split(package.path, ';')
|
||||||
opts = {
|
opts.settings = {
|
||||||
settings = {
|
Lua = {
|
||||||
Lua = {
|
runtime = {
|
||||||
runtime = {
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||||
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
version = 'LuaJIT',
|
||||||
version = 'LuaJIT',
|
-- Setup your lua path
|
||||||
-- Setup your lua path
|
path = runtime_path
|
||||||
path = runtime_path
|
},
|
||||||
},
|
diagnostics = {
|
||||||
diagnostics = {
|
-- Get the language server to recognize the `vim` global
|
||||||
-- Get the language server to recognize the `vim` global
|
globals = {'vim'}
|
||||||
globals = {'vim'}
|
},
|
||||||
},
|
workspace = {
|
||||||
workspace = {
|
-- Make the server aware of Neovim runtime files
|
||||||
-- Make the server aware of Neovim runtime files
|
library = vim.api.nvim_get_runtime_file("", true)
|
||||||
library = vim.api.nvim_get_runtime_file("", true)
|
},
|
||||||
},
|
-- Do not send telemetry data containing a randomized but unique identifier
|
||||||
-- Do not send telemetry data containing a randomized but unique identifier
|
telemetry = {enable = false}
|
||||||
telemetry = {enable = false}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
opts.on_attach = buf_map_keys
|
||||||
|
server:setup(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This setup() function is exactly the same as lspconfig's setup function.
|
|
||||||
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
|
|
||||||
server:setup(opts)
|
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue