mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-02-26 05:46:00 +01:00
Removed "originalString" property from commands
This commit is contained in:
parent
7ef4e45945
commit
2b7c311a2b
src
com/maddyhome/idea/vim
main/antlr
test/org/jetbrains/plugins/ideavim/ui
@ -32,7 +32,6 @@ import com.maddyhome.idea.vim.common.TextRange
|
||||
import com.maddyhome.idea.vim.ex.ExCommand.Constants.MAX_RECURSION
|
||||
import com.maddyhome.idea.vim.ex.ranges.LineRange
|
||||
import com.maddyhome.idea.vim.ex.ranges.Ranges
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup
|
||||
import com.maddyhome.idea.vim.group.RegisterGroup
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.helper.Msg
|
||||
@ -55,9 +54,8 @@ data class ExCommand(val ranges: Ranges, var command: String, var argument: Stri
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
processCommand(editor, context, MAX_RECURSION, skipHistory)
|
||||
processCommand(editor, context, MAX_RECURSION)
|
||||
return ExecutionResult.Success
|
||||
}
|
||||
|
||||
@ -66,13 +64,8 @@ data class ExCommand(val ranges: Ranges, var command: String, var argument: Stri
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
aliasCountdown: Int,
|
||||
skipHistory: Boolean,
|
||||
) {
|
||||
|
||||
if (aliasCountdown == MAX_RECURSION && !skipHistory) {
|
||||
VimPlugin.getHistory().addEntry(HistoryGroup.COMMAND, originalString)
|
||||
}
|
||||
|
||||
if (command.isEmpty()) {
|
||||
logger.warn("CMD is empty")
|
||||
return
|
||||
@ -93,7 +86,7 @@ data class ExCommand(val ranges: Ranges, var command: String, var argument: Stri
|
||||
logger.warn("Command alias is empty")
|
||||
return
|
||||
}
|
||||
Executor.execute(commandAlias.command, editor, context, skipHistory)
|
||||
Executor.execute(commandAlias.command, editor, context, skipHistory = true, indicateErrors = true)
|
||||
}
|
||||
// todo nullable editor & context
|
||||
|
||||
|
@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.maddyhome.idea.vim.VimPlugin
|
||||
import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup
|
||||
import com.maddyhome.idea.vim.vimscript.model.VimContext
|
||||
import com.maddyhome.idea.vim.vimscript.parser.VimscriptParser
|
||||
import java.io.File
|
||||
@ -34,11 +35,14 @@ object Executor {
|
||||
|
||||
@kotlin.jvm.Throws(ExException::class)
|
||||
fun execute(scriptString: String, editor: Editor?, context: DataContext?, skipHistory: Boolean, indicateErrors: Boolean = true) {
|
||||
if (!skipHistory) {
|
||||
VimPlugin.getHistory().addEntry(HistoryGroup.COMMAND, scriptString)
|
||||
}
|
||||
val script = VimscriptParser.parse(scriptString)
|
||||
val vimContext = VimContext()
|
||||
for (unit in script.units) {
|
||||
try {
|
||||
unit.execute(editor, context, vimContext, skipHistory)
|
||||
unit.execute(editor, context, vimContext)
|
||||
} catch (e: ExException) {
|
||||
if (indicateErrors) {
|
||||
VimPlugin.showMessage(e.message)
|
||||
|
@ -5,5 +5,5 @@ import com.intellij.openapi.editor.Editor
|
||||
|
||||
interface Executable {
|
||||
|
||||
fun execute(editor: Editor?, context: DataContext?, vimContext: VimContext, skipHistory: Boolean = true): ExecutionResult
|
||||
fun execute(editor: Editor?, context: DataContext?, vimContext: VimContext): ExecutionResult
|
||||
}
|
||||
|
@ -9,12 +9,11 @@ data class Script(val units: List<Executable>) : Executable {
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
var latestResult: ExecutionResult = ExecutionResult.Success
|
||||
for (unit in units) {
|
||||
if (latestResult is ExecutionResult.Success) {
|
||||
latestResult = unit.execute(editor, context, vimContext, skipHistory)
|
||||
latestResult = unit.execute(editor, context, vimContext)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import com.maddyhome.idea.vim.ex.ExException
|
||||
import com.maddyhome.idea.vim.ex.MissingRangeException
|
||||
import com.maddyhome.idea.vim.ex.NoRangeAllowedException
|
||||
import com.maddyhome.idea.vim.ex.ranges.Ranges
|
||||
import com.maddyhome.idea.vim.group.HistoryGroup
|
||||
import com.maddyhome.idea.vim.helper.MessageHelper
|
||||
import com.maddyhome.idea.vim.helper.Msg
|
||||
import com.maddyhome.idea.vim.helper.exitVisualMode
|
||||
@ -20,13 +19,13 @@ import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
|
||||
import com.maddyhome.idea.vim.vimscript.model.VimContext
|
||||
import java.util.*
|
||||
|
||||
sealed class Command(var commandRanges: Ranges, val originalString: String) : Executable {
|
||||
sealed class Command(var commandRanges: Ranges) : Executable {
|
||||
|
||||
abstract val argFlags: CommandHandlerFlags
|
||||
protected open val optFlags: EnumSet<CommandFlags> = noneOfEnum()
|
||||
|
||||
abstract class ForEachCaret(ranges: Ranges, originalString: String) :
|
||||
Command(ranges, originalString = originalString) {
|
||||
abstract class ForEachCaret(ranges: Ranges) :
|
||||
Command(ranges) {
|
||||
abstract fun processCommand(
|
||||
editor: Editor,
|
||||
caret: Caret,
|
||||
@ -35,8 +34,8 @@ sealed class Command(var commandRanges: Ranges, val originalString: String) : Ex
|
||||
): ExecutionResult
|
||||
}
|
||||
|
||||
abstract class SingleExecution(ranges: Ranges, originalString: String) :
|
||||
Command(ranges, originalString = originalString) {
|
||||
abstract class SingleExecution(ranges: Ranges) :
|
||||
Command(ranges) {
|
||||
abstract fun processCommand(editor: Editor?, context: DataContext?, vimContext: VimContext): ExecutionResult
|
||||
}
|
||||
|
||||
@ -45,12 +44,8 @@ sealed class Command(var commandRanges: Ranges, val originalString: String) : Ex
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
|
||||
if (!skipHistory) {
|
||||
VimPlugin.getHistory().addEntry(HistoryGroup.COMMAND, originalString)
|
||||
}
|
||||
checkRanges()
|
||||
|
||||
var result: ExecutionResult = ExecutionResult.Success
|
||||
|
@ -14,8 +14,7 @@ data class DelfunctionCommand(
|
||||
val scope: Scope?,
|
||||
val name: String,
|
||||
val ignoreIfMissing: Boolean,
|
||||
val commandString: String,
|
||||
) : Command.SingleExecution(ranges, commandString) {
|
||||
) : Command.SingleExecution(ranges) {
|
||||
|
||||
override val argFlags = CommandHandlerFlags(RangeFlag.RANGE_FORBIDDEN, Access.READ_ONLY, emptySet())
|
||||
|
||||
|
@ -8,8 +8,8 @@ import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
|
||||
import com.maddyhome.idea.vim.vimscript.model.VimContext
|
||||
import com.maddyhome.idea.vim.vimscript.model.expressions.Expression
|
||||
|
||||
class EchoCommand(val ranges: Ranges, val args: List<Expression>, val commandString: String) :
|
||||
Command.SingleExecution(ranges, commandString) {
|
||||
class EchoCommand(val ranges: Ranges, val args: List<Expression>) :
|
||||
Command.SingleExecution(ranges) {
|
||||
|
||||
override val argFlags = CommandHandlerFlags(RangeFlag.RANGE_FORBIDDEN, Access.READ_ONLY, emptySet())
|
||||
|
||||
|
@ -11,8 +11,8 @@ import com.maddyhome.idea.vim.vimscript.model.ExecutionResult
|
||||
import com.maddyhome.idea.vim.vimscript.model.VimContext
|
||||
import java.lang.Integer.min
|
||||
|
||||
data class GoToLineCommand(val ranges: Ranges, val commandString: String) :
|
||||
Command.ForEachCaret(ranges, commandString) {
|
||||
data class GoToLineCommand(val ranges: Ranges) :
|
||||
Command.ForEachCaret(ranges) {
|
||||
|
||||
override val argFlags = CommandHandlerFlags(RangeFlag.RANGE_REQUIRED, Access.READ_ONLY, emptySet())
|
||||
|
||||
|
@ -26,8 +26,7 @@ data class LetCommand(
|
||||
val variable: Expression,
|
||||
val operator: AssignmentOperator,
|
||||
val expression: Expression,
|
||||
val commandString: String,
|
||||
) : Command.SingleExecution(ranges, commandString) {
|
||||
) : Command.SingleExecution(ranges) {
|
||||
|
||||
override val argFlags = CommandHandlerFlags(RangeFlag.RANGE_FORBIDDEN, Access.READ_ONLY, emptySet())
|
||||
|
||||
|
@ -14,8 +14,7 @@ data class SubstituteCommand(
|
||||
val variable: Expression,
|
||||
val operator: AssignmentOperator,
|
||||
val expression: Expression,
|
||||
val commandString: String,
|
||||
) : Command.SingleExecution(ranges, commandString) {
|
||||
) : Command.SingleExecution(ranges) {
|
||||
|
||||
override val argFlags = CommandHandlerFlags(RangeFlag.RANGE_OPTIONAL, Access.SELF_SYNCHRONIZED, emptySet())
|
||||
|
||||
|
@ -21,7 +21,6 @@ data class FunctionDeclaration(
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
FunctionStorage.storeFunction(this, vimContext)
|
||||
return ExecutionResult.Success
|
||||
|
@ -13,7 +13,6 @@ data class IfStatement(val conditionToBody: List<Pair<Expression, List<Executabl
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
var result: ExecutionResult = ExecutionResult.Success
|
||||
var statementsToExecute: List<Executable>? = null
|
||||
@ -26,7 +25,7 @@ data class IfStatement(val conditionToBody: List<Pair<Expression, List<Executabl
|
||||
if (statementsToExecute != null) {
|
||||
for (statement in statementsToExecute) {
|
||||
if (result is ExecutionResult.Success) {
|
||||
result = statement.execute(editor, context, vimContext, skipHistory)
|
||||
result = statement.execute(editor, context, vimContext)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ data class ReturnStatement(val expression: Expression) : Executable {
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
return ExecutionResult.Return(expression.evaluate(editor, context, vimContext))
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ data class ThrowStatement(val expression: Expression) : Executable {
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
throw ExException(expression.evaluate(editor, context, vimContext).toString())
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ data class TryStatement(val tryBlock: TryBlock, val catchBlocks: List<CatchBlock
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
var uncaughtException: ExException? = null
|
||||
var result: ExecutionResult = ExecutionResult.Success
|
||||
@ -55,7 +54,6 @@ data class TryBlock(val body: List<Executable>) : Executable {
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
return executeBody(body, editor, context, vimContext)
|
||||
}
|
||||
@ -66,7 +64,6 @@ data class CatchBlock(val pattern: String, val body: List<Executable>) : Executa
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
return executeBody(body, editor, context, vimContext)
|
||||
}
|
||||
@ -77,7 +74,6 @@ data class FinallyBlock(val body: List<Executable>) : Executable {
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
return executeBody(body, editor, context, vimContext)
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ object BreakStatement : Executable {
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
return ExecutionResult.Break
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ object ContinueStatement : Executable {
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
return ExecutionResult.Continue
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ data class ForLoop(val variable: String, val iterable: Expression, val body: Lis
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
var result: ExecutionResult = ExecutionResult.Success
|
||||
var iterableValue = iterable.evaluate(editor, context, vimContext)
|
||||
@ -29,7 +28,7 @@ data class ForLoop(val variable: String, val iterable: Expression, val body: Lis
|
||||
VariableService.storeVariable(Variable(null, variable), VimString(i.toString()), editor, context, vimContext)
|
||||
for (statement in body) {
|
||||
if (result is ExecutionResult.Success) {
|
||||
result = statement.execute(editor, context, vimContext, skipHistory)
|
||||
result = statement.execute(editor, context, vimContext)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
@ -54,7 +53,7 @@ data class ForLoop(val variable: String, val iterable: Expression, val body: Lis
|
||||
)
|
||||
for (statement in body) {
|
||||
if (result is ExecutionResult.Success) {
|
||||
result = statement.execute(editor, context, vimContext, skipHistory)
|
||||
result = statement.execute(editor, context, vimContext)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
@ -13,13 +13,12 @@ data class WhileLoop(val condition: Expression, val body: List<Executable>) : Ex
|
||||
editor: Editor?,
|
||||
context: DataContext?,
|
||||
vimContext: VimContext,
|
||||
skipHistory: Boolean,
|
||||
): ExecutionResult {
|
||||
var result: ExecutionResult = ExecutionResult.Success
|
||||
while (condition.evaluate(editor, context, vimContext).asBoolean()) {
|
||||
for (statement in body) {
|
||||
if (result is ExecutionResult.Success) {
|
||||
result = statement.execute(editor, context, vimContext, skipHistory)
|
||||
result = statement.execute(editor, context, vimContext)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ object CommandVisitor : VimscriptBaseVisitor<Executable>() {
|
||||
val variable: Expression = expressionVisitor.visit(ctx.expr(0))
|
||||
val operator = getByValue(ctx.assignmentOperator().text)
|
||||
val expression: Expression = expressionVisitor.visit(ctx.expr(1))
|
||||
return LetCommand(ranges, variable, operator, expression, nameFromContext(ctx))
|
||||
return LetCommand(ranges, variable, operator, expression)
|
||||
}
|
||||
|
||||
override fun visitEchoCommand(ctx: EchoCommandContext): Command {
|
||||
@ -131,7 +131,7 @@ object CommandVisitor : VimscriptBaseVisitor<Executable>() {
|
||||
expressionVisitor.visit(tree)
|
||||
}
|
||||
.collect(Collectors.toList())
|
||||
return EchoCommand(ranges, expressions, nameFromContext(ctx))
|
||||
return EchoCommand(ranges, expressions)
|
||||
}
|
||||
|
||||
override fun visitDelfunctionCommand(ctx: DelfunctionCommandContext): Executable {
|
||||
@ -140,12 +140,12 @@ object CommandVisitor : VimscriptBaseVisitor<Executable>() {
|
||||
if (ctx.functionRef().anyScope() != null) Scope.getByValue(ctx.functionRef().anyScope().text) else null
|
||||
val functionName = ctx.functionRef().functionName().text
|
||||
val ignoreIfMissing = ctx.replace().childCount > 0
|
||||
return DelfunctionCommand(ranges, functionScope, functionName, ignoreIfMissing, ctx.text)
|
||||
return DelfunctionCommand(ranges, functionScope, functionName, ignoreIfMissing)
|
||||
}
|
||||
|
||||
override fun visitGoToLineCommand(ctx: VimscriptParser.GoToLineCommandContext): Command {
|
||||
val ranges: Ranges = parseRanges(ctx.range())
|
||||
return GoToLineCommand(ranges, nameFromContext(ctx))
|
||||
return GoToLineCommand(ranges)
|
||||
}
|
||||
|
||||
override fun visitOtherCommand(ctx: OtherCommandContext): ExCommand {
|
||||
|
@ -56,9 +56,9 @@ functionRef: (anyScope ':')? functionName;
|
||||
argumentsDeclaration: (variableName WS* (WS* ',' WS* variableName)*)?;
|
||||
command:
|
||||
':'* WS* range WS* #GoToLineCommand
|
||||
| ':'* WS* range? WS* ':'* WS* ECHO (WS+ expr)* WS* #EchoCommand
|
||||
| ':'* WS* range? WS* ':'* WS* LET WS* expr WS* assignmentOperator WS* expr WS* #LetCommand
|
||||
| ':'* WS* range? DELF (replace)? WS+ functionRef #DelfunctionCommand
|
||||
| ':'* WS* range? WS* ':'* WS* ECHO (WS+ expr)* WS* comment? #EchoCommand
|
||||
| ':'* WS* range? WS* ':'* WS* LET WS* expr WS* assignmentOperator WS* expr WS* comment? #LetCommand
|
||||
| ':'* WS* range? DELF (replace)? WS+ functionRef comment? #DelfunctionCommand
|
||||
| ':'* WS* range? WS* ':'* WS* commandName (WS* commandArgument)? #OtherCommand
|
||||
;
|
||||
assignmentOperator: '='|'+='|'-='|'*='|'/='|'%='|'.=';
|
||||
|
@ -70,6 +70,28 @@ class ReloadVimRcTest : VimTestCase() {
|
||||
// assertTrue(VimRcFileState.equalTo(document))
|
||||
// }
|
||||
|
||||
@TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
fun `test equalTo with whitespaces and comments`() {
|
||||
val s = " " // Just to see whitespaces in the following code
|
||||
val origFile = """
|
||||
map x y|"comment
|
||||
let g:x = 5
|
||||
let g:y = 3 " another comment
|
||||
""".trimIndent()
|
||||
val changedFile = """
|
||||
" comment
|
||||
map x y
|
||||
let g:x = ${s}${s}${s}5
|
||||
let g:y = 3
|
||||
""".trimIndent()
|
||||
|
||||
VimRcFileState.saveFileState("", origFile)
|
||||
|
||||
val document = editorFactory.createDocument(changedFile)
|
||||
|
||||
assertTrue(VimRcFileState.equalTo(document))
|
||||
}
|
||||
|
||||
@TestWithoutNeovim(reason = SkipNeovimReason.NOT_VIM_TESTING)
|
||||
fun `test equalTo add line`() {
|
||||
val origFile = """
|
||||
|
Loading…
Reference in New Issue
Block a user