Restore quick doc for it parameter and this of extension function

This commit is contained in:
Nikolay Krasko
2017-04-01 03:10:14 +03:00
parent eb4e6e6c1a
commit b4ebd6074c
6 changed files with 73 additions and 1 deletions
@@ -24,6 +24,7 @@ import com.intellij.lang.java.JavaDocumentationProvider
import com.intellij.openapi.diagnostic.Logger
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiManager
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
import org.jetbrains.kotlin.config.LanguageVersionSettings
@@ -151,6 +152,23 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
}
private fun getText(element: PsiElement, originalElement: PsiElement?, quickNavigation: Boolean): String? {
if (element is PsiWhiteSpace) {
val itElement = findElementWithText(originalElement, "it")
val itReference = itElement?.getParentOfType<KtNameReferenceExpression>(false)
if (itReference != null) {
return getText(itReference, originalElement, quickNavigation)
}
}
if (element is KtTypeReference) {
val declaration = element.parent
if (declaration is KtCallableDeclaration && declaration.receiverTypeReference == element) {
val thisElement = findElementWithText(originalElement, "this")
if (thisElement != null) {
return getText(declaration, originalElement, quickNavigation)
}
}
}
if (element is KtClass && element.isEnum()) {
// When caret on special enum function (e.g SomeEnum.values<caret>())
@@ -301,5 +319,14 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
return null
}
private fun findElementWithText(element: PsiElement?, text: String): PsiElement? {
return when {
element == null -> null
element.text == text -> element
element.prevLeaf()?.text == text -> element.prevLeaf()
else -> null
}
}
}
}
@@ -0,0 +1,7 @@
fun foo() {
listOf(1).forEach {
println(it<caret>)
}
}
//INFO: <pre><b>value-parameter</b> it: Int</pre>
+1 -1
View File
@@ -1,6 +1,6 @@
fun foo() {
listOf(1).forEach {
println(it<caret>)
println(i<caret>t)
}
}
+10
View File
@@ -0,0 +1,10 @@
interface Foo
fun foo(a: Any) {}
fun Foo.bar() {
foo(th<caret>is)
}
//INFO: <pre><b>public</b> <b>fun</b> <a href="psi_element://Foo">Foo</a>.bar(): Unit <i>defined in</i> root package</pre>
+10
View File
@@ -0,0 +1,10 @@
interface Foo
fun foo(a: Any) {}
fun Foo.bar() {
foo(this<caret>)
}
//INFO: <pre><b>public</b> <b>fun</b> <a href="psi_element://Foo">Foo</a>.bar(): Unit <i>defined in</i> root package</pre>
@@ -48,6 +48,12 @@ public class QuickDocProviderTestGenerated extends AbstractQuickDocProviderTest
doTest(fileName);
}
@TestMetadata("AtImplicitLambdaParametEnd.kt")
public void testAtImplicitLambdaParametEnd() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/AtImplicitLambdaParametEnd.kt");
doTest(fileName);
}
@TestMetadata("AtImplicitLambdaParameter.kt")
public void testAtImplicitLambdaParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/AtImplicitLambdaParameter.kt");
@@ -90,6 +96,18 @@ public class QuickDocProviderTestGenerated extends AbstractQuickDocProviderTest
doTest(fileName);
}
@TestMetadata("ExtensionReceiver.kt")
public void testExtensionReceiver() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/ExtensionReceiver.kt");
doTest(fileName);
}
@TestMetadata("ExtensionReceiverEnd.kt")
public void testExtensionReceiverEnd() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/ExtensionReceiverEnd.kt");
doTest(fileName);
}
@TestMetadata("IndentedCodeBlock.kt")
public void testIndentedCodeBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/IndentedCodeBlock.kt");