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

Purity plugin IDE integration #28

Open
raulraja opened this issue Oct 1, 2019 · 4 comments
Open

Purity plugin IDE integration #28

raulraja opened this issue Oct 1, 2019 · 4 comments
Assignees

Comments

@raulraja
Copy link
Member

raulraja commented Oct 1, 2019

The original version of the purity plugin checks when a function returns Unit or contains calls in its body to other functions that it return Unit.

This plugin should show visually in the editor this is happening and provide intentions to refactor the function to become suspend. This is the IDE piece of the purity plugin.

@jansorg
Copy link
Contributor

jansorg commented Oct 10, 2019

@raulraja Could you provide a pointer to the existing code of the purity plugin? I'm not seeing it in arrow-meta-protoype

@raulraja
Copy link
Member Author

@i-walker was the last one fiddling with it

@i-walker
Copy link
Member

i-walker commented Oct 10, 2019

@jansorg I started the plugin as an Inspection, but I don't had time, yet to figure out how to register an unregistered Extension to the IDE successfully.

In the ide dsl you would write something like this:

val IdeMetaPlugin.dummyIdePlugin: Plugin
  get() = "PurityIdePlugin" {
    meta(
      addLocalInspectionToolToIdeRegistry(),
      addApplicableInspection(
        defaultFixText = "Impure",
        inspectionHighlightType = { ProblemHighlightType.ERROR },
        kClass = KtNamedFunction::class.java,
        highlightingRange = { f -> f.textRange },
        inspectionText = { f -> "Function $f should be suspended" },
        applyTo = { f, project, editor ->
          f.addModifier(KtTokens.SUSPEND_KEYWORD)
        },
        isApplicable = { f: KtNamedFunction ->
          f.nameIdentifier != null && !f.hasModifier(KtTokens.SUSPEND_KEYWORD) &&
            f.resolveToDescriptorIfAny()?.run {
              !isSuspend && (ReturnsCheck.ReturnsUnit.check(this) || ExtendedReturnsCheck.ReturnsNothing.check(this)
                || ExtendedReturnsCheck.ReturnsNullableNothing.check(this))
            } == true
        }
      )
    )
  }
fun IdeMetaPlugin.addLocalInspectionToolToIdeRegistry(): ExtensionPhase =
    registerExtensionPoint(
      EP_NAME,
      LocalInspectionTool::class.java
    )

This is a simplified version from our legacy attempt here:
https://github.com/arrow-kt/arrow-meta-prototype/blob/8afa971fb60f629dee02ad5ea698269f7772e2a8/compiler-plugin/src/main/java/arrow/plugin/MetaClassBuilderInterceptorExtension.kt

The problem is that even though I can debug that addLocalInspectionToolToIdeRegistry, works. The inspection is not there every time I run the Ide instance.

@rachelcarmena rachelcarmena transferred this issue from arrow-kt/arrow Oct 27, 2019
@i-walker
Copy link
Member

We should keep that open because we're still working on traversing and resolving the type of each Call of a Function.
This code would not be inspected by the current purity plugin:

object Impure {
    fun sideEffect()=
        println("BOOM!")

    suspend fun other(): Unit {
        println("other")
    }

    val x = { println() }

    fun another2(): String {
        1; println("test");
        {
            { println() }
        }()
        return "another"
    }
}

@i-walker i-walker reopened this Nov 11, 2019
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