diff --git a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/CmdCommandTest.kt b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/CmdCommandTest.kt index 948c53d89..de6c78f07 100644 --- a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/CmdCommandTest.kt +++ b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/CmdCommandTest.kt @@ -19,6 +19,7 @@ package org.jetbrains.plugins.ideavim.ex.implementation.commands import com.maddyhome.idea.vim.VimPlugin +import com.maddyhome.idea.vim.api.injector import org.jetbrains.plugins.ideavim.VimTestCase /** @@ -130,6 +131,22 @@ class CmdCommandTest : VimTestCase() { assertPluginError(false) } + fun `test add command with range`() { + VimPlugin.getCommand().resetAliases() + configureByText("\n") + typeText(commandToKeys("command! -range Error echo <args>")) + assertPluginError(false) + assertEquals("'-range' is not supported by `command`", injector.messages.getStatusBarMessage()) + } + + fun `test add command with complete`() { + VimPlugin.getCommand().resetAliases() + configureByText("\n") + typeText(commandToKeys("command! -complete=color Error echo <args>")) + assertPluginError(false) + assertEquals("'-complete' is not supported by `command`", injector.messages.getStatusBarMessage()) + } + fun `test add command with arguments short`() { VimPlugin.getCommand().resetAliases() configureByText("\n") diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands/CmdCommand.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands/CmdCommand.kt index 4504b4766..552d36567 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands/CmdCommand.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands/CmdCommand.kt @@ -35,6 +35,18 @@ import com.maddyhome.idea.vim.vimscript.model.ExecutionResult data class CmdCommand(val ranges: Ranges, val argument: String) : Command.SingleExecution(ranges) { override val argFlags = flags(RangeFlag.RANGE_FORBIDDEN, ArgumentFlag.ARGUMENT_OPTIONAL, Access.READ_ONLY) + private val unsupportedArgs = listOf( + Regex("-range(=[^ ])?") to "-range", + Regex("-complete=[^ ]*") to "-complete", + Regex("-count=[^ ]*") to "-count", + Regex("-addr=[^ ]*") to "-addr", + Regex("-bang") to "-bang", + Regex("-bar") to "-bar", + Regex("-register") to "-register", + Regex("-buffer") to "-buffer", + Regex("-keepscript") to "-keepscript", + ) + // Static definitions needed for aliases. private companion object { const val overridePrefix = "!" @@ -76,6 +88,14 @@ data class CmdCommand(val ranges: Ranges, val argument: String) : Command.Single argument = argument.removePrefix(overridePrefix).trim() } + for ((arg, message) in unsupportedArgs) { + val match = arg.find(argument) + match?.range?.let { + argument = argument.removeRange(it) + injector.messages.showStatusBarMessage("'$message' is not supported by `command`") + } + } + // Handle alias arguments val hasArguments = argument.startsWith(argsPrefix) var minNumberOfArgs = 0