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

Make the completion of struct more consistent #182

Closed
scottming opened this issue May 25, 2023 · 3 comments
Closed

Make the completion of struct more consistent #182

scottming opened this issue May 25, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@scottming
Copy link
Collaborator

This #181 PR has dramatically improved the struct completions, but we can do even better by making the struct completion more consistent. Currently, we can complete sub-module structs in some places, while in others, we cannot.

image

image

@scottming scottming self-assigned this May 25, 2023
@scottming scottming added the enhancement New feature or request label May 25, 2023
@scottming
Copy link
Collaborator Author

Actually, swapping the order solves this problem https://github.com/lexical-lsp/lexical/compare/main...scottming:lexical:make-struct-completions-more-consistent?expand=1, but I'm not sure if it's an improvement in user experience because sometimes you may want the current module more and other times you may want its sub-module more. In some auto-completion clients, once you have completed a sub-module, its order will be at the forefront, which may bring up other issues.

before

image

after

image

Problem

after you completed the %Document.Edit{}, and type %Do| again

image

@scohen
Copy link
Collaborator

scohen commented May 25, 2023

So two things:
The first thing to focus on is to take control of emitting completions for structs away from elixir_sense, and instead build identical functionality inside of lexical using what we already have. That shouldn't be too hard in my estimation, the tools already exist, it's just putting them to use. The toughest thing will be fuzzy matching, but I think that's not so bad. What I'd do is build an index like this:

  1. Split the modules on ".". Then group them by their prefixes. So, the layout will look like:
[] => [every struct module name]
["Lexical"] => [every struct module name that lexical defines]
["Lexical", "Document"] => [every struct module name under "Lexical.Document"
  1. Then , when you're completing, use Code.Fragment.cursor_context there are, I believe two cases you can get back:
    a. {:struct, {:dot, {:alias, 'Foo.Bar'}}}. Take "Foo.Bar", split it on "." and return all the struct names with that prefix. This is an exact match, as the prefix is complete, and there's no suffix.
    b. {:struct, 'Foo.Bar.Ba'} Split on ".", then search exact on the prefix "Foo.Bar" and do a fuzzy match on "Ba" vs. the module names using String.jaro_distance. Pick some value that gets a pretty good match, and return any module names that are over that value.

I also had a thought about the UX of struct completions this morning that I'd like to try.
The first rule is we only complete structs that are direct descendants of the typed module, so if I type %Lexical. I'd get completions for %Lexical.Document{} and %Lexical.Project{}. However, preceding the struct suggestions, we'd get additional matches that will allow us to explore further. In the case above, I'd see %Lexical.Document... (6 more) and Lexical.Server... (2 more). Selecting those would complete %Lexical.Document.|and %Lexical.Server. at which point, I'd see more of the subtree. To make what I'm saying more clear, imagine the following table is the menu.

Label Insert text
%Lexical.Document... (6 more structs) %Lexical.Document.
%Lexical.Server... (2 more structs) %Lexical.Server.
%Lexical.Document{} (Struct) %Lexical.Document{$1}
%Lexical.Project{} (Struct) %Lexical.Project{$1}

@scohen
Copy link
Collaborator

scohen commented Aug 10, 2023

@scottming I believe this is complete. I'm going to close this issue, re-open it if I'm incorrect.

@scohen scohen closed this as completed Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants