Skip to content

Commit

Permalink
ctrl+click for inlay type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Oct 24, 2024
1 parent a3beaeb commit a783a4f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 10 additions & 33 deletions src/main/kotlin/org/move/ide/hints/type/MvTypeHintsFactory.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +15,7 @@ object MvTypeHintsFactory {
treeBuilder.typeHint(0, type)
}

// private const val UNNAMED_MARK = "<unnamed>"
// private const val UNNAMED_MARK = "<unnamed>"
private const val ANONYMOUS_MARK = "<anonymous>"

private fun PresentationTreeBuilder.typeHint(level: Int, type: Ty) {
Expand All @@ -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),
Expand Down Expand Up @@ -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 <T> PresentationTreeBuilder.join(
elements: List<T>,
op: PresentationTreeBuilder.(T) -> Unit,
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/org/move/lang/core/psi/ext/PsiElement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ fun PsiElement.cameBefore(element: PsiElement) =
inline val <T: StubElement<*>> StubBasedPsiElement<T>.greenStub: T?
get() = (this as? StubBasedPsiElementBase<T>)?.greenStub

fun <T: PsiElement> T.asSmartPointer() = SmartPointerManager.createPointer(this)

val PsiElement.stubParent: PsiElement?
get() {
if (this is StubBasedPsiElement<*>) {
Expand Down

0 comments on commit a783a4f

Please sign in to comment.