updates to code completion, gen-ai functionality, and nvim-tree

This commit is contained in:
Ellis Rahhal 2025-02-15 20:45:53 -08:00
parent 0c6dab5310
commit a68c97c516
6 changed files with 215 additions and 161 deletions

View file

@ -1,155 +1,174 @@
{ ... }:
{
programs.nixvim = {
plugins.cmp = {
enable = true;
autoEnableSources = true;
settings = {
enabled.__raw = ''
function()
local filetype = vim.api.nvim_buf_get_option(0, "filetype")
if filetype == "TelescopePrompt" then
return false
end
return true
end
'';
sources = [
{ name = "nvim_lua"; }
{ name = "nvim_lsp"; }
{ name = "emoji"; }
{
name = "buffer"; # text within current buffer
option.get_bufnrs.__raw = "vim.api.nvim_list_bufs";
keywordLength = 3;
}
# { name = "copilot"; } # enable/disable copilot
{
name = "path"; # file system paths
keywordLength = 3;
}
{
name = "luasnip"; # snippets
keywordLength = 3;
}
{ name = "cmdline"; }
];
formatting = {
fields = [ "kind" "abbr" "menu" ];
format = ''
function(entry, vim_item)
local 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 = "",
}
vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
vim_item.menu = ({
path = "[Path]",
nvim_lua = "[NVIM_LUA]",
nvim_lsp = "[LSP]",
luasnip = "[Snippet]",
buffer = "[Buffer]",
})[entry.source.name]
return vim_item
end
'';
};
completion = {
completeopt = "menuone,noselect";
plugins = {
cmp-cmdline.enable = true;
cmp-git.enable = true;
cmp-npm.enable = true;
cmp-path.enable = true;
cmp-rg.enable = true;
cmp-tmux.enable = true;
cmp-treesitter.enable = true;
cmp-zsh.enable = true;
cmp_yanky.enable = true;
copilot-cmp = {
enable = true;
settings = {
event = ["InsertEnter" "LspAttach"]; # When to trigger Copilot
fix_pairs = true; # Fix parentheses/brackets completion
};
};
cmp = {
enable = true;
autoEnableSources = true;
experimental = { ghost_text = true; };
performance = {
debounce = 60;
fetchingTimeout = 200;
maxViewEntries = 30;
};
snippet = {
expand = ''
function(args)
require('luasnip').lsp_expand(args.body)
settings = {
enabled.__raw = ''
function()
local filetype = vim.api.nvim_buf_get_option(0, "filetype")
if filetype == "TelescopePrompt" then
return false
end
return true
end
'';
};
window = {
completion = { border = "solid"; };
documentation = { border = "solid"; };
};
sources = [
{ name = "nvim_lua"; }
{ 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;
}
{ name = "cmdline"; }
];
mapping = {
"<C-j>" = "cmp.mapping.select_next_item()";
"<C-n>" = "cmp.mapping.select_next_item()";
"<C-k>" = "cmp.mapping.select_prev_item()";
"<C-p>" = "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-c>" = "cmp.mapping.complete()";
"<Tab>" = "cmp.mapping.confirm({ select = false })";
# "<Tab>" = ''
# cmp.mapping(function(fallback)
# -- local context = require("cmp.config.context")
# -- local is_comment = context.in_treesitter_capture("comment") == true or context.in_syntax_group("Comment")
#
# local col = vim.fn.col('.') - 1
# local line = vim.fn.getline('.')
# local char_under_cursor = string.sub(line, col, col)
#
# if col == 0 or string.match(char_under_cursor, '%s') then
# fallback()
# elseif cmp.visible() then
# cmp.confirm({ select = true })
# else
# fallback()
# end
# end, { "i", "s" })
# '';
"<S-Tab>" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })";
"<C-l>" = ''
cmp.mapping(function()
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
formatting = {
fields = [ "kind" "abbr" "menu" ];
format = ''
function(entry, vim_item)
local 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 = "",
}
vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
vim_item.menu = ({
path = "[Path]",
nvim_lua = "[NVIM_LUA]",
nvim_lsp = "[LSP]",
luasnip = "[Snippet]",
buffer = "[Buffer]",
})[entry.source.name]
return vim_item
end
end, { 'i', 's' })
'';
"<C-h>" = ''
cmp.mapping(function()
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
'';
};
completion = {
completeopt = "menuone,noselect";
};
autoEnableSources = true;
experimental = { ghost_text = true; };
performance = {
debounce = 60;
fetchingTimeout = 200;
maxViewEntries = 30;
};
snippet = {
expand = ''
function(args)
require('luasnip').lsp_expand(args.body)
end
end, { 'i', 's' })
'';
'';
};
window = {
completion = { border = "solid"; };
documentation = { border = "solid"; };
};
mapping = {
"<C-j>" = "cmp.mapping.select_next_item()";
"<C-n>" = "cmp.mapping.select_next_item()";
"<C-k>" = "cmp.mapping.select_prev_item()";
"<C-p>" = "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-c>" = "cmp.mapping.complete()";
"<Tab>" = "cmp.mapping.confirm({ select = false })";
# "<Tab>" = ''
# cmp.mapping(function(fallback)
# -- local context = require("cmp.config.context")
# -- local is_comment = context.in_treesitter_capture("comment") == true or context.in_syntax_group("Comment")
#
# local col = vim.fn.col('.') - 1
# local line = vim.fn.getline('.')
# local char_under_cursor = string.sub(line, col, col)
#
# if col == 0 or string.match(char_under_cursor, '%s') then
# fallback()
# elseif cmp.visible() then
# cmp.confirm({ select = true })
# else
# fallback()
# end
# end, { "i", "s" })
# '';
"<S-Tab>" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })";
"<C-l>" = ''
cmp.mapping(function()
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
end
end, { 'i', 's' })
'';
"<C-h>" = ''
cmp.mapping(function()
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
end
end, { 'i', 's' })
'';
};
};
};
};

