From 502844d1e0dafc8956741a74b6207645f21e2408 Mon Sep 17 00:00:00 2001 From: doyle Date: Sat, 18 Jun 2022 18:34:51 +1000 Subject: [PATCH] nvim stuff --- Installer/os_nvim_init.vim | 56 ++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/Installer/os_nvim_init.vim b/Installer/os_nvim_init.vim index 83dd9b0..4a5e323 100644 --- a/Installer/os_nvim_init.vim +++ b/Installer/os_nvim_init.vim @@ -79,48 +79,61 @@ lua <', vim.lsp.buf.code_action, bufopts) - vim.keymap.set('n', '', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'gs', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'ga', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gR', vim.lsp.buf.rename, bufopts) end -- Request additional completion capabilities from the LSP server(s) local lspconfig = require('lspconfig') - local servers = { 'clangd', } - for _, lsp in ipairs(servers) do - lspconfig[lsp].setup { on_attach = custom_on_attach, capabilities = custom_capabilities, } - end + + -- Clangd LSP Setup + -- =========================================================================== + lspconfig.clangd.setup { + on_attach = custom_on_attach, + capabilities = custom_capabilities, + single_file_support = false, --- Don't launch LSP if the directory does not have LSP metadata + } -- Autocomplete Setup -- =========================================================================== local luasnip = require 'luasnip' local cmp = require 'cmp' + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, + completion = { autocomplete = false }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(-1), -- Scroll the docs up by 1 line - [''] = cmp.mapping.scroll_docs(1), -- Scroll the docs down by 1 line + [''] = cmp.mapping.scroll_docs(-1), -- Scroll the docs up by 1 line + [''] = cmp.mapping.scroll_docs(1), -- Scroll the docs down by 1 line [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, - [''] = cmp.mapping(function(fallback) -- Move down the autocomplete list + [''] = cmp.mapping(function(fallback) -- Move down the autocomplete list + cmp.complete() if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() else fallback() end end, { 'i', 's' }), - [''] = cmp.mapping(function(fallback) -- Move up the autocomplete list + [''] = cmp.mapping(function(fallback) -- Move up the autocomplete list if cmp.visible() then cmp.select_prev_item() elseif luasnip.jumpable(-1) then @@ -131,23 +144,18 @@ lua <