diff --git a/.all-contributorsrc b/.all-contributorsrc index fc6bbd7e..e734b8a4 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -81,6 +81,13 @@ "avatar_url": "https://avatars.githubusercontent.com/u/4156525?v=4", "profile": "https://github.com/shaungarwood", "contributions": ["code"] + }, + { + "login": "neutrinoA4", + "name": "neutrinoA4", + "avatar_url": "https://avatars.githubusercontent.com/u/122616073?v=4", + "profile": "https://github.com/neutrinoA4", + "contributions": ["code", "doc"] } ], "contributorsPerLine": 7, diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fea78a3..c630af62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## [1.6.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.5.0...v1.6.0) (2024-02-18) + + +### Features + +* add language settings for copilot answers ([8e40e41](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8e40e41c5bdabe675b2e54c80347dd85f1a9d550)) +* add support for visual mode in show_prompt_actions function ([13dfbba](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/13dfbba39e2202ad6bae5b4806ce7e42f75c94a0)) +* disable vim diagnostics on chat buffer for vsplit handler ([fe1808e](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/fe1808e51760c2fa71ca4176551161c73b2f2f73)) + + +### Bug Fixes + +* add validation before call FixDiagnostic command ([81c5060](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/81c506027e6a638973e3187dd98fc70cae024719)) +* reorder system prompt and language prompt ([0d474a1](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0d474a14b3bf67469946aa639e3de1a42b016373)) + ## [1.5.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.4.0...v1.5.0) (2024-02-17) diff --git a/README.md b/README.md index b6cf11bc..6edf20c0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square)](#contributors-) @@ -36,6 +36,7 @@ return { show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response. + language = "English" -- Copilot answer language settings when using default prompts. Default language is English. -- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks. }, build = function() @@ -244,6 +245,12 @@ To integrate CopilotChat with Telescope, you can add the following configuration end, desc = "CopilotChat - Help actions", }, + { + "ccp", + ":lua require('CopilotChat.code_actions').show_prompt_actions(true)", + mode = "x", + desc = "CopilotChat - Prompt actions", + }, } } ``` @@ -409,7 +416,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d gptlang
gptlang

💻 📖 - Dung Duc Huynh (Kaka)
Dung Duc Huynh (Kaka)

💻 📖 + Dung Duc Huynh (Kaka)
Dung Duc Huynh (Kaka)

💻 📖 Ahmed Haracic
Ahmed Haracic

💻 Trí Thiện Nguyễn
Trí Thiện Nguyễn

💻 He Zhizhou
He Zhizhou

💻 @@ -421,6 +428,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Katsuhiko Nishimra
Katsuhiko Nishimra

💻 Erno Hopearuoho
Erno Hopearuoho

💻 Shaun Garwood
Shaun Garwood

💻 + neutrinoA4
neutrinoA4

