[command-completion] IDEA-359174 i18name as main lookup

- delete commandId

GitOrigin-RevId: 95e3fe56ded2e99ac7902b53549ee15f86013963
This commit is contained in:
Mikhail Pyltsin
2025-06-11 17:02:49 +00:00
committed by intellij-monorepo-bot
parent a36ca2612b
commit 78ad85bd97
37 changed files with 77 additions and 110 deletions
@@ -36,7 +36,7 @@ internal class GenerateGetterSetterHandleCompletionCommandProvider : CommandProv
if (modCommandAction == null || modCommandAction.getPresentation(actionContext) == null) continue
result.add(BaseGenerateGetterSetterHandleCompletionCommand(case.generateGetter,
case.generateSetter,
case.name,
listOf(case.name),
case.i18nName,
HighlightInfoLookup(field.textRange, EditorColors.SEARCH_RESULT_ATTRIBUTES, 0)) {
IntentionPreviewComputable(context.project, action, context.psiFile, context.editor, context.offset).call()
@@ -51,7 +51,7 @@ private data class GetterSetterCase(val generateGetter: Boolean, val generateSet
private class BaseGenerateGetterSetterHandleCompletionCommand(
val generateGetter: Boolean,
val generateSetter: Boolean,
override val commandId: String,
override val synonyms: List<String>,
override val presentableName: String,
override val highlightInfo: HighlightInfoLookup?,
private val preview: () -> IntentionPreviewInfo?,
@@ -50,8 +50,8 @@ internal class JavaCreateFromUsagesCompletionCommand(val psiClass: PsiClass) : C
private val methodNames: Set<String> = psiClass.allMethods.map { it.name }.toSet()
override val commandId: String
get() = "Create method from usage"
override val synonyms: List<String>
get() = listOf("Create method from usage")
override val presentableName: @Nls String
get() = QuickFixBundle.message("create.method.from.usage.family")
override val icon: Icon?
@@ -84,7 +84,7 @@ internal class JavaCreateFromUsagesCompletionCommand(val psiClass: PsiClass) : C
generateActions(expression).firstOrNull { it is CreateMethodAction }
}
}?: return
ShowIntentionActionsHandler.chooseActionAndInvoke(psiFile, editor, action, commandId)
ShowIntentionActionsHandler.chooseActionAndInvoke(psiFile, editor, action, presentableName)
}
override fun customPrefixMatcher(prefix: String): PrefixMatcher {
@@ -62,8 +62,8 @@ private class JavaDeleteCompletionCommand(
override val highlightInfo: HighlightInfoLookup?,
private val preview: IntentionPreviewInfo,
) : CompletionCommand(), CompletionCommandWithPreview, DumbAware {
override val commandId: String
get() = "Delete element"
override val synonyms: List<String>
get() = listOf("delete", "remove")
override val presentableName: @Nls String
get() = JavaBundle.message("command.completion.delete.element.text")
override val icon: Icon?
@@ -50,8 +50,8 @@ internal class JavaInlineVariableCompletionCommandProvider : CommandProvider {
private class JavaInlineVariableCompletionCommand(
override val highlightInfo: HighlightInfoLookup?,
) : CompletionCommand(), DumbAware, CompletionCommandWithPreview {
override val commandId: String
get() = "Inline"
override val synonyms: List<String>
get() = listOf("inline", "insert")
override val presentableName: @Nls String
get() = JavaBundle.message("command.completion.inline.text")
@@ -42,8 +42,8 @@ internal class JavaIntroduceVariableCommandProvider : CommandProvider {
}
internal class JavaIntroduceVariableCommand : CompletionCommand(), CompletionCommandWithPreview {
override val commandId: String
get() = "Introduce variable"
override val synonyms: List<String>
get() = listOf("Introduce variable")
@Suppress("HardCodedStringLiteral")
override val presentableName: @Nls String
@@ -260,7 +260,7 @@ class JavaCommandsCompletionTest : LightFixtureCompletionTestCase() {
}
}""".trimIndent())
val elements = myFixture.completeBasic()
selectItem(elements.first { element -> element.lookupString.contains("Comment with line", ignoreCase = true) })
selectItem(elements.first { element -> element.lookupString.contains("Comment line", ignoreCase = true) })
myFixture.checkResult("""
class A {
public String getY() {
@@ -565,7 +565,7 @@ class JavaCommandsCompletionTest : LightFixtureCompletionTestCase() {
myFixture.doHighlighting()
myFixture.type(".")
val elements = myFixture.completeBasic()
selectItem(elements.first { element -> element.lookupString.contains("comment with line", ignoreCase = true) })
selectItem(elements.first { element -> element.lookupString.contains("comment line", ignoreCase = true) })
myFixture.checkResult("""
class A {
void foo() {
@@ -39,7 +39,6 @@
- customPrefixMatcher(java.lang.String):com.intellij.codeInsight.completion.PrefixMatcher
- a:execute(I,com.intellij.psi.PsiFile,com.intellij.openapi.editor.Editor):V
- getAdditionalInfo():java.lang.String
- a:getCommandId():java.lang.String
- getHighlightInfo():com.intellij.codeInsight.completion.command.HighlightInfoLookup
- a:getIcon():javax.swing.Icon
- a:getPresentableName():java.lang.String
@@ -22,11 +22,6 @@ import javax.swing.Icon
* This class is marked as experimental and may change in future releases.
*/
abstract class CompletionCommand : UserDataHolderBase() {
/**
* ID to identify this command. It is also used as a lookup string.
* It should present this action in English
*/
abstract val commandId: String
/**
* Represents a localized, human-readable name for the command, used as a main lookup string
@@ -73,7 +68,7 @@ abstract class CompletionCommand : UserDataHolderBase() {
abstract fun execute(offset: Int, psiFile: PsiFile, editor: Editor?)
override fun toString(): String {
return "CompletionCommand(name='$commandId', class='${this::class.simpleName}')"
return "CompletionCommand(presentableName='$presentableName', class='${this::class.simpleName}')"
}
@@ -615,10 +615,12 @@ command.completion.filter.hint=press ''{0}'' to show commands
command.completion.project.tool.text=Project tool
command.completion.recent.files.text=Recent files
command.completion.generate.text=Generate ''{0}''
command.completion.psi.element.comment.line.text=Comment/uncomment with Line Comment
command.completion.psi.element.comment.block.text=Comment/uncomment with Block Comment
command.completion.psi.element.comment.line.text=Comment/uncomment with line comment
command.completion.psi.element.comment.block.text=Comment with block comment
command.completion.psi.element.uncomment.block.text=Uncomment
command.completion.copy.reference.description=Copy reference for ''{0}''
command.completion.copy.reference.text=Copy reference
command.completion.comment.line.with.line.comment.text=Comment line with line comment
command.completion.GotoDeclaration.text=Go to declaration
options.command.completion.display.name=Command Completion
options.command.completion.enabled=Enable command completion
+5 -8
View File
@@ -189,10 +189,10 @@ c:com.intellij.codeInsight.actions.VcsFacade
- <init>():V
- f:execute(I,com.intellij.psi.PsiFile,com.intellij.openapi.editor.Editor):V
- a:findTargetToRefactor(com.intellij.psi.PsiElement):com.intellij.psi.PsiElement
- f:getCommandId():java.lang.String
- f:getIcon():javax.swing.Icon
- f:getPresentableName():java.lang.String
- getPreview():com.intellij.codeInsight.intention.preview.IntentionPreviewInfo
- f:getSynonyms():java.util.List
*a:com.intellij.codeInsight.completion.command.commands.AbstractFormatCodeCompletionCommandProvider
- com.intellij.codeInsight.completion.command.CommandProvider
- <init>():V
@@ -211,7 +211,6 @@ c:com.intellij.codeInsight.actions.VcsFacade
- b:<init>(com.intellij.codeInsight.actions.CodeInsightAction,java.lang.String,java.lang.String,I,kotlin.jvm.internal.DefaultConstructorMarker):V
- execute(I,com.intellij.psi.PsiFile,com.intellij.openapi.editor.Editor):V
- f:getAction():com.intellij.codeInsight.actions.CodeInsightAction
- getCommandId():java.lang.String
- f:getCustomI18nName():java.lang.String
- f:getCustomName():java.lang.String
- getIcon():javax.swing.Icon
@@ -267,12 +266,11 @@ c:com.intellij.codeInsight.actions.VcsFacade
*c:com.intellij.codeInsight.completion.command.commands.ActionCommandProvider
- com.intellij.codeInsight.completion.command.CommandProvider
- com.intellij.openapi.project.DumbAware
- <init>(java.lang.String,java.lang.String,java.lang.String,javax.swing.Icon,java.lang.Integer,java.lang.String,java.util.List):V
- b:<init>(java.lang.String,java.lang.String,java.lang.String,javax.swing.Icon,java.lang.Integer,java.lang.String,java.util.List,I,kotlin.jvm.internal.DefaultConstructorMarker):V
- <init>(java.lang.String,java.lang.String,javax.swing.Icon,java.lang.Integer,java.lang.String,java.util.List):V
- b:<init>(java.lang.String,java.lang.String,javax.swing.Icon,java.lang.Integer,java.lang.String,java.util.List,I,kotlin.jvm.internal.DefaultConstructorMarker):V
- p:createCommand(com.intellij.codeInsight.completion.command.CommandCompletionProviderContext):com.intellij.codeInsight.completion.command.commands.ActionCompletionCommand
- pf:createCommandWithNameIdentifier(com.intellij.codeInsight.completion.command.CommandCompletionProviderContext):com.intellij.codeInsight.completion.command.commands.ActionCompletionCommand
- f:getActionId():java.lang.String
- f:getCommandId():java.lang.String
- getCommands(com.intellij.codeInsight.completion.command.CommandCompletionProviderContext):java.util.List
- f:getIcon():javax.swing.Icon
- f:getPresentableName():java.lang.String
@@ -286,12 +284,11 @@ c:com.intellij.codeInsight.actions.VcsFacade
- com.intellij.codeInsight.completion.command.CompletionCommand
- com.intellij.codeInsight.completion.command.CompletionCommandWithPreview
- com.intellij.openapi.project.DumbAware
- <init>(java.lang.String,java.lang.String,java.lang.String,java.lang.String,javax.swing.Icon,java.lang.Integer,com.intellij.codeInsight.completion.command.HighlightInfoLookup,java.util.List):V
- b:<init>(java.lang.String,java.lang.String,java.lang.String,java.lang.String,javax.swing.Icon,java.lang.Integer,com.intellij.codeInsight.completion.command.HighlightInfoLookup,java.util.List,I,kotlin.jvm.internal.DefaultConstructorMarker):V
- <init>(java.lang.String,java.lang.String,java.lang.String,javax.swing.Icon,java.lang.Integer,com.intellij.codeInsight.completion.command.HighlightInfoLookup,java.util.List):V
- b:<init>(java.lang.String,java.lang.String,java.lang.String,javax.swing.Icon,java.lang.Integer,com.intellij.codeInsight.completion.command.HighlightInfoLookup,java.util.List,I,kotlin.jvm.internal.DefaultConstructorMarker):V
- execute(I,com.intellij.psi.PsiFile,com.intellij.openapi.editor.Editor):V
- f:getActionId():java.lang.String
- getAdditionalInfo():java.lang.String
- getCommandId():java.lang.String
- getHighlightInfo():com.intellij.codeInsight.completion.command.HighlightInfoLookup
- getIcon():javax.swing.Icon
- getPresentableName():java.lang.String
@@ -86,7 +86,7 @@ private class CommandCompletionDocumentationTarget(
completionLookupElement.renderElement(presentation)
return TargetPresentation.builder(presentation.itemText
?: completionLookupElement.command.commandId).icon(presentation.icon).containerText(presentation.tailText).presentation()
?: completionLookupElement.command.presentableName).icon(presentation.icon).containerText(presentation.tailText).presentation()
}
override fun computeDocumentation(): DocumentationResult? {
@@ -167,8 +167,7 @@ internal class CommandCompletionProvider : CompletionProvider<CompletionParamete
if (additionalInfo.isNotEmpty()) {
tailText += " ($additionalInfo)"
}
val name = presentableName.ifEmpty { command.commandId }
val lookupString = name.trim().let {
val lookupString = presentableName.trim().let {
if (it.length > 50) {
it.substring(0, 50) + "\u2026"
}
@@ -177,7 +176,6 @@ internal class CommandCompletionProvider : CompletionProvider<CompletionParamete
}
}
val element: LookupElement = CommandCompletionLookupElement(LookupElementBuilder.create(lookupString)
.withLookupString(command.commandId)
.withLookupString(lookupString)
.withLookupStrings(command.synonyms)
.withPresentableText(lookupString)
@@ -199,7 +197,7 @@ internal class CommandCompletionProvider : CompletionProvider<CompletionParamete
private fun createSorter(completionParameters: CompletionParameters): CompletionSorter {
var weigher = CompletionService.getCompletionService().emptySorter()
.weigh(object : LookupElementWeigher("priority", true, false) {
override fun weigh(element: LookupElement): Comparable<*>? {
override fun weigh(element: LookupElement): Comparable<*> {
if (element.`as`(CommandCompletionLookupElement::class.java) == null) return 0.0
return element.`as`(PrioritizedLookupElement::class.java)?.priority ?: 0.0
}
@@ -361,7 +359,7 @@ internal sealed interface InvocationCommandType {
internal fun findActualIndex(suffix: String, text: CharSequence, offset: Int): Int {
var indexOf = suffix.length
if (offset > text.length || offset == 0) return 0
while (indexOf > 0 && offset - indexOf >= 0 && text.substring(offset - indexOf, offset) != suffix.substring(0, indexOf)) {
while (indexOf > 0 && offset - indexOf >= 0 && text.substring(offset - indexOf, offset) != suffix.take(indexOf)) {
indexOf--
}
//try to find outside
@@ -57,7 +57,7 @@ internal class CommandInsertHandler(private val completionCommand: CompletionCom
ApplicationManager.getApplication().invokeLater {
CommandProcessor.getInstance().executeCommand(context.project, {
completionCommand.execute(startOffset, psiFile, editor)
}, completionCommand.commandId, completionCommand)
}, completionCommand.presentableName, completionCommand)
}
}
@@ -27,7 +27,6 @@ import javax.swing.Icon
* allowing actions to be triggered through code completion features.
*
* @property actionId The unique identifier of the IDE action to be executed
* @property commandId id, which will be used as lookup string
* @property presentableName The display internationalized name of the command
* @property icon Optional icon to be displayed with the command
* @property priority Optional priority value affecting command ordering
@@ -35,7 +34,6 @@ import javax.swing.Icon
*/
open class ActionCommandProvider(
@field:Language("devkit-action-id") var actionId: String,
val commandId: String,
val presentableName: @Nls String,
val icon: Icon? = null,
val priority: Int? = null,
@@ -68,7 +66,6 @@ open class ActionCommandProvider(
*/
protected open fun createCommand(context: CommandCompletionProviderContext): ActionCompletionCommand? =
ActionCompletionCommand(actionId = actionId,
commandId = commandId,
presentableActionName = presentableName,
icon = icon,
priority = priority,
@@ -125,7 +122,7 @@ open class ActionCommandProvider(
}
val range = element.textRange ?: return null
return ActionCompletionCommand(actionId = actionId,
commandId = commandId,
synonyms = synonyms,
presentableActionName = presentableName,
icon = icon,
priority = priority,
@@ -143,7 +140,6 @@ open class ActionCommandProvider(
@Suppress("HardCodedStringLiteral")
open class ActionCompletionCommand(
@field:Language("devkit-action-id") var actionId: String,
override val commandId: String,
presentableActionName: @Nls String,
private val previewText: @Nls String?,
override val icon: Icon? = null,
@@ -8,12 +8,11 @@ import com.intellij.psi.PsiFile
abstract class AbstractChangeSignatureCompletionCommandProvider : ActionCommandProvider(
actionId = "ChangeSignature",
commandId = "Change signature",
presentableName = ActionsBundle.message("action.ChangeSignature.text"),
icon = null,
priority = -100,
previewText = ActionsBundle.message("action.ChangeSignature.description"),
synonyms = listOf("Change definition", "Change parameters")
synonyms = listOf("Change definition", "Change parameters", "Change signature")
) {
override fun isApplicable(offset: Int, psiFile: PsiFile, editor: Editor?): Boolean {
@@ -35,7 +34,7 @@ abstract class AbstractChangeSignatureCompletionCommandProvider : ActionCommandP
override fun createCommand(context: CommandCompletionProviderContext): ActionCompletionCommand? {
return object : ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
synonyms = super.synonyms,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -13,7 +13,7 @@ import com.intellij.psi.PsiNameIdentifierOwner
abstract class AbstractCopyFQNCompletionCommandProvider :
ActionCommandProvider(actionId = "CopyReference",
commandId = "Copy reference",
synonyms = listOf("Copy reference", "Copy FQN"),
presentableName = CodeInsightBundle.message("command.completion.copy.reference.text"),
icon = null,
priority = -150,
@@ -45,7 +45,7 @@ abstract class AbstractCopyFQNCompletionCommandProvider :
}
val range = element.textRange ?: return null
return ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
synonyms = super.synonyms,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -7,12 +7,11 @@ import com.intellij.psi.PsiFile
abstract class AbstractExtractConstantCompletionCommandProvider :
ActionCommandProvider(actionId = "IntroduceConstant",
commandId = "Introduce constant",
presentableName = ActionsBundle.message("action.IntroduceConstant.text"),
icon = null,
priority = -150,
previewText = ActionsBundle.message("action.IntroduceConstant.description"),
synonyms = listOf("Extract constant")) {
synonyms = listOf("Extract constant", "Introduce constant")) {
override fun isApplicable(offset: Int, psiFile: PsiFile, editor: Editor?): Boolean {
if (!super.isApplicable(offset, psiFile, editor)) return false
return findOffsetToCall(offset, psiFile) != null
@@ -24,12 +23,11 @@ abstract class AbstractExtractConstantCompletionCommandProvider :
abstract class AbstractExtractFieldCompletionCommandProvider :
ActionCommandProvider(actionId = "IntroduceField",
commandId = "Introduce field",
presentableName = ActionsBundle.message("action.IntroduceField.text"),
icon = null,
priority = -150,
previewText = ActionsBundle.message("action.IntroduceField.description"),
synonyms = listOf("Extract field")) {
synonyms = listOf("Extract field", "Introduce field")) {
override fun isApplicable(offset: Int, psiFile: PsiFile, editor: Editor?): Boolean {
if (!super.isApplicable(offset, psiFile, editor)) return false
return findOffsetToCall(offset, psiFile) != null
@@ -40,12 +38,11 @@ abstract class AbstractExtractFieldCompletionCommandProvider :
abstract class AbstractExtractParameterCompletionCommandProvider :
ActionCommandProvider(actionId = "IntroduceParameter",
commandId = "Introduce parameter",
presentableName = ActionsBundle.message("action.IntroduceParameter.text"),
icon = null,
priority = -150,
previewText = ActionsBundle.message("action.IntroduceParameter.description"),
synonyms = listOf("Extract parameter")) {
synonyms = listOf("Extract parameter", "Introduce parameter")) {
override fun isApplicable(offset: Int, psiFile: PsiFile, editor: Editor?): Boolean {
if (!super.isApplicable(offset, psiFile, editor)) return false
return findOffsetToCall(offset, psiFile) != null
@@ -32,8 +32,8 @@ abstract class AbstractFormatCodeCompletionCommandProvider :
}
abstract class AbstractFormatCodeCompletionCommand : CompletionCommand(), CompletionCommandWithPreview {
final override val commandId: String
get() = "Format"
final override val synonyms: List<String>
get() = listOf("Format")
@Suppress("HardCodedStringLiteral")
final override val presentableName: @Nls String
@@ -80,8 +80,6 @@ abstract class AbstractGenerateCommandProvider : CommandProvider, DumbAware {
var customName: String? = null,
var customI18nName: @Nls String? = null,
) : CompletionCommand() {
override val commandId: String
get() = customName ?: ("Generate \'" + action.templateText + "\'")
override val presentableName: @Nls String
get() = customI18nName ?: (CodeInsightBundle.message("command.completion.generate.text", action.templateText))
override val icon: Icon?
@@ -11,7 +11,7 @@ import com.intellij.psi.PsiFile
abstract class AbstractGoToDeclarationCompletionCommandProvider :
ActionCommandProvider(actionId = "GotoDeclaration",
commandId = "Go to declaration",
synonyms = listOf("Go to declaration", "Find declaration"),
presentableName = CodeInsightBundle.message("command.completion.GotoDeclaration.text"),
icon = null,
priority = -100,
@@ -10,7 +10,7 @@ import com.intellij.psi.PsiFile
abstract class AbstractGoToImplementationCompletionCommandProvider :
ActionCommandProvider(actionId = "GotoImplementation",
commandId = "Go to implementation",
synonyms = listOf("Go to implementation"),
presentableName = ActionsBundle.message("action.GotoImplementation.text"),
icon = null,
priority = -100,
@@ -10,7 +10,7 @@ import com.intellij.psi.PsiFile
abstract class AbstractGoToSuperMethodCompletionCommandProvider :
ActionCommandProvider(actionId = "GotoSuperMethod",
commandId = "Go to super method",
synonyms = listOf("Go to super method"),
presentableName = ActionsBundle.message("action.GotoSuperMethod.text"),
icon = null,
priority = -100,
@@ -8,7 +8,7 @@ import com.intellij.psi.PsiFile
abstract class AbstractInlineMethodCompletionCommandProvider :
ActionCommandProvider(actionId = "Inline",
commandId = "Inline",
synonyms = listOf("Inline"),
presentableName = ActionsBundle.message("action.Inline.text"),
icon = null,
priority = -150,
@@ -21,7 +21,7 @@ abstract class AbstractInlineMethodCompletionCommandProvider :
override fun createCommand(context: CommandCompletionProviderContext): ActionCompletionCommand? {
return object : ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
synonyms = super.synonyms,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -8,7 +8,7 @@ import com.intellij.psi.PsiFile
abstract class AbstractMoveCompletionCommandProvider : ActionCommandProvider(
actionId = "Move",
commandId = "Move",
synonyms = listOf("Move"),
presentableName = ActionsBundle.message("action.Move.text"),
icon = null,
priority = -100,
@@ -34,7 +34,7 @@ abstract class AbstractMoveCompletionCommandProvider : ActionCommandProvider(
override fun createCommand(context: CommandCompletionProviderContext): ActionCompletionCommand? {
return object : ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
synonyms = super.synonyms,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -56,7 +56,7 @@ abstract class AbstractMoveCompletionCommandProvider : ActionCommandProvider(
abstract class AbstractCopyClassCompletionCommandProvider : ActionCommandProvider(
actionId = "CopyElement",
commandId = "Copy",
synonyms = listOf("Copy"),
presentableName = ActionsBundle.message("action.CopyElement.text"),
icon = null,
priority = -100,
@@ -82,7 +82,7 @@ abstract class AbstractCopyClassCompletionCommandProvider : ActionCommandProvide
override fun createCommand(context: CommandCompletionProviderContext): ActionCompletionCommand? {
return object : ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
synonyms = super.synonyms,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -14,7 +14,6 @@ import com.intellij.psi.PsiNameIdentifierOwner
import com.intellij.psi.PsiNamedElement
abstract class AbstractRenameActionCommandProvider : ActionCommandProvider(actionId = IdeActions.ACTION_RENAME,
commandId = "Rename",
presentableName = ActionsBundle.message("action.RenameElement.text"),
previewText = ActionsBundle.message("action.RenameElement.description"),
synonyms = listOf("Rename", "Change name")) {
@@ -36,7 +35,7 @@ abstract class AbstractRenameActionCommandProvider : ActionCommandProvider(actio
element = element.nameIdentifier
}
return object : ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
synonyms = super.synonyms,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -12,7 +12,7 @@ import com.intellij.psi.PsiFile
abstract class AbstractShowUsagesActionCompletionCommandProvider :
ActionCommandProvider(actionId = ShowUsagesAction.ID,
commandId = "Show usages",
synonyms = listOf("Show usages"),
presentableName = ActionsBundle.message("action.ShowUsages.text"),
icon = null,
priority = -100,
@@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nls
import javax.swing.Icon
internal class DirectErrorFixCompletionCommand(
override val commandId: @Nls String,
override val presentableName: @Nls String,
override val priority: Int?,
override val icon: Icon?,
override val highlightInfo: HighlightInfoLookup,
@@ -37,9 +37,6 @@ internal class DirectErrorFixCompletionCommand(
private val previewProvider: () -> IntentionPreviewInfo?,
) : CompletionCommand(), CompletionCommandWithPreview {
override val presentableName: @Nls String
get() = commandId
override fun execute(offset: Int, psiFile: PsiFile, editor: Editor?) {
if (editor == null) return
val injectedLanguageManager = InjectedLanguageManager.getInstance(psiFile.project)
@@ -85,7 +82,7 @@ internal class DirectErrorFixCompletionCommand(
if (currentName.startsWith("<html>") && currentName.endsWith("</html>")) {
currentName = currentName.substring(6, currentName.length - 7)
}
if (currentName == commandId) {
if (currentName == presentableName) {
return@jobToIndicator fix.action
}
}
@@ -95,7 +92,7 @@ internal class DirectErrorFixCompletionCommand(
}
}
if (action == null) return
ShowIntentionActionsHandler.chooseActionAndInvoke(topLevelPsiFile, topLevelEditor, action, commandId)
ShowIntentionActionsHandler.chooseActionAndInvoke(topLevelPsiFile, topLevelEditor, action, presentableName)
}
override fun getPreview(): IntentionPreviewInfo? {
@@ -34,7 +34,7 @@ import javax.swing.Icon
internal class DirectInspectionFixCompletionCommand(
private val inspectionId: String,
override val commandId: @Nls String,
override val presentableName: @Nls String,
override val priority: Int?,
override val icon: Icon?,
override val highlightInfo: HighlightInfoLookup,
@@ -42,9 +42,6 @@ internal class DirectInspectionFixCompletionCommand(
private val previewProvider: () -> IntentionPreviewInfo?,
) : CompletionCommand(), CompletionCommandWithPreview {
override val presentableName: @Nls String
get() = commandId
override fun execute(offset: Int, psiFile: PsiFile, editor: Editor?) {
if (editor == null) return
//todo merge with error finder
@@ -94,7 +91,7 @@ internal class DirectInspectionFixCompletionCommand(
val fixes = descriptor.fixes ?: continue
for (i in 0..fixes.size - 1) {
val intentionAction = wrap(descriptor, i)
if (intentionAction.text == commandId && availableFor(psiFile, editor, targetOffset, intentionAction)) {
if (intentionAction.text == presentableName && availableFor(psiFile, editor, targetOffset, intentionAction)) {
return@readAction intentionAction
}
}
@@ -108,7 +105,7 @@ internal class DirectInspectionFixCompletionCommand(
val marker = editor.document.createRangeMarker(offset, offset)
val targetMarker = editor.document.createRangeMarker(targetOffset, targetOffset)
editor.caretModel.moveToOffset(targetOffset)
ShowIntentionActionsHandler.chooseActionAndInvoke(topLevelFile, topLevelEditor, action, commandId)
ShowIntentionActionsHandler.chooseActionAndInvoke(topLevelFile, topLevelEditor, action, presentableName)
if (targetMarker.isValid && targetMarker.startOffset != editor.caretModel.offset) {
//probably, intention moves the cursor
return
@@ -240,7 +240,7 @@ internal class DirectIntentionCommandProvider : CommandProvider {
result[toolId + ":" + action.text] = (DirectInspectionFixCompletionCommand(
inspectionId = toolId,
commandId = action.text,
presentableName = action.text,
priority = priority,
icon = icon,
highlightInfo = HighlightInfoLookup(textRange, level.attributesKey, priority),
@@ -335,7 +335,7 @@ internal class DirectIntentionCommandProvider : CommandProvider {
@Suppress("HardCodedStringLiteral")
name = name.substring(prefix.length, name.length - suffix.length)
}
val command = DirectErrorFixCompletionCommand(commandId = name,
val command = DirectErrorFixCompletionCommand(presentableName = name,
priority = 100,
icon = AllIcons.Actions.QuickfixBulb,
highlightInfo = HighlightInfoLookup(TextRange(info.startOffset, info.endOffset),
@@ -22,9 +22,6 @@ internal class IntentionCompletionCommand(
private val previewProvider: () -> IntentionPreviewInfo?,
) : CompletionCommand(), CompletionCommandWithPreview {
override val commandId: String
get() = intentionAction.text
override val presentableName: @Nls String
get() = intentionAction.text
@@ -43,7 +40,7 @@ internal class IntentionCompletionCommand(
editor.putUserData(KEY_FORCE_CARET_OFFSET, ForceOffsetData(myOffset, offset))
}
if (availableFor) {
ShowIntentionActionsHandler.chooseActionAndInvoke(psiFile, editor, intentionAction.action, commandId)
ShowIntentionActionsHandler.chooseActionAndInvoke(psiFile, editor, intentionAction.action, presentableName)
}
if (!intentionAction.action.startInWriteAction() || (targetMarker.isValid && targetMarker.startOffset != editor.caretModel.offset)) {
//probably, intention moves the cursor or async gui
@@ -1,6 +1,7 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.completion.command.commands
import com.intellij.codeInsight.CodeInsightBundle
import com.intellij.codeInsight.completion.command.CommandCompletionProviderContext
import com.intellij.idea.ActionsBundle
import com.intellij.openapi.editor.Editor
@@ -12,15 +13,15 @@ import com.intellij.psi.PsiFile
*/
internal class LineCommentCompletionCommandProvider :
ActionCommandProvider(actionId = "CommentByLineComment",
commandId = "Comment line",
presentableName = ActionsBundle.message("action.CommentByLineComment.text"),
synonyms = listOf("Comment line"),
presentableName = CodeInsightBundle.message("command.completion.comment.line.with.line.comment.text"),
icon = null,
priority = -100,
previewText = ActionsBundle.message("action.CommentByLineComment.description")) {
override fun createCommand(context: CommandCompletionProviderContext): ActionCompletionCommand {
return object : ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
synonyms = super.synonyms,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -8,7 +8,7 @@ import com.intellij.psi.PsiFile
internal class OptimizeImportCompletionCommandProvider :
ActionCommandProvider(actionId = "OptimizeImports",
commandId = "Optimize imports",
synonyms = listOf("Optimize imports"),
presentableName = ActionsBundle.message("action.OptimizeImports.text"),
icon = null,
priority = -100,
@@ -16,7 +16,7 @@ import com.intellij.psi.util.PsiTreeUtil
internal class PsiElementCommentByBlockCompletionCommandProvider : ActionCommandProvider(
actionId = "CommentByBlockComment",
commandId = "Comment/uncomment by block comment",
synonyms = listOf("Comment/uncomment by block comment"),
presentableName = CodeInsightBundle.message("command.completion.psi.element.comment.block.text"),
previewText = ActionsBundle.message("action.CommentByBlockComment.description")) {
override fun isApplicable(offset: Int, psiFile: PsiFile, editor: Editor?): Boolean {
@@ -29,10 +29,10 @@ internal class PsiElementCommentByBlockCompletionCommandProvider : ActionCommand
override fun createCommand(context: CommandCompletionProviderContext): ActionCompletionCommand? {
val element = getHighLevelContext(context.offset, context.psiFile) ?: return null
val range = element.textRange ?: return null
val adjustedName = if (element is PsiComment) "Uncomment" else "Comment by block comment"
val adjustedName = if (element is PsiComment) CodeInsightBundle.message("command.completion.psi.element.uncomment.block.text") else presentableName
return object : ActionCompletionCommand(actionId = super.actionId,
commandId = adjustedName,
presentableActionName = super.presentableName,
synonyms = super.synonyms,
presentableActionName = adjustedName,
icon = super.icon,
priority = super.priority,
previewText = super.previewText,
@@ -55,7 +55,7 @@ internal class PsiElementCommentByBlockCompletionCommandProvider : ActionCommand
internal class PsiElementCommentByLineCompletionCommandProvider : ActionCommandProvider(
actionId = "CommentByLineComment",
commandId = "Comment by line comment",
synonyms = listOf("Comment by line comment"),
presentableName = CodeInsightBundle.message("command.completion.psi.element.comment.line.text"),
previewText = ActionsBundle.message("action.CommentByLineComment.description")) {
override fun isApplicable(offset: Int, psiFile: PsiFile, editor: Editor?): Boolean {
@@ -79,7 +79,6 @@ internal class PsiElementCommentByLineCompletionCommandProvider : ActionCommandP
val element = getHighLevelContext(context.offset, context.psiFile) ?: return null
val range = element.textRange ?: return null
return object : ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -15,7 +15,6 @@ import com.intellij.psi.PsiNamedElement
@Deprecated("Use AbstractRenameActionCommandProvider instead")
internal class RenameActionCommandProvider : ActionCommandProvider(actionId = IdeActions.ACTION_RENAME,
commandId = "Rename",
presentableName = ActionsBundle.message("action.RenameElement.text"),
previewText = ActionsBundle.message("action.RenameElement.description"),
synonyms = listOf("Rename", "Change name")) {
@@ -31,7 +30,7 @@ internal class RenameActionCommandProvider : ActionCommandProvider(actionId = Id
element = element.nameIdentifier
}
return ActionCompletionCommand(actionId = super.actionId,
commandId = super.commandId,
synonyms = super.synonyms,
presentableActionName = super.presentableName,
icon = super.icon,
priority = super.priority,
@@ -28,7 +28,6 @@ import com.intellij.platform.ide.progress.runWithModalProgressBlocking
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.util.containers.JBIterable.from
import org.jetbrains.annotations.Nls
import java.util.function.Predicate
import javax.swing.Icon
@@ -131,12 +130,10 @@ private fun collectActions(
private class RunMarkerCompletionCommand(
private val offsetElement: Int,
@param:NlsSafe override val commandId: String,
@param:NlsSafe override val presentableName: String,
override val icon: Icon?,
override val additionalInfo: String?,
) : CompletionCommand(), PossiblyDumbAware {
override val presentableName: @Nls String
get() = commandId
override fun execute(offset: Int, psiFile: PsiFile, editor: Editor?) {
val (_, collectedActions) = runWithModalProgressBlocking(psiFile.project, AnalysisBundle.message("scanning.scope.progress.title")) {
@@ -149,7 +146,7 @@ private class RunMarkerCompletionCommand(
cachedIntentions.wrapAndUpdateGutters()
var intentionAction: IntentionAction? = null
for (caching in cachedIntentions.gutters) {
if (caching.text == commandId) {
if (caching.text == presentableName) {
intentionAction = caching.action
break
}
@@ -157,7 +154,7 @@ private class RunMarkerCompletionCommand(
if (intentionAction == null) return
if (editor == null) return
if (ShowIntentionActionsHandler.availableFor(psiFile, editor, offset, intentionAction)) {
ShowIntentionActionsHandler.chooseActionAndInvoke(psiFile, editor, intentionAction, commandId)
ShowIntentionActionsHandler.chooseActionAndInvoke(psiFile, editor, intentionAction, presentableName)
}
}
}
@@ -82,8 +82,8 @@ internal class KotlinCreateFromUsagesCompletionCommand(val ktClass: KtClass) : C
(ktClass.symbol as? KaClassSymbol)?.memberScope?.declarations?.map { it.name?.identifier }?.filterNotNull()?.toSet()
} ?: emptySet()
override val commandId: String
get() = "Create method from usage"
override val synonyms: List<String>
get() = listOf("Create method from usage")
override val presentableName: @Nls String
get() = QuickFixBundle.message("create.method.from.usage.family")
override val icon: Icon?
@@ -134,7 +134,7 @@ internal class KotlinCreateFromUsagesCompletionCommand(val ktClass: KtClass) : C
it.javaClass.name == "org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.CreateKotlinCallableAction" &&
it.text.contains(KotlinBundle.message("text.member"))
} ?: return
ShowIntentionActionsHandler.chooseActionAndInvoke(psiFile, editor, action, commandId)
ShowIntentionActionsHandler.chooseActionAndInvoke(psiFile, editor, action, presentableName)
}
override fun customPrefixMatcher(prefix: String): PrefixMatcher {
@@ -68,8 +68,8 @@ private class KotlinDeleteCompletionCommand(
override val highlightInfo: HighlightInfoLookup?,
private val preview: IntentionPreviewInfo,
) : CompletionCommand(), CompletionCommandWithPreview, DumbAware {
override val commandId: String
get() = "Delete element"
override val synonyms: List<String>
get() = listOf("Delete element")
override val presentableName: @Nls String
get() = ActionsBundle.message("action.EditorDelete.text")
override val icon: Icon?