Skip to content

Commit

Permalink
Revert "Fix(VIM-3376): Refactor the way IdeaVim executes actions"
Browse files Browse the repository at this point in the history
This reverts commit 2451403
  • Loading branch information
AlexPl292 committed Jul 31, 2024
1 parent 5dc860f commit d02f0e1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 72 deletions.
16 changes: 8 additions & 8 deletions .teamcity/_Self/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ object Constants {
const val EAP_CHANNEL = "eap"
const val DEV_CHANNEL = "Dev"

const val GITHUB_TESTS = "2024.1.2"
const val NVIM_TESTS = "2024.1.2"
const val PROPERTY_TESTS = "2024.1.2"
const val LONG_RUNNING_TESTS = "2024.1.2"
const val QODANA_TESTS = "2024.1.2"
const val RELEASE = "2024.1.2"
const val GITHUB_TESTS = "2024.1.1"
const val NVIM_TESTS = "2024.1.1"
const val PROPERTY_TESTS = "2024.1.1"
const val LONG_RUNNING_TESTS = "2024.1.1"
const val QODANA_TESTS = "2024.1.1"
const val RELEASE = "2024.1.1"

const val RELEASE_DEV = "2024.1.2"
const val RELEASE_EAP = "2024.1.2"
const val RELEASE_DEV = "2024.1.1"
const val RELEASE_EAP = "2024.1.1"
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# https://data.services.jetbrains.com/products?code=IC
# Maven releases are here: https://www.jetbrains.com/intellij-repository/releases
# And snapshots: https://www.jetbrains.com/intellij-repository/snapshots
ideaVersion=2024.1.2
ideaVersion=2024.1.1
# Values for type: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type
ideaType=IC
instrumentPluginCode=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.maddyhome.idea.vim.helper.isPrimaryEditor
import com.maddyhome.idea.vim.helper.updateCaretsVisualAttributes
import com.maddyhome.idea.vim.newapi.actionStartedFromVim
import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.runningIJAction
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode
import java.awt.event.KeyEvent
Expand Down Expand Up @@ -165,7 +164,6 @@ internal abstract class OctopusHandler(private val nextHandler: EditorActionHand
}

if (dataContext?.actionStartedFromVim == true) return true
if (runningIJAction) return true

return false
}
Expand Down
98 changes: 42 additions & 56 deletions src/main/java/com/maddyhome/idea/vim/helper/IjActionExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@

package com.maddyhome.idea.vim.helper

import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContextWrapper
import com.intellij.openapi.actionSystem.EmptyAction
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.actionSystem.ex.ActionUtil
import com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks
import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.command.UndoConfirmationPolicy
import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.editor.actionSystem.DocCommandGroupId
import com.intellij.openapi.util.ActionCallback
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.util.NlsContexts
import com.intellij.openapi.util.await
import com.intellij.openapi.util.registry.Registry
import com.maddyhome.idea.vim.RegisterActions
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.NativeAction
Expand All @@ -37,11 +36,10 @@ import com.maddyhome.idea.vim.handler.EditorActionHandlerBase
import com.maddyhome.idea.vim.newapi.IjNativeAction
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.runFromVimKey
import com.maddyhome.idea.vim.newapi.runningIJAction
import kotlinx.coroutines.runBlocking
import org.jetbrains.annotations.NonNls
import java.awt.Component
import javax.swing.JComponent
import javax.swing.SwingUtilities

