-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactoring of inline edit commands
- Loading branch information
Showing
18 changed files
with
128 additions
and
157 deletions.
There are no files selected for viewing
41 changes: 0 additions & 41 deletions
41
src/main/kotlin/com/sourcegraph/cody/edit/DocumentCodeActionHandler.kt
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
src/main/kotlin/com/sourcegraph/cody/edit/DocumentCodeSession.kt
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
src/main/kotlin/com/sourcegraph/cody/edit/EditCodeActionHandler.kt
This file was deleted.
Oops, something went wrong.
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
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
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/sourcegraph/cody/edit/actions/DocumentCodeAction.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.sourcegraph.cody.edit.actions | ||
|
||
import com.intellij.openapi.project.DumbAware | ||
import com.sourcegraph.cody.autocomplete.action.CodyAction | ||
|
||
class DocumentCodeAction : | ||
EditCommandAction({ editor, fixupService -> fixupService.startDocumentCode(editor) }), | ||
CodyAction, | ||
DumbAware |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/sourcegraph/cody/edit/actions/EditCodeAction.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.sourcegraph.cody.edit.actions | ||
|
||
import com.intellij.openapi.project.DumbAware | ||
import com.sourcegraph.cody.autocomplete.action.CodyAction | ||
|
||
class EditCodeAction : | ||
EditCommandAction({ editor, fixupService -> fixupService.startCodeEdit(editor) }), | ||
CodyAction, | ||
DumbAware |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/sourcegraph/cody/edit/actions/EditCommandAction.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.sourcegraph.cody.edit.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.editor.actionSystem.EditorAction | ||
import com.intellij.openapi.project.DumbAware | ||
import com.sourcegraph.cody.autocomplete.action.CodyAction | ||
import com.sourcegraph.cody.config.CodyApplicationSettings | ||
import com.sourcegraph.cody.edit.FixupService | ||
import com.sourcegraph.config.ConfigUtil | ||
|
||
open class EditCommandAction(runAction: (Editor, FixupService) -> Unit) : | ||
EditorAction(EditCommandActionHandler(runAction)), CodyAction, DumbAware { | ||
override fun update(e: AnActionEvent) { | ||
super.update(e) | ||
|
||
e.presentation.isVisible = | ||
ConfigUtil.isFeatureFlagEnabled("cody.feature.inline-edits") || | ||
CodyApplicationSettings.instance.isInlineEditionEnabled | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/sourcegraph/cody/edit/actions/EditCommandActionHandler.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.sourcegraph.cody.edit.actions | ||
|
||
import com.intellij.openapi.actionSystem.DataContext | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.editor.Caret | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler | ||
import com.sourcegraph.cody.edit.FixupService | ||
import com.sourcegraph.utils.CodyEditorUtil | ||
|
||
open class EditCommandActionHandler(val runAction: (Editor, FixupService) -> Unit) : | ||
EditorActionHandler() { | ||
private val logger = Logger.getInstance(EditCommandActionHandler::class.java) | ||
|
||
override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean { | ||
return CodyEditorUtil.isEditorValidForAutocomplete(editor) | ||
} | ||
|
||
override fun doExecute(editor: Editor, where: Caret?, dataContext: DataContext?) { | ||
val project = editor.project | ||
if (project == null) { | ||
logger.warn("No project found, cannot run FixupService action for ${this.javaClass.name}") | ||
} else { | ||
runAction(editor, FixupService.getInstance(project)) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/sourcegraph/cody/edit/sessions/DocumentCodeSession.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sourcegraph.cody.edit.sessions | ||
|
||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.Project | ||
import com.sourcegraph.cody.agent.CodyAgent | ||
import com.sourcegraph.cody.agent.protocol.EditTask | ||
import com.sourcegraph.cody.edit.FixupService | ||
import java.util.concurrent.CompletableFuture | ||
|
||
class DocumentCodeSession( | ||
controller: FixupService, | ||
editor: Editor, | ||
project: Project, | ||
document: Document | ||
) : FixupSession(controller, editor, project, document) { | ||
override fun makeEditingRequest(agent: CodyAgent): CompletableFuture<EditTask> { | ||
return agent.server.commandsDocument() | ||
} | ||
} |
19 changes: 3 additions & 16 deletions
19
.../com/sourcegraph/cody/edit/EditSession.kt → ...aph/cody/edit/sessions/EditCodeSession.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,43 +1,30 @@ | ||
package com.sourcegraph.cody.edit | ||
package com.sourcegraph.cody.edit.sessions | ||
|
||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.Project | ||
import com.sourcegraph.cody.agent.CodyAgent | ||
import com.sourcegraph.cody.agent.protocol.ChatModelsResponse | ||
import com.sourcegraph.cody.agent.protocol.EditTask | ||
import com.sourcegraph.cody.agent.protocol.InlineEditParams | ||
import com.sourcegraph.cody.edit.FixupService | ||
import java.util.concurrent.CompletableFuture | ||
|
||
/** | ||
* Manages the state machine for inline-edit requests. | ||
* | ||
* @param instructions The user's instructions for fixing up the code. | ||
*/ | ||
class EditSession( | ||
class EditCodeSession( | ||
controller: FixupService, | ||
editor: Editor, | ||
project: Project, | ||
document: Document, | ||
val instructions: String, | ||
private val chatModelProvider: ChatModelsResponse.ChatModelProvider, | ||
) : FixupSession(controller, editor, project, document) { | ||
private val logger = Logger.getInstance(EditSession::class.java) | ||
|
||
override fun makeEditingRequest(agent: CodyAgent): CompletableFuture<EditTask> { | ||
val params = InlineEditParams(instructions, chatModelProvider.model) | ||
return agent.server.commandsEdit(params) | ||
} | ||
|
||
override fun dispose() {} | ||
|
||
override fun diff() {} | ||
|
||
override fun retry() { | ||
// TODO: The actual prompt is displayed as ghost text in the text input field. | ||
// E.g. "Write a brief documentation comment for the selected code <etc.>" | ||
// We need to send the prompt along with the lenses, so that the client can display it. | ||
EditCommandPrompt(controller, editor, "Edit instructions and Retry").displayPromptUI() | ||
} | ||
} |
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
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.