-- Helper function for creating keymaps. function nnoremap(rhs, lhs, desc) local bufopts = { noremap=true, silent=true, buffer=bufnr, desc = desc } vim.keymap.set("n", rhs, lhs, bufopts) end -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer function default_on_attach(client, bufnr) -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions nnoremap('gD', vim.lsp.buf.declaration, "Go to declaration") nnoremap('gd', vim.lsp.buf.definition, "Go to definition") nnoremap('K', vim.lsp.buf.hover, "Hover text") nnoremap('gi', vim.lsp.buf.implementation, "Go to implementation") nnoremap('', vim.lsp.buf.signature_help, "Show signature") nnoremap('wa', vim.lsp.buf.add_workspace_folder, "Add workspace folder") nnoremap('wr', vim.lsp.buf.remove_workspace_folder, "Remove workspace folder") nnoremap('wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, "List workspace folders") nnoremap('D', vim.lsp.buf.type_definition, "Go to type definition") nnoremap('rn', vim.lsp.buf.rename, "Rename") nnoremap('ca', vim.lsp.buf.code_action, "Code actions") nnoremap('gr', vim.lsp.buf.references, "Find references") nnoremap('f', function() vim.lsp.buf.format { async = true } end, "Format file") end function read_configuration() local configuration = {} local chunk, err = loadfile(os.getenv('HOME') .. '/.config/nvim/config', 't', configuration) if chunk then chunk() end return configuration end