vim.opt.completeopt = { "menuone", "noselect", "popup" } vim.lsp.config['lua_ls'] = { -- Command and arguments to start the server. cmd = { 'lua-language-server' }, -- Filetypes to automatically attach to. filetypes = { 'lua' }, -- Sets the "workspace" to the directory where any of these files is found. -- Files that share a root directory will reuse the LSP server connection. -- Nested lists indicate equal priority, see |vim.lsp.Config|. root_markers = { { '.luarc.json', '.luarc.jsonc' }, '.git' }, -- Specific settings to send to the server. The schema is server-defined. -- Example: https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json settings = { Lua = { runtime = { version = 'LuaJIT', } } } } vim.lsp.config['clangd'] = { cmd = { 'clangd' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' }, root_markers = { --'.clangd', --'.clang-tidy', --'.clang-format', --'compile_commands.json', --'compile_flags.txt', --'configure.ac', -- AutoTools '.git', }, capabilities = { textDocument = { completion = { editsNearCursor = true, }, }, offsetEncoding = { 'utf-8', 'utf-16' }, }, vim.keymap.set("i", "", vim.lsp.completion.get, { desc = "trigger autocompletion" }) } vim.lsp.enable('lua_ls') vim.lsp.enable('clangd') vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('my.lsp', {}), callback = function(args) local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) -- Enable auto-completion. Note: Use CTRL-Y to select an item. |complete_CTRL-Y| if client:supports_method('textDocument/completion') then -- Optional: trigger autocompletion on EVERY keypress. May be slow! local chars = {}; for i = 32, 126 do table.insert(chars, string.char(i)) end client.server_capabilities.completionProvider.triggerCharacters = chars vim.lsp.completion.enable(true, client.id, args.buf, {autotrigger = true}) end end, }) -- open autocomplete menu when pressing vim.keymap.set('i', '', function() vim.lsp.completion.get() end)