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

Fixes backslash unicode autocompletion #2504

Closed
wants to merge 4 commits into from

Conversation

VarLad
Copy link
Contributor

@VarLad VarLad commented May 19, 2022

Fixes #1807

@VarLad VarLad marked this pull request as draft May 19, 2022 12:44
@VarLad
Copy link
Contributor Author

VarLad commented May 19, 2022

Currently, the purpose of this PR is to catch all the issues which occur because of this fix, and try solving it here before merging

@@ -3587,7 +3587,7 @@ pub fn completion(cx: &mut Context) {
use helix_core::chars;
let mut iter = text.chars_at(cursor);
iter.reverse();
let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
let offset = iter.take_while(|ch| chars::char_is_whitespace(*ch)).count();
Copy link
Member

@archseer archseer May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the reverse of what you want: you want to scan backwards while char is not whitespace (stop on first whitespace)

Copy link
Contributor Author

@VarLad VarLad May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archseer doing !chars::char_is_whitespace seems to break everything
Another solution proposed @ChrHorn chars::char_is_word(*ch) || *ch == '\\' which solves this particular problem.
I guess we can go along with that for now?
It would be nice if we could define this logic for the Julia LSP specifically so as to not break other langauges

@ChrHorn
Copy link
Contributor

ChrHorn commented May 19, 2022

As mentioned, using only whitespace as a separator will break ., ::, etc.

An alternative proposal

I am not really sure that we actually need the filter by prefix logic. Just send all the results and let the UI handle the filerting/sorting. Would then be able to match expressions that don't start with the same prefix. That's how it's done in VSCode.

VSCode Example:
image

Sorting is currently alphabetical in Helix and would have to be improved.
image

@VarLad
Copy link
Contributor Author

VarLad commented May 19, 2022

@archseer For now I've used the same workaround as @ChrHorn
It would be nice if we were able to do this in a "more general manner" (this one seems like a hack for Julia)

@VarLad VarLad marked this pull request as ready for review May 19, 2022 22:05
@the-mikedavis the-mikedavis added the S-waiting-on-review Status: Awaiting review from a maintainer. label May 19, 2022
@archseer
Copy link
Member

The more general way would be to use the trigger_character list from the LSP if available:

https://github.com/helix-editor/helix/blob/8493b5fca68097efd258ff0ffbcb6863e0c362c9/helix-term/src/commands.rs#L2676-L2682=

So you keep scanning back until you hit one of these characters (if the list is empty, just use is_word like before)

@the-mikedavis the-mikedavis removed the S-waiting-on-review Status: Awaiting review from a maintainer. label May 20, 2022
@VarLad VarLad marked this pull request as draft May 20, 2022 09:08
@VarLad VarLad marked this pull request as ready for review May 23, 2022 19:12
@VarLad
Copy link
Contributor Author

VarLad commented May 23, 2022

@archseer Does this make sense? 😅

@VarLad VarLad marked this pull request as draft May 23, 2022 19:28
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are a bit more idiomatic

helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
@VarLad
Copy link
Contributor Author

VarLad commented May 23, 2022

It still doesn't trigger on . (for example, Base.)
That worked before (without this PR), so something is wrong with the logic here.
On the other hand, \ does trigger now

@VarLad
Copy link
Contributor Author

VarLad commented May 25, 2022

Here's a summary of discussion on Matrix:

I talked to the folks who implemented the LS in Julia, and according to them, cases like :: and \\ are "same as completions after any whitespace". I went back to try implementing stopping at whitespaces.
I found the fact that let offset = iter.take_while(|ch| chars::char_is_whitespace(*ch)).count(); gives a problematic (although mostly working) result, while let offset = iter.take_while(|ch| !chars::char_is_whitespace(*ch)).count(); as weird.
Since the logic says that we should stop at the first whitespace, which didn't work, while its opposite seems to work.
An explanation by @ChrHorn is,

The good results with char_is_whitespace, are because empty prefix. The prefix is only used to prefilter the results. So empty prefix means not filtering by prefix. You send the whole completion responds to the UI which then does another round of filtering, that's why it works. The sorting is currently broken, that's why the results are a bit unordered.

Awaiting further input from @archseer on how to approach this

@maxtremblay
Copy link

Hello, I just want to say that I would really like this feature to be merged. Anything I can do to help?

@ChrHorn
Copy link
Contributor

ChrHorn commented Aug 28, 2022

Best way to fix this issue is getting #3215 merged. Then we could get rid off the prefix filter which would also fix the backslash issue.

@kirawi kirawi added A-helix-term Area: Helix term improvements S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. labels Sep 13, 2022
@VarLad VarLad closed this Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to autocomplete Unicode characters with Julia language server
6 participants