Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.

Context-aware "use" completions#336

Merged
scohen merged 3 commits into
mainfrom
context-aware-use
Aug 23, 2023
Merged

Context-aware "use" completions#336
scohen merged 3 commits into
mainfrom
context-aware-use

Conversation

@scohen

@scohen scohen commented Aug 16, 2023

Copy link
Copy Markdown
Collaborator

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

scohen commented Aug 16, 2023

Copy link
Copy Markdown
Collaborator Author

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.
@scohen scohen force-pushed the context-aware-use branch from 9fed5c9 to 8760b80 Compare August 16, 2023 00:49
Comment thread apps/remote_control/test/lexical/remote_control/modules_test.exs
Comment thread apps/server/lib/lexical/server/code_intelligence/completion.ex Outdated
@scottming

scottming commented Aug 16, 2023

Copy link
Copy Markdown
Collaborator

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

scohen commented Aug 16, 2023

Copy link
Copy Markdown
Collaborator Author

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
@scohen scohen deleted the context-aware-use branch August 23, 2023 20:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improved use completions

2 participants