Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOL: Python 3.10 and disable extra info #22

Merged
merged 5 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 8 additions & 26 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"files": [
"README.md"
],
"files": ["README.md"],
"imageSize": 100,
"commit": false,
"commitType": "docs",
Expand All @@ -12,65 +10,49 @@
"name": "gptlang",
"avatar_url": "https://avatars.githubusercontent.com/u/121417512?v=4",
"profile": "https://github.com/gptlang",
"contributions": [
"code",
"doc"
]
"contributions": ["code", "doc"]
},
{
"login": "jellydn",
"name": "Dung Duc Huynh (Kaka)",
"avatar_url": "https://avatars.githubusercontent.com/u/870029?v=4",
"profile": "https://productsway.com/",
"contributions": [
"code",
"doc"
]
"contributions": ["code", "doc"]
},
{
"login": "qoobes",
"name": "Ahmed Haracic",
"avatar_url": "https://avatars.githubusercontent.com/u/58834655?v=4",
"profile": "https://qoobes.dev",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "ziontee113",
"name": "Trí Thiện Nguyễn",
"avatar_url": "https://avatars.githubusercontent.com/u/102876811?v=4",
"profile": "https://youtube.com/@ziontee113",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "Cassius0924",
"name": "He Zhizhou",
"avatar_url": "https://avatars.githubusercontent.com/u/62874592?v=4",
"profile": "https://github.com/Cassius0924",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "rguruprakash",
"name": "Guruprakash Rajakkannu",
"avatar_url": "https://avatars.githubusercontent.com/u/9963717?v=4",
"profile": "https://www.linkedin.com/in/guruprakashrajakkannu/",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "kristofka",
"name": "kristofka",
"avatar_url": "https://avatars.githubusercontent.com/u/140354?v=4",
"profile": "https://github.com/kristofka",
"contributions": [
"code"
]
"contributions": ["code"]
}
],
"contributorsPerLine": 7,
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: Release
on:
push:
branches:
- release
pull_request:
branches:
- main
- release

jobs:
release:
Expand Down
45 changes: 19 additions & 26 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,49 @@

## [1.2.0](https://github.com/jellydn/CopilotChat.nvim/compare/v1.1.0...v1.2.0) (2024-02-04)


### Features

