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

Expansion of Application.compile_env/3 doesn't work with paths #161

Open
xxdavid opened this issue Jul 15, 2022 · 3 comments
Open

Expansion of Application.compile_env/3 doesn't work with paths #161

xxdavid opened this issue Jul 15, 2022 · 3 comments

Comments

@xxdavid
Copy link

xxdavid commented Jul 15, 2022

First, thank you so much for the amazing ElixirLS and the underlying ElixirSense. ❤️

I really like the feature of inference of application env variables when using modules attributes, which was introduced by #133. The only thing I miss is the support for expressions like Application.compile_env(:my_app, [:key, :foo, :bar]) (see Application.compile_env/3 docs). The PR treats compile_env/3 and get_env/3 the same (and similarly the bang versions) but the functions differ in whether they support paths/list in the second argument (get_env does not). Thus, the inference for expression like the one mentioned does not work.

As compile_env is a macro, it cannot be called with apply. But maybe in case we get compile_env with a path, we can call get_env with the first element of the path and then traverse the returned expression on our own (similarly to how it is done in the compile_env macro itself).

Would a PR be welcomed?

@lukaszsamson
Copy link
Collaborator

Would a PR be welcomed?

Yes

@gugahoa
Copy link
Contributor

gugahoa commented Aug 12, 2022

A quick way to do it is to define a new function, like this one and pattern match on args when it's a non-empty list.
In that case, you can use apply with the first element on the list, and then use get_in(result, rest_of_path)

@lukaszsamson
Copy link
Collaborator

A quick way to do it is to define a new function, like this one and pattern match on args when it's a non-empty list. In that case, you can use apply with the first element on the list, and then use get_in(result, rest_of_path)

This cannot be easily implemented. List comprehension has landed only recently in #168 but the type system of the Binding module is not powerful enough to handle this case. It makes a simplified guess of lists type basing on the first element.

the type of this expression

Application.compile_env(:my_app, [:key, :foo, :bar])

is

{
   :call,
   {:atom, Application},
   :compile_env,
   [atom: :my_app, list: {:atom, :key}]
}

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

No branches or pull requests

3 participants