View file

@ -1,7 +1,20 @@
{ pkgs, ... }:
{
programs.nixvim.plugins = {
codecompanion = {
programs.nixvim = {
keymaps = [
{
mode = [ "n" ];
key = "<c-c>";
action = ":CodeCompanionActions<CR>";
}
{
mode = [ "n" ];
key = ",c";
action = ":CodeCompanionChat Toggle<CR>";
}
];
plugins.codecompanion = {
enable = true;
settings = {

View file

@ -26,13 +26,7 @@
gitsigns.enable = true;
indent-blankline.enable = true;
lightline.enable = false;
lsp-signature.enable = true;
# config = ''
# lua << EOF
# require("lsp_signature").setup()
# EOF
# '';
# lsp-signature.enable = true;
lualine.enable = true;
nix.enable = true;
noice.enable = true;
@ -58,6 +52,7 @@
# EOF
# '';
oil.enable = true;
rainbow-delimiters.enable = true;
sleuth.enable = true;
treesitter.enable = false;
@ -67,5 +62,6 @@
# ## Only on unstable at the moment
web-devicons.enable = true;
which-key.enable = true;
yanky.enable = true;
};
}

View file

@ -1,6 +1,15 @@
{ ... }:
{
programs.nixvim = {
# keymaps = [
# {
# mode = "i";
# key = "<c-c>";
# action.__raw = ''function() require("luasnip.extras.select_choice")() end'';
# options.desc = "Search";
# }
# ];
plugins.luasnip = {
enable = true;
@ -28,14 +37,5 @@
# '';
};
};
# keymaps = [
# {
# mode = "i";
# key = "<c-c>";
# action.__raw = ''function() require("luasnip.extras.select_choice")() end'';
# options.desc = "Search";
# }
# ];
};
}

View file

@ -8,6 +8,19 @@
};
};
extraConfigLua = ''
function _G.launch_find_files_wrapped()
-- Try custom function first
local handled = require('treeutils').launch_find_files()
if handled == "default" then
-- If custom function didn't handle it, execute default behavior
local default_key = vim.api.nvim_replace_termcodes('<c-f>', true, true, true)
vim.api.nvim_feedkeys(default_key, 'n', false)
end
end
'';
keymaps = [
## Go to current buffer's file in nvim-tree
{
@ -25,7 +38,7 @@
{
mode = [ "n" ];
key = "<c-f>";
action = "<cmd>lua require('treeutils').launch_find_files()<CR>";
action = "<cmd>lua launch_find_files_wrapped()<CR>";
options = { noremap = true; };
}
{

View file

@ -22,15 +22,28 @@ function M.launch_live_grep(opts)
end
function M.launch_find_files(opts)
return M.launch_telescope("find_files", opts)
return M.launch_telescope("find_files", opts, { active_only_in_tree = true })
end
function M.launch_telescope(func_name, opts)
function M.launch_telescope(func_name, opts, internal_opts)
internal_opts = internal_opts or {}
local buffname = vim.fn.bufname()
if (internal_opts.active_only_in_tree) then
-- Make sure this is being called in NvimTree
if (string.sub(buffname, 1, string.len('NvimTree')) ~= 'NvimTree') then
return "default"
end
end
local telescope_status_ok, _ = pcall(require, "telescope")
if not telescope_status_ok then
return
end
local node = api.tree.get_node_under_cursor()
if (node == nil) then
-- Tree is probably not open
return
end
local is_folder = node.fs_stat and node.fs_stat.type == 'directory' or false
local basedir = is_folder and node.absolute_path or vim.fn.fnamemodify(node.absolute_path, ":h")
if (node.name == '..' and TreeExplorer ~= nil) then