💻 📖 diff --git a/doc/CopilotChat.txt b/doc/CopilotChat.txt index cc4df58b..440f4577 100644 --- a/doc/CopilotChat.txt +++ b/doc/CopilotChat.txt @@ -1,4 +1,4 @@ -*CopilotChat.txt* For NVIM v0.8.0 Last change: 2024 February 17 +*CopilotChat.txt* For NVIM v0.8.0 Last change: 2024 February 18 ============================================================================== Table of Contents *CopilotChat-table-of-contents* @@ -55,6 +55,7 @@ LAZY.NVIM ~ show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response. + language = "English" -- Copilot answer language settings when using default prompts. Default language is English. -- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks. }, build = function() @@ -275,6 +276,12 @@ configuration to your keymap: end, desc = "CopilotChat - Help actions", }, + { + "ccp", + ":lua require('CopilotChat.code_actions').show_prompt_actions(true)", + mode = "x", + desc = "CopilotChat - Prompt actions", + }, } } < @@ -453,7 +460,7 @@ CONTRIBUTORS ✨ *CopilotChat-copilot-chat-for-neovim-contributors-✨* Thanks goes to these wonderful people (emoji key ): -gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻kristofka💻PostCyberPunk📖Katsuhiko Nishimra💻Erno Hopearuoho💻Shaun Garwood💻This project follows the all-contributors +gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻kristofka💻PostCyberPunk📖Katsuhiko Nishimra💻Erno Hopearuoho💻Shaun Garwood💻neutrinoA4💻 📖This project follows the all-contributors specification. Contributions of any kind are welcome! @@ -465,7 +472,7 @@ STARGAZERS OVER TIME ~ ============================================================================== 2. Links *CopilotChat-links* -1. *All Contributors*: https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square +1. *All Contributors*: https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square 2. *@jellydn*: 3. *Chat Demo*: https://i.gyazo.com/10fbd1543380d15551791c1a6dcbcd46.gif 4. *Explain Code Demo*: https://i.gyazo.com/e5031f402536a1a9d6c82b2c38d469e3.gif diff --git a/lua/CopilotChat/code_actions.lua b/lua/CopilotChat/code_actions.lua index 1c19e551..561477f5 100644 --- a/lua/CopilotChat/code_actions.lua +++ b/lua/CopilotChat/code_actions.lua @@ -7,9 +7,9 @@ local conf = require('telescope.config').values local utils = require('CopilotChat.utils') local help_actions = {} -local prompt_actions = {} +local user_prompt_actions = {} -local function fix_diagnostic() +local function generate_fix_diagnostic_prompt() local diagnostic = utils.get_diagnostics() local file_name = vim.fn.expand('%:t') local line_number = vim.fn.line('.') @@ -21,7 +21,7 @@ local function fix_diagnostic() .. diagnostic end -local function explain_diagnostic() +local function generate_explain_diagnostic_prompt() local diagnostic = utils.get_diagnostics() local file_name = vim.fn.expand('%:t') local line_number = vim.fn.line('.') @@ -37,7 +37,7 @@ end --- This will copy all the lines in the buffer to the unnamed register --- Then will send the diagnostic to copilot chat ---@param prefix string -local function help_command(prefix) +local function diagnostic_help_command(prefix) if prefix == nil then prefix = '' else @@ -71,7 +71,7 @@ end --- This will show all the user prompts in the telescope picker --- Then will execute the command selected by the user ---@param prefix string -local function prompt_command(prefix) +local function generate_prompt_command(prefix) if prefix == nil then prefix = '' else @@ -85,7 +85,7 @@ local function prompt_command(prefix) -- Get value from the prompt_actions and execute the command local value = '' - for _, action in pairs(prompt_actions) do + for _, action in pairs(user_prompt_actions) do if action.name == selection[1] then value = action.label break @@ -101,11 +101,11 @@ end local function show_help_actions() help_actions = { { - label = fix_diagnostic(), + label = generate_fix_diagnostic_prompt(), name = 'Fix diagnostic', }, { - label = explain_diagnostic(), + label = generate_explain_diagnostic_prompt(), name = 'Explain diagnostic', }, } @@ -117,44 +117,52 @@ local function show_help_actions() -- Show the menu with telescope pickers local opts = themes.get_dropdown({}) - local picker_names = {} + local action_names = {} for _, value in pairs(help_actions) do - table.insert(picker_names, value.name) + table.insert(action_names, value.name) end telescope_pickers .new(opts, { prompt_title = 'Copilot Chat Help Actions', finder = finders.new_table({ - results = picker_names, + results = action_names, }), sorter = conf.generic_sorter(opts), - attach_mappings = help_command('CopilotChat'), + attach_mappings = diagnostic_help_command('CopilotChat'), }) :find() end -local function show_prompt_actions() +--- Show prompt actions +---@param is_in_visual_mode boolean? +local function show_prompt_actions(is_in_visual_mode) -- Convert user prompts to a table of actions - prompt_actions = {} + user_prompt_actions = {} for key, prompt in pairs(vim.g.copilot_chat_user_prompts) do - table.insert(prompt_actions, { name = key, label = prompt }) + table.insert(user_prompt_actions, { name = key, label = prompt }) + end + + local cmd = 'CopilotChat' + + if is_in_visual_mode then + cmd = "'<,'>CopilotChatVisual" end -- Show the menu with telescope pickers local opts = themes.get_dropdown({}) - local picker_names = {} - for _, value in pairs(prompt_actions) do - table.insert(picker_names, value.name) + local action_names = {} + for _, value in pairs(user_prompt_actions) do + table.insert(action_names, value.name) end telescope_pickers .new(opts, { prompt_title = 'Copilot Chat Actions', finder = finders.new_table({ - results = picker_names, + results = action_names, }), sorter = conf.generic_sorter(opts), - attach_mappings = prompt_command('CopilotChat'), + attach_mappings = generate_prompt_command(cmd), }) :find() end diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index f1ba227f..99994646 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -15,6 +15,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {} -- - disable_extra_info: ('yes' | 'no') default: 'yes'. -- - hide_system_prompt: ('yes' | 'no') default: 'yes'. -- - proxy: (string?) default: ''. +-- - language: (string?) default: ''. -- - prompts: (table?) default: default_prompts. -- - debug: (boolean?) default: false. M.setup = function(options) @@ -22,6 +23,7 @@ M.setup = function(options) vim.g.copilot_chat_disable_separators = options and options.disable_extra_info or 'yes' vim.g.copilot_chat_hide_system_prompt = options and options.hide_system_prompt or 'yes' vim.g.copilot_chat_proxy = options and options.proxy or '' + vim.g.copilot_chat_language = options and options.language or '' local debug = options and options.debug or false _COPILOT_CHAT_GLOBAL_CONFIG.debug = debug @@ -39,6 +41,11 @@ M.setup = function(options) -- Troubleshoot and fix the diagnostic issue at the current cursor position. utils.create_cmd('CopilotChatFixDiagnostic', function() local diagnostic = utils.get_diagnostics() + if diagnostic == 'No diagnostics available' then + vim.notify('No diagnostic issue found at the current cursor position.', vim.log.levels.INFO) + return + end + local file_name = vim.fn.expand('%:t') local line_number = vim.fn.line('.') -- Copy all the lines from current buffer to unnamed register diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index 4d3e88fc..bd5ff58d 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -26,6 +26,7 @@ def __init__(self, nvim: MyNvim, buffer: MyBuffer): self.copilot: Copilot = None self.buffer: MyBuffer = buffer self.proxy: str = os.getenv("HTTPS_PROXY") or os.getenv("ALL_PROXY") or "" + self.language = self.nvim.eval("g:copilot_chat_language") # public @@ -79,6 +80,14 @@ def _construct_system_prompt(self, prompt: str): system_prompt = system_prompts.COPILOT_TESTS elif prompt == system_prompts.EXPLAIN_SHORTCUT: system_prompt = system_prompts.COPILOT_EXPLAIN + if self.language != "": + system_prompt = ( + system_prompts.PROMPT_ANSWER_LANGUAGE_TEMPLATE.substitute( + language=self.language + ) + + "\n" + + system_prompt + ) return system_prompt def _add_start_separator( diff --git a/rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py b/rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py index ed938c30..1f206527 100644 --- a/rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/inplace_chat_handler.py @@ -20,6 +20,7 @@ def __init__(self, nvim: MyNvim): self.diff_mode: bool = False self.model: str = MODEL_GPT4 self.system_prompt: str = "SENIOR_DEVELOPER_PROMPT" + self.language = self.nvim.eval("g:copilot_chat_language") # Add user prompts collection self.user_prompts = self.nvim.eval("g:copilot_chat_user_prompts") diff --git a/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py b/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py index 70284b61..16dce5cd 100644 --- a/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py @@ -14,6 +14,7 @@ def __init__(self, nvim: MyNvim): "filetype": "copilot-chat", }, ) + self.language = self.nvim.eval("g:copilot_chat_language") def vsplit(self): self.buffer.option("filetype", "copilot-chat") @@ -36,6 +37,9 @@ def vsplit(self): ) self.nvim.current.window.vars[var_key] = True + """ Disable vim diagnostics on the chat buffer """ + self.nvim.command(":lua vim.diagnostic.disable()") + def toggle_vsplit(self): """Toggle vsplit chat window.""" var_key = "copilot_chat" diff --git a/rplugin/python3/CopilotChat/prompts.py b/rplugin/python3/CopilotChat/prompts.py index 1290cbb0..a42a0c5f 100644 --- a/rplugin/python3/CopilotChat/prompts.py +++ b/rplugin/python3/CopilotChat/prompts.py @@ -1,3 +1,5 @@ +from string import Template + # pylint: disable=locally-disabled, multiple-statements, fixme, line-too-long COPILOT_INSTRUCTIONS = """You are an AI programming assistant. When asked for you name, you must respond with "GitHub Copilot". @@ -249,3 +251,4 @@ """ PROMPT_SIMPLE_DOCSTRING = "add simple docstring to this code" PROMPT_SEPARATE = "add comments separating the code into sections" +PROMPT_ANSWER_LANGUAGE_TEMPLATE = Template("Please answer in ${language}") diff --git a/version.txt b/version.txt index bc80560f..dc1e644a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.5.0 +1.6.0