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

[BUG] New declaration is not discoverable by IDE #389

Closed
kptlronyttcna opened this issue Jan 2, 2020 · 8 comments
Closed

[BUG] New declaration is not discoverable by IDE #389

kptlronyttcna opened this issue Jan 2, 2020 · 8 comments
Labels
bug Something isn't working question Further information is requested

Comments

@kptlronyttcna
Copy link

kptlronyttcna commented Jan 2, 2020

Describe the bug
New declarations are not discoverable by IDE.

To Reproduce
Steps to reproduce the behavior:
Change HelloWorldPlugin in examples to declare a new function. For example helloWorld2 instead of helloWorld. Then use helloWorld2 in main. The program compiles successfully and works, but the IDE can't find helloWorld2 and shows it in red.

Expected behavior
I'm not sure if I can expect the IDE to recognize that new function. If this is not a bug, is there a way to make the IDE see the transformed AST?

@kptlronyttcna kptlronyttcna added the bug Something isn't working label Jan 2, 2020
@rachelcarmena
Copy link
Member

Hi @kptlronyttcna , thanks for your feedback! Please, could you confirm us that:

fun helloWorld(): Unit = TODO()

was also updated when doing that change?

Thanks in advance!

@rachelcarmena rachelcarmena added the question Further information is requested label Jan 7, 2020
@kptlronyttcna
Copy link
Author

kptlronyttcna commented Jan 9, 2020

I don't know how to check that. But I know that helloWorld2 was indeed defined as the program compiled and ran successfully. This is the code I used:

val Meta.helloWorld: Plugin
  get() =
    "Hello World" {
      meta(
        namedFunction({ name == "helloWorld" }) { c ->
          Transform.replace(
            replacing = c,
            newDeclaration =
            """|fun helloWorld2(): Unit =  <-------------------- CHANGED THIS LINE
               |  println("Hello ΛRROW Meta!")
               |""".function.syntheticScope
          )
        }
      )
    }

@rachelcarmena
Copy link
Member

Great, thanks @kptlronyttcna ! And did you change hello-world/use-plugin/src/main/kotlin/io/arrowkt/example/HelloWorld.kt?

@kptlronyttcna
Copy link
Author

Yes, forgot to mention that.

package io.arrowkt.example

//metadebug

fun helloWorld(): Unit = TODO()

fun main() {
  helloWorld2() <---- Changed this line. It compiles and works but Intellij shows it in red and does not autocomplete
}

@rachelcarmena
Copy link
Member

Thanks @kptlronyttcna ! Please, try to update the helloWorld function as well and reopen in case it doesn't work. Thanks!!

@kptlronyttcna
Copy link
Author

kptlronyttcna commented Jan 9, 2020

So at the end, are you saying that I cannot expect the IDE to recognize new declarations defined with arrow meta? Imagine instead of using Transform.replace, I use some other transform to add helloWorld2 while leaving helloWorld untouched. Can the IDE know about helloWorld2 even though it's not anywhere in the code but will be declared by arrow meta during compilation? This is possible with annotation based code-gen tools (google/dagger for example), I was wondering if it would be possible with arrow meta as well.

@MikeDepies
Copy link

You have to create a counterpart IDE plugin for your compiler plugin. Meta facilitates this as well. So its possible, but this example does not showcase it.

@kptlronyttcna
Copy link
Author

A sample showcasing that feature would be awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants