-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement lenses using codeVision package #2318
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d67dbda
Initial implementation of lenses using codeVision
pkukielka 91f59ab
Add settings provider
pkukielka 7617f0c
Add tests
pkukielka f5a7aa8
Update recordings
pkukielka 48e9346
Re-enable disabled test
pkukielka 38de580
Revert cody commit
pkukielka e0763ca
Improve test debug logs
pkukielka 529d880
Small fixes
pkukielka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
108 changes: 39 additions & 69 deletions
108
src/integrationTest/kotlin/com/sourcegraph/cody/edit/DocumentCodeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,87 @@ | ||
package com.sourcegraph.cody.edit | ||
|
||
import com.sourcegraph.cody.edit.actions.DocumentCodeAction | ||
import com.sourcegraph.cody.edit.actions.lenses.EditAcceptAction | ||
import com.sourcegraph.cody.edit.actions.lenses.EditCancelAction | ||
import com.sourcegraph.cody.edit.actions.lenses.EditUndoAction | ||
import com.sourcegraph.cody.edit.widget.LensAction | ||
import com.sourcegraph.cody.edit.widget.LensHotkey | ||
import com.sourcegraph.cody.edit.widget.LensIcon | ||
import com.sourcegraph.cody.edit.widget.LensLabel | ||
import com.sourcegraph.cody.edit.widget.LensSpinner | ||
import com.sourcegraph.cody.edit.widget.LensWidgetGroup | ||
import com.sourcegraph.cody.edit.lenses.actions.EditAcceptAction | ||
import com.sourcegraph.cody.edit.lenses.actions.EditCancelAction | ||
import com.sourcegraph.cody.edit.lenses.actions.EditUndoAction | ||
import com.sourcegraph.cody.edit.lenses.providers.EditAcceptCodeVisionProvider | ||
import com.sourcegraph.cody.edit.lenses.providers.EditCancelCodeVisionProvider | ||
import com.sourcegraph.cody.edit.lenses.providers.EditUndoCodeVisionProvider | ||
import com.sourcegraph.cody.edit.lenses.providers.EditWorkingCodeVisionProvider | ||
import com.sourcegraph.cody.util.CodyIntegrationTextFixture | ||
import com.sourcegraph.cody.util.CustomJunitClassRunner | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.startsWith | ||
import org.junit.Ignore | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(CustomJunitClassRunner::class) | ||
class DocumentCodeTest : CodyIntegrationTextFixture() { | ||
|
||
@Test | ||
@Ignore | ||
fun testGetsWorkingGroupLens() { | ||
val codeLensGroup = runAndWaitForLenses(DocumentCodeAction.ID, EditCancelAction.ID) | ||
val codeLenses = runAndWaitForLenses(DocumentCodeAction.ID, EditCancelAction.ID) | ||
|
||
val inlayModel = myFixture.editor.inlayModel | ||
val blockElements = inlayModel.getBlockElementsInRange(0, myFixture.editor.document.textLength) | ||
val lensesGroups = blockElements.mapNotNull { it.renderer as? LensWidgetGroup } | ||
|
||
assertEquals("There should be exactly one lenses group", 1, lensesGroups.size) | ||
|
||
assertTrue("codeLensGroup cannot be null", codeLensGroup != null) | ||
assertEquals("There are 2 lenses expected, working lens and cancel lens", 2, codeLenses.size) | ||
// Lens group should match the expected structure. | ||
val theWidgets = codeLensGroup!!.widgets | ||
assertEquals( | ||
"First lens should be working lens", | ||
codeLenses[0].command?.command, | ||
EditWorkingCodeVisionProvider.command) | ||
assertEquals( | ||
"Second lens should be cancel lens", | ||
codeLenses[1].command?.command, | ||
EditCancelCodeVisionProvider.command) | ||
|
||
assertEquals("Lens group should have 9 widgets", 9, theWidgets.size) | ||
assertTrue("Zeroth lens group should be an icon", theWidgets[0] is LensIcon) | ||
assertTrue( | ||
"First lens group is space separator label", (theWidgets[1] as LensLabel).text == " ") | ||
assertTrue("Second lens group is a spinner", theWidgets[2] is LensSpinner) | ||
assertTrue( | ||
"Third lens group is space separator label", (theWidgets[3] as LensLabel).text == " ") | ||
assertTrue( | ||
"Fourth lens group is a description label", | ||
(theWidgets[4] as LensAction).text == " Cody is working...") | ||
assertTrue( | ||
"Fifth lens group is separator label", | ||
(theWidgets[5] as LensLabel).text == LensesService.SEPARATOR) | ||
assertTrue("Sixth lens group should be an action", theWidgets[6] is LensAction) | ||
assertTrue("Seventh lens group should be a label with a hotkey", theWidgets[7] is LensHotkey) | ||
// We could try to Cancel the action, but there is no guarantee we can do it before edit will | ||
// finish. It is safer to just wait for edit to finish and then undo it. | ||
waitForSuccessfulEdit() | ||
|
||
runLensAction(codeLensGroup, EditCancelAction.ID) | ||
assertNoInlayShown() | ||
runAndWaitForCleanState(EditUndoAction.ID) | ||
} | ||
|
||
@Test | ||
fun testShowsAcceptLens() { | ||
val codeLensGroup = runAndWaitForLenses(DocumentCodeAction.ID, EditAcceptAction.ID) | ||
assertInlayIsShown() | ||
val codeLenses = runAndWaitForLenses(DocumentCodeAction.ID, EditAcceptAction.ID) | ||
assertNotNull("Lens group should be displayed", codeLenses.isNotEmpty()) | ||
|
||
// Lens group should match the expected structure. | ||
val inlayModel = myFixture.editor.inlayModel | ||
val blockElements = inlayModel.getBlockElementsInRange(0, myFixture.editor.document.textLength) | ||
val lensesGroups = blockElements.mapNotNull { it.renderer as? LensWidgetGroup } | ||
val lenses = lensesGroups.firstOrNull() | ||
|
||
assertNotNull("Lens group should be displayed", lenses) | ||
|
||
val widgets = lenses!!.widgets | ||
// There are 13 widgets as of the time of writing, but the UX could change, so check robustly. | ||
assertTrue("Lens group should have at least 4 widgets", widgets.size >= 4) | ||
assertNotNull( | ||
"Lens group should contain Accept action", | ||
widgets.find { widget -> widget is LensAction && widget.actionId == EditAcceptAction.ID }) | ||
assertNotNull( | ||
"Lens group should contain Show Undo action", | ||
widgets.find { widget -> widget is LensAction && widget.actionId == EditUndoAction.ID }) | ||
assertEquals("Lens group should have 4 lenses", 2, codeLenses.size) | ||
assertEquals( | ||
"First lens should be accept lens", | ||
codeLenses[0].command?.command, | ||
EditAcceptCodeVisionProvider.command) | ||
assertEquals( | ||
"Second lens should be undo lens", | ||
codeLenses[1].command?.command, | ||
EditUndoCodeVisionProvider.command) | ||
|
||
// Make sure a doc comment was inserted. | ||
assertTrue(hasJavadocComment(myFixture.editor.document.text)) | ||
|
||
runLensAction(codeLensGroup!!, EditUndoAction.ID) | ||
assertNoInlayShown() | ||
runAndWaitForCleanState(EditUndoAction.ID) | ||
} | ||
|
||
@Test | ||
fun testAccept() { | ||
assertNoInlayShown() | ||
val acceptLens = runAndWaitForLenses(DocumentCodeAction.ID, EditAcceptAction.ID) | ||
assertTrue("Accept lens should be displayed", acceptLens != null) | ||
assertInlayIsShown() | ||
val codeLenses = runAndWaitForLenses(DocumentCodeAction.ID, EditAcceptAction.ID) | ||
assertNotNull("Lens group should be displayed", codeLenses.isNotEmpty()) | ||
|
||
runLensAction(acceptLens!!, EditAcceptAction.ID) | ||
assertNoInlayShown() | ||
runAndWaitForCleanState(EditAcceptAction.ID) | ||
assertThat(myFixture.editor.document.text, startsWith("/**")) | ||
} | ||
|
||
@Test | ||
fun testUndo() { | ||
val originalDocument = myFixture.editor.document.text | ||
val undoLens = runAndWaitForLenses(DocumentCodeAction.ID, EditUndoAction.ID) | ||
assertTrue("Undo lens should be displayed", undoLens != null) | ||
val codeLenses = runAndWaitForLenses(DocumentCodeAction.ID, EditUndoAction.ID) | ||
assertNotNull("Lens group should be displayed", codeLenses.isNotEmpty()) | ||
assertNotSame( | ||
"Expected document to be changed", originalDocument, myFixture.editor.document.text) | ||
assertInlayIsShown() | ||
|
||
runLensAction(undoLens!!, EditUndoAction.ID) | ||
runAndWaitForCleanState(EditUndoAction.ID) | ||
assertEquals( | ||
"Expected document changes to be reverted", | ||
originalDocument, | ||
myFixture.editor.document.text) | ||
assertNoInlayShown() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need
runAndWaitForCleanState
? we could userunAndWaitForLenses
directlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but it is not obvious that
runAndWaitForLenses(actionIdToRun)
wait for no lenses to be visible anymore.Or maybe I should change name of this function?