-
Notifications
You must be signed in to change notification settings - Fork 194
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
Quickfix for importing modules #161
Comments
Can you give some example scenarios when a quickfix suggestion for importing a module would be shown? Although, it might make more sense to provide a quickfix suggestion for aliasing a module. |
Quickfix import, alas and require would definitely be useful. Unfortunately I don't think it's doable without compilation traces (which means elixir >= 1.10). |
@lukaszsamson couldn't we support a quickfix for alias using a similar module list as the one that we used for the workspace symbols provider? Although compiler tracing might make it easier, but I think it will be a while before we want to require that users run their code with Elixir 1.10. Also I think adding a |
Also @hworld a PR would be very welcome that provided similar functionality to the php "use" that you show, although that be implemented by providing a |
@axelson Yep, it might be doable. We'd need to parse compiler warnings/errors, extract the module thet misses requre/alias, do the search and find place to insert code.
@hworld If you would like to take it up then open a PR to SuggestionsProvider in https://github.com/elixir-lsp/elixir_sense |
I've opened a draft elixir-sense PR regarding this. I'm also working on an PR for elixir-ls. One thing that I would like to get some suggestions on is, how to find the line where the |
You could place it before any module attributes, but after any |
Yeah, what am not sure is how to programmatically get the line that's safe to insert for the alias. Because the module attributes could be multi-line, I don't think it would be safe to insert say on the next line of a module attribute always |
What about inserting before what ever comes after a module attribute
… On 9/05/2022, at 4:31 PM, Ajay ***@***.***> wrote:
Yeah, what am not sure is how to programmatically get the line that's safe to insert for the alias. Because the module attributes could be multi-line, I don't think it would be safe to insert say on the next line of a module attribute always
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
|
That would be nice. I just don't know how to figure out the line that comes after a module attribute (considering multiline strings and such). |
Maybe you can use `quote do` inside `iex` to help you look at the AST
```
iex(4)> quote do
...(4)> defmodule Example do
...(4)> alias Bla
...(4)>
...(4)> @moduledoc """
...(4)> woooo
...(4)> """
...(4)>
...(4)> def fun, do: 1
...(4)> end
...(4)> end
{:defmodule, [context: Elixir, import: Kernel],
[
{:__aliases__, [alias: false], [:Example]},
[
do: {:__block__, [],
[
{:alias, [context: Elixir], [{:__aliases__, [alias: false], [:Bla]}]},
{:@, [context: Elixir, import: Kernel],
[{:moduledoc, [context: Elixir], ["woooo\n"]}]},
{:def, [context: Elixir, import: Kernel],
[{:fun, [if_undefined: :apply, context: Elixir], Elixir}, [do: 1]]}
]}
]
]}
iex(5)>
```
… On 10/05/2022, at 2:53 AM, Ajay ***@***.***> wrote:
That would be nice. I just don't know how to figure out the line that comes after a module attribute (considering multiline strings and such).
—
Reply to this email directly, view it on GitHub <#161 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEFME3MKHTRHOKJYX34MXBTVJERFLANCNFSM4LTZLKQQ>.
You are receiving this because you are subscribed to this thread.
|
There’d normally be a `line: integer` keyword arg in the 2nd element of every 3-element tuple.
Inside a module is a __block__ type, which is just a list of statements. Eg `@moduledoc` would be a statement, so just find the statement after that.
Anyway, i have no idea what is exposed to Elixir LS or how it works
|
It would be great to have quickfix suggestions for importing modules.
The text was updated successfully, but these errors were encountered: