diff --git a/.all-contributorsrc b/.all-contributorsrc index a09b7ebb..49348a58 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -102,6 +102,20 @@ "avatar_url": "https://avatars.githubusercontent.com/u/3443378?v=4", "profile": "https://github.com/AdrielVelazquez", "contributions": ["code", "doc"] + }, + { + "login": "deathbeam", + "name": "Tomas Slusny", + "avatar_url": "https://avatars.githubusercontent.com/u/5115805?v=4", + "profile": "https://github.com/deathbeam", + "contributions": ["code", "doc"] + }, + { + "login": "nisalVD", + "name": "Nisal", + "avatar_url": "https://avatars.githubusercontent.com/u/30633436?v=4", + "profile": "http://nisalvd.netlify.com/", + "contributions": ["doc"] } ], "contributorsPerLine": 7, diff --git a/.github/workflows/deploy-gh-pages.yml b/.github/workflows/deploy-gh-pages.yml new file mode 100644 index 00000000..007d254c --- /dev/null +++ b/.github/workflows/deploy-gh-pages.yml @@ -0,0 +1,50 @@ +name: Deploy Github Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v4 + - name: Build with Jekyll + uses: actions/jekyll-build-pages@v1 + with: + source: ./ + destination: ./_site + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a0cc66fc..822466c5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,10 +3,6 @@ on: push: branches: - release - pull_request: - branches: - - main - - release permissions: contents: write @@ -17,11 +13,10 @@ jobs: name: release runs-on: ubuntu-latest steps: - - uses: google-github-actions/release-please-action@v3 + - uses: google-github-actions/release-please-action@v4 id: release with: release-type: simple - package-name: CopilotChat.nvim token: ${{ secrets.GITHUB_TOKEN }} - uses: actions/checkout@v3 - name: tag stable versions diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b83089ed..1f9f6923 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ repos: - repo: https://github.com/psf/black - rev: "23.10.0" + rev: "24.2.0" hooks: - id: black - repo: https://github.com/PyCQA/flake8 - rev: "6.1.0" + rev: "7.0.0" hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-prettier - rev: "fc260393cc4ec09f8fc0a5ba4437f481c8b55dc1" + rev: "v4.0.0-alpha.8" hooks: - id: prettier diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..1b763b1b --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e73ac88..8b10796e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## [1.9.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.8.0...v1.9.0) (2024-02-24) + + +### Features + +* Add support for clear_chat_on_new_prompt config option ([7dc8771](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/7dc877196296d1f2515ea1c24d0e7d3d4cb8d3b4)) + + +### Bug Fixes + +* enable vim diagnostics after finish the conversation ([a0a5a2a](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/a0a5a2a9ae0edf79cdf05620fcead7d59575d306)), closes [#72](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/72) + + +### Reverts + +* add CopilotPlugin back ([713ca00](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/713ca00ef29a56c4c132809f07ea49a63ca8d492)) + ## [1.8.0](https://github.com/CopilotC-Nvim/CopilotChat.nvim/compare/v1.7.1...v1.8.0) (2024-02-23) diff --git a/README.md b/README.md index cb99195f..115a205e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,18 @@ # Copilot Chat for Neovim +![Prerequisite](https://img.shields.io/badge/python-%3E%3D3.10-blue.svg) +[![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://copilotc-nvim.github.io/CopilotChat.nvim/) +[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/CopilotC-Nvim/CopilotChat.nvim/main.svg)](https://results.pre-commit.ci/latest/github/CopilotC-Nvim/CopilotChat.nvim/main) + -[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors-) +> [!NOTE] +> We are excited to announce that we are currently migrating the plugin to fully Lua in the [canary](https://github.com/CopilotC-Nvim/CopilotChat.nvim/tree/canary) branch. + > [!NOTE] > A new command, `CopilotChatBuffer` has been added. It allows you to chat with Copilot using the entire content of the buffer. @@ -49,7 +56,7 @@ return { end, event = "VeryLazy", keys = { - { "ccb", "CopilotChatBuffer", desc = "CopilotChat - Chat with current buffer" }, + { "ccb", ":CopilotChatBuffer ", desc = "CopilotChat - Chat with current buffer" }, { "cce", "CopilotChatExplain", desc = "CopilotChat - Explain code" }, { "cct", "CopilotChatTests", desc = "CopilotChat - Generate tests" }, { @@ -59,7 +66,7 @@ return { }, { "ccv", - ":CopilotChatVisual", + ":CopilotChatVisual ", mode = "x", desc = "CopilotChat - Open in vertical split", }, @@ -185,6 +192,7 @@ You have the ability to tailor this plugin to your specific needs using the conf show_help = 'yes', -- Show help text for CopilotChatInPlace disable_extra_info = 'no', -- Disable extra information in the response hide_system_prompt = 'yes', -- Hide system prompts in the response + clear_chat_on_new_prompt = 'no', -- If yes then clear chat history on new prompt proxy = '', -- Proxies requests via https or socks prompts = { -- Set dynamic prompts for CopilotChat commands Explain = 'Explain how it works.', @@ -280,6 +288,26 @@ For further reference, you can view @jellydn's [configuration](https://github.co ## Tips +### Quick chat with your buffer + +To chat with Copilot using the entire content of the buffer, you can add the following configuration to your keymap: + +```lua + -- Quick chat with Copilot + { + "ccq", + function() + local input = vim.fn.input("Quick Chat: ") + if input ~= "" then + vim.cmd("CopilotChatBuffer " .. input) + end + end, + desc = "CopilotChat - Quick chat", + }, +``` + +[![Chat with buffer](https://i.gyazo.com/9b8cbf1d78a19f326282a6520bc9aab0.gif)](https://gyazo.com/9b8cbf1d78a19f326282a6520bc9aab0) + ### Integration with `telescope.nvim` To integrate CopilotChat with Telescope, you can add the following configuration to your keymap: @@ -496,6 +524,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Jack Muratore
Jack Muratore

