Skip to content

Conversation

@CeleritasCelery
Copy link
Contributor

Currently copilot.el assumes that the completion text will go all the way to the end of the line, but this is not always the case. When this happens it will lead to incorrectly deleting the text that used to be there. This will lead to unbalanced parens or quotes.

This PR fixes this by using the API's :end property to determine where the end of the completed text should go.

Example:
text given to copilot

print("hello |")

copilot will return the text world.

With the current implementation this will be the result if the user accepts the completion:

print("hello world

After this PR, the result would be as expected:

print("hello world")

This will resolve issues like #77 #62 #117

CeleritasCelery and others added 2 commits April 22, 2023 14:23
Currently copilot.el assumes that the completion text will go all the way to the
end of the line. But this is not always the case. When this happens it
will lead to incorrectly deleting the text that used to be there. This will lead
to unbalanced parens or quotes.

The fix is to use the API's :end property to determine where the end of the
completed text should go.

Example:
text given to copilot
```python
print("hello |")
```
copilot will return the text `world`.

With the current implementation this will be the result if the user accepts the completion:
```python
print("hello world
```

After this PR, the result would be as expected:
```python
print("hello world")
```
@zerolfx
Copy link
Collaborator

zerolfx commented Apr 23, 2023

Thanks for your work. You have solved a long-standing problem.

I made some minor changes by refactoring the code and changing the meaning of the end property from length to absolute position. Additionally, I removed the calls to goto-line, as it is only intended for interactive use.

@zerolfx zerolfx merged commit 798bf58 into copilot-emacs:main Apr 23, 2023
@CeleritasCelery
Copy link
Contributor Author

Thanks. I initially tried to use end as an absolute position like you did, but it doesn't work when you have automatic pair insertion (via smartparens, electric-pair-mode, cleverparens, etc). The issue is that if I insert ( it will also insert ). The end position should move forward 2 places, but we only advance it one with cl-incf. I don't know of a reliable way to detect the auto-pair case, so that is why I defined end to be an offset from the end of the line.

@zerolfx
Copy link
Collaborator

zerolfx commented Apr 23, 2023

Oh no, I haven't tested that case. I will revert my changes if there is a bug.

@zerolfx
Copy link
Collaborator

zerolfx commented Apr 23, 2023

Fixed in 7986e38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants