From bb092ad64977f8c0abfefb364be2c59e43082543 Mon Sep 17 00:00:00 2001 From: jaydamani Date: Wed, 31 Mar 2021 15:08:29 +0530 Subject: [PATCH] fixed mappings for lspconfigs --- lua/nvim-lspconfig/lua.lua | 66 ++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/lua/nvim-lspconfig/lua.lua b/lua/nvim-lspconfig/lua.lua index 60426017..98ba1aee 100644 --- a/lua/nvim-lspconfig/lua.lua +++ b/lua/nvim-lspconfig/lua.lua @@ -1,34 +1,44 @@ vim.cmd [[packadd nvim-lspconfig]] vim.cmd [[packadd nvim-compe]] +local nvim_lsp = require('lspconfig') +function on_attach(client) -local function buf_set_keymap(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) -end -local function buf_set_option(...) - vim.api.nvim_buf_set_option(bufnr, ...) + + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + + -- Set some keybinds conditional on server capabilities + if client.resolved_capabilities.document_formatting then + buf_set_keymap("n", "f", "lua vim.lsp.buf.formatting()", opts) + elseif client.resolved_capabilities.document_range_formatting then + buf_set_keymap("n", "f", "lua vim.lsp.buf.range_formatting()", opts) + end + +end + +local servers = { "tsserver" } +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { on_attach = on_attach } end -buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") --- Mappings. -local opts = {noremap = true, silent = true} -buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) -buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) -buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) -buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) -buf_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) -buf_set_keymap("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", opts) -buf_set_keymap("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", opts) -buf_set_keymap("n", "wl", "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) -buf_set_keymap("n", "D", "lua vim.lsp.buf.type_definition()", opts) -buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) -buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) -buf_set_keymap("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) -buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) -buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) -buf_set_keymap("n", "q", "lua vim.lsp.diagnostic.set_loclist()", opts) - --- lsp for html , css and js/ts -require "lspconfig".tsserver.setup {} -require "lspconfig".cssls.setup {} -require "lspconfig".html.setup {}