mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[param hints] allow to enable OptionInfo hints with alt-enter
This commit is contained in:
@@ -67,6 +67,9 @@ sealed class HintInfo {
|
||||
}
|
||||
|
||||
open val optionName = option.name
|
||||
|
||||
fun isOptionEnabled(): Boolean = option.isEnabled()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -75,6 +78,8 @@ data class Option(val id: String,
|
||||
val name: String,
|
||||
val defaultValue: Boolean) {
|
||||
|
||||
fun isEnabled() = get()
|
||||
|
||||
fun get(): Boolean {
|
||||
return ParameterNameHintsSettings.getInstance().getOption(id) ?: defaultValue
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
|
||||
import com.intellij.openapi.editor.impl.EditorImpl
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
@@ -200,6 +201,60 @@ class DisableCustomHintsOption: IntentionAction, HighPriorityAction {
|
||||
override fun startInWriteAction() = false
|
||||
}
|
||||
|
||||
class EnableCustomHintsOption: IntentionAction, HighPriorityAction {
|
||||
|
||||
companion object {
|
||||
private val presentableFamilyName = CodeInsightBundle.message("inlay.hints.intention.family.name")
|
||||
}
|
||||
|
||||
private var lastOptionName = ""
|
||||
|
||||
override fun getText(): String {
|
||||
if (lastOptionName.startsWith("show", ignoreCase = true)) {
|
||||
return lastOptionName.capitalizeFirstLetter()
|
||||
}
|
||||
return CodeInsightBundle.message("inlay.hints.enable.custom.option", lastOptionName)
|
||||
}
|
||||
|
||||
override fun getFamilyName(): String = presentableFamilyName
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean {
|
||||
if (!EditorSettingsExternalizable.getInstance().isShowParameterNameHints) return false
|
||||
if (editor !is EditorImpl) return false
|
||||
|
||||
InlayParameterHintsExtension.forLanguage(file.language) ?: return false
|
||||
|
||||
val option = getDisabledOptionInfoAtCaretOffset(editor, file) ?: return false
|
||||
lastOptionName = option.optionName
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun getDisabledOptionInfoAtCaretOffset(editor: Editor, file: PsiFile): HintInfo.OptionInfo? {
|
||||
val offset = editor.caretModel.offset
|
||||
|
||||
val element = file.findElementAt(offset) ?: return null
|
||||
val provider = InlayParameterHintsExtension.forLanguage(file.language) ?: return null
|
||||
|
||||
val target = PsiTreeUtil.findFirstParent(element, { provider.hasDisabledOptionHintInfo(it) }) ?: return null
|
||||
return provider.getHintInfo(target) as? HintInfo.OptionInfo
|
||||
}
|
||||
|
||||
override fun invoke(project: Project, editor: Editor, file: PsiFile) {
|
||||
val option = getDisabledOptionInfoAtCaretOffset(editor, file) ?: return
|
||||
option.enable()
|
||||
}
|
||||
|
||||
override fun startInWriteAction() = false
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun InlayParameterHintsProvider.hasDisabledOptionHintInfo(element: PsiElement): Boolean {
|
||||
val info = getHintInfo(element)
|
||||
return info is HintInfo.OptionInfo && !info.isOptionEnabled()
|
||||
}
|
||||
|
||||
|
||||
class ToggleInlineHintsAction : AnAction() {
|
||||
|
||||
@@ -309,4 +364,5 @@ fun isPossibleHintNearOffset(file: PsiFile, offset: Int): Boolean {
|
||||
fun MethodInfo.toPattern() = this.fullyQualifiedName + '(' + this.paramNames.joinToString(",") + ')'
|
||||
|
||||
|
||||
private fun String.capitalize() = StringUtil.capitalizeWords(this, true)
|
||||
private fun String.capitalize() = StringUtil.capitalizeWords(this, true)
|
||||
private fun String.capitalizeFirstLetter() = StringUtil.capitalize(this)
|
||||
@@ -704,6 +704,9 @@
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInsight.hints.DisableCustomHintsOption</className>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInsight.hints.EnableCustomHintsOption</className>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInsight.intention.impl.QuickEditAction</className>
|
||||
<category>Language Injection</category>
|
||||
|
||||
Reference in New Issue
Block a user