Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

IDEA-15406 - Cannot navigate to kotlin-dsl sources from .kt files when using kotlin-dsl Gradle plugin in IntelliJ IDEA #514

Open
stephan-gh opened this issue Sep 28, 2017 · 11 comments

Comments

@stephan-gh
Copy link

stephan-gh commented Sep 28, 2017

I'm using the kotlin-dsl Gradle plugin to create a new Gradle plugin written in Kotlin together with IntelliJ IDEA. When using the kotlin-dsl extension methods in build.gradle.kts, navigation to the source works correctly. However, it does not work when using the kotlin-dsl Gradle plugin. Instead, IntelliJ IDEA navigates to the decompiled stub source file.

Using the test class below, the two methods marked with a comment do not have sources attached:

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.task
import org.gradle.kotlin.dsl.withType

class TestPlugin : Plugin<Project> {
    override fun apply(project: Project) {
        project.run {
            // Cannot navigate to source of "withType"
            plugins.withType<JavaPlugin> {
                
            }
            
            // Cannot navigate to source of "task"
            task<Jar>("customJar") {
                
            }
        }
    }
}

I can provide a full test project if necessary. However, it's simple to reproduce by applying the kotlin-dsl Gradle plugin in a project and then using the test class above.

Expected Behavior

Navigation to sources should work in IntelliJ IDEA for kotlin-dsl extension methods when using the kotlin-dsl Gradle plugin to create a Gradle plugin.

Current Behavior

IntelliJ IDEA navigates to a decompiled stub source file.

@eskatos
Copy link
Member

eskatos commented Oct 5, 2017

Thanks for the report @Minecrell!
I confirmed this locally.
Navigating to Gradle Kotlin DSL source works.
Navigating to Gradle API (gradleApi()) source doesn't.
We'll look into this.

@stephan-gh
Copy link
Author

@eskatos Weird, it's the exact opposite for me(?). I was able to navigate to Gradle API source (e.g. the Project or Task interface) but not to the source of Gradle Kotlin DSL (e.g. additional extension it adds).

@eskatos
Copy link
Member

eskatos commented Oct 5, 2017

@Minecrell 🤔 which version of IntelliJ and the Kotlin Plugin for it are you using?

@stephan-gh
Copy link
Author

stephan-gh commented Oct 5, 2017

@eskatos IntelliJ IDEA 2017.2.5 with Gradle 4.2 (and the version of kotlin-dsl it bundles). I used "Use local Gradle distribution" if that makes any difference.

I just tried with "Use default Gradle wrapper" and the latest snapshot distribution used on the develop branch and the same happens.

For reference, the project I'm testing with is available at https://github.com/Minecrell/plugin-yml. In PlatformPlugin.kt I'm able to navigate to the source of Project or Project.getExtensions(), but not to the task<T> or plugins.withType<T> extension method from kotlin-dsl.

@bamboo bamboo added this to the 1.0.0 milestone Jan 19, 2018
@eskatos eskatos modified the milestones: 1.0.0, 0.18.x May 15, 2018
@eskatos eskatos modified the milestones: 0.18.x, 0.19.x May 24, 2018
@eskatos
Copy link
Member

eskatos commented Jul 16, 2018

I can't reproduce using Gradle 4.9 on IntelliJ IDEA 2018.1.6 nor on 2018.2.RC.

Here's a cast using the former:

kotlin-dsl-plugin-navigation-to-sources

Also validated in some buildSrc.

@eskatos
Copy link
Member

eskatos commented Jul 16, 2018

Note I'm using a -bin distribution when testing.

After invalidating all IntelliJ caches, restarting, I can reproduce the issues:

  • navigation to Gradle API sources from .kt files fails
  • navigation to Gradle Kotlin DSL API sources from .kt files fails

kotlin-dsl-plugin-navigation-to-sources-after-invalidating-caches

For the Gradle Kotlin DSL API, sources are embedded in the jars.
It seems IntelliJ is not picking up the sources from them.

For the Gradle API, it's another story and is currently enabled by using a -all distribution.

Interestingly as soon as you open a .gradle.kts file, then IntelliJ resolves the sources for the script editor and then they are available when navigating from .kt files. Somehow, IntelliJ shares the sources it recognizes from the script source-path with the Kotlin files from source sets.
The gif in the previous comment was done after doing just that, that's why the navigation to sources was working. Confusing, but it provides a work around.

@eskatos
Copy link
Member

eskatos commented Jul 17, 2018

IntelliJ issue for recognizing sources embedded in jars:
https://youtrack.jetbrains.com/issue/IDEA-15406

@eskatos eskatos changed the title Cannot navigate to kotlin-dsl sources when using kotlin-dsl Gradle plugin in IntelliJ IDEA Cannot navigate to kotlin-dsl sources from .kt files when using kotlin-dsl Gradle plugin in IntelliJ IDEA Jul 17, 2018
@eskatos
Copy link
Member

eskatos commented Jul 17, 2018

And the gradle/gradle issue for IDE plugins to provide Gradle sources:
gradle/gradle#1003

@eskatos eskatos self-assigned this Jul 19, 2018
@eskatos
Copy link
Member

eskatos commented Jul 19, 2018

We can't work around https://youtrack.jetbrains.com/issue/IDEA-15406 by publishing -sources jar as it would require adding a remote repository.

@eskatos
Copy link
Member

eskatos commented Jul 19, 2018

To sum up:

Navigating to Gradle API sources from .kt files when the kotlin-dsl plugin is applied

Navigating to Kotlin DSL sources from .kt files when the kotlin-dsl plugin is applied

@eskatos eskatos changed the title Cannot navigate to kotlin-dsl sources from .kt files when using kotlin-dsl Gradle plugin in IntelliJ IDEA IDEA-15406 - Cannot navigate to kotlin-dsl sources from .kt files when using kotlin-dsl Gradle plugin in IntelliJ IDEA Jul 20, 2018
@eskatos
Copy link
Member

eskatos commented Jul 20, 2018

Turning this issue into a vendor issue for IDEA-15406.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants