diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index 54670ac..b50d726 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -42,6 +42,20 @@ in { after = '' ${optionalString luasnipEnable "local luasnip = require('luasnip')"} local cmp = require("cmp") + + local kinds = require("cmp.types").lsp.CompletionItemKind + local deprio = function(kind) + return function(e1, e2) + if e1:get_kind() == kind then + return false + end + if e2:get_kind() == kind then + return true + end + return nil + end + end + cmp.setup(${toLuaObject cfg.setupOpts}) ${optionalString config.vim.lazy.enable diff --git a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix index 8246e71..d63ed73 100644 --- a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix +++ b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix @@ -29,6 +29,8 @@ in { sorting.comparators = mkOption { type = mergelessListOf (either str luaInline); default = [ + (mkLuaInline "deprio(kinds.Text)") + (mkLuaInline "deprio(kinds.Snippet)") "offset" "exact" "score" @@ -43,6 +45,12 @@ in { (see `:help cmp-config.sorting.comparators`), or a string, in which case the builtin comparator with that name will be used. + + A `deprio` function and a `kinds` + (`require("cmp.types").lsp.CompletionItemKind`) variable is provided + above `setupOpts`. By passing a type to the funcion, the returned + function will be a comparator that always ranks the specified kind the + lowest. ''; apply = map ( c: