Skip to content

Commit 20a4234

Browse files
committed
fix: multi-byte languages by manually tracking last_line_col for buf_set_text
1 parent a734732 commit 20a4234

4 files changed

Lines changed: 38 additions & 57 deletions

File tree

.all-contributorsrc

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"files": [
3-
"README.md"
4-
],
2+
"files": ["README.md"],
53
"imageSize": 100,
64
"commit": false,
75
"commitType": "docs",
@@ -12,74 +10,56 @@
1210
"name": "gptlang",
1311
"avatar_url": "https://avatars.githubusercontent.com/u/121417512?v=4",
1412
"profile": "https://github.com/gptlang",
15-
"contributions": [
16-
"code",
17-
"doc"
18-
]
13+
"contributions": ["code", "doc"]
1914
},
2015
{
2116
"login": "jellydn",
2217
"name": "Dung Duc Huynh (Kaka)",
2318
"avatar_url": "https://avatars.githubusercontent.com/u/870029?v=4",
2419
"profile": "https://productsway.com/",
25-
"contributions": [
26-
"code",
27-
"doc"
28-
]
20+
"contributions": ["code", "doc"]
2921
},
3022
{
3123
"login": "qoobes",
3224
"name": "Ahmed Haracic",
3325
"avatar_url": "https://avatars.githubusercontent.com/u/58834655?v=4",
3426
"profile": "https://qoobes.dev",
35-
"contributions": [
36-
"code"
37-
]
27+
"contributions": ["code"]
3828
},
3929
{
4030
"login": "ziontee113",
4131
"name": "Trí Thiện Nguyễn",
4232
"avatar_url": "https://avatars.githubusercontent.com/u/102876811?v=4",
4333
"profile": "https://youtube.com/@ziontee113",
44-
"contributions": [
45-
"code"
46-
]
34+
"contributions": ["code"]
4735
},
4836
{
4937
"login": "Cassius0924",
5038
"name": "He Zhizhou",
5139
"avatar_url": "https://avatars.githubusercontent.com/u/62874592?v=4",
5240
"profile": "https://github.com/Cassius0924",
53-
"contributions": [
54-
"code"
55-
]
41+
"contributions": ["code"]
5642
},
5743
{
5844
"login": "rguruprakash",
5945
"name": "Guruprakash Rajakkannu",
6046
"avatar_url": "https://avatars.githubusercontent.com/u/9963717?v=4",
6147
"profile": "https://www.linkedin.com/in/guruprakashrajakkannu/",
62-
"contributions": [
63-
"code"
64-
]
48+
"contributions": ["code"]
6549
},
6650
{
6751
"login": "kristofka",
6852
"name": "kristofka",
6953
"avatar_url": "https://avatars.githubusercontent.com/u/140354?v=4",
7054
"profile": "https://github.com/kristofka",
71-
"contributions": [
72-
"code"
73-
]
55+
"contributions": ["code"]
7456
},
7557
{
7658
"login": "PostCyberPunk",
7759
"name": "PostCyberPunk",
7860
"avatar_url": "https://avatars.githubusercontent.com/u/134976996?v=4",
7961
"profile": "https://github.com/PostCyberPunk",
80-
"contributions": [
81-
"doc"
82-
]
62+
"contributions": ["doc"]
8363
}
8464
],
8565
"contributorsPerLine": 7,

CHANGELOG.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,32 @@
22

33
## 1.0.0 (2024-02-06)
44

5-
65
### ⚠ BREAKING CHANGES
76

8-
* disable extra info as default
9-
* drop new buffer mode
7+
- disable extra info as default
8+
- drop new buffer mode
109

1110
### Features
1211

