Skip to content

Commit

Permalink
feat: cmp
Browse files Browse the repository at this point in the history
  • Loading branch information
erictossell committed Jul 13, 2024
1 parent def3d45 commit ac820b4
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 15 deletions.
123 changes: 118 additions & 5 deletions config/cmp.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,121 @@
{
plugins.cmp = {
enable = true;
autoEnableSources = true;
plugins = {
cmp-emoji = { enable = true; };
cmp = {
enable = true;
settings = {
autoEnableSources = true;
experimental = { ghost_text = true; };
performance = {
debounce = 60;
fetchingTimeout = 200;
maxViewEntries = 30;
};
snippet = { expand = "luasnip"; };
formatting = { fields = [ "kind" "abbr" "menu" ]; };
sources = [
{ name = "nvim_lsp"; }
{ name = "emoji"; }
{
name = "buffer"; # text within current buffer
option.get_bufnrs.__raw = "vim.api.nvim_list_bufs";
keywordLength = 3;
}
{ name = "copilot"; }
{
name = "path"; # file system paths
keywordLength = 3;
}
{
name = "luasnip"; # snippets
keywordLength = 3;
}
];

window = {
completion = { border = "solid"; };
documentation = { border = "solid"; };
};

mapping = {
"<Tab>" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})";
"<C-j>" = "cmp.mapping.select_next_item()";
"<C-k>" = "cmp.mapping.select_prev_item()";
"<C-e>" = "cmp.mapping.abort()";
"<C-b>" = "cmp.mapping.scroll_docs(-4)";
"<C-f>" = "cmp.mapping.scroll_docs(4)";
"<C-Space>" = "cmp.mapping.complete()";
"<CR>" = "cmp.mapping.confirm({ select = true })";
"<S-CR>" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })";
};
};
};
cmp-nvim-lsp = { enable = true; }; # lsp
cmp-buffer = { enable = true; };
cmp-path = { enable = true; }; # file system paths
cmp_luasnip = { enable = true; }; # snippets
cmp-cmdline = { enable = false; }; # autocomplete for cmdline
};

plugins.cmp-buffer.enable = true;
extraConfigLua = ''
luasnip = require("luasnip")
kind_icons = {
Text = "󰊄",
Method = "",
Function = "󰡱",
Constructor = "",
Field = "",
Variable = "󱀍",
Class = "",
Interface = "",
Module = "󰕳",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "",
Event = "",
Operator = "",
TypeParameter = "",
}
local cmp = require'cmp'
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({'/', "?" }, {
sources = {
{ name = 'buffer' }
}
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- 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' }
}),
-- formatting = {
-- format = function(_, vim_item)
-- vim_item.kind = cmdIcons[vim_item.kind] or "FOO"
-- return vim_item
-- end
-- }
}) '';
}
23 changes: 14 additions & 9 deletions config/copilot.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
plugins = {
#copilot-lua.enable = true;
#copilot-cmp.enable = true;
copilot-vim = {
enable = true;
settings = {
filetypes = { "*" = true; };
};
};
plugins.copilot-cmp = {
enable = true;
};
plugins.copilot-lua = {
enable = true;
suggestion = { enabled = false; };
panel = { enabled = false; };
};

extraConfigLua = ''
require("copilot").setup({
suggestion = { enabled = false },
panel = { enabled = false },
})
'';
}
1 change: 1 addition & 0 deletions config/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
./keymaps.nix
./lsp.nix
./lualine.nix
./luasnip.nix
./markdown.nix
./neo-tree.nix
./telescope.nix
Expand Down
2 changes: 1 addition & 1 deletion config/lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
jsonls.enable = true;
lua-ls.enable = true;
# nixd.enable = true;
nil_ls.enable = true;
nil-ls.enable = true;
ruff-lsp.enable = true;
rust-analyzer = {
enable = true;
Expand Down
15 changes: 15 additions & 0 deletions config/luasnip.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ pkgs, ... }: {
plugins.luasnip = {
enable = true;
extraConfig = {
enable_autosnippets = true;
store_selection_keys = "<Tab>";
};
fromVscode = [
{
lazyLoad = true;
paths = "${pkgs.vimPlugins.friendly-snippets}";
}
];
};
}

0 comments on commit ac820b4

Please sign in to comment.