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

Detect override def run: ZIO[_, _, ZIO[_, _, _]] #443

Open
jamesward opened this issue May 15, 2023 · 6 comments
Open

Detect override def run: ZIO[_, _, ZIO[_, _, _]] #443

jamesward opened this issue May 15, 2023 · 6 comments

Comments

@jamesward
Copy link

jamesward commented May 15, 2023

Would it be possible to detect a run that has a ZIO which has a ZIO in the A ? I sometimes do this with ZIO Direct:

object Main extends ZIOAppDefault:
  override def run =
    defer {
      Console.printLine("hello, world")
    }

Which doesn't work because I need to actually run my printLine in the defer. Or maybe ZIO Direct should produce a warning? Not sure the right place to catch me from doing something silly.

@myazinn
Copy link
Collaborator

myazinn commented May 15, 2023

Actually, we already have an inspection that detects discarded effect (due to Unit discarding). We can expand it to trigger when ZIO effect is treated as Any, but I'm not sure if it'll cause false positives or not 🤔

@hmemcpy
Copy link
Collaborator

hmemcpy commented May 15, 2023

Thanks for the suggestion! I admit I haven't yet got the chance to play with zio-direct, but I know that the library ships with some IntelliJ support to help with the type inference for its macros.

Maybe @deusaquilus could elaborate on whether this is possible to detect via the defer macro. Having said this, I think it would be wise to include zio-direct support in the plugin directly.

@hmemcpy
Copy link
Collaborator

hmemcpy commented May 15, 2023

Ah right, I now remember why we didn't put it in the plugin - whitebox macros don't have extension points from IntelliJ plugins - they are installed and instantiated via a different mechanism. I'll have to explore whether it's possible to hack the "library extension provider"

Alex was kind enough to document it. https://zio.dev/zio-direct/intellij-support/

@hmemcpy
Copy link
Collaborator

hmemcpy commented May 15, 2023

(mostly a note-to-self) Lastly, I forgot about this, but @unkarjedy was able to load the extension with reflection (promising to make the method to do this public ;)). So there might be a way to hack support for this in the plugin. I'll look into it soon.

@unkarjedy
Copy link

@hmemcpy
I've just pushed a change to make it public in idea232.x, but only as @TestOnly.
You might also look at org.jetbrains.plugins.scala.components.libextensions.LibraryExtensionsManager#addExtension

@deusaquilus
Copy link

@jamesward I think ZIO-Direct should produce a warning in this situation. I'm pretty sure it does so in Metals. Need to look into what I'm doing in the ZIO-Direct IntelliJ plugin.

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

5 participants