From b4e210c6a3b98ae4b6ec6c45ffdd72c9fbe71138 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 Aug 2025 11:03:06 +0000 Subject: [PATCH 1/2] Initial plan From 99af19f2f02a988cadc226cd8d40708f383f5a2c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 Aug 2025 11:14:08 +0000 Subject: [PATCH 2/2] Complete copilot chat integration with lua-tiktoken support Co-authored-by: gignsky <13265812+gignsky@users.noreply.github.com> --- flake.nix | 4 ++ full.nix | 4 +- plugins/optional/copilot.nix | 92 +++++++++++++++++++++++++++++++++--- 3 files changed, 93 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index e970a38..71811f1 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,10 @@ url = "github:moyiz/git-dev.nvim"; flake = false; }; + lua-tiktoken = { + url = "github:gptlang/lua-tiktoken"; + flake = false; + }; }; outputs = diff --git a/full.nix b/full.nix index b82869f..f64fb82 100644 --- a/full.nix +++ b/full.nix @@ -4,11 +4,13 @@ let themeryModule = import ./plugins/optional/themery-nvim.nix { inherit inputs pkgs; }; # Import the git-dev module with inputs passed through gitDevModule = import ./plugins/optional/git-dev-nvim.nix { inherit inputs pkgs; }; + # Import the copilot module with inputs passed through + copilotModule = import ./plugins/optional/copilot.nix { inherit inputs pkgs; }; in { imports = [ ./minimal.nix - ./plugins/optional/copilot.nix + copilotModule themeryModule gitDevModule ]; diff --git a/plugins/optional/copilot.nix b/plugins/optional/copilot.nix index e399c06..2318020 100644 --- a/plugins/optional/copilot.nix +++ b/plugins/optional/copilot.nix @@ -1,5 +1,12 @@ # https://github.com/CopilotC-Nvim/CopilotChat.nvim -{ pkgs, ... }: +{ inputs, pkgs, ... }: +let + # Build lua-tiktoken from source for enhanced token counting + lua-tiktoken = pkgs.vimUtils.buildVimPlugin { + name = "lua-tiktoken"; + src = inputs.lua-tiktoken; + }; +in { config.vim = { assistant.copilot = { @@ -8,11 +15,84 @@ panel.layout.position = "right"; }; }; - extraPlugins.copilotChat = { - package = pkgs.vimPlugins.CopilotChat-nvim; - setup = '' - require('copilotChat') - ''; + + # Add tiktoken as an extra package for enhanced token counting + extraPackages = with pkgs; [ + # Try to include tiktoken-related packages + (python3Packages.tiktoken or null) + ]; + + extraPlugins = { + copilotChat = { + package = pkgs.vimPlugins.CopilotChat-nvim; + setup = '' + require('CopilotChat').setup({ + -- Chat integration settings + debug = false, + show_help = "yes", + + -- Window settings for chat + window = { + layout = 'float', + relative = 'cursor', + width = 1, + height = 0.4, + row = 1 + }, + + -- Mappings + mappings = { + complete = { + detail = 'Use @ or / for options.', + insert ='', + }, + close = { + normal = 'q', + insert = '' + }, + reset = { + normal ='', + insert = '' + }, + submit_prompt = { + normal = '', + insert = '' + }, + accept_diff = { + normal = '', + insert = '' + }, + show_diff = { + normal = 'gd' + }, + show_system_prompt = { + normal = 'gp' + }, + show_user_selection = { + normal = 'gs' + }, + }, + }) + + -- Add keymaps for quick access + vim.keymap.set('n', 'cc', 'CopilotChat', { desc = 'Open Copilot Chat' }) + vim.keymap.set('v', 'cc', 'CopilotChatVisual', { desc = 'Open Copilot Chat with selection' }) + vim.keymap.set('n', 'ce', 'CopilotChatExplain', { desc = 'Explain code' }) + vim.keymap.set('n', 'ct', 'CopilotChatTests', { desc = 'Generate tests' }) + vim.keymap.set('n', 'cr', 'CopilotChatReview', { desc = 'Review code' }) + vim.keymap.set('n', 'cf', 'CopilotChatFixDiagnostic', { desc = 'Fix diagnostic' }) + vim.keymap.set('n', 'co', 'CopilotChatOptimize', { desc = 'Optimize code' }) + ''; + }; + + # Add lua-tiktoken for enhanced token counting + luaTiktoken = { + package = lua-tiktoken; + setup = '' + -- lua-tiktoken provides more accurate token counting for chat contexts + -- CopilotChat will automatically use it if available + ''; + }; }; }; }