@Service
internal class IjActionExecutor : VimActionExecutor {
Expand Down Expand Up @@ -76,53 +74,45 @@ internal class IjActionExecutor : VimActionExecutor {
val dataContext = DataContextWrapper(context.ij)
dataContext.putUserData(runFromVimKey, true)

val contextComponent = PlatformCoreDataKeys.CONTEXT_COMPONENT.getData(dataContext) ?: editor?.ij?.component ?: run {
LOG.error("Cannot get context component")
return false
val actionId = ActionManager.getInstance().getId(ijAction)
val event = AnActionEvent(
null,
dataContext,
ActionPlaces.KEYBOARD_SHORTCUT,
ijAction.templatePresentation.clone(),
ActionManager.getInstance(),
0,
)
// beforeActionPerformedUpdate should be called to update the action. It fixes some rider-specific problems.
// because rider use async update method. See VIM-1819.
// This method executes inside of lastUpdateAndCheckDumb
// Another related issue: VIM-2604

// This is a hack to fix the tests and fix VIM-3332
// We should get rid of it in VIM-3376
if (actionId == "RunClass" || actionId == IdeActions.ACTION_COMMENT_LINE || actionId == IdeActions.ACTION_COMMENT_BLOCK) {
ijAction.beforeActionPerformedUpdate(event)
if (!event.presentation.isEnabled) return false
} else {
if (!ActionUtil.lastUpdateAndCheckDumb(ijAction, event, false)) return false
}

val result = withRunningAction {
val result = withStringRegistryOption {
ActionManager.getInstance()
.tryToExecute(ijAction, null, contextComponent, ActionPlaces.KEYBOARD_SHORTCUT, true)
}
result.wait()
}
return result.isDone
}

private fun <T> withRunningAction(block: () -> T): T {
runningIJAction = true
try {
return block()
} finally {
runningIJAction = false
}
}

private fun ActionCallback.wait(): ActionCallback {
runBlocking {
try {
await()
} catch (_: RuntimeException) {
// Nothing
// The exception happens when the action is rejected
// and the exception message explains the reason for rejection
// At the moment, we don't process this information
if (ijAction is ActionGroup && !event.presentation.isPerformGroup) {
// Some ActionGroups should not be performed, but shown as a popup
val popup = JBPopupFactory.getInstance()
.createActionGroupPopup(event.presentation.text, ijAction, dataContext, false, null, -1)
val component = dataContext.getData(PlatformDataKeys.CONTEXT_COMPONENT)
if (component != null) {
val window = SwingUtilities.getWindowAncestor(component)
if (window != null) {
popup.showInCenterOf(window)
}
return true
}
}
return this
}

@Suppress("SameParameterValue")
private fun <T> withStringRegistryOption(block: () -> T): T {
val registry = Registry.get("actionSystem.update.beforeActionPerformedUpdate")
val oldValue = registry.asString()
registry.setValue("on")
try {
return block()
} finally {
registry.setValue(oldValue)
popup.showInFocusCenter()
return true
} else {
performDumbAwareWithCallbacks(ijAction, event) { ijAction.actionPerformed(event) }
return true
}
}

Expand Down Expand Up @@ -216,8 +206,4 @@ internal class IjActionExecutor : VimActionExecutor {
override fun getActionIdList(idPrefix: String): List<String> {
return ActionManager.getInstance().getActionIdList(idPrefix)
}

companion object {
private val LOG = logger<IjActionExecutor>()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ internal open class IjEditorExecutionContext(override val context: DataContext)
// This key is stored in data context when the action is started from vim
internal val runFromVimKey = Key.create<Boolean>("RunFromVim")

/**
* Sometimes we can't rely on [runFromVimKey] because the data context is created after the execution
*/
internal var runningIJAction: Boolean = false

/**
* Check if the action with this data context was started from Vim
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

/**
Expand Down Expand Up @@ -50,6 +51,7 @@ class MotionActionTest : VimTestCase() {
}

@Test
@Disabled("VIM-3376")
fun testEscapeInCommand() {
val content = """
on${c}e two
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimBehaviorDiffers
import org.jetbrains.plugins.ideavim.VimTestCase
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

/**
Expand Down Expand Up @@ -73,6 +74,7 @@ class SelectKeyHandlerTest : VimTestCase() {

@TestWithoutNeovim(SkipNeovimReason.SELECT_MODE)
@Test
@Disabled("VIM-3376")
fun `test char mode backspace`() {
this.doTest(
listOf("gh", "<BS>"),
Expand All @@ -98,6 +100,7 @@ class SelectKeyHandlerTest : VimTestCase() {

@TestWithoutNeovim(SkipNeovimReason.SELECT_MODE)
@Test
@Disabled("VIM-3376")
fun `test char mode delete`() {
this.doTest(
listOf("gh", "<DEL>"),
Expand Down

0 comments on commit d02f0e1

Please sign in to comment.