feat: allow tab to accept

This commit is contained in:
Jacob Kim 2025-07-09 09:11:29 -07:00
parent 9c21c059e2
commit daf69ae504
4 changed files with 46 additions and 6 deletions

View file

@ -1,6 +1,7 @@
package com.github.continuedev.continueintellijextension.actions
import com.github.continuedev.continueintellijextension.autocomplete.AcceptAutocompleteAction
import com.github.continuedev.continueintellijextension.nextEdit.AcceptNextEditAction
import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings
import com.intellij.openapi.actionSystem.ActionPromoter
import com.intellij.openapi.actionSystem.AnAction
@ -19,6 +20,13 @@ class ContinueActionPromote : ActionPromoter {
}
}
if (actions.any { it is AcceptNextEditAction }) {
val settings = service<ContinueExtensionSettings>()
if (settings.continueState.showIDECompletionSideBySide) {
return actions.filterIsInstance<AcceptNextEditAction>()
}
}
val rejectDiffActions = actions.filterIsInstance<RejectDiffAction>()
if (rejectDiffActions.isNotEmpty()) {
return rejectDiffActions

View file

@ -0,0 +1,25 @@
package com.github.continuedev.continueintellijextension.nextEdit
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.actionSystem.EditorAction
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
class AcceptNextEditAction : EditorAction(object : EditorActionHandler() {
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
ApplicationManager.getApplication().runWriteAction {
editor.project?.service<NextEditService>()?.accept()
}
}
override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean {
val nextEditService = editor.project?.service<NextEditService>();
val enabled = editor == nextEditService?.pendingCompletion?.editor
// && caret.offset == autocompleteService.pendingCompletion?.offset
&& nextEditService.pendingCompletion?.text != null
return enabled
}
})

View file

@ -109,7 +109,7 @@ class NextEditService(private val project: Project) {
// val nextEditWindowService = project.service<NextEditWindowService>()
val nextEditWindowService = NextEditWindowService.getInstance(project)
// val codeViewer = nextEditWindowService.createCodeViewer(prediction, "ts")
nextEditWindowService.showCodePreview(prediction, editor)
nextEditWindowService.showCodePreview(prediction, editor, completionId)
// editor.contentComponent.removeAll()
// editor.contentComponent.add(codeViewer)
// editor.contentComponent.revalidate()
@ -293,7 +293,7 @@ class NextEditService(private val project: Project) {
editor.caretModel.moveToOffset(offset + text.length)
project.service<ContinuePluginService>().coreMessenger?.request(
"autocomplete/accept",
"nextEdit/accept",
hashMapOf("completionId" to completion.completionId),
null,
({})
@ -357,17 +357,17 @@ class NextEditService(private val project: Project) {
renderCompletion(editor, completion.offset, completion.text!!)
}
private fun cancelCompletion(completion: PendingCompletion) {
// Send cancellation message to core
private fun rejectCompletion(completion: PendingCompletion) {
// Send rejection message to core
widget?.setLoading(false)
project.service<ContinuePluginService>().coreMessenger?.request("autocomplete/cancel", null, null, ({}))
project.service<ContinuePluginService>().coreMessenger?.request("nextEdit/reject", null, null, ({}))
}
fun clearCompletions(editor: Editor, completion: PendingCompletion? = pendingCompletion) {
if (isInjectedFile(editor)) return
if (completion != null) {
cancelCompletion(completion)
// cancelCompletion(completion)
if (completion.completionId == pendingCompletion?.completionId) pendingCompletion = null
}
disposeInlayRenderer(editor)

View file

@ -169,6 +169,13 @@
<keyboard-shortcut keymap="Mac OS X" first-keystroke="TAB"/>
</action>
<action id="com.github.continuedev.continueintellijextension.nextEdit.AcceptNextEditAction"
class="com.github.continuedev.continueintellijextension.nextEdit.AcceptNextEditAction"
text="Accept Autocomplete Suggestion" description="Accept Next Edit Prediction">
<keyboard-shortcut keymap="$default" first-keystroke="TAB"/>
<keyboard-shortcut keymap="Mac OS X" first-keystroke="TAB"/>
</action>
<action id="com.github.continuedev.continueintellijextension.autocomplete.CancelAutocompleteAction"
class="com.github.continuedev.continueintellijextension.autocomplete.CancelAutocompleteAction"
text="Cancel Autocomplete Suggestion" description="Cancel Autocomplete Suggestion">