diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2775d68c..b3bfeef3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -313,6 +313,7 @@ jobs: name: ui-test-ide-logs-${{ matrix.os }}-${{ matrix.shard }} path: | out/ide-tests/tests/*/*/*-test/ + out/ide-tests/tests/*/*/*-probe/ !out/ide-tests/tests/**/heap-dump/ out/resource-usage.log retention-days: 7 diff --git a/src/runtime/notebook/backend/src/main/kotlin/me/helvert/codebridge/notebook/HostedNotebooks.kt b/src/runtime/notebook/backend/src/main/kotlin/me/helvert/codebridge/notebook/HostedNotebooks.kt index 3ed015a9..00e5d0ae 100644 --- a/src/runtime/notebook/backend/src/main/kotlin/me/helvert/codebridge/notebook/HostedNotebooks.kt +++ b/src/runtime/notebook/backend/src/main/kotlin/me/helvert/codebridge/notebook/HostedNotebooks.kt @@ -616,6 +616,11 @@ internal class HostedNotebooks(private val project: Project, private val scope: is NotebookModel.Edit.Outputs -> broadcast(open, NotebookEventDto.Outputs(edit.handle, edit.after.map(NotebookModel::outputDto))) } dirtied(open) + // A separate RPC reply can overtake the edit flow. Restore selection in that flow so + // a move's splice cannot remove the views the client has just selected. + if (replayed.selection.isNotEmpty()) { + open.editors[editorId]?.events?.trySend(NotebookEventDto.Selected(replayed.selection)) + } replayed.selection } diff --git a/src/runtime/notebook/frontend/src/main/kotlin/me/helvert/codebridge/notebook/NotebookEditor.kt b/src/runtime/notebook/frontend/src/main/kotlin/me/helvert/codebridge/notebook/NotebookEditor.kt index c0b31940..5cbce89d 100644 --- a/src/runtime/notebook/frontend/src/main/kotlin/me/helvert/codebridge/notebook/NotebookEditor.kt +++ b/src/runtime/notebook/frontend/src/main/kotlin/me/helvert/codebridge/notebook/NotebookEditor.kt @@ -259,6 +259,16 @@ internal class NotebookEditor( event.cells.forEachIndexed { offset, cell -> insert(event.start + offset, cell) } } is NotebookEventDto.Text -> cell(event.handle)?.setText(event.text) + is NotebookEventDto.Selected -> { + // Keep editing where the user went while the undo or redo was on its way. + if (cellList.isFocusOwner || focused == null) { + event.handles.lastOrNull()?.let(::cell)?.let { last -> + select(last) + anchor = cell(event.handles.first()) + highlight() + } + } + } is NotebookEventDto.Outputs -> cell(event.handle)?.setOutputs(event.outputs) is NotebookEventDto.Run -> { cell(event.handle)?.setRun(event.run) @@ -668,19 +678,9 @@ internal class NotebookEditor( cells.getOrNull(index.coerceIn(0, cells.size - 1))?.let(::select) } - /** Undoes or redoes the notebook's last cell edit, then selects the cells it touched. */ + /** Undoes or redoes the notebook's last cell edit; its flow restores selection after the edits. */ private fun replay(step: suspend NotebookApi.(ProjectId, String) -> List) { - call { projectId -> - val handles = step(projectId, id).ifEmpty { return@call } - // Unless the user went on to edit a cell meanwhile, as VS Code keeps the focus where it is. - whenShown({ it.handle == handles.last() }) { last -> - if (cellList.isFocusOwner || focused == null) { - select(last) - anchor = cell(handles.first()) - highlight() - } - } - } + call { step(it, id) } } private fun runCells(handles: List) { diff --git a/src/runtime/notebook/shared/src/main/kotlin/me/helvert/codebridge/notebook/NotebookApi.kt b/src/runtime/notebook/shared/src/main/kotlin/me/helvert/codebridge/notebook/NotebookApi.kt index da3800dd..94994163 100644 --- a/src/runtime/notebook/shared/src/main/kotlin/me/helvert/codebridge/notebook/NotebookApi.kt +++ b/src/runtime/notebook/shared/src/main/kotlin/me/helvert/codebridge/notebook/NotebookApi.kt @@ -80,7 +80,8 @@ interface NotebookApi : RemoteApi { /** * Takes back the notebook's last insert, delete, move, paste, join or output clearing, made in any of its * editors; cell text is each cell editor's own to undo. The handles of the cells to select for - * it, top to bottom: empty when there was nothing to take back or no cell is left. + * it, top to bottom: empty when there was nothing to take back or no cell is left. Selection + * also arrives as [NotebookEventDto.Selected], after the edit events in this editor's flow. */ suspend fun undo(projectId: ProjectId, editorId: String): List @@ -150,6 +151,10 @@ sealed interface NotebookEventDto { @Serializable data class Spliced(val start: Int, val deleted: Int, val cells: List) : NotebookEventDto + /** Selects [handles] in the editor that undid or redid an edit, after that edit's events. */ + @Serializable + data class Selected(val handles: List) : NotebookEventDto + /** Another editor of the notebook changed cell [handle]'s text. */ @Serializable data class Text(val handle: Int, val text: String) : NotebookEventDto diff --git a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/PluginUnderTest.kt b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/PluginUnderTest.kt index c6662b3d..f95f3744 100644 --- a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/PluginUnderTest.kt +++ b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/PluginUnderTest.kt @@ -108,8 +108,15 @@ internal fun IDERemDevTestContext.install(installed: Installed) { // The driver's robot posts mouse and key events into IdeEventQueue instead of moving the OS // cursor, so a run does not take over the developer's mouse and keyboard. The UI is driven in // the client; the backend gets it too in case a test drives backend UI. - applyVMOptionsPatch { addSystemProperty(INPUT_EVENTS_ROBOT, true) } - frontendIDEContext.applyVMOptionsPatch { addSystemProperty(INPUT_EVENTS_ROBOT, true) } + applyVMOptionsPatch { + addSystemProperty(INPUT_EVENTS_ROBOT, true) + addSystemProperty("rdct.wire.timeout.pings", 60) + } + frontendIDEContext.applyVMOptionsPatch { + addSystemProperty(INPUT_EVENTS_ROBOT, true) + // Busy CI startup can pause a peer beyond the default 15-second heartbeat deadline. + addSystemProperty("rdct.wire.timeout.pings", 60) + } } /** A plugin's directory in a test sandbox, which the Gradle task names in [property]. */ diff --git a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt index b588eb94..6ac3af87 100644 --- a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt +++ b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt @@ -1,6 +1,7 @@ package me.helvert.codebridge.uitest.runtime import com.intellij.driver.client.Remote +import com.intellij.driver.model.OnDispatcher import com.intellij.driver.sdk.ui.components.UiComponent import com.intellij.driver.sdk.ui.components.common.JEditorUiComponent import com.intellij.driver.sdk.ui.components.common.editor.completionList @@ -383,9 +384,18 @@ class SplitModeNotebookTest { awaitProbeValue("the move of both undone as one step", ::cells) { it == listOf("two", "three", "one", "two") } hostCells("""["two\n2\n2","three\n3\n3","one\n1\n1","two\n2\n2"]""") - // The undo leaves both selected again, so they are dragged together once more. The cells come - // back from the backend apart from the selection, which may follow them a moment later. + // Selection follows the edit events, so it cannot be cleared by a late splice. awaitProbeValue("both cells selected again by the undo", ::selected) { it == listOf(true, true, false, false) } + repeat(3) { + frame.keyboard { hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_SHIFT, KeyEvent.VK_Z) } + awaitProbeValue("the move of both redone", ::cells) { it == listOf("one", "two", "two", "three") } + hostCells("""["one\n1\n1","two\n2\n2","two\n2\n2","three\n3\n3"]""") + awaitProbeValue("both cells selected again by the redo", ::selected) { it == listOf(false, false, true, true) } + frame.keyboard { hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_Z) } + awaitProbeValue("the move of both undone again", ::cells) { it == listOf("two", "three", "one", "two") } + hostCells("""["two\n2\n2","three\n3\n3","one\n1\n1","two\n2\n2"]""") + awaitProbeValue("both cells selected again by the undo", ::selected) { it == listOf(true, true, false, false) } + } driver.withContext { driver.ui.dragAndDrop(handles()[0], to = handles()[3]) } awaitProbeValue("both cells, still selected, moved last again", ::cells) { it == listOf("one", "two", "two", "three") } hostCells("""["one\n1\n1","two\n2\n2","two\n2\n2","three\n3\n3"]""") @@ -450,17 +460,23 @@ class SplitModeNotebookTest { awaitProbeValue("'$item' in the cell's menu", { runCatching { menu.rawItems }.getOrDefault(emptyList()) }) { items -> items.any { it.startsWith(item) } } - menu.clickItem(item, fullMatch = false) + driver.withContext(OnDispatcher.EDT) { menu.component.requestFocus() } + awaitProbeValue("the cell menu focused", { menu.isFocusOwner() }) { it } + menu.selectItem(item, fullMatch = false) + menu.keyboard { key(KeyEvent.VK_ENTER) } + awaitProbeValue("the cell menu closed", { menu.present() }) { !it } } awaitProbeValue("the notebook's cells in the client", ::cells) { it == listOf("one", "two") } // Copy Cell Down: a copy below, as one step that undo takes back. - fromMenu("Copy Cell Down") - awaitProbeValue("the copy below the cell", ::cells) { it == listOf("one", "one", "two") } - hostCells("""["one","one","two"]""") - frame.keyboard { hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_Z) } - awaitProbeValue("the copy undone", ::cells) { it == listOf("one", "two") } + repeat(3) { + fromMenu("Copy Cell Down") + awaitProbeValue("the copy below the cell", ::cells) { it == listOf("one", "one", "two") } + hostCells("""["one","one","two"]""") + frame.keyboard { hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_Z) } + awaitProbeValue("the copy undone", ::cells) { it == listOf("one", "two") } + } // Join With Next Cell: one cell, their texts a line apart. fromMenu("Join With Next Cell") diff --git a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/vscode/SplitModeTabColorProbe.kt b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/vscode/SplitModeTabColorProbe.kt index 3a69f596..a8aba5c6 100644 --- a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/vscode/SplitModeTabColorProbe.kt +++ b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/vscode/SplitModeTabColorProbe.kt @@ -6,7 +6,7 @@ import com.intellij.driver.model.OnDispatcher import com.intellij.driver.model.RdTarget import com.intellij.driver.sdk.Project import com.intellij.driver.sdk.VirtualFile -import com.intellij.driver.sdk.invokeAction +import com.intellij.driver.sdk.invokeActionWithRetries import com.intellij.driver.sdk.singleProject import com.intellij.driver.sdk.ui.components.common.codeEditor import com.intellij.driver.sdk.ui.components.common.ideFrame @@ -85,7 +85,8 @@ class SplitModeTabColorProbe { val driver = run.driver val editor = driver.ideFrame { }.codeEditor() editor.goToPosition(1, 24) // The declaration of Shape, whose subtype is Circle. - driver.invokeAction("TypeHierarchy", component = editor.component) + // The action's availability follows the caret across the split after the client moves it. + driver.invokeActionWithRetries("TypeHierarchy", maxAttempts = 120) val texts = awaitValue("Circle in the client's type hierarchy", { driver.ideFrame { }.getAllTexts().map { it.text } }) { values -> values.any { it.contains("Circle") } }