diff --git a/modules/nix/nvim/cmp.nix b/modules/nix/nvim/cmp.nix index 1be390f..74a8e5f 100644 --- a/modules/nix/nvim/cmp.nix +++ b/modules/nix/nvim/cmp.nix @@ -1,35 +1,154 @@ -{ config, pkgs, nixvim, ...}: +_: +let + get_bufnrs.__raw = '' + function() + local buf_size_limit = 1024 * 1024 -- 1MB size limit + local bufs = vim.api.nvim_list_bufs() + local valid_bufs = {} + for _, buf in ipairs(bufs) do + if vim.api.nvim_buf_is_loaded(buf) and vim.api.nvim_buf_get_offset(buf, vim.api.nvim_buf_line_count(buf)) < buf_size_limit then + table.insert(valid_bufs, buf) + end + end + return valid_bufs + end + ''; +in { - programs.nixvim.plugins = { - cmp-nvim-lsp.enable = true; - cmp-path.enable = true; - cmp-buffer.enable = true; - cmp-clippy.enable = true; - cmp = { - enable = true; - autoEnableSources = false; - cmdline = { - completion = { - autocomplete = "require('cmp.types').cmp.TriggerEvent.TextChanged"; - completeopt = [ "menu" "menuone" "noinsert" "noselect" ]; - }; + plugins = { + cmp = { + enable = true; + autoEnableSources = true; + + settings = { + mapping = { + "" = # Lua + "cmp.mapping.scroll_docs(-4)"; + "" = # Lua + "cmp.mapping.scroll_docs(4)"; + "" = # Lua + "cmp.mapping.complete()"; + "" = # Lua + "cmp.mapping.close()"; + "" = # Lua + "cmp.mapping(cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})"; + "" = # Lua + "cmp.mapping(cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})"; + "" = # Lua + "cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace })"; + }; + + preselect = # Lua + "cmp.PreselectMode.None"; + + snippet.expand = # Lua + "function(args) require('luasnip').lsp_expand(args.body) end"; + + sources = [ + { + name = "nvim_lsp"; + priority = 1000; + option = { + inherit get_bufnrs; }; - settings = { - mapping = { - "" = "cmp.mapping.complete()"; - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.close()"; - "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.confirm({ select = false })"; - "" = "cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's'})"; - "" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})"; - }; - sources = [ - { name = "nvim_lsp"; keyword_length = 1; max_item_count = 5; } - { name = "path"; keyword_length = 1; max_item_count = 5; } - { name = "clippy"; keyword_length = 1; max_item_count = 5; } - ]; - }; - }; - }; + } + { + name = "nvim_lsp_signature_help"; + priority = 1000; + option = { + inherit get_bufnrs; + }; + } + { + name = "nvim_lsp_document_symbol"; + priority = 1000; + option = { + inherit get_bufnrs; + }; + } + { + name = "treesitter"; + priority = 850; + option = { + inherit get_bufnrs; + }; + } + { + name = "luasnip"; + priority = 750; + } + { + name = "buffer"; + priority = 500; + option = { + inherit get_bufnrs; + }; + } + { + name = "copilot"; + priority = 400; + } + { + name = "rg"; + priority = 300; + } + { + name = "path"; + priority = 300; + } + { + name = "cmdline"; + priority = 300; + } + { + name = "spell"; + priority = 300; + } + { + name = "git"; + priority = 250; + } + { + name = "zsh"; + priority = 250; + } + { + name = "calc"; + priority = 150; + } + { + name = "emoji"; + priority = 100; + } + ]; + }; + }; + + friendly-snippets.enable = true; + luasnip.enable = true; + + lspkind = { + enable = true; + + cmp = { + enable = true; + + menu = { + buffer = ""; + calc = ""; + cmdline = ""; + codeium = "󱜙"; + emoji = "󰞅"; + git = ""; + luasnip = "󰩫"; + neorg = ""; + nvim_lsp = ""; + nvim_lua = ""; + path = ""; + spell = ""; + treesitter = "󰔱"; + }; + }; + }; + }; } diff --git a/modules/nix/nvim/cmp.nix.bak b/modules/nix/nvim/cmp.nix.bak new file mode 100644 index 0000000..1be390f --- /dev/null +++ b/modules/nix/nvim/cmp.nix.bak @@ -0,0 +1,35 @@ +{ config, pkgs, nixvim, ...}: +{ + programs.nixvim.plugins = { + cmp-nvim-lsp.enable = true; + cmp-path.enable = true; + cmp-buffer.enable = true; + cmp-clippy.enable = true; + cmp = { + enable = true; + autoEnableSources = false; + cmdline = { + completion = { + autocomplete = "require('cmp.types').cmp.TriggerEvent.TextChanged"; + completeopt = [ "menu" "menuone" "noinsert" "noselect" ]; + }; + }; + settings = { + mapping = { + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.close()"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.confirm({ select = false })"; + "" = "cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's'})"; + "" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})"; + }; + sources = [ + { name = "nvim_lsp"; keyword_length = 1; max_item_count = 5; } + { name = "path"; keyword_length = 1; max_item_count = 5; } + { name = "clippy"; keyword_length = 1; max_item_count = 5; } + ]; + }; + }; + }; +}