local nvim_lsp = require('lspconfig') -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function() local function set_keymap(...) vim.api.nvim_set_keymap(...) end local function set_option(...) vim.api.nvim_set_option(...) end -- Enable completion triggered by set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. local opts = { noremap=true, silent=true } -- See `:help vim.lsp.*` for documentation on any of the below functions set_keymap('', ';lc', 'lua vim.lsp.buf.declaration()', opts) set_keymap('', ';lf', 'lua vim.lsp.buf.definition()', opts) set_keymap('', ';lh', 'lua vim.lsp.buf.hover()', opts) set_keymap('', ';li', 'lua vim.lsp.buf.implementation()', opts) set_keymap('', ';ls', 'lua vim.lsp.buf.signature_help()', opts) set_keymap('', ';lwa', 'lua vim.lsp.buf.add_workspace_folder()', opts) set_keymap('', ';lwr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) set_keymap('', ';lw', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) set_keymap('', ';lt', 'lua vim.lsp.buf.type_definition()', opts) set_keymap('', ';lr', 'lua vim.lsp.buf.rename()', opts) set_keymap('', ';la', 'lua vim.lsp.buf.code_action()', opts) set_keymap('', ';lc', 'lua vim.lsp.buf.references()', opts) set_keymap('', ';lo', 'lua vim.diagnostic.open_float()', opts) set_keymap('', ';ln', 'lua vim.diagnostic.goto_prev()', opts) set_keymap('', ';lp', 'lua vim.diagnostic.goto_next()', opts) set_keymap('', ';lm', 'lua vim.lsp.buf.formatting()', opts) end -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -- the packages for these servers are: pyright, rust-analyzer, texlab, and lua-language-server local servers = { 'pyright', 'rust_analyzer', 'texlab'} for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { flags = { debounce_text_changes = 150, } } end --lua-language-server needs seperate config. local runtime_path = vim.split(package.path, ';') table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") require'lspconfig'.sumneko_lua.setup { 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, }, }, }, } on_attach()