local M = {} -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches local servers = { "tsserver" "purescriptls" } function M.map(buf, mode, lhs, rhs, opts) local options = { noremap=true, silent=true } if opts then options = vim.tbl_extend('force', options, opts) end map(buf, mode, lhs, rhs, options) end function on_attach(client, bufnr) -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Go to declaration / definition / implementation map(bufnr, "n", 'gD', 'lua vim.lsp.buf.declaration()') map(bufnr, "n", 'gd', 'lua vim.lsp.buf.definition()') map(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()') -- Hover map(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()') map(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()') -- Workspace stuff map(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()') map(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()') map(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))') -- Code actions map(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()') map(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()') map(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()') map(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()') map(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()') end function M.setup() for _, lsp in pairs(servers) do require('lspconfig')[lsp].setup { on_attach = on_attach, flags = { debounce_text_changes = 150, -- This will be the default in neovim 0.7+ } } end end return M