From d8bb39b8bc920bb74201a095190cd2d768944b39 Mon Sep 17 00:00:00 2001 From: gptlang Date: Thu, 8 Feb 2024 11:51:21 +0000 Subject: [PATCH] finally fix multi-byte language issues --- .all-contributorsrc | 38 +++++--------------- CHANGELOG.md | 44 +++++++++++------------- rplugin/python3/copilot.py | 7 ++-- rplugin/python3/handlers/chat_handler.py | 6 ++-- 4 files changed, 38 insertions(+), 57 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 59f826dd..034e0948 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1,7 +1,5 @@ { - "files": [ - "README.md" - ], + "files": ["README.md"], "imageSize": 100, "commit": false, "commitType": "docs", @@ -12,74 +10,56 @@ "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"] }, { "login": "PostCyberPunk", "name": "PostCyberPunk", "avatar_url": "https://avatars.githubusercontent.com/u/134976996?v=4", "profile": "https://github.com/PostCyberPunk", - "contributions": [ - "doc" - ] + "contributions": ["doc"] } ], "contributorsPerLine": 7, diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e76e454..df286ceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,34 +2,32 @@ ## 1.0.0 (2024-02-06) - ### ⚠ BREAKING CHANGES -* disable extra info as default -* drop new buffer mode +- disable extra info as default +- drop new buffer mode ### Features -* add a note for help user to continue the chat ([8a80ee7](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8a80ee7d3f9d0dcb65b315255d629c2cd8263dac)) -* add CCExplain command ([640f361](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/640f361a54be51e7c479257c374d4a26d8fcd31d)) -* add CCTests command ([b34a78f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b34a78f05ebe65ca093e4dc4b66de9120a681f4c)) -* add configuration options for wrap and filetype ([b4c6e76](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b4c6e760232ec54d4632edef3869e1a05ec61751)) -* add CopilotChatDebugInfo command ([#51](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/51)) ([89b6276](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/89b6276e995de2e05ea391a9d1045676737c93bd)) -* add CopilotChatToggleLayout ([07988b9](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/07988b95a412756169016e991dabcf190a930c7e)) -* add debug flag ([d0dbd4c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/d0dbd4c6fb9be75ccaa591b050198d40c097f423)) -* add health check ([974f14f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/974f14f0d0978d858cbe0126568f30fd63262cb6)) -* add new keymap to get previous user prompt ([6e7e80f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/6e7e80f118c589a009fa1703a284ad292260e3a0)) -* set filetype to markdown and text wrapping ([9b19d51](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/9b19d51deacdf5c958933e99a2e75ebe4c968a9b)) -* show chat in markdown format ([9c14152](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/9c141523de12e723b1d72d95760f2daddcecd1d9)) -* show date time and additional information on end separator ([#53](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/53)) ([b8d0a9d](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b8d0a9d0e0824ff3b643a2652202be2a51b37dbc)) - +- add a note for help user to continue the chat ([8a80ee7](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8a80ee7d3f9d0dcb65b315255d629c2cd8263dac)) +- add CCExplain command ([640f361](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/640f361a54be51e7c479257c374d4a26d8fcd31d)) +- add CCTests command ([b34a78f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b34a78f05ebe65ca093e4dc4b66de9120a681f4c)) +- add configuration options for wrap and filetype ([b4c6e76](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b4c6e760232ec54d4632edef3869e1a05ec61751)) +- add CopilotChatDebugInfo command ([#51](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/51)) ([89b6276](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/89b6276e995de2e05ea391a9d1045676737c93bd)) +- add CopilotChatToggleLayout ([07988b9](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/07988b95a412756169016e991dabcf190a930c7e)) +- add debug flag ([d0dbd4c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/d0dbd4c6fb9be75ccaa591b050198d40c097f423)) +- add health check ([974f14f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/974f14f0d0978d858cbe0126568f30fd63262cb6)) +- add new keymap to get previous user prompt ([6e7e80f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/6e7e80f118c589a009fa1703a284ad292260e3a0)) +- set filetype to markdown and text wrapping ([9b19d51](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/9b19d51deacdf5c958933e99a2e75ebe4c968a9b)) +- show chat in markdown format ([9c14152](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/9c141523de12e723b1d72d95760f2daddcecd1d9)) +- show date time and additional information on end separator ([#53](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/53)) ([b8d0a9d](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b8d0a9d0e0824ff3b643a2652202be2a51b37dbc)) ### Bug Fixes -* **ci:** generate doc ([6287fd4](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/6287fd452d83d43a739d4c7c7a5524537032fc5d)) -* **ci:** generate vimdoc on main branch ([94fb10c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/94fb10cb65bc32cc0c1d96c93ec2d94c4f5d40eb)) -* **ci:** setup release action ([2f1e046](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/2f1e0466af30c26fdcd2b94d331ea4004d32bb07)) -* **ci:** skip git hook on vimdoc ([94fb10c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/94fb10cb65bc32cc0c1d96c93ec2d94c4f5d40eb)) -* Close spinner if the buffer does not exist ([#11](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/11)) ([0ea238d](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0ea238d7be9c7872dd9932a56d3521531b2297db)) -* handle get remote plugin path on Windows ([0b917f6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0b917f633eaef621d293f344965e9e0545be9a80)) -* remove LiteralString, use Any for fixing issue on Python 3.10 ([b68c352](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b68c3522d03c8ac9a332169c56e725b69a43b07c)), closes [#45](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/45) +- **ci:** generate doc ([6287fd4](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/6287fd452d83d43a739d4c7c7a5524537032fc5d)) +- **ci:** generate vimdoc on main branch ([94fb10c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/94fb10cb65bc32cc0c1d96c93ec2d94c4f5d40eb)) +- **ci:** setup release action ([2f1e046](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/2f1e0466af30c26fdcd2b94d331ea4004d32bb07)) +- **ci:** skip git hook on vimdoc ([94fb10c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/94fb10cb65bc32cc0c1d96c93ec2d94c4f5d40eb)) +- Close spinner if the buffer does not exist ([#11](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/11)) ([0ea238d](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0ea238d7be9c7872dd9932a56d3521531b2297db)) +- handle get remote plugin path on Windows ([0b917f6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0b917f633eaef621d293f344965e9e0545be9a80)) +- remove LiteralString, use Any for fixing issue on Python 3.10 ([b68c352](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b68c3522d03c8ac9a332169c56e725b69a43b07c)), closes [#45](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/45) diff --git a/rplugin/python3/copilot.py b/rplugin/python3/copilot.py index ee471b64..4a86ae26 100644 --- a/rplugin/python3/copilot.py +++ b/rplugin/python3/copilot.py @@ -127,10 +127,11 @@ def ask( ) ) for line in response.iter_lines(): - line = line.decode("utf-8").replace("data: ", "").strip() - if line.startswith("[DONE]"): + line: bytes = line + line = line.replace(b"data: ", b"") + if line.startswith(b"[DONE]"): break - elif line == "": + elif line == b"": continue try: line = json.loads(line) diff --git a/rplugin/python3/handlers/chat_handler.py b/rplugin/python3/handlers/chat_handler.py index e410d8ce..166af537 100644 --- a/rplugin/python3/handlers/chat_handler.py +++ b/rplugin/python3/handlers/chat_handler.py @@ -216,6 +216,7 @@ def _add_chat_messages( self.nvim.out_write("Successfully authenticated with Copilot\n") self.copilot.authenticate() + last_line_col = 0 for token in self.copilot.ask( system_prompt, prompt, code, language=cast(str, file_type), model=model ): @@ -224,8 +225,6 @@ def _add_chat_messages( ) buffer_lines = cast(list[str], self.buffer.lines()) last_line_row = len(buffer_lines) - 1 - last_line_col = len(buffer_lines[-1]) - self.nvim.api.buf_set_text( self.buffer.number, last_line_row, @@ -234,6 +233,9 @@ def _add_chat_messages( last_line_col, token.split("\n"), ) + last_line_col += len(token.encode("utf-8")) + if "\n" in token: + last_line_col = 0 def _add_end_separator(self, model: str, disable_separators: bool = False): current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")