From a783a4f3b1cb9277d45654c249a73ce14b9bad0c Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Thu, 24 Oct 2024 16:53:15 +0200 Subject: [PATCH] ctrl+click for inlay type hints --- .../runConfigurations/aptos/FunctionCall.kt | 3 +- .../toolwindow/ProjectsTreeMouseListener.kt | 1 + .../move/ide/hints/type/MvTypeHintsFactory.kt | 43 +++++-------------- .../org/move/lang/core/psi/ext/PsiElement.kt | 2 - 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/main/kotlin/org/move/cli/runConfigurations/aptos/FunctionCall.kt b/src/main/kotlin/org/move/cli/runConfigurations/aptos/FunctionCall.kt index 6a1a97683..f82566312 100644 --- a/src/main/kotlin/org/move/cli/runConfigurations/aptos/FunctionCall.kt +++ b/src/main/kotlin/org/move/cli/runConfigurations/aptos/FunctionCall.kt @@ -1,6 +1,7 @@ package org.move.cli.runConfigurations.aptos import com.intellij.psi.SmartPsiElementPointer +import com.intellij.psi.createSmartPointer import org.move.lang.core.psi.MvFunction import org.move.lang.core.psi.parametersAsBindings import org.move.lang.core.psi.ext.* @@ -59,7 +60,7 @@ data class FunctionCall( for (parameterName in parameterNames) { nullParams[parameterName] = null } - return FunctionCall(function.asSmartPointer(), nullTypeParams, nullParams) + return FunctionCall(function.createSmartPointer(), nullTypeParams, nullParams) } } } diff --git a/src/main/kotlin/org/move/cli/toolwindow/ProjectsTreeMouseListener.kt b/src/main/kotlin/org/move/cli/toolwindow/ProjectsTreeMouseListener.kt index 38444a52d..c5def6756 100644 --- a/src/main/kotlin/org/move/cli/toolwindow/ProjectsTreeMouseListener.kt +++ b/src/main/kotlin/org/move/cli/toolwindow/ProjectsTreeMouseListener.kt @@ -12,6 +12,7 @@ import com.intellij.openapi.diagnostic.LogLevel.WARNING import com.intellij.openapi.diagnostic.logger import com.intellij.psi.NavigatablePsiElement import com.intellij.psi.PsiElement +import com.intellij.util.PsiNavigateUtil import org.move.cli.toolwindow.MoveProjectsTreeStructure.MoveSimpleNode import org.move.ide.notifications.logOrShowBalloon import java.awt.event.MouseAdapter diff --git a/src/main/kotlin/org/move/ide/hints/type/MvTypeHintsFactory.kt b/src/main/kotlin/org/move/ide/hints/type/MvTypeHintsFactory.kt index c48d99868..e4b58f3b6 100644 --- a/src/main/kotlin/org/move/ide/hints/type/MvTypeHintsFactory.kt +++ b/src/main/kotlin/org/move/ide/hints/type/MvTypeHintsFactory.kt @@ -1,9 +1,9 @@ package org.move.ide.hints.type -import com.intellij.codeInsight.hints.declarative.CollapseState +import com.intellij.codeInsight.hints.declarative.* import com.intellij.codeInsight.hints.declarative.CollapseState.Collapsed import com.intellij.codeInsight.hints.declarative.CollapseState.Expanded -import com.intellij.codeInsight.hints.declarative.PresentationTreeBuilder +import com.intellij.psi.createSmartPointer import org.move.ide.presentation.hintText import org.move.lang.core.types.ty.Ty import org.move.lang.core.types.ty.TyAdt @@ -15,7 +15,7 @@ object MvTypeHintsFactory { treeBuilder.typeHint(0, type) } -// private const val UNNAMED_MARK = "" + // private const val UNNAMED_MARK = "" private const val ANONYMOUS_MARK = "" private fun PresentationTreeBuilder.typeHint(level: Int, type: Ty) { @@ -31,7 +31,13 @@ object MvTypeHintsFactory { private fun PresentationTreeBuilder.adtTypeHint(level: Int, tyAdt: TyAdt) { val itemName = tyAdt.item.name ?: ANONYMOUS_MARK - text(itemName) + text( + itemName, + InlayActionData( + PsiPointerInlayActionPayload(tyAdt.item.createSmartPointer()), + PsiPointerInlayActionNavigationHandler.HANDLER_ID + ) + ) if (tyAdt.typeArguments.isEmpty()) return collapsibleList( state = calcCollapseState(level, tyAdt), @@ -84,35 +90,6 @@ object MvTypeHintsFactory { }) } -// private fun PresentationTreeBuilder.classTypeHint(level: Int, classType: PsiClassType) { -// val aClass = classType.resolve() -// -// val className = classType.className ?: ANONYMOUS_MARK // TODO here it may be not exactly true, the class might be unresolved -// text(className, aClass?.qualifiedName?.let { InlayActionData(StringInlayActionPayload(it), JavaFqnDeclarativeInlayActionHandler.HANDLER_NAME) }) -// if (classType.parameterCount == 0) return -// collapsibleList(expandedState = { -// toggleButton { -// text("<") -// } -// join( -// classType.parameters, -// op = { -// typeHint(level + 1, it) -// }, -// separator = { -// text(", ") -// } -// ) -// toggleButton { -// text(">") -// } -// }, collapsedState = { -// toggleButton { -// text("<...>") -// } -// }) -// } - private fun PresentationTreeBuilder.join( elements: List, op: PresentationTreeBuilder.(T) -> Unit, diff --git a/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt b/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt index c2c6983c9..49b76cea2 100644 --- a/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt +++ b/src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt @@ -295,8 +295,6 @@ fun PsiElement.cameBefore(element: PsiElement) = inline val > StubBasedPsiElement.greenStub: T? get() = (this as? StubBasedPsiElementBase)?.greenStub -fun T.asSmartPointer() = SmartPointerManager.createPointer(this) - val PsiElement.stubParent: PsiElement? get() { if (this is StubBasedPsiElement<*>) {