Inlay Hints - Support for multiple languages
How to embed hints in all development languages。
java
kotlin
Below is my code
<codeInsight.daemonBoundCodeVisionProvider implementation="com.github.liminany.leanissjetbrainsideextension.inlay.hints1.JavaInheritorsCodeVisionProvider"/>
package com.github.liminany.leanissjetbrainsideextension.inlay.hints1
import com.intellij.codeInsight.hints.codeVision.InheritorsCodeVisionProvider
import com.intellij.codeInsight.codeVision.CodeVisionRelativeOrdering
import com.intellij.codeInsight.daemon.impl.JavaCodeVisionUsageCollector
import com.intellij.codeInsight.daemon.impl.MarkerType
import com.intellij.lang.java.JavaLanguage
import com.intellij.notification.NotificationDisplayType
import com.intellij.notification.NotificationGroup
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
import com.intellij.openapi.editor.Editor
import com.intellij.psi.*
import java.awt.event.MouseEvent
/**
* @Description //TODO
*
* @Date 2023/12/7 15:50
* @Author yongwangat
**/
class JavaInheritorsCodeVisionProvider: InheritorsCodeVisionProvider() {
companion object {
const val ID: String = "java.inheritors"
}
override fun acceptsFile(file: PsiFile): Boolean = true
// override fun acceptsElement(element: PsiElement): Boolean =
// element is PsiClass && element !is PsiTypeParameter || element is PsiMethod
override fun acceptsElement(element: PsiElement): Boolean = true
override fun getVisionInfo(element: PsiElement, file: PsiFile): CodeVisionInfo? {
//在方法上嵌入提示
if (element is PsiMethod) {
return CodeVisionInfo(
"vision"
)
}
return null
}
override fun getHint(element: PsiElement, file: PsiFile): String? {
return getVisionInfo(element, file)?.text
}
//记录点击次数
override fun logClickToFUS(element: PsiElement, hint: String) {
}
//点击触发事件
override fun handleClick(editor: Editor, element: PsiElement, event: MouseEvent?) {
val notificationGroup = NotificationGroup("AISE.Notification", NotificationDisplayType.BALLOON, true)
val notify = notificationGroup.createNotification("你好", NotificationType.INFORMATION)
Notifications.Bus.notify(notify)
}
override val relativeOrderings: List<CodeVisionRelativeOrdering>
get() = emptyList()
override val id: String
get() = ID
}
Please sign in to leave a comment.
Hi,
This information is present on the Inlay Hints documentation page:
https://plugins.jetbrains.com/docs/intellij/inlay-hints.html#further-tips
Hello, one more question, how to add an icon to the embedded prompt
See com.intellij.codeInsight.hints.presentation.IconPresentation and other inlay presentations with “icon” in the name.
Thanks solved