13-
* add a note for help user to continue the chat ([8a80ee7](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8a80ee7d3f9d0dcb65b315255d629c2cd8263dac))
14-
* add CCExplain command ([640f361](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/640f361a54be51e7c479257c374d4a26d8fcd31d))
15-
* add CCTests command ([b34a78f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b34a78f05ebe65ca093e4dc4b66de9120a681f4c))
16-
* add configuration options for wrap and filetype ([b4c6e76](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b4c6e760232ec54d4632edef3869e1a05ec61751))
17-
* add CopilotChatDebugInfo command ([#51](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/51)) ([89b6276](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/89b6276e995de2e05ea391a9d1045676737c93bd))
18-
* add CopilotChatToggleLayout ([07988b9](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/07988b95a412756169016e991dabcf190a930c7e))
19-
* add debug flag ([d0dbd4c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/d0dbd4c6fb9be75ccaa591b050198d40c097f423))
20-
* add health check ([974f14f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/974f14f0d0978d858cbe0126568f30fd63262cb6))
21-
* add new keymap to get previous user prompt ([6e7e80f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/6e7e80f118c589a009fa1703a284ad292260e3a0))
22-
* set filetype to markdown and text wrapping ([9b19d51](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/9b19d51deacdf5c958933e99a2e75ebe4c968a9b))
23-
* show chat in markdown format ([9c14152](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/9c141523de12e723b1d72d95760f2daddcecd1d9))
24-
* 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))
25-
12+
- add a note for help user to continue the chat ([8a80ee7](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/8a80ee7d3f9d0dcb65b315255d629c2cd8263dac))
13+
- add CCExplain command ([640f361](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/640f361a54be51e7c479257c374d4a26d8fcd31d))
14+
- add CCTests command ([b34a78f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b34a78f05ebe65ca093e4dc4b66de9120a681f4c))
15+
- add configuration options for wrap and filetype ([b4c6e76](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/b4c6e760232ec54d4632edef3869e1a05ec61751))
16+
- add CopilotChatDebugInfo command ([#51](https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/51)) ([89b6276](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/89b6276e995de2e05ea391a9d1045676737c93bd))
17+
- add CopilotChatToggleLayout ([07988b9](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/07988b95a412756169016e991dabcf190a930c7e))
18+
- add debug flag ([d0dbd4c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/d0dbd4c6fb9be75ccaa591b050198d40c097f423))
19+
- add health check ([974f14f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/974f14f0d0978d858cbe0126568f30fd63262cb6))
20+
- add new keymap to get previous user prompt ([6e7e80f](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/6e7e80f118c589a009fa1703a284ad292260e3a0))
21+
- set filetype to markdown and text wrapping ([9b19d51](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/9b19d51deacdf5c958933e99a2e75ebe4c968a9b))
22+
- show chat in markdown format ([9c14152](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/9c141523de12e723b1d72d95760f2daddcecd1d9))
23+
- 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))
2624

2725
### Bug Fixes
2826

29-
* **ci:** generate doc ([6287fd4](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/6287fd452d83d43a739d4c7c7a5524537032fc5d))
30-
* **ci:** generate vimdoc on main branch ([94fb10c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/94fb10cb65bc32cc0c1d96c93ec2d94c4f5d40eb))
31-
* **ci:** setup release action ([2f1e046](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/2f1e0466af30c26fdcd2b94d331ea4004d32bb07))
32-
* **ci:** skip git hook on vimdoc ([94fb10c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/94fb10cb65bc32cc0c1d96c93ec2d94c4f5d40eb))
33-
* 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))
34-
* handle get remote plugin path on Windows ([0b917f6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0b917f633eaef621d293f344965e9e0545be9a80))
35-
* 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)
27+
- **ci:** generate doc ([6287fd4](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/6287fd452d83d43a739d4c7c7a5524537032fc5d))
28+
- **ci:** generate vimdoc on main branch ([94fb10c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/94fb10cb65bc32cc0c1d96c93ec2d94c4f5d40eb))
29+
- **ci:** setup release action ([2f1e046](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/2f1e0466af30c26fdcd2b94d331ea4004d32bb07))
30+
- **ci:** skip git hook on vimdoc ([94fb10c](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/94fb10cb65bc32cc0c1d96c93ec2d94c4f5d40eb))
31+
- 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))
32+
- handle get remote plugin path on Windows ([0b917f6](https://github.com/CopilotC-Nvim/CopilotChat.nvim/commit/0b917f633eaef621d293f344965e9e0545be9a80))
33+
- 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)

rplugin/python3/copilot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ def ask(
127127
)
128128
)
129129
for line in response.iter_lines():
130-
line = line.decode("utf-8").replace("data: ", "").strip()
131-
if line.startswith("[DONE]"):
130+
line: bytes = line
131+
line = line.replace(b"data: ", b"")
132+
if line.startswith(b"[DONE]"):
132133
break
133-
elif line == "":
134+
elif line == b"":
134135
continue
135136
try:
136137
line = json.loads(line)

rplugin/python3/handlers/chat_handler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def _add_chat_messages(
216216
self.nvim.out_write("Successfully authenticated with Copilot\n")
217217
self.copilot.authenticate()
218218

219+
last_line_col = 0
219220
for token in self.copilot.ask(
220221
system_prompt, prompt, code, language=cast(str, file_type), model=model
221222
):
@@ -224,8 +225,6 @@ def _add_chat_messages(
224225
)
225226
buffer_lines = cast(list[str], self.buffer.lines())
226227
last_line_row = len(buffer_lines) - 1
227-
last_line_col = len(buffer_lines[-1])
228-
229228
self.nvim.api.buf_set_text(
230229
self.buffer.number,
231230
last_line_row,
@@ -234,6 +233,9 @@ def _add_chat_messages(
234233
last_line_col,
235234
token.split("\n"),
236235
)
236+
last_line_col += len(token.encode("utf-8"))
237+
if "\n" in token:
238+
last_line_col = 0
237239

238240
def _add_end_separator(self, model: str, disable_separators: bool = False):
239241
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

0 commit comments

Comments
 (0)