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

[RFC]: add fuzzy auto-completion in REPL #1845

Open
3 tasks done
Snehil-Shah opened this issue Mar 12, 2024 · 10 comments · May be fixed by #1855
Open
3 tasks done

[RFC]: add fuzzy auto-completion in REPL #1845

Snehil-Shah opened this issue Mar 12, 2024 · 10 comments · May be fixed by #1855
Assignees
Labels
Accepted RFC feature request which has been accepted. difficulty: 3 Likely to be challenging but manageable. Enhancement Issue or pull request for enhancing existing functionality. JavaScript Issue involves or relates to JavaScript. priority: Normal Normal priority concern or feature request. REPL Issue or pull request specific to the project REPL. RFC Request for comments. Feature requests and proposed changes.

Comments

@Snehil-Shah
Copy link
Contributor

Description

This RFC proposes adding fuzzy auto-completion extending the current strict auto-completion. This would allow us to forgive things like spelling mistakes and suggest more relevant completions.

Related Issues

Related issues stdlib-js/google-summer-of-code#1

Questions

I played around a bit trying to write a fuzzy matching algorithm and using existing ones.
Right now we are lexicographically sorting the completion results. should we do the same with fuzzy results mixed in? or should aim to sort results by 'relevancy'?

Other

No.

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.
@Snehil-Shah Snehil-Shah linked a pull request Mar 12, 2024 that will close this issue
1 task
@kgryte kgryte added RFC Request for comments. Feature requests and proposed changes. REPL Issue or pull request specific to the project REPL. labels Mar 15, 2024
@kgryte
Copy link
Member

kgryte commented Mar 15, 2024

@Snehil-Shah Thanks for opening this. I think if we are to add support for fuzzy auto-completion, we'd want to rank/list according to relevancy, similar to how fuzzy search might work in a search engine. Lexicographic makes sense currently, as completions are exact prefix matches and we don't have additional criteria for sorting otherwise.

Similar to a search engine displaying results, we probably want a means for visually highlighting what is matching (e.g., if I type ys, then we could mark the fuzzy match in bold yes).

@kgryte kgryte added Accepted RFC feature request which has been accepted. Enhancement Issue or pull request for enhancing existing functionality. difficulty: 3 Likely to be challenging but manageable. priority: Normal Normal priority concern or feature request. JavaScript Issue involves or relates to JavaScript. labels Mar 15, 2024
@kgryte
Copy link
Member

kgryte commented Mar 26, 2024

Recently came across https://github.com/JunoLab/FuzzyCompletions.jl/blob/master/src/FuzzyCompletions.jl which uses Levenshtein distance and a fudge factor for scoring suggestions.

@kgryte
Copy link
Member

kgryte commented Mar 27, 2024

...and also a fuzzy completer implementation in Prompt Toolkit: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/fuzzy_completer.py

@Snehil-Shah
Copy link
Contributor Author

Snehil-Shah commented Mar 27, 2024

@kgryte I don't think levenshtein distance is a good algorithm for code-completion as mentioned in OP of #1855 as a difference in length of the input and completion would also affect the score, which means it can score an exact prefix match worse than a not-so-exact match with a shorter length.

The prompt toolkit's algorithm is good and simple, but is not forgiving to spelling mistakes, as it requires each letter of the input string to exist in the completion string. I think we can modify this a bit using my own algorithm (#1855) to account for spelling mistakes as well

@kgryte
Copy link
Member

kgryte commented Mar 27, 2024

@Snehil-Shah Yes, that's fair. Although you could probably combine Levenshtein with other approaches, such as favoring exact prefix matches.

@Snehil-Shah
Copy link
Contributor Author

@Snehil-Shah Yes, that's fair. Although you could probably combine Levenshtein with other approaches, such as favoring exact prefix matches.

I think prompt toolkit's algorithm would be better than the levenshtein's. I edited the above reply in case you didn't read that..

@kgryte
Copy link
Member

kgryte commented Mar 27, 2024

@Snehil-Shah That's fair. At this point, you are the expert!

@kgryte
Copy link
Member

kgryte commented Mar 28, 2024

@kgryte
Copy link
Member

kgryte commented Apr 5, 2024

Another fuzzy match algorithm: https://github.com/junegunn/fzf/blob/master/src/algo/algo.go

@kgryte
Copy link
Member

kgryte commented Apr 5, 2024

Another fuzzy match algorithm: https://github.com/helix-editor/nucleo/tree/master/matcher/src

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted RFC feature request which has been accepted. difficulty: 3 Likely to be challenging but manageable. Enhancement Issue or pull request for enhancing existing functionality. JavaScript Issue involves or relates to JavaScript. priority: Normal Normal priority concern or feature request. REPL Issue or pull request specific to the project REPL. RFC Request for comments. Feature requests and proposed changes.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants