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

Completion replaces existing word incorrectly if they end on the same letter #5676

Closed
aral opened this issue Jan 25, 2023 · 6 comments
Closed

Comments

@aral
Copy link
Contributor

aral commented Jan 25, 2023

Token following where a completion should be inserted is erroneously replaced with the completion.

Screenshot from 2023-01-25 13-57-45

I press i and start typing.

Screenshot from 2023-01-25 13-57-50

So far, so good…

Screenshot from 2023-01-25 13-57-53

I select the first completion. And it replaces “events” instead of being inserted before it.

Screenshot from 2023-01-25 13-57-57

helix 22.12 (08c35ab6) on Fedora Silverblue 37 in Black Box terminal under GNOME.

Possibly related to #2580

@archseer
Copy link
Member

I think this is just a missing config here:

lsp::CompletionTextEdit::InsertAndReplace(item) => {
// TODO: support using "insert" instead of "replace" via user config
lsp::TextEdit::new(item.replace, item.new_text.clone())
}

@archseer
Copy link
Member

@pascalkuthe you mentioned this on another issue somewhere ^

@pascalkuthe
Copy link
Member

Sorry forgot about this @archseer .

This is indeed intended behavior. LSPs provide two options for handeling autocompletions: replace or insert.
Helix is currently hardcoded to always use the replace edit. Many editors default to insert instead (vscode and nvim.cmp do atleast). I think adding a config option here would be an easy PR. all we need to do is to add a condition to use item.insert instead of item.replace in the snippet @archseer linked.

@aral
Copy link
Contributor Author

aral commented Jan 27, 2023

@pascalkuthe @archseer When would this ever be the desired behaviour? It results in corrupted syntax. I’d highly recommend making insert the default behaviour. I don’t remember once ending up with corrupted syntax while using VSCode (and I’m so glad I don’t have to use VSCode anymore for a multitude of other reasons).

Also, note that the replacement isn’t being carried out perfectly either (the selection goes up to but does not include the final “t”). That might be a separate bug, thought.

@pascalkuthe
Copy link
Member

Simple let's say you have two functions foo_bar and foo_rab.
Right now your code is test.foo_rab() but you want to change it to test.foo_bar so you can just start the autcompletion at foo_ and select foo_bar and the _rab is automatically removed. The replace behavior is valid and has it's place. There is good reason that both options are included in the LSP spec.

Offering an option definitely makes sense. I also prefer the insert behavior (seems more consistent for insert mode, I usually delete in normal mode instead of insert mode) but both have their merit.

@pascalkuthe
Copy link
Member

Duplicate of #4380

@pascalkuthe pascalkuthe marked this as a duplicate of #4380 Jan 28, 2023
@pascalkuthe pascalkuthe closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2023
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

No branches or pull requests

3 participants