Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<Int>) {
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<Int>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ interface NotebookApi : RemoteApi<Unit> {
/**
* 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<Int>

Expand Down Expand Up @@ -150,6 +151,10 @@ sealed interface NotebookEventDto {
@Serializable
data class Spliced(val start: Int, val deleted: Int, val cells: List<CellDto>) : NotebookEventDto

/** Selects [handles] in the editor that undid or redid an edit, after that edit's events. */
@Serializable
data class Selected(val handles: List<Int>) : NotebookEventDto

/** Another editor of the notebook changed cell [handle]'s text. */
@Serializable
data class Text(val handle: Int, val text: String) : NotebookEventDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]. */
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"]""")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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") } }
Expand Down
Loading