From c858af776852a79e658dadff654eb23c31770db7 Mon Sep 17 00:00:00 2001 From: natto1784 Date: Tue, 8 Feb 2022 17:00:36 +0530 Subject: [PATCH] neovim: upgrade to nvim-cmp from nvim-compe --- home/config/xmonad/xmobar.hs | 2 +- home/config/xmonad/xmonad.hs | 4 +- home/stuff/services.nix | 6 +- hosts/satori/pkgs.nix | 1 + modules/nvim/default.nix | 12 ++- modules/nvim/init.lua | 177 ++++++++++++++++++----------------- 6 files changed, 109 insertions(+), 93 deletions(-) diff --git a/home/config/xmonad/xmobar.hs b/home/config/xmonad/xmobar.hs index 9a6853c..7b80f08 100644 --- a/home/config/xmonad/xmobar.hs +++ b/home/config/xmonad/xmobar.hs @@ -42,7 +42,7 @@ config = ], sepChar = "*", alignSep = "--", - template = " *UnsafeStdinReader* " ++ sep ++ " *mpd* -- *multicpu* " ++ sep ++ " *memory* " ++ sep ++ " *wlp0s20f3* " ++ sep ++ " *battery* " ++ sep ++ " \xf028 *pamixer*% " ++ sep ++ " *date* - *time* *tray*" + template = " *UnsafeStdinReader* " ++ sep ++ " *mpd* -- *multicpu* " ++ sep ++ " *memory* " ++ sep ++ " *wlp0s20f3* " ++ sep ++ " *battery* " ++ sep ++ " \xf028 *pamixer*% " ++ sep ++ " *date* - *time* " ++ sep ++ "*tray*" } main :: IO () diff --git a/home/config/xmonad/xmonad.hs b/home/config/xmonad/xmonad.hs index 41f0970..461d62c 100644 --- a/home/config/xmonad/xmonad.hs +++ b/home/config/xmonad/xmonad.hs @@ -247,8 +247,8 @@ main = do xmproc <- spawnPipe ("xmobar " ++ myXmobarrc) , logHook = dynamicLogWithPP xmobarPP { ppOutput = hPutStrLn xmproc , ppCurrent = xmobarColor activeWinColor "" . wrap "(" ")" - , ppVisible = xmobarColor activeWinColor "" - , ppHidden = xmobarColor inactiveWinColor "" + , ppVisible = xmobarColor activeWinColor "" + , ppHidden = xmobarColor inactiveWinColor "" , ppTitle = xmobarColor fgColor "" . shorten 40 , ppLayout = const "" , ppUrgent = xmobarColor urgentWinColor "" . wrap "!" "" diff --git a/home/stuff/services.nix b/home/stuff/services.nix index 6adc7c7..46d506f 100644 --- a/home/stuff/services.nix +++ b/home/stuff/services.nix @@ -90,15 +90,15 @@ in enable = true; config = { geometry = "1x1-0"; - max_geometry = "5x0"; + max_geometry = "10x0"; window_type = "dock"; sticky = true; - scrollbars = "horizontal"; icon_size = 23; background = "#1d2021"; - grow_gravity = "E"; icon_gravity = "E"; + grow_gravity = "E"; kludges = "force_icons_size"; + window_layer = "top"; }; }; }; diff --git a/hosts/satori/pkgs.nix b/hosts/satori/pkgs.nix index 8dd7855..b562cbd 100644 --- a/hosts/satori/pkgs.nix +++ b/hosts/satori/pkgs.nix @@ -29,6 +29,7 @@ ccls clang-tools nodePackages.typescript-language-server + nodePackages.svelte-language-server rnix-lsp python3Packages.python-lsp-server haskell-language-server diff --git a/modules/nvim/default.nix b/modules/nvim/default.nix index dacd147..1a3e02f 100644 --- a/modules/nvim/default.nix +++ b/modules/nvim/default.nix @@ -21,15 +21,23 @@ vim-floaterm vim-closetag nerdcommenter - nvim-compe + nvim-cmp + cmp_luasnip + cmp-nvim-lsp + cmp-path + cmp-calc + cmp-emoji + # cmp-look + cmp-buffer nvim-lspconfig barbar-nvim presence-nvim nvim-web-devicons nvim-tree-lua - vim-vsnip + luasnip nvim-treesitter vim-latex-live-preview + lspkind-nvim # (gruvbox.overrideAttrs (oa: { patches = [ ./gruvbox.patch ]; })) base16-vim ]; diff --git a/modules/nvim/init.lua b/modules/nvim/init.lua index 6617818..c9884b1 100644 --- a/modules/nvim/init.lua +++ b/modules/nvim/init.lua @@ -7,9 +7,7 @@ local getvar = vim.api.nvim_get_var function hi(hi_var, hi_value) comm("hi " .. hi_var .. " " .. hi_value) end - --SETTINGS - vim.o.cmdheight = 1 vim.o.modifiable = true vim.o.cursorline = true @@ -40,7 +38,6 @@ vim.o.clipboard = "unnamedplus" vim.o.completeopt = "menuone,noselect" vim.o.cursorcolumn = true - --KEYBINDS --Colemak-DH bind fuction for hjkl [mnei]) @@ -140,10 +137,6 @@ bind('n', "", ":NvimTreeToggle", {noremap=true, silent=true}) bind('n', "r", ":NvimTreeRefresh", {noremap=true, silent=true}) bind('n', "f", ":NvimTreeFindFile", {noremap=true, silent=true}) ---theme ---im.g.gruvbox_italic=1 ---vim.g.gruvbox_contrast_dark="hard" ---vim.g.gruvbox_contrast_light="hard" vim.o.background="dark" comm("colorscheme base16-tomorrow-night") @@ -216,75 +209,104 @@ local on_attach = function(client, bufnr) buf_set_keymap('n', "", "lua vim.lsp.buf.formatting()", {silent=true, noremap=true}) end -require'compe'.setup { - enabled = true; - autocomplete = true; - debug = false; - min_length = 1; - preselect = 'enable'; - throttle_time = 80; - source_timeout = 200; - incomplete_delay = 400; - max_abbr_width = 100; - max_kind_width = 100; - max_menu_width = 100; - documentation = true; - - source = { - path = true; - buffer = true; - nvim_lsp = true; - calc = true; - spell = true; - treesitter = true; - nvim_lua = true; - vsnip = true; - }; +local servers = { "ccls", "rust_analyzer", "tsserver", "hls", "pylsp", "texlab", "rnix", "terraform_lsp" } +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true +capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + 'documentation', + 'detail', + 'additionalTextEdits', + } } -local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) +local nvimlsp = require('lspconfig') +for _, lsp in ipairs(servers) do + nvimlsp[lsp].setup { capabilities = capabilities, on_attach = on_attach } end -local check_back_space = function() - local col = vim.fn.col('.') - 1 - if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then - return true - else - return false + + +local luasnip = require 'luasnip' +local cmp = require 'cmp' +cmp.setup { + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, + [''] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end end -end + }, + sources = { + { name = 'nvim_lsp'}, + { name = 'path'}, + { name = 'nvim_lua'}, + { name = 'luasnip'}, + { name = 'calc'}, + { name = 'emoji'}, + { name = 'buffer'}, + { name = 'look'}, + }, + formatting = { + format = require('lspkind').cmp_format({ + with_text = true, + menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + nvim_lua = "[Lua]", + latex_symbols = "[Latex]", + }) + }), + }, +} + cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + } + }) -vim.g.vsnip_snippet_dir = "/home/natto/.vsnip" --- Use (s-)tab to: ---- move to prev/next item in completion menuone ---- jump to prev/next snippet's placeholder -_G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#available", {1}) == 1 then - return t "(vsnip-expand-or-jump)" - elseif check_back_space() then - return t "" - else - return vim.fn['compe#complete']() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then - return t "(vsnip-jump-prev)" - else - -- If is not working in your terminal, change it to - return t "" - end -end + -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) -bind("i", "", "v:lua.tab_complete()", {expr = true, silent = true}) -bind("s", "", "v:lua.tab_complete()", {expr = true, silent = true}) -bind("i", "", "v:lua.s_tab_complete()", {expr = true, silent = true}) -bind("s", "", "v:lua.s_tab_complete()", {expr = true, silent = true}) -bind("i", "", "compe#confirm('')", {expr = true, silent = true}) +--bind("i", "", "v:lua.tab_complete()", {expr = true, silent = true}) +--bind("s", "", "v:lua.tab_complete()", {expr = true, silent = true}) +--bind("i", "", "v:lua.s_tab_complete()", {expr = true, silent = true}) +--bind("s", "", "v:lua.s_tab_complete()", {expr = true, silent = true}) +--bind("i", "", "compe#confirm('')", {expr = true, silent = true}) comm("set shortmess+=c") @@ -340,21 +362,6 @@ local statusline = { } vim.o.statusline = table.concat(statusline) -local servers = { "ccls", "rust_analyzer", "tsserver", "hls", "pylsp", "texlab", "rnix", "terraform_lsp" } -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true -capabilities.textDocument.completion.completionItem.resolveSupport = { - properties = { - 'documentation', - 'detail', - 'additionalTextEdits', - } -} - -local nvimlsp = require('lspconfig') -for _, lsp in ipairs(servers) do - nvimlsp[lsp].setup { capabilities = capabilities, on_attach = on_attach } -end vim.g.tex_flavor = "latex" comm("set syntax=off")