diff --git a/plugins/cmp.nix b/plugins/cmp.nix index c33ef46..ecfb677 100644 --- a/plugins/cmp.nix +++ b/plugins/cmp.nix @@ -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 = { - "" = "cmp.mapping.select_next_item()"; - "" = "cmp.mapping.select_next_item()"; - "" = "cmp.mapping.select_prev_item()"; - "" = "cmp.mapping.select_prev_item()"; - "" = "cmp.mapping.abort()"; - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.complete()"; - "" = "cmp.mapping.confirm({ select = false })"; - # "" = '' - # 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" }) - # ''; - "" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })"; - "" = '' - 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' }) - ''; - "" = '' - 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 = { + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.abort()"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.complete()"; + "" = "cmp.mapping.confirm({ select = false })"; + # "" = '' + # 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" }) + # ''; + "" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })"; + "" = '' + cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }) + ''; + "" = '' + cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }) + ''; + }; }; }; }; diff --git a/plugins/codecompanion.nix b/plugins/codecompanion.nix index 51abadd..2a9178f 100644 --- a/plugins/codecompanion.nix +++ b/plugins/codecompanion.nix @@ -1,7 +1,20 @@ { pkgs, ... }: { - programs.nixvim.plugins = { - codecompanion = { + programs.nixvim = { + keymaps = [ + { + mode = [ "n" ]; + key = ""; + action = ":CodeCompanionActions"; + } + { + mode = [ "n" ]; + key = ",c"; + action = ":CodeCompanionChat Toggle"; + } + ]; + + plugins.codecompanion = { enable = true; settings = { diff --git a/plugins/default.nix b/plugins/default.nix index 67a8483..0bd925e 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -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; }; } diff --git a/plugins/luasnip.nix b/plugins/luasnip.nix index 7610225..cdc7103 100644 --- a/plugins/luasnip.nix +++ b/plugins/luasnip.nix @@ -1,6 +1,15 @@ { ... }: { programs.nixvim = { + # keymaps = [ + # { + # mode = "i"; + # key = ""; + # action.__raw = ''function() require("luasnip.extras.select_choice")() end''; + # options.desc = "Search"; + # } + # ]; + plugins.luasnip = { enable = true; @@ -28,14 +37,5 @@ # ''; }; }; - - # keymaps = [ - # { - # mode = "i"; - # key = ""; - # action.__raw = ''function() require("luasnip.extras.select_choice")() end''; - # options.desc = "Search"; - # } - # ]; }; } diff --git a/plugins/nvim-tree.nix b/plugins/nvim-tree.nix index 169d134..897c0ac 100644 --- a/plugins/nvim-tree.nix +++ b/plugins/nvim-tree.nix @@ -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('', 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 = ""; - action = "lua require('treeutils').launch_find_files()"; + action = "lua launch_find_files_wrapped()"; options = { noremap = true; }; } { diff --git a/plugins/treeutils.lua b/plugins/treeutils.lua index 89b4569..30dae54 100644 --- a/plugins/treeutils.lua +++ b/plugins/treeutils.lua @@ -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