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

Code fragment APIs #12690

Closed
josevalim opened this issue Jun 21, 2023 · 2 comments
Closed

Code fragment APIs #12690

josevalim opened this issue Jun 21, 2023 · 2 comments

Comments

@josevalim
Copy link
Member

josevalim commented Jun 21, 2023

For example, I would like something that would tell me

|> Foo.

"Yep, this is definitely in a pipe, and also this is the beginning of a call to a function in the Foo module"

Right now, I don't get that ability with anything I see in Code.Fragment.

for example:

Code.Fragment.container_cursor_to_quoted("|> Foo.")
{:ok, {:__cursor__, [line: 1], []}

and

Code.Fragment.cursor_context("|> Foo.")
{:dot, {:alias, 'Foo'}, []}

More helpful, but has no idea that I'm in a pipeline. We would like to know if we're in a pipeline because when we complete the arguments to functions, we remove the first one. We have similar needs for function captures as well, as we offer completions for &something/1 and &something(args).

Originally posted by @scohen in #12645 (comment)

@josevalim
Copy link
Member Author

@scohen I moved it here to avoid side-tracking the other issue (I will delete the comments from there).

@josevalim
Copy link
Member Author

Operator support to container_quoted was only added on v1.15 as per your request. But remember you need to give it full code:

iex(1)> Code.Fragment.container_cursor_to_quoted("Bar |> Foo.")
{:ok,
 {:|>, [line: 1],
  [{:__aliases__, [line: 1], [:Bar]}, {:__cursor__, [line: 1], []}]}}

For aliases, require, and import, we also discussed this in another issue:

#12566 (comment)

IEx handles both the alias and the struct cases, so its source code can be checked as an example.

There was also a discussion here: #12673

I will close this but feel free to drop additional comments (and I will reopen if we find something that needs to be supported).

@josevalim josevalim changed the title Code context Code fragment APIs Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant