helix icon indicating copy to clipboard operation
helix copied to clipboard

completion fix

Open cossonleo opened this issue 2 years ago • 13 comments

Completion will not work correct When We type chars between sended to completion request and recived the result. These chars will not be replaced by completion items.

cossonleo avatar Mar 15 '22 22:03 cossonleo

How to reproduce the issue? Oh, I just realized I have this issue.

pickfire avatar Mar 22 '22 00:03 pickfire

I don't quite understand the issue, we track the initial trigger_offset when completion is triggered: https://github.com/helix-editor/helix/blob/7eb013c6fb33df40b2fae31c9d08f7da275cd963/helix-term/src/commands.rs#L3490

Then we use that trigger offset when needed: https://github.com/helix-editor/helix/blob/7eb013c6fb33df40b2fae31c9d08f7da275cd963/helix-term/src/ui/completion.rs#L111-L117

We also remove any extra text: https://github.com/helix-editor/helix/blob/7eb013c6fb33df40b2fae31c9d08f7da275cd963/helix-term/src/ui/completion.rs#L133-L134

archseer avatar Mar 22 '22 02:03 archseer

We might need to call .savepoint sooner, inside fn completion rather than here https://github.com/helix-editor/helix/blob/0062af6a19d96e0a4c3f94e3e44c179230e005b9/helix-term/src/ui/completion.rs#L152-L153

archseer avatar Mar 22 '22 02:03 archseer

We might need to call .savepoint sooner, inside fn completion rather than here

https://github.com/helix-editor/helix/blob/0062af6a19d96e0a4c3f94e3e44c179230e005b9/helix-term/src/ui/completion.rs#L152-L153

Yes In the current implementation, there are still redundant characters. It occurs when the completion request is sent and wait response. At this time, we type char again.

cossonleo avatar Mar 31 '22 02:03 cossonleo

How to reproduce the issue?

Although it is a small regular event that affects normal editing

gopls 0.7.0 helix 0.6 .config/helix/config.toml

  idle-timeout = 40

helix_completion

cossonleo avatar Mar 31 '22 03:03 cossonleo

I've been seeing the same completion problems with ElixirLS and ErlangLS. I'm not sure if it's the slowness of the LS or my low idle-timeout config but when I type and get completion as I type, C-n/C-ping to one of the candidates does sometimes end up with a suffix like the screenshot. I hadn't really locked down what triggered it but it seems like if I deliberately pause before pressing C-n/C-p it doesn't happen (on master).

I just took this branch for a spin though and it seems to solve my completion problems.

the-mikedavis avatar Apr 19 '22 23:04 the-mikedavis

~I ran with this change yesterday and I noticed that the completion menu seems to pop up less. I imagine that what's happening is that I trigger the idle-timeout between keystrokes and the keystrokes following the auto-complete request cancel that request. (I haven't really looked at the change yet though so take that description with a grain of salt)~

edit: this is my own doing - going into verbose mode and tailing the logs shows that it's the server that's being slow.

the-mikedavis avatar Apr 21 '22 16:04 the-mikedavis

Hey @cossonleo I want to finally get this merged but I'm trying to understand the fix. Does it immediately set a save point, then when completion data arrives it filters that based on new input?

archseer avatar Aug 04 '22 04:08 archseer

Hey @cossonleo I want to finally get this merged but I'm trying to understand the fix. Does it immediately set a save point, then when completion data arrives it filters that based on new input?

Yes, Method Completion::new() will call recompute_filter(editor) to filter the data.

cossonleo avatar Aug 04 '22 14:08 cossonleo

@archseer The PR is ready for merging. Do you have any other suggestions.

cossonleo avatar Aug 26 '22 16:08 cossonleo

Sorry, I'll look at this PR this week!

archseer avatar Sep 02 '22 02:09 archseer

Looks like my comments didn't get posted last time: I think moving doc.savepoint() before the callback is the only change needed to fix the completion. Why is savepoint now storing version?

archseer avatar Sep 10 '22 12:09 archseer

Looks like my comments didn't get posted last time: I think moving doc.savepoint() before the callback is the only change needed to fix the completion. Why is savepoint now storing version?

We should discard the completion's result responsed after trigger the next completion. So we need to store the version to determine whether to discard.

cossonleo avatar Sep 10 '22 14:09 cossonleo

On my system, this patch causes completion to fail completely. Logs show

2022-10-06T17:19:39.010 helix_lsp::transport [ERROR] err: <- StreamClosed
2022-10-06T17:19:39.012 helix_lsp::transport [ERROR] err: <- StreamClosed

This is gopls 0.9.5 with go 1.19.2.

EDIT: with hx -vvv, completion works, but I still get the problems described in #4131.

sbromberger avatar Oct 06 '22 21:10 sbromberger

I think this is the code that handles it in VSCode: https://github.com/microsoft/vscode/blob/ba9399b83d048e780646896d5f81bcc08d759c6b/src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel.ts#L539-L548

kirawi avatar Dec 27 '22 21:12 kirawi

I don't have enough context to be confident in my conflict resolutions, but I merged this into master at https://github.com/rcorre/helix/commit/51f8b6732610b23011f38b2863afa26809b89bf0 and it seems to fix #4851 for me.

rcorre avatar Feb 09 '23 11:02 rcorre

Superseded by #6173

pascalkuthe avatar Mar 03 '23 15:03 pascalkuthe