diff --git a/nvim/.config/nvim/lua/lsp.lua b/nvim/.config/nvim/lua/lsp.lua index 72f048e..4bcceed 100644 --- a/nvim/.config/nvim/lua/lsp.lua +++ b/nvim/.config/nvim/lua/lsp.lua @@ -31,64 +31,21 @@ vim.lsp.config("texlab", { }) - --- --- --- Completion config --- --- - - -vim.o.completeopt = "menu,menuone,noinsert,fuzzy" - -vim.api.nvim_set_keymap("i", "", "", { noremap = true }) - -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)) - - -- Make tab accept the selected completion - vim.keymap.set('i', '', function() - if vim.fn.pumvisible() == 1 then - return '' - else - return '' - end - end, { expr = true }) - - -- Make enter just insert a newline (don't accept completion) - vim.keymap.set('i', '', function() - if vim.fn.pumvisible() == 1 then - return '' - else - return '' - end - end, { expr = true }) - - if client:supports_method('textDocument/completion') then - -- Trigger autocompletion on every keypress - 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 - - vim.keymap.set('n', '', - function() vim.lsp.buf.format() end, { - desc = "Format", - noremap = true, - silent = true - }) - vim.keymap.set('i', '', - function() vim.lsp.buf.format() end, { - desc = "Format", - noremap = true, - silent = true - }) - - vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, { desc = "Go to definition" }) - end, +vim.lsp.config('clangd', { + cmd = { + "clangd", + "--background-index", + "--clang-tidy", + "--completion-style=bundled", + "--cross-file-rename", + "--header-insertion=iwyu", + -- Required for embedded system compilers + "--query-driver=/**/*g++", + "--offset-encoding=utf-16" + -- "-j=8", + -- "--malloc-trim", + -- "--pch-storage=memory" + } }) @@ -125,3 +82,38 @@ vim.api.nvim_create_autocmd("CursorHold", { }) end, }) + + +-- +-- +-- Keymaps +-- +-- + + +-- TODO: Do I need this if I use nvim-cmp? +vim.o.completeopt = "menu,menuone,noinsert,fuzzy" + +vim.api.nvim_set_keymap("i", "", "", { noremap = true }) + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('my.lsp', {}), + callback = function(args) + vim.keymap.set('n', '', + function() vim.lsp.buf.format() end, { + desc = "Format", + noremap = true, + silent = true + }) + vim.keymap.set('i', '', + function() vim.lsp.buf.format() end, { + desc = "Format", + noremap = true, + silent = true + }) + vim.keymap.set("n", "gd", + function() vim.lsp.buf.definition() end, { + desc = "Go to definition" + }) + end, +}) diff --git a/nvim/.config/nvim/lua/plugins/luasnip/init.lua b/nvim/.config/nvim/lua/plugins/luasnip/init.lua index 953bd98..75f294f 100644 --- a/nvim/.config/nvim/lua/plugins/luasnip/init.lua +++ b/nvim/.config/nvim/lua/plugins/luasnip/init.lua @@ -8,7 +8,7 @@ return { -- TODO: Find out how to enable autosnippets without having the status line disappear require("luasnip").config.set_config({ - -- enable_autosnippets = true, + enable_autosnippets = true, store_selection_keys = "v" }) diff --git a/nvim/.config/nvim/lua/plugins/nvim-cmp.lua b/nvim/.config/nvim/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..b69611a --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/nvim-cmp.lua @@ -0,0 +1,70 @@ +return +{ + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + 'L3MON4D3/LuaSnip', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'hrsh7th/cmp-nvim-lsp', + -- TODO: Do I need these? + 'hrsh7th/cmp-cmdline', + -- 'hrsh7th/cmp-nvim-lsp-signature-help', + 'saadparwaiz1/cmp_luasnip' + }, + config = function() + local cmp = require('cmp') + + cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + -- window = { + -- -- completion = cmp.config.window.bordered(), + -- -- documentation = cmp.config.window.bordered(), + -- }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, { + { name = 'buffer' }, + }) + }) + + -- -- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below + -- -- Set configuration for specific filetype. + -- cmp.setup.filetype('gitcommit', { + -- sources = cmp.config.sources({ + -- { name = 'git' }, + -- }, { + -- { name = 'buffer' }, + -- }) + -- }) + -- require("cmp_git").setup() + + -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) + + -- -- Set up lspconfig. + -- local capabilities = require('cmp_nvim_lsp').default_capabilities() + -- -- Replace with each lsp server you've enabled. + -- vim.lsp.config('', { + -- capabilities = capabilities + -- }) + -- vim.lsp.enable('') + end + +}