diff --git a/home/.config/nvim/lua/pluginconf/lsp.lua b/home/.config/nvim/lua/pluginconf/lsp.lua index cbd3948..551f1be 100644 --- a/home/.config/nvim/lua/pluginconf/lsp.lua +++ b/home/.config/nvim/lua/pluginconf/lsp.lua @@ -1,39 +1,78 @@ 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', 'lua vim.lsp.buf.declaration()', + keymapOpts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', + keymapOpts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', keymapOpts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', + keymapOpts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', + keymapOpts) + buf_set_keymap('n', 'wa', + 'lua vim.lsp.buf.add_workspace_folder()', keymapOpts) + buf_set_keymap('n', 'wr', + 'lua vim.lsp.buf.remove_workspace_folder()', + keymapOpts) + buf_set_keymap('n', 'wl', + 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', + keymapOpts) + buf_set_keymap('n', 'D', + 'lua vim.lsp.buf.type_definition()', keymapOpts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', + keymapOpts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', + keymapOpts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', + keymapOpts) + buf_set_keymap('n', 'e', + 'lua vim.lsp.diagnostic.show_line_diagnostics()', + keymapOpts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', + keymapOpts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', + keymapOpts) + buf_set_keymap('n', 'q', + 'lua vim.lsp.diagnostic.set_loclist()', keymapOpts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', + keymapOpts) +end + -- 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). lsp_installer.on_server_ready(function(server) local opts = {} - print(server.name) - -- (optional) Customize the options passed to the server - if server.name == "sumneko_lua" then + -- Lua specific settings + if server_name == "sumneko_lua" then local runtime_path = vim.split(package.path, ';') - opts = { - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - -- Setup your lua path - path = runtime_path - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = {'vim'} - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true) - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = {enable = false} - } + opts.settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'} + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true) + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = {enable = false} } } + opts.on_attach = buf_map_keys + server:setup(opts) 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)