Fix for KT-13400, KT-13389 Resolving FQN in quick doc
Problem related to not complete fix in KT-10398
This commit is contained in:
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea
|
||||
import com.intellij.lang.documentation.AbstractDocumentationProvider
|
||||
import com.intellij.lang.java.JavaDocumentationProvider
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiManager
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
|
||||
@@ -57,7 +56,7 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
||||
val bindingContext = navElement.analyze(BodyResolveMode.PARTIAL)
|
||||
val contextDescriptor = bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, navElement] ?: return null
|
||||
val descriptors = resolveKDocLink(bindingContext, navElement.getResolutionFacade(),
|
||||
contextDescriptor, null, StringUtil.split(link, ","))
|
||||
contextDescriptor, null, link.split('.'))
|
||||
val target = descriptors.firstOrNull() ?: return null
|
||||
return DescriptorToSourceUtilsIde.getAnyDeclaration(psiManager.project, target)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package a.b.c
|
||||
|
||||
class D {
|
||||
|
||||
}
|
||||
|
||||
fun <caret>foo() {
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package doc
|
||||
|
||||
fun topLevelFun() {}
|
||||
|
||||
/**
|
||||
* @see doc.topLevelFun
|
||||
*/
|
||||
class Doc<caret>Referrer
|
||||
@@ -0,0 +1,8 @@
|
||||
package doc
|
||||
|
||||
val topLevelProperty = "A"
|
||||
|
||||
/**
|
||||
* @see doc.topLevelProperty
|
||||
*/
|
||||
class Doc<caret>Referrer
|
||||
@@ -24,7 +24,9 @@ import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFunction
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.junit.Assert
|
||||
|
||||
@@ -58,9 +60,27 @@ class QuickDocNavigationTest() : KotlinLightCodeInsightFixtureTestCase() {
|
||||
Assert.assertEquals("InputStream", (secondaryTarget as PsiClass).name)
|
||||
}
|
||||
|
||||
fun testQualifiedName() {
|
||||
val target = resolveDocLink("a.b.c.D")
|
||||
UsefulTestCase.assertInstanceOf(target, KtClass::class.java)
|
||||
Assert.assertEquals("D", (target as KtClass).name)
|
||||
}
|
||||
|
||||
fun testTopLevelFun() {
|
||||
val target = resolveDocLink("doc.topLevelFun")
|
||||
UsefulTestCase.assertInstanceOf(target, KtFunction::class.java)
|
||||
Assert.assertEquals("topLevelFun", (target as KtFunction).name)
|
||||
}
|
||||
|
||||
fun testTopLevelProperty() {
|
||||
val target = resolveDocLink("doc.topLevelProperty")
|
||||
UsefulTestCase.assertInstanceOf(target, KtProperty::class.java)
|
||||
Assert.assertEquals("topLevelProperty", (target as KtProperty).name)
|
||||
}
|
||||
|
||||
private fun resolveDocLink(linkText: String): PsiElement? {
|
||||
myFixture.configureByFile(getTestName(true) + ".kt")
|
||||
val source = myFixture.elementAtCaret.getParentOfType<KtFunction>(false)
|
||||
val source = myFixture.elementAtCaret.getParentOfType<KtDeclaration>(false)
|
||||
return KotlinQuickDocumentationProvider().getDocumentationElementForLink(
|
||||
myFixture.psiManager, linkText, source)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user