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

Context-aware "use" completions #336

Merged
merged 3 commits into from
Aug 23, 2023
Merged

Context-aware "use" completions #336

merged 3 commits into from
Aug 23, 2023

Conversation

scohen
Copy link
Collaborator

@scohen scohen commented Aug 16, 2023

When using use, we would complete any module, even those without __using__ macros defined.

This PR filters any suggestions inside a use directive to ensure that any suggested modules (or a submodule) contain a using macro of arity 1.

One thing that cropped up is that not all modules are loaded when queried, so I had to use :code.all_available to generate the module list. This wasn't super duper fast, so I had to put a cache in front of it, which is the large part of this PR.

Another oddity is that I couldn't just send anonymous functions as predicates, so I had to come up with a way to implement filtering logic across distribution, so I did a matchspec-like thingy, which was a bit ugly, so I made some syntax to make it look like function captures.

Fixes #330

@scohen scohen requested a review from scottming August 16, 2023 00:41
@scohen
Copy link
Collaborator Author

scohen commented Aug 16, 2023

Note: this is intended to land after we get 0.3 out.

When using `use`, we would complete any module, even those without
`__using__` macros defined.

This PR filters any suggestions inside a `use` directive to ensure
that any suggested modules (or a submodule) contain a __using__ macro
of arity 1.

One thing that cropped up is that not all modules are loaded when
queried, so I had to use `:code.all_available` to generate the module
list. This wasn't super duper fast, so I had to put a cache in front
of it, which is the large part of this PR.

Another oddity is that I couldn't just send anonymous functions as
predicates, so I had to come up with a way to implement filtering
logic across distribution, so I did a matchspec-like thingy, which was
a bit ugly, so I made some syntax to make it look like function captures.
@scottming
Copy link
Collaborator

scottming commented Aug 16, 2023

I tried this branch, works great.

BTW, Perhaps it is unrelated to this PR, but should we let use| to complete use |, removing the existing two use completions?

I mean: use(module) and use(module, opts)

CleanShot 2023-08-16 at 20 24 07@2x

@scohen
Copy link
Collaborator Author

scohen commented Aug 16, 2023

Agree with your screenshot, we should emit a snippet

@scohen scohen changed the title Conext-aware "use" completions Context-aware "use" completions Aug 22, 2023
@scohen scohen merged commit bfa253f into main Aug 23, 2023
6 checks passed
@scohen scohen deleted the context-aware-use branch August 23, 2023 20:30
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

Successfully merging this pull request may close these issues.

Improved use completions
2 participants