* show date time and additional information on end separator ([#53](https://github.com/jellydn/CopilotChat.nvim/issues/53)) ([b8d0a9d](https://github.com/jellydn/CopilotChat.nvim/commit/b8d0a9d0e0824ff3b643a2652202be2a51b37dbc))

- show date time and additional information on end separator ([#53](https://github.com/jellydn/CopilotChat.nvim/issues/53)) ([b8d0a9d](https://github.com/jellydn/CopilotChat.nvim/commit/b8d0a9d0e0824ff3b643a2652202be2a51b37dbc))

### Bug Fixes

* handle get remote plugin path on Windows ([0b917f6](https://github.com/jellydn/CopilotChat.nvim/commit/0b917f633eaef621d293f344965e9e0545be9a80))
- handle get remote plugin path on Windows ([0b917f6](https://github.com/jellydn/CopilotChat.nvim/commit/0b917f633eaef621d293f344965e9e0545be9a80))

## [1.1.0](https://github.com/jellydn/CopilotChat.nvim/compare/v1.0.0...v1.1.0) (2024-02-04)


### Features

* add CopilotChatDebugInfo command ([#51](https://github.com/jellydn/CopilotChat.nvim/issues/51)) ([89b6276](https://github.com/jellydn/CopilotChat.nvim/commit/89b6276e995de2e05ea391a9d1045676737c93bd))
- add CopilotChatDebugInfo command ([#51](https://github.com/jellydn/CopilotChat.nvim/issues/51)) ([89b6276](https://github.com/jellydn/CopilotChat.nvim/commit/89b6276e995de2e05ea391a9d1045676737c93bd))

## 1.0.0 (2024-02-03)


### ⚠ BREAKING CHANGES

* drop new buffer mode
- drop new buffer mode

### Features

* add a note for help user to continue the chat ([8a80ee7](https://github.com/jellydn/CopilotChat.nvim/commit/8a80ee7d3f9d0dcb65b315255d629c2cd8263dac))
* add CCExplain command ([640f361](https://github.com/jellydn/CopilotChat.nvim/commit/640f361a54be51e7c479257c374d4a26d8fcd31d))
* add CCTests command ([b34a78f](https://github.com/jellydn/CopilotChat.nvim/commit/b34a78f05ebe65ca093e4dc4b66de9120a681f4c))
* add configuration options for wrap and filetype ([b4c6e76](https://github.com/jellydn/CopilotChat.nvim/commit/b4c6e760232ec54d4632edef3869e1a05ec61751))
* add CopilotChatToggleLayout ([07988b9](https://github.com/jellydn/CopilotChat.nvim/commit/07988b95a412756169016e991dabcf190a930c7e))
* add debug flag ([d0dbd4c](https://github.com/jellydn/CopilotChat.nvim/commit/d0dbd4c6fb9be75ccaa591b050198d40c097f423))
* add health check ([974f14f](https://github.com/jellydn/CopilotChat.nvim/commit/974f14f0d0978d858cbe0126568f30fd63262cb6))
* add new keymap to get previous user prompt ([6e7e80f](https://github.com/jellydn/CopilotChat.nvim/commit/6e7e80f118c589a009fa1703a284ad292260e3a0))
* set filetype to markdown and text wrapping ([9b19d51](https://github.com/jellydn/CopilotChat.nvim/commit/9b19d51deacdf5c958933e99a2e75ebe4c968a9b))
* show chat in markdown format ([9c14152](https://github.com/jellydn/CopilotChat.nvim/commit/9c141523de12e723b1d72d95760f2daddcecd1d9))

- add a note for help user to continue the chat ([8a80ee7](https://github.com/jellydn/CopilotChat.nvim/commit/8a80ee7d3f9d0dcb65b315255d629c2cd8263dac))
- add CCExplain command ([640f361](https://github.com/jellydn/CopilotChat.nvim/commit/640f361a54be51e7c479257c374d4a26d8fcd31d))
- add CCTests command ([b34a78f](https://github.com/jellydn/CopilotChat.nvim/commit/b34a78f05ebe65ca093e4dc4b66de9120a681f4c))
- add configuration options for wrap and filetype ([b4c6e76](https://github.com/jellydn/CopilotChat.nvim/commit/b4c6e760232ec54d4632edef3869e1a05ec61751))
- add CopilotChatToggleLayout ([07988b9](https://github.com/jellydn/CopilotChat.nvim/commit/07988b95a412756169016e991dabcf190a930c7e))
- add debug flag ([d0dbd4c](https://github.com/jellydn/CopilotChat.nvim/commit/d0dbd4c6fb9be75ccaa591b050198d40c097f423))
- add health check ([974f14f](https://github.com/jellydn/CopilotChat.nvim/commit/974f14f0d0978d858cbe0126568f30fd63262cb6))
- add new keymap to get previous user prompt ([6e7e80f](https://github.com/jellydn/CopilotChat.nvim/commit/6e7e80f118c589a009fa1703a284ad292260e3a0))
- set filetype to markdown and text wrapping ([9b19d51](https://github.com/jellydn/CopilotChat.nvim/commit/9b19d51deacdf5c958933e99a2e75ebe4c968a9b))
- show chat in markdown format ([9c14152](https://github.com/jellydn/CopilotChat.nvim/commit/9c141523de12e723b1d72d95760f2daddcecd1d9))

### Bug Fixes

* **ci:** generate doc ([6287fd4](https://github.com/jellydn/CopilotChat.nvim/commit/6287fd452d83d43a739d4c7c7a5524537032fc5d))
* Close spinner if the buffer does not exist ([#11](https://github.com/jellydn/CopilotChat.nvim/issues/11)) ([0ea238d](https://github.com/jellydn/CopilotChat.nvim/commit/0ea238d7be9c7872dd9932a56d3521531b2297db))
* remove LiteralString, use Any for fixing issue on Python 3.10 ([b68c352](https://github.com/jellydn/CopilotChat.nvim/commit/b68c3522d03c8ac9a332169c56e725b69a43b07c)), closes [#45](https://github.com/jellydn/CopilotChat.nvim/issues/45)

- **ci:** generate doc ([6287fd4](https://github.com/jellydn/CopilotChat.nvim/commit/6287fd452d83d43a739d4c7c7a5524537032fc5d))
- Close spinner if the buffer does not exist ([#11](https://github.com/jellydn/CopilotChat.nvim/issues/11)) ([0ea238d](https://github.com/jellydn/CopilotChat.nvim/commit/0ea238d7be9c7872dd9932a56d3521531b2297db))
- remove LiteralString, use Any for fixing issue on Python 3.10 ([b68c352](https://github.com/jellydn/CopilotChat.nvim/commit/b68c3522d03c8ac9a332169c56e725b69a43b07c)), closes [#45](https://github.com/jellydn/CopilotChat.nvim/issues/45)

### Reverts

* change back to CopilotChat command ([e304f79](https://github.com/jellydn/CopilotChat.nvim/commit/e304f792a5fbba412c2a5a1f717ec7e2ab12e5b0))

- change back to CopilotChat command ([e304f79](https://github.com/jellydn/CopilotChat.nvim/commit/e304f792a5fbba412c2a5a1f717ec7e2ab12e5b0))

### Code Refactoring

* drop new buffer mode ([0a30b7c](https://github.com/jellydn/CopilotChat.nvim/commit/0a30b7cfbd8b52bf8a9e4cd96dcade4995e6eb3a))
- drop new buffer mode ([0a30b7c](https://github.com/jellydn/CopilotChat.nvim/commit/0a30b7cfbd8b52bf8a9e4cd96dcade4995e6eb3a))
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Copilot Chat for Neovim

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

> [!NOTE]
Expand All @@ -23,7 +25,6 @@ It will prompt you with instructions on your first start. If you already have `C
return {
{
"jellydn/CopilotChat.nvim",
dependencies = { "zbirenbaum/copilot.lua" }, -- Or { "github/copilot.vim" }
opts = {
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
Expand Down
5 changes: 2 additions & 3 deletions doc/CopilotChat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ LAZY.NVIM ~
return {
{
"jellydn/CopilotChat.nvim",
dependencies = { "zbirenbaum/copilot.lua" }, -- Or { "github/copilot.vim" }
opts = {
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
Expand Down Expand Up @@ -309,14 +308,14 @@ CONTRIBUTORS ✨ *CopilotChat-copilot-chat-for-neovim-contributors-✨*
Thanks goes to these wonderful people (emoji key
<https://allcontributors.org/docs/en/emoji-key>):

gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻This project follows the all-contributors
gptlang💻 📖Dung Duc Huynh (Kaka)💻 📖Ahmed Haracic💻Trí Thiện Nguyễn💻He Zhizhou💻Guruprakash Rajakkannu💻kristofka💻This project follows the all-contributors
<https://github.com/all-contributors/all-contributors> specification.
Contributions of any kind welcome!

==============================================================================
2. Links *CopilotChat-links*

1. *All Contributors*: https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square
1. *All Contributors*: https://img.shields.io/badge/all_contributors-7-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
Expand Down
1 change: 1 addition & 0 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ _COPILOT_CHAT_GLOBAL_CONFIG = {}
-- - debug: (boolean?) default: false.
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 false
local debug = options and options.debug or false
_COPILOT_CHAT_GLOBAL_CONFIG.debug = debug

Expand Down
50 changes: 40 additions & 10 deletions rplugin/python3/handlers/chat_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from datetime import datetime
from typing import Optional, cast

Expand All @@ -18,7 +19,7 @@ def is_module_installed(name):
class ChatHandler:
def __init__(self, nvim: MyNvim, buffer: MyBuffer):
self.nvim: MyNvim = nvim
self.copilot = None
self.copilot: Copilot = None
self.buffer: MyBuffer = buffer

# public
Expand All @@ -34,9 +35,9 @@ def chat(
disable_end_separator: bool = False,
model: str = "gpt-4",
):
no_annoyance = self.nvim.eval("g:copilot_chat_disable_separators") == "yes"
if system_prompt is None:
system_prompt = self._construct_system_prompt(prompt)

# Start the spinner
self.nvim.exec_lua('require("CopilotChat.spinner").show()')

Expand All @@ -45,15 +46,17 @@ def chat(
)

if not disable_start_separator:
self._add_start_separator(system_prompt, prompt, code, filetype, winnr)
self._add_start_separator(
system_prompt, prompt, code, filetype, winnr, no_annoyance
)

self._add_chat_messages(system_prompt, prompt, code, filetype, model)

# Stop the spinner
self.nvim.exec_lua('require("CopilotChat.spinner").hide()')

if not disable_end_separator:
self._add_end_separator(model)
self._add_end_separator(model, no_annoyance)

# private

Expand All @@ -74,14 +77,15 @@ def _add_start_separator(
code: str,
file_type: str,
winnr: int,
no_annoyance: bool = False,
):
if is_module_installed("tiktoken"):
if is_module_installed("tiktoken") and not no_annoyance:
self._add_start_separator_with_token_count(
system_prompt, prompt, code, file_type, winnr
)
else:
self._add_regular_start_separator(
system_prompt, prompt, code, file_type, winnr
system_prompt, prompt, code, file_type, winnr, no_annoyance
)

def _add_regular_start_separator(
Expand All @@ -91,15 +95,17 @@ def _add_regular_start_separator(
code: str,
file_type: str,
winnr: int,
no_annoyance: bool = False,
):
if code:
if code and not no_annoyance:
code = f"\n \nCODE:\n```{file_type}\n{code}\n```"

last_row_before = len(self.buffer.lines())
system_prompt_height = len(system_prompt.split("\n"))
code_height = len(code.split("\n"))

start_separator = f"""### User
start_separator = (
f"""### User

SYSTEM PROMPT:
```
Expand All @@ -110,8 +116,13 @@ def _add_regular_start_separator(
### Copilot

"""
if not no_annoyance
else f"### User\n{prompt}\n\n### Copilot\n\n"
)
self.buffer.append(start_separator.split("\n"))

if no_annoyance:
return
self._add_folds(code, code_height, last_row_before, system_prompt_height, winnr)

def _add_start_separator_with_token_count(
Expand Down Expand Up @@ -186,6 +197,21 @@ def _add_chat_messages(
):
if self.copilot is None:
self.copilot = Copilot()
if self.copilot.github_token is None:
req = self.copilot.request_auth()
self.nvim.out_write(
f"Please visit {req['verification_uri']} and enter the code {req['user_code']}\n"
)
current_time = time.time()
wait_until = current_time + req["expires_in"]
while self.copilot.github_token is None:
self.copilot.poll_auth(req["device_code"])
time.sleep(req["interval"])
if time.time() > wait_until:
self.nvim.out_write("Timed out waiting for authentication\n")
return
self.nvim.out_write("Successfully authenticated with Copilot\n")
self.copilot.authenticate()

for token in self.copilot.ask(
system_prompt, prompt, code, language=cast(str, file_type), model=model
Expand All @@ -206,13 +232,17 @@ def _add_chat_messages(
token.split("\n"),
)

def _add_end_separator(self, model: str):
def _add_end_separator(self, model: str, no_annoyance: 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}."
additional_instructions = (
"\n> For additional queries, please use the `CopilotChat` command."
)
disclaimer = "\n> Please be aware that the AI's output may not always be accurate. Always cross-verify the output.\n---\n"
disclaimer = "\n> Please be aware that the AI's output may not always be accurate. Always cross-verify the output."

end_message = model_info + additional_instructions + disclaimer

if no_annoyance:
end_message = "\n" + current_datetime + "\n---\n"

self.buffer.append(end_message.split("\n"))
6 changes: 3 additions & 3 deletions rplugin/python3/mypynvim/ui_components/popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from copy import deepcopy
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union, Unpack
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union

if TYPE_CHECKING:
from mypynvim.core.nvim import MyNvim
Expand All @@ -14,7 +14,7 @@
from mypynvim.core.window import MyWindow

from .calculator import Calculator
from .types import PaddingKeys, PopUpArgs, PopUpConfiguration, Relative
from .types import PaddingKeys, PopUpConfiguration, Relative


@dataclass
Expand All @@ -33,7 +33,7 @@ def __init__(
padding: PaddingKeys = {},
enter: bool = False,
opts={},
**kwargs: Unpack[PopUpArgs],
**kwargs,
):
self.nvim: MyNvim = nvim
self.calculator: Calculator = Calculator(self.nvim)
Expand Down
Loading