about summary refs log tree commit diff stats
path: root/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix122
1 files changed, 82 insertions, 40 deletions
diff --git a/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix b/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix
index 8d61dbd7..315f3fc7 100644
--- a/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix
+++ b/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix
@@ -1,3 +1,12 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
 {
   config,
   lib,
@@ -5,49 +14,82 @@
 }: let
   cfg = config.soispha.programs.nvim;
 in {
-  home-manager.users.soispha.programs.nixvim.plugins.cmp = lib.mkIf cfg.enable {
-    /*
-    TODO: integrate this:
-    ```lua
-      enabled = {
-      function()
-          -- disable completion in comments
-          local context = require 'cmp.config.context'
-          -- keep command mode completion enabled when cursor is in a comment
-          -- te
-          if vim.api.nvim_get_mode().mode == 'c' then
-              return true
-          else
-              return not context.in_treesitter_capture("comment")
-                  and not context.in_syntax_group("Comment")
+  home-manager.users.soispha.programs.nixvim = lib.mkIf cfg.enable {
+    opts.completeopt = [
+      "menu" # Show completions in a menu
+      "menuone" # Also open menu, when only one completion exists
+      "noselect" # Do not pre select one of the completions
+    ];
+
+    keymaps = [
+      {
+        key = "hh";
+        mode = ["i"];
+        action.__raw = ''
+          function()
+            require('cmp').select_next_item()
           end
-      end
-      },
-    ```
-    */
-    enable = true;
-    autoEnableSources = true;
-    settings = {
-      mapping = {
-        # TODO: add support for desc and which key here
-        "<C-d>" = "cmp.mapping.scroll_docs(-4)"; # desc = "Scroll up by four lines"
-        "<C-f>" = "cmp.mapping.scroll_docs(4)"; # desc = "Scroll down by four lines"
-        "HH" = "cmp.mapping.complete()"; # desc = "Confirm snipped"
-      };
+        '';
+        options.desc = "go forward in completion menu";
+      }
+      {
+        key = "uu";
+        mode = ["i"];
+        action.__raw = ''
+          function()
+            require('cmp').confirm()
+          end
+        '';
+        options.desc = "confirm the selected item";
+      }
+
+      {
+        key = "<C-d>";
+        mode = ["i"];
+        action.__raw = ''
+          function()
+            require('cmp').mapping.scroll_docs(-4)
+          end
+        '';
+        options.desc = "Scroll up by four lines";
+      }
+      {
+        key = "<C-f>";
+        mode = ["i"];
+        action.__raw = ''
+          function()
+            require('cmp').mapping.scroll_docs(4)
+          end
+        '';
+        options.desc = "Scroll down by four lines";
+      }
+    ];
+
+    plugins.cmp = {
+      enable = true;
+      autoEnableSources = true;
 
-      snippet.expand = "function(args) require('luasnip').lsp_expand(args.body) end";
+      settings = {
+        mapping = {};
 
-      sources = [
-        {name = "nvim_lsp";}
-        {name = "luasnip";}
-        {name = "path";}
-        {name = "git";} # TODO: I might want to add config to allow all issues/prs <2023-10-16>
-        # {name = "convertionalcommits";} # TODO: Useless without commitlint [https://commitlint.js.org/] <2023-10-16>
-        # {name = "rg";} # TODO: This might really RIP-grep my system <2023-10-16>
-        # {name = "buffer";}
-        # {name = "digraphs";}
-        {name = "calc";}
-      ];
+        snippet.expand.__raw = ''
+          function(args)
+            require('luasnip').lsp_expand(args.body)
+          end
+        '';
+
+        sources = [
+          {name = "nvim_lsp";}
+          {name = "luasnip";}
+          {name = "path";}
+          {name = "git";} # TODO: I might want to add config to allow all issues/prs <2023-10-16>
+          # {name = "convertionalcommits";} # TODO: Useless without commitlint [https://commitlint.js.org/] <2023-10-16>
+          # {name = "rg";} # TODO: This might really RIP-grep my system <2023-10-16>
+          # {name = "buffer";}
+          # {name = "digraphs";}
+          {name = "calc";}
+        ];
+      };
     };
   };
 }