From f0f2241438b9aa579c46b5a8a09f78c42386a640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sat, 2 Mar 2024 22:02:14 +0100 Subject: [PATCH] fix(nvim): Translate nvim-cmp to nixvim --- nvim/plugins/cmp.nix | 88 ------------------------------------ nvim/plugins/default.nix | 96 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 89 deletions(-) delete mode 100644 nvim/plugins/cmp.nix diff --git a/nvim/plugins/cmp.nix b/nvim/plugins/cmp.nix deleted file mode 100644 index 681990e..0000000 --- a/nvim/plugins/cmp.nix +++ /dev/null @@ -1,88 +0,0 @@ -{ - enable = true; - # Snippets - snippet.luasnip.enable = true; - # Completion Sources - sources = { - buffer.enable = true; - buffer.groupIndex = 3; - calc.enable = true; - calc.groupIndex = 2; - conventionalcommits.enable = true; - conventionalcommits.groupIndex = 1; - # cmdline.enable = true; - crates.enable = true; - crates.groupIndex = 1; - digraphs.enable = true; - digraphs.groupIndex = 3; - # emoji.enable = true; - # fuzzy_buffer.enable = true; - # fuzzy_path.enable = true; - luasnip.enable = true; - luasnip.groupIndex = 1; - nvim_lsp.enable = true; - nvim_lsp.groupIndex = 1; - nvim_lsp_document_symbol.enable = true; - nvim_lsp_document_symbol.groupIndex = 1; - nvim_lsp_signature_help.enable = true; - nvim_lsp_signature_help.groupIndex = 1; - path.enable = true; - path.groupIndex = 2; - # rg.enable = true; - spell.enable = true; - spell.groupIndex = 2; - treesitter.enable = true; - treesitter.groupIndex = 2; - zsh.enable = true; - zsh.groupIndex = 1; - }; - # Menu Icons - formatting.format = "require('lspkind').cmp_format { mode = 'symbol', maxwidth = 50 }"; - mappingPresets = [ "insert" ]; - mapping = { - "" = { - modes = [ "i" "s" ]; - action = '' - function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif require("luasnip").expand_or_jumpable() then - require("luasnip").expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end - ''; - }; - "" = { - modes = [ "i" "s" ]; - action = '' - function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif require("luasnip").jumpable(-1) then - require("luasnip").jump(-1) - else - fallback() - end - end - ''; - }; - "" = '' - cmp.mapping(function(fallback) - if require("luasnip").choice_active() then - require("luasnip").next_choice() - else - fallback() - end - end) - ''; - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.complete {}"; - "" = "cmp.mapping.close()"; - "" = "cmp.mapping.confirm { select = true }"; - }; -} diff --git a/nvim/plugins/default.nix b/nvim/plugins/default.nix index e1e51e3..69ce763 100644 --- a/nvim/plugins/default.nix +++ b/nvim/plugins/default.nix @@ -1,4 +1,30 @@ { + cmp-buffer.enable = true; + cmp-clippy.enable = true; + cmp-cmdline.enable = true; + cmp-nvim-lsp.enable = true; + cmp-nvim-lsp-document-symbol.enable = true; + cmp-nvim-lsp-signature-help.enable = true; + cmp-path.enable = true; + cmp-rg.enable = true; + cmp-spell.enable = true; + cmp-treesitter.enable = true; + cmp-zsh.enable = true; + conform-nvim = { + enable = true; + formattersByFt = { + "_" = [ "trim_whitespace" ]; + c = [ "clang_format" ]; + cpp = [ "clang_format" ]; + lua = [ "stylua" ]; + nix = [ "nixpkgs_fmt" ]; + rust = [ "rustfmt" ]; + sh = [ "shfmt" ]; + toml = [ "taplo" ]; + yaml = [ "yamlfmt" ]; + zig = [ "zigfmt" ]; + }; + }; gitsigns.enable = true; lsp = { enable = true; @@ -32,7 +58,75 @@ enable = true; extraConfig = { update_events = "TextChanged,TextChangedI"; }; }; - nvim-cmp = import ./cmp.nix; + nvim-cmp = { + enable = true; + # Snippets + snippet.expand = "luasnip"; + # Completion Sources + sources = [ + { name = "buffer"; groupIndex = 3; } + { name = "calc"; groupIndex = 2; } + { name = "conventionalcommits"; groupIndex = 1; } + { name = "crates"; groupIndex = 1; } + { name = "luasnip"; groupIndex = 1; } + { name = "nvim_lsp"; groupIndex = 1; } + { name = "nvim_lsp_document_symbol"; groupIndex = 1; } + { name = "nvim_lsp_signature_help"; groupIndex = 1; } + { name = "path"; groupIndex = 2; } + { name = "spell"; groupIndex = 2; } + { name = "treesitter"; groupIndex = 2; } + { name = "zsh"; groupIndex = 1; } + ]; + # Menu Icons + formatting.format = "require('lspkind').cmp_format { mode = 'symbol', maxwidth = 50 }"; + mappingPresets = [ "insert" ]; + mapping = { + "" = { + modes = [ "i" "s" ]; + action = '' + function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + require("luasnip").expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end + ''; + }; + "" = { + modes = [ "i" "s" ]; + action = '' + function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end + ''; + }; + "" = '' + cmp.mapping(function(fallback) + if require("luasnip").choice_active() then + require("luasnip").next_choice() + else + fallback() + end + end) + ''; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.complete {}"; + "" = "cmp.mapping.close()"; + "" = "cmp.mapping.confirm { select = true }"; + }; + }; nvim-colorizer = { enable = true; userDefaultOptions = {