mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-02 10:34:04 +02:00
Skip unsupported arguments in command
VIM-2720
This commit is contained in:
parent
48033ecb85
commit
2dae43258c
src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands
@ -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")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user