💻 Adriel Velazquez
Adriel Velazquez

💻 📖 + + Tomas Slusny
Tomas Slusny

💻 📖 + Nisal
Nisal

📖 + diff --git a/doc/CopilotChat.txt b/doc/CopilotChat.txt index 75b15b3b..84da67f8 100644 --- a/doc/CopilotChat.txt +++ b/doc/CopilotChat.txt @@ -1,4 +1,4 @@ -*CopilotChat.txt* For NVIM v0.8.0 Last change: 2024 February 23 +*CopilotChat.txt* For NVIM v0.8.0 Last change: 2024 February 28 ============================================================================== Table of Contents *CopilotChat-table-of-contents* @@ -16,9 +16,16 @@ Table of Contents *CopilotChat-table-of-contents* ============================================================================== 1. Copilot Chat for Neovim *CopilotChat-copilot-chat-for-neovim* + + + |CopilotChat-| + [!NOTE] We are excited to announce that we are currently migrating the plugin + to fully Lua in the canary + branch. + [!NOTE] A new command, `CopilotChatBuffer` has been added. It allows you to chat with Copilot using the entire content of the buffer. @@ -68,7 +75,7 @@ LAZY.NVIM ~ end, event = "VeryLazy", keys = { - { "ccb", "CopilotChatBuffer", desc = "CopilotChat - Chat with current buffer" }, + { "ccb", ":CopilotChatBuffer ", desc = "CopilotChat - Chat with current buffer" }, { "cce", "CopilotChatExplain", desc = "CopilotChat - Explain code" }, { "cct", "CopilotChatTests", desc = "CopilotChat - Generate tests" }, { @@ -78,7 +85,7 @@ LAZY.NVIM ~ }, { "ccv", - ":CopilotChatVisual", + ":CopilotChatVisual ", mode = "x", desc = "CopilotChat - Open in vertical split", }, @@ -210,6 +217,7 @@ configuration options outlined below: show_help = 'yes', -- Show help text for CopilotChatInPlace disable_extra_info = 'no', -- Disable extra information in the response hide_system_prompt = 'yes', -- Hide system prompts in the response + clear_chat_on_new_prompt = 'no', -- If yes then clear chat history on new prompt proxy = '', -- Proxies requests via https or socks prompts = { -- Set dynamic prompts for CopilotChat commands Explain = 'Explain how it works.', @@ -313,6 +321,28 @@ CHAT WITH COPILOT WITH ALL CONTENTS OF INFOCUS BUFFER ~ TIPS *CopilotChat-copilot-chat-for-neovim-tips* +QUICK CHAT WITH YOUR BUFFER ~ + +To chat with Copilot using the entire content of the buffer, you can add the +following configuration to your keymap: + +>lua + -- Quick chat with Copilot + { + "ccq", + function() + local input = vim.fn.input("Quick Chat: ") + if input ~= "" then + vim.cmd("CopilotChatBuffer " .. input) + end + end, + desc = "CopilotChat - Quick chat", + }, +< + + + + INTEGRATION WITH TELESCOPE.NVIM ~ To integrate CopilotChat with Telescope, you can add the following @@ -527,7 +557,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💻neutrinoA4💻 📖Jack Muratore💻Adriel Velazquez💻 📖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💻 📖Jack Muratore💻Adriel Velazquez💻 📖Tomas Slusny💻 📖Nisal📖This project follows the all-contributors specification. Contributions of any kind are welcome! @@ -539,23 +569,27 @@ STARGAZERS OVER TIME ~ ============================================================================== 2. Links *CopilotChat-links* -1. *All Contributors*: https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square -2. *@treyhunner*: -3. *@nekowasabi*: -4. *@jellydn*: -5. *Chat Demo*: https://i.gyazo.com/10fbd1543380d15551791c1a6dcbcd46.gif -6. *Explain Code Demo*: https://i.gyazo.com/e5031f402536a1a9d6c82b2c38d469e3.gif -7. *Generate tests*: https://i.gyazo.com/f285467d4b8d8f8fd36aa777305312ae.gif -8. *Fix diagnostic*: https://i.gyazo.com/4aff3fdbc5c3eee59cb68939546fa2be.gif -9. *Fold Demo*: https://i.gyazo.com/766fb3b6ffeb697e650fc839882822a8.gif -10. *In-place Demo*: https://i.gyazo.com/4a5badaa109cd483c1fc23d296325cb0.gif -11. *Toggle*: https://i.gyazo.com/db5af9e5d88cd2fd09f58968914fa521.gif -12. *Help action with Copilot Chat*: https://i.gyazo.com/146dc35368592ba9f5de047ddc4728ad.gif -13. *Select action base on user prompts*: https://i.gyazo.com/a9c41e6398591c2f1d1d872fd58a2c63.gif -14. *Layout*: https://i.gyazo.com/550daf6cbb729027ca9bd703c21af53e.png -15. *Debug Info*: https://i.gyazo.com/bf00e700bcee1b77bcbf7b516b552521.gif -16. *@ecosse3*: -17. *Stargazers over time*: https://starchart.cc/CopilotC-Nvim/CopilotChat.nvim.svg +1. *Prerequisite*: https://img.shields.io/badge/python-%3E%3D3.10-blue.svg +2. *Documentation*: https://img.shields.io/badge/documentation-yes-brightgreen.svg +3. *pre-commit.ci status*: https://results.pre-commit.ci/badge/github/CopilotC-Nvim/CopilotChat.nvim/main.svg +4. *All Contributors*: https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square +5. *@treyhunner*: +6. *@nekowasabi*: +7. *@jellydn*: +8. *Chat Demo*: https://i.gyazo.com/10fbd1543380d15551791c1a6dcbcd46.gif +9. *Explain Code Demo*: https://i.gyazo.com/e5031f402536a1a9d6c82b2c38d469e3.gif +10. *Generate tests*: https://i.gyazo.com/f285467d4b8d8f8fd36aa777305312ae.gif +11. *Fix diagnostic*: https://i.gyazo.com/4aff3fdbc5c3eee59cb68939546fa2be.gif +12. *Fold Demo*: https://i.gyazo.com/766fb3b6ffeb697e650fc839882822a8.gif +13. *In-place Demo*: https://i.gyazo.com/4a5badaa109cd483c1fc23d296325cb0.gif +14. *Toggle*: https://i.gyazo.com/db5af9e5d88cd2fd09f58968914fa521.gif +15. *Chat with buffer*: https://i.gyazo.com/9b8cbf1d78a19f326282a6520bc9aab0.gif +16. *Help action with Copilot Chat*: https://i.gyazo.com/146dc35368592ba9f5de047ddc4728ad.gif +17. *Select action base on user prompts*: https://i.gyazo.com/a9c41e6398591c2f1d1d872fd58a2c63.gif +18. *Layout*: https://i.gyazo.com/550daf6cbb729027ca9bd703c21af53e.png +19. *Debug Info*: https://i.gyazo.com/bf00e700bcee1b77bcbf7b516b552521.gif +20. *@ecosse3*: +21. *Stargazers over time*: https://starchart.cc/CopilotC-Nvim/CopilotChat.nvim.svg Generated by panvimdoc diff --git a/lua/CopilotChat/health.lua b/lua/CopilotChat/health.lua index 5893f812..227d76f9 100644 --- a/lua/CopilotChat/health.lua +++ b/lua/CopilotChat/health.lua @@ -31,6 +31,11 @@ end -- Add health check for python3 and pynvim function M.check() start('CopilotChat.nvim health check') + if vim.g.loaded_python3_provider == 0 then + warn('Python 3 provider is disabled. Please enable it to use CopilotChat.nvim') + return + end + local python_version = run_python_command('--version') if python_version == false then diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index bba15a1e..d0adfb5a 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -14,6 +14,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {} -- - show_help: ('yes' | 'no') default: 'yes'. -- - disable_extra_info: ('yes' | 'no') default: 'yes'. -- - hide_system_prompt: ('yes' | 'no') default: 'yes'. +-- - clear_chat_on_new_prompt: ('yes' | 'no') default: 'no'. -- - proxy: (string?) default: ''. -- - language: (string?) default: ''. -- - temperature: (string?) default: '0.1'. Value between 0.0 and 1.0. @@ -23,6 +24,7 @@ M.setup = function(options) vim.g.copilot_chat_show_help = options and options.show_help or 'yes' 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_clear_chat_on_new_prompt = options and options.clear_chat_on_new_prompt or 'no' vim.g.copilot_chat_proxy = options and options.proxy or '' vim.g.copilot_chat_language = options and options.language or '' vim.g.copilot_chat_temperature = options and options.temperature or '0.1' diff --git a/rplugin/python3/CopilotChat/__init__.py b/rplugin/python3/CopilotChat/__init__.py index 446ecc17..cd83906c 100644 --- a/rplugin/python3/CopilotChat/__init__.py +++ b/rplugin/python3/CopilotChat/__init__.py @@ -1 +1 @@ -from .copilot_plugin import CopilotPlugin as CopilotPlugin +from .copilot_plugin import CopilotPlugin as CopilotPlugin # noqa: F401 diff --git a/rplugin/python3/CopilotChat/copilot.py b/rplugin/python3/CopilotChat/copilot.py index d4945ab7..2723c5dd 100644 --- a/rplugin/python3/CopilotChat/copilot.py +++ b/rplugin/python3/CopilotChat/copilot.py @@ -79,8 +79,7 @@ def poll_auth(self, device_code: str) -> bool: def authenticate(self): if self.github_token is None: raise Exception("No token found") - self.vscode_sessionid = str( - uuid.uuid4()) + str(round(time.time() * 1000)) + self.vscode_sessionid = str(uuid.uuid4()) + str(round(time.time() * 1000)) url = "https://api.github.com/copilot_internal/v2/token" headers = { "authorization": f"token {self.github_token}", @@ -90,6 +89,8 @@ def authenticate(self): } self.token = self.session.get(url, headers=headers).json() + if not self.token.get("token"): + raise Exception(f"Failed to authenticate: {self.token}") def reset(self): self.chat_history = [] @@ -142,14 +143,14 @@ def ask( error_code = response.json().get("error", {}).get("code") if error_code and error_messages.get(response.status_code): - error_messages[ - response.status_code - ] = f"{error_messages[response.status_code]}: {error_code}" + error_messages[response.status_code] = ( + f"{error_messages[response.status_code]}: {error_code}" + ) raise Exception( error_messages.get( - response.status_code, f"Unknown error: { - response.status_code}" + response.status_code, + f"Unknown error: {response.status_code}", ) ) for line in response.iter_lines(): @@ -185,9 +186,8 @@ def _get_embeddings(self, inputs: list[typings.FileExtract]): if i + 18 > len(inputs): data = utilities.generate_embedding_request(inputs[i:]) else: - data = utilities.generate_embedding_request(inputs[i: i + 18]) - response = self.session.post( - url, headers=self._headers(), json=data).json() + data = utilities.generate_embedding_request(inputs[i : i + 18]) + response = self.session.post(url, headers=self._headers(), json=data).json() if "data" not in response: raise Exception(f"Error fetching embeddings: {response}") for embedding in response["data"]: @@ -220,8 +220,7 @@ def main(): copilot = Copilot(token) if copilot.github_token is None: req = copilot.request_auth() - print("Please visit", req["verification_uri"], - "and enter", req["user_code"]) + print("Please visit", req["verification_uri"], "and enter", req["user_code"]) while not copilot.poll_auth(req["device_code"]): time.sleep(req["interval"]) print("Successfully authenticated") diff --git a/rplugin/python3/CopilotChat/copilot_plugin.py b/rplugin/python3/CopilotChat/copilot_plugin.py index f7c0c3a1..d12ada86 100644 --- a/rplugin/python3/CopilotChat/copilot_plugin.py +++ b/rplugin/python3/CopilotChat/copilot_plugin.py @@ -10,8 +10,7 @@ @pynvim.plugin class CopilotPlugin(object): def __init__(self, nvim: pynvim.Nvim): - self.nvim: MyNvim = MyNvim( - nvim, PLUGIN_MAPPING_CMD, PLUGIN_AUTOCMD_CMD) + self.nvim: MyNvim = MyNvim(nvim, PLUGIN_MAPPING_CMD, PLUGIN_AUTOCMD_CMD) self.vsplit_chat_handler = None self.inplace_chat_handler = None @@ -30,7 +29,7 @@ def copilot_agent_buffer_cmd(self, args: list[str]): self.init_vsplit_chat_handler() current_buffer = self.nvim.current.buffer lines = current_buffer[:] - # Get code from the current infocus buffer + # Get code from the current in focus buffer code = "\n".join(lines) if self.vsplit_chat_handler: file_type = self.nvim.current.buffer.options["filetype"] @@ -50,7 +49,6 @@ def copilot_agent_cmd(self, args: list[str]): @pynvim.command("CopilotChatReset") def copilot_agent_reset_cmd(self): if self.vsplit_chat_handler: - self.vsplit_chat_handler.copilot.reset() self.vsplit_chat_handler.reset_buffer() @pynvim.command("CopilotChatVisual", nargs="1", range="") @@ -58,7 +56,7 @@ def copilot_agent_visual_cmd(self, args: list[str], range: list[int]): self.init_vsplit_chat_handler() if self.vsplit_chat_handler: file_type = self.nvim.current.buffer.options["filetype"] - code_lines = self.nvim.current.buffer[range[0] - 1: range[1]] + code_lines = self.nvim.current.buffer[range[0] - 1 : range[1]] code = "\n".join(code_lines) self.vsplit_chat_handler.vsplit() self.vsplit_chat_handler.chat(args[0], file_type, code) @@ -83,8 +81,7 @@ def inplace_cmd(self, args: list[str], range: list[int]): self.init_inplace_chat_handler() if self.inplace_chat_handler: file_type = self.nvim.current.buffer.options["filetype"] - code_lines = self.nvim.current.buffer[range[0] - 1: range[1]] + code_lines = self.nvim.current.buffer[range[0] - 1 : range[1]] code = "\n".join(code_lines) user_buffer = self.nvim.current.buffer - self.inplace_chat_handler.mount( - code, file_type, range, user_buffer) + self.inplace_chat_handler.mount(code, file_type, range, user_buffer) diff --git a/rplugin/python3/CopilotChat/handlers/chat_handler.py b/rplugin/python3/CopilotChat/handlers/chat_handler.py index 3bc8788d..fdd4beed 100644 --- a/rplugin/python3/CopilotChat/handlers/chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/chat_handler.py @@ -44,6 +44,9 @@ def chat( disable_end_separator: bool = False, model: str = "gpt-4", ): + """Disable vim diagnostics on the chat buffer""" + self.nvim.command(":lua vim.diagnostic.disable()") + disable_separators = ( self.nvim.eval("g:copilot_chat_disable_separators") == "yes" ) @@ -330,6 +333,9 @@ def _add_chat_messages( 'require("CopilotChat.utils").log_info(...)', "Copilot answered" ) + """ Enable vim diagnostics on the chat buffer after the chat is complete """ + self.nvim.command(":lua vim.diagnostic.enable()") + def _add_end_separator(self, model: str, disable_separators: bool = False): current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") model_info = f"\n#### Answer provided by Copilot (Model: `{model}`) on {current_datetime}." diff --git a/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py b/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py index 1608c53a..ccce3d3b 100644 --- a/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py +++ b/rplugin/python3/CopilotChat/handlers/vsplit_chat_handler.py @@ -15,6 +15,9 @@ def __init__(self, nvim: MyNvim): }, ) self.language = self.nvim.eval("g:copilot_chat_language") + self.clear_chat_on_new_prompt = ( + self.nvim.eval("g:copilot_chat_clear_chat_on_new_prompt") == "yes" + ) def vsplit(self): self.buffer.option("filetype", "copilot-chat") @@ -37,9 +40,6 @@ 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" @@ -55,9 +55,15 @@ def toggle_vsplit(self): self.buffer.option("filetype", "markdown") def chat(self, prompt: str, filetype: str, code: str = ""): + if self.clear_chat_on_new_prompt: + self.reset_buffer() + self.buffer.option("filetype", "markdown") super().chat(prompt, filetype, code, self.nvim.current.window.handle) + # TODO:Clear the token count on reset def reset_buffer(self): """Reset the chat buffer.""" + if self.copilot: + self.copilot.reset() self.buffer.clear() diff --git a/version.txt b/version.txt index 27f9cd32..9ab8337f 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.8.0 +1.9.1