chore: cleanup
This commit is contained in:
parent
dce9169593
commit
bef0812f0d
4 changed files with 12 additions and 218 deletions
|
|
@ -11,8 +11,8 @@ import com.github.continuedev.continueintellijextension.utils.uuid
|
|||
import com.intellij.codeInsight.inline.completion.*
|
||||
import com.intellij.codeInsight.inline.completion.elements.InlineCompletionElement
|
||||
import com.intellij.codeInsight.inline.completion.elements.InlineCompletionGrayTextElement
|
||||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionSuggestion
|
||||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionSingleSuggestion
|
||||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionSuggestion
|
||||
import com.intellij.codeInsight.inline.completion.suggestion.InlineCompletionVariant
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.project.Project
|
||||
|
|
|
|||
|
|
@ -121,12 +121,9 @@ class NextEditJumpManager(private val project: Project) {
|
|||
if (completionContent != null &&
|
||||
isContentIdentical(editor, nextJumpLocation, completionContent)
|
||||
) {
|
||||
println("Skipping jump as content is identical at jump location")
|
||||
return false
|
||||
}
|
||||
|
||||
println("Suggesting jump from line ${currentPosition.line} to line ${nextJumpLocation.line}")
|
||||
|
||||
// Update state
|
||||
jumpState = jumpState.copy(
|
||||
inProgress = true,
|
||||
|
|
@ -151,9 +148,7 @@ class NextEditJumpManager(private val project: Project) {
|
|||
editor.scrollingModel.scrollTo(nextJumpLocation, ScrollType.CENTER)
|
||||
|
||||
result = true
|
||||
println("DEBUG: suggestJump completed successfully")
|
||||
} catch (e: Exception) {
|
||||
println("DEBUG: Error in suggestJump UI operations: $e")
|
||||
// Reset state on error
|
||||
jumpState = jumpState.copy(inProgress = false)
|
||||
result = false
|
||||
|
|
@ -266,7 +261,6 @@ class NextEditJumpManager(private val project: Project) {
|
|||
// Force focus after popup is shown
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
popupComponent.requestFocusInWindow()
|
||||
println("DEBUG: Jump popup shown and focus requested")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
jumpPopup?.showInBestPositionFor(editor)
|
||||
|
|
@ -331,8 +325,6 @@ class NextEditJumpManager(private val project: Project) {
|
|||
}
|
||||
|
||||
private fun addKeyboardShortcuts(panel: JComponent, editor: Editor) {
|
||||
println("DEBUG: Adding keyboard shortcuts to jump panel")
|
||||
|
||||
// CRITICAL: Disable focus traversal for Tab key
|
||||
panel.setFocusTraversalKeysEnabled(false)
|
||||
|
||||
|
|
@ -343,7 +335,6 @@ class NextEditJumpManager(private val project: Project) {
|
|||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "acceptJump")
|
||||
actionMap.put("acceptJump", object : AbstractAction() {
|
||||
override fun actionPerformed(e: ActionEvent?) {
|
||||
println("DEBUG: Accept jump action triggered!")
|
||||
acceptJump(editor)
|
||||
}
|
||||
})
|
||||
|
|
@ -352,55 +343,31 @@ class NextEditJumpManager(private val project: Project) {
|
|||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "rejectJump")
|
||||
actionMap.put("rejectJump", object : AbstractAction() {
|
||||
override fun actionPerformed(e: ActionEvent?) {
|
||||
println("DEBUG: Reject jump action triggered!")
|
||||
rejectJump()
|
||||
}
|
||||
})
|
||||
|
||||
panel.isFocusable = true
|
||||
|
||||
// Debug listeners
|
||||
panel.addFocusListener(object : java.awt.event.FocusListener {
|
||||
override fun focusGained(e: java.awt.event.FocusEvent?) {
|
||||
println("DEBUG: Jump panel gained focus")
|
||||
}
|
||||
|
||||
override fun focusLost(e: java.awt.event.FocusEvent?) {
|
||||
println("DEBUG: Jump panel lost focus")
|
||||
}
|
||||
})
|
||||
|
||||
panel.addKeyListener(object : java.awt.event.KeyListener {
|
||||
override fun keyPressed(e: KeyEvent?) {
|
||||
println("DEBUG: Jump panel key pressed: ${e?.keyCode} (Tab = ${KeyEvent.VK_TAB}, Esc = ${KeyEvent.VK_ESCAPE})")
|
||||
}
|
||||
|
||||
override fun keyReleased(e: KeyEvent?) {}
|
||||
override fun keyTyped(e: KeyEvent?) {}
|
||||
})
|
||||
|
||||
panel.addHierarchyListener { e ->
|
||||
if (e.changeFlags and java.awt.event.HierarchyEvent.SHOWING_CHANGED.toLong() != 0L) {
|
||||
if (panel.isShowing) {
|
||||
println("DEBUG: Jump panel is showing, requesting focus")
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val focusResult = panel.requestFocusInWindow()
|
||||
println("DEBUG: Jump panel focus request result: $focusResult")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// panel.addHierarchyListener { e ->
|
||||
// if (e.changeFlags and java.awt.event.HierarchyEvent.SHOWING_CHANGED.toLong() != 0L) {
|
||||
// if (panel.isShowing) {
|
||||
// println("DEBUG: Jump panel is showing, requesting focus")
|
||||
// ApplicationManager.getApplication().invokeLater {
|
||||
// val focusResult = panel.requestFocusInWindow()
|
||||
// println("DEBUG: Jump panel focus request result: $focusResult")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private fun acceptJump(editor: Editor) {
|
||||
val state = jumpState
|
||||
if (!state.inProgress || state.jumpPosition == null || state.editor == null) {
|
||||
println("DEBUG: Cannot accept jump - invalid state: ${!state.inProgress} ${state.jumpPosition == null} ${state.editor == null}")
|
||||
return
|
||||
}
|
||||
|
||||
println("Accepting jump to position: ${state.jumpPosition}")
|
||||
|
||||
// Update state BEFORE clearing decorations to prevent cancel callback from triggering reject
|
||||
jumpState = jumpState.copy(justAccepted = true)
|
||||
|
||||
|
|
@ -431,12 +398,9 @@ class NextEditJumpManager(private val project: Project) {
|
|||
|
||||
private fun rejectJump() {
|
||||
if (!jumpState.inProgress) {
|
||||
println("DEBUG: Cannot reject jump - not in progress")
|
||||
return
|
||||
}
|
||||
|
||||
println("Rejecting jump - deleting chain")
|
||||
|
||||
// Delete the chain
|
||||
deleteChainCallback?.invoke()
|
||||
|
||||
|
|
@ -506,50 +470,6 @@ class NextEditJumpManager(private val project: Project) {
|
|||
}
|
||||
}
|
||||
|
||||
// private fun registerSelectionChangeHandler() {
|
||||
// val selectionManager = project.getService(SelectionChangeManager::class.java)
|
||||
//
|
||||
// selectionManager.registerListener(
|
||||
// "nextEditJumpManager",
|
||||
// { event, state -> handleSelectionChange(event, state) },
|
||||
// HandlerPriority.HIGH
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// private suspend fun handleSelectionChange(
|
||||
// event: SelectionEvent,
|
||||
// state: StateSnapshot
|
||||
// ): Boolean {
|
||||
// // Preserve chain during jump operations
|
||||
// when {
|
||||
// state.jumpInProgress -> {
|
||||
// println("Jump in progress, preserving chain")
|
||||
//
|
||||
// // Check if cursor moved away from expected position
|
||||
// val currentPos = event.editor.caretModel.logicalPosition
|
||||
// val oldPos = jumpState.oldCursorPosition
|
||||
// val jumpPos = jumpState.jumpPosition
|
||||
//
|
||||
// // If cursor moved but not to jump position, reject the jump
|
||||
// if (oldPos != null && jumpPos != null &&
|
||||
// !currentPos.equals(oldPos) && !currentPos.equals(jumpPos)
|
||||
// ) {
|
||||
// println("DEBUG: Cursor moved unexpectedly, rejecting jump")
|
||||
// rejectJump()
|
||||
// }
|
||||
//
|
||||
// return true
|
||||
// }
|
||||
//
|
||||
// state.jumpJustAccepted -> {
|
||||
// println("Jump just accepted, preserving chain")
|
||||
// return true
|
||||
// }
|
||||
//
|
||||
// else -> return false
|
||||
// }
|
||||
// }
|
||||
|
||||
fun cleanup() {
|
||||
clearJumpState()
|
||||
triggerInlineSuggestCallback = null
|
||||
|
|
|
|||
|
|
@ -56,8 +56,6 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
|
|||
currCursorPos: Pair<Int, Int>,
|
||||
lastUuid: String?
|
||||
): NextEditOutcome? {
|
||||
println("Case 1: Typing (chain does not exist)")
|
||||
|
||||
// Start a new chain
|
||||
startChain()
|
||||
|
||||
|
|
@ -75,8 +73,6 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
|
|||
|
||||
// Case 2: Jumping (chain exists, jump was taken).
|
||||
override suspend fun handleCase2(): NextEditOutcome? {
|
||||
println("Case 2: Jumping (chain exists, jump was taken)")
|
||||
|
||||
val jumpManager = project.service<NextEditJumpManager>()
|
||||
|
||||
// Reset jump state
|
||||
|
|
@ -90,15 +86,12 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
|
|||
return outcome
|
||||
} else {
|
||||
// This technically should not happen according to the TypeScript comment
|
||||
println("Error: No saved completion found after jump was taken")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// Case 3: Accepting next edit outcome (chain exists, jump is not taken).
|
||||
override suspend fun handleCase3(editor: Editor, currentCursorPos: Pair<Int, Int>): NextEditOutcome? {
|
||||
println("Case 3: Accepting next edit outcome (chain exists, jump is not taken)")
|
||||
|
||||
val jumpManager = project.service<NextEditJumpManager>()
|
||||
|
||||
// Try suggesting jump for each location in the chain
|
||||
|
|
@ -107,7 +100,6 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
|
|||
while (chainExists() && !isJumpSuggested) {
|
||||
val nextItemInChain = getNextInChain()
|
||||
if (nextItemInChain == null) {
|
||||
println("No more items in chain")
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +133,6 @@ class ContinueNextEditService(private val project: Project) : NextEditService {
|
|||
}
|
||||
|
||||
if (!isJumpSuggested) {
|
||||
println("No suitable jump location found after trying all positions")
|
||||
deleteChain()
|
||||
return null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,15 +53,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
newCode: String,
|
||||
diffLines: List<DiffLine>
|
||||
) {
|
||||
println("DEBUG: showNextEditWindow called with:")
|
||||
println(" currCursorPos: $currCursorPos")
|
||||
println(" editableRegionStartLine: $editableRegionStartLine")
|
||||
println(" editableRegionEndLine: $editableRegionEndLine")
|
||||
println(" oldCode length: ${oldCode.length}")
|
||||
println(" newCode length: ${newCode.length}")
|
||||
println(" document total lines: ${editor.document.lineCount}")
|
||||
println(" document writable: ${editor.document.isWritable}")
|
||||
|
||||
// Clear existing decorations first
|
||||
hideAllNextEditWindows()
|
||||
|
||||
|
|
@ -81,8 +72,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
diffLines
|
||||
)
|
||||
|
||||
println("DEBUG: isLineDelete: $isLineDelete")
|
||||
|
||||
// Show the code popup with the new suggestion
|
||||
showCodePopup(editor, newCode, diffLines) { action ->
|
||||
when (action) {
|
||||
|
|
@ -210,7 +199,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
// Force focus after popup is shown
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
popupComponent.requestFocusInWindow()
|
||||
println("DEBUG: Popup shown and focus requested")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
popup.showInBestPositionFor(editor)
|
||||
|
|
@ -258,9 +246,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
|
||||
// Check for DPI scaling
|
||||
val scale = JBUI.scale(1f)
|
||||
println("DEBUG: UI scale factor: $scale")
|
||||
println("DEBUG: FontMetrics - height: $height, ascent: $ascent")
|
||||
println("DEBUG: Font size from font object: ${font.size}")
|
||||
|
||||
// Adjust for DPI scaling
|
||||
val adjustedFontSize = if (scale > 1f) {
|
||||
|
|
@ -269,8 +254,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
font.size
|
||||
}
|
||||
|
||||
println("DEBUG: Adjusted font size: $adjustedFontSize")
|
||||
|
||||
return adjustedFontSize
|
||||
}
|
||||
|
||||
|
|
@ -282,8 +265,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
}
|
||||
|
||||
private fun createCodeDisplayPanel(editor: Editor, code: String, diffLines: List<DiffLine>): JComponent {
|
||||
println("DEBUG: createCodeDisplayPanel - START")
|
||||
|
||||
try {
|
||||
val scheme = EditorColorsManager.getInstance().globalScheme
|
||||
val editorFont = editor.colorsScheme.getFont(com.intellij.openapi.editor.colors.EditorFontType.PLAIN)
|
||||
|
|
@ -299,10 +280,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
|
||||
val adjustedLineHeight = actualFontSize
|
||||
|
||||
println("DEBUG: Using font size: $actualFontSize")
|
||||
println("DEBUG: Editor line height: $editorLineHeight, adjusted: $adjustedLineHeight")
|
||||
println("DEBUG: UI scale: $uiScale")
|
||||
|
||||
// Get file type for proper syntax highlighting
|
||||
val fileType = getCurrentFileType(editor)
|
||||
|
||||
|
|
@ -397,8 +374,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
val backgroundHex =
|
||||
String.format("#%02x%02x%02x", backgroundColor.red, backgroundColor.green, backgroundColor.blue)
|
||||
|
||||
println("DEBUG: HTML font - Family: $fontFamily, Size: ${fontSize}px, LineHeight: ${lineHeight}px")
|
||||
|
||||
if (text.trim().isEmpty()) {
|
||||
return "<html><body style='margin:0; padding:2px 6px; background-color:$backgroundHex;'>" +
|
||||
"<div style='font-family:\"$fontFamily\"; font-size:${fontSize}px; line-height:${lineHeight}px; background-color:$backgroundHex;'> </div>" +
|
||||
|
|
@ -600,8 +575,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
}
|
||||
|
||||
private fun addKeyboardShortcuts(panel: JComponent, onAction: (PopupAction) -> Unit) {
|
||||
println("DEBUG: Adding keyboard shortcuts to panel")
|
||||
|
||||
// CRITICAL FIX: Disable focus traversal for Tab key
|
||||
panel.setFocusTraversalKeysEnabled(false)
|
||||
|
||||
|
|
@ -612,7 +585,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "accept")
|
||||
actionMap.put("accept", object : AbstractAction() {
|
||||
override fun actionPerformed(e: ActionEvent?) {
|
||||
println("DEBUG: Accept action triggered!")
|
||||
onAction(PopupAction.ACCEPT)
|
||||
}
|
||||
})
|
||||
|
|
@ -621,44 +593,11 @@ class NextEditWindowManager(private val project: Project) {
|
|||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "reject")
|
||||
actionMap.put("reject", object : AbstractAction() {
|
||||
override fun actionPerformed(e: ActionEvent?) {
|
||||
println("DEBUG: Reject action triggered!")
|
||||
onAction(PopupAction.REJECT)
|
||||
}
|
||||
})
|
||||
|
||||
panel.isFocusable = true
|
||||
|
||||
// Keep your existing debug listeners
|
||||
panel.addFocusListener(object : java.awt.event.FocusListener {
|
||||
override fun focusGained(e: java.awt.event.FocusEvent?) {
|
||||
println("DEBUG: Panel gained focus")
|
||||
}
|
||||
|
||||
override fun focusLost(e: java.awt.event.FocusEvent?) {
|
||||
println("DEBUG: Panel lost focus")
|
||||
}
|
||||
})
|
||||
|
||||
panel.addKeyListener(object : java.awt.event.KeyListener {
|
||||
override fun keyPressed(e: KeyEvent?) {
|
||||
println("DEBUG: Key pressed: ${e?.keyCode} (Tab = ${KeyEvent.VK_TAB})")
|
||||
}
|
||||
|
||||
override fun keyReleased(e: KeyEvent?) {}
|
||||
override fun keyTyped(e: KeyEvent?) {}
|
||||
})
|
||||
|
||||
panel.addHierarchyListener { e ->
|
||||
if (e.changeFlags and java.awt.event.HierarchyEvent.SHOWING_CHANGED.toLong() != 0L) {
|
||||
if (panel.isShowing) {
|
||||
println("DEBUG: Panel is showing, requesting focus")
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val focusResult = panel.requestFocusInWindow()
|
||||
println("DEBUG: Focus request result: $focusResult")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderDeletionDecorations(
|
||||
|
|
@ -834,12 +773,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
endLine: Int,
|
||||
isLineDelete: Boolean = false
|
||||
) {
|
||||
println("DEBUG: acceptEdit called with:")
|
||||
println(" newText: '$newText'")
|
||||
println(" startLine: $startLine")
|
||||
println(" endLine: $endLine")
|
||||
println(" isLineDelete: $isLineDelete")
|
||||
|
||||
isAccepted = true
|
||||
|
||||
// Clear handler before making document changes that move cursor
|
||||
|
|
@ -850,20 +783,16 @@ class NextEditWindowManager(private val project: Project) {
|
|||
try {
|
||||
// Fix: Use the simpler WriteCommandAction.runWriteCommandAction
|
||||
WriteCommandAction.runWriteCommandAction(project) {
|
||||
println("DEBUG: Inside WriteCommandAction")
|
||||
val document = editor.document
|
||||
|
||||
// Validate line indices
|
||||
val totalLines = document.lineCount
|
||||
println("DEBUG: Total lines in document: $totalLines")
|
||||
|
||||
if (startLine < 0 || startLine >= totalLines) {
|
||||
println("ERROR: Invalid startLine $startLine (total lines: $totalLines)")
|
||||
return@runWriteCommandAction
|
||||
}
|
||||
|
||||
if (endLine < 0 || endLine >= totalLines) {
|
||||
println("ERROR: Invalid endLine $endLine (total lines: $totalLines)")
|
||||
return@runWriteCommandAction
|
||||
}
|
||||
|
||||
|
|
@ -875,53 +804,33 @@ class NextEditWindowManager(private val project: Project) {
|
|||
// If this isn't the last line, extend to include the newline character
|
||||
if (startLine < document.lineCount - 1) {
|
||||
endOffset = document.getLineStartOffset(startLine + 1)
|
||||
println("DEBUG: Line delete - including newline, endOffset: $endOffset")
|
||||
} else {
|
||||
// If it's the last line, just delete to end of line
|
||||
endOffset = document.getLineEndOffset(startLine)
|
||||
println("DEBUG: Line delete - last line, endOffset: $endOffset")
|
||||
}
|
||||
|
||||
println("DEBUG: Line deletion offsets:")
|
||||
println(" startOffset: $startOffset")
|
||||
println(" endOffset: $endOffset")
|
||||
|
||||
val oldText = document.getText(TextRange(startOffset, endOffset))
|
||||
println("DEBUG: Deleting text: '$oldText'")
|
||||
|
||||
// Delete the entire line including newline
|
||||
document.deleteString(startOffset, endOffset)
|
||||
println("DEBUG: Line deletion completed")
|
||||
|
||||
} else {
|
||||
// Handle normal text replacement
|
||||
val startOffset = document.getLineStartOffset(startLine)
|
||||
val endOffset = document.getLineEndOffset(endLine)
|
||||
|
||||
println("DEBUG: Normal edit offsets:")
|
||||
println(" startOffset: $startOffset")
|
||||
println(" endOffset: $endOffset")
|
||||
println(" document length: ${document.textLength}")
|
||||
|
||||
if (startOffset < 0 || endOffset > document.textLength || startOffset > endOffset) {
|
||||
println("ERROR: Invalid offsets - startOffset: $startOffset, endOffset: $endOffset, docLength: ${document.textLength}")
|
||||
return@runWriteCommandAction
|
||||
}
|
||||
|
||||
// Show what we're replacing
|
||||
val oldText = document.getText(TextRange(startOffset, endOffset))
|
||||
println("DEBUG: Replacing text:")
|
||||
println(" Old: '$oldText'")
|
||||
println(" New: '$newText'")
|
||||
|
||||
// Perform the replacement
|
||||
document.replaceString(startOffset, endOffset, newText)
|
||||
println("DEBUG: Document replacement completed")
|
||||
}
|
||||
}
|
||||
|
||||
println("DEBUG: WriteCommandAction completed successfully")
|
||||
|
||||
coroutineScope.launch(Dispatchers.EDT) {
|
||||
InlineCompletionUtils.triggerInlineCompletion(
|
||||
editor,
|
||||
|
|
@ -935,7 +844,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
|
||||
// Log acceptance (placeholder)
|
||||
currentCompletionId?.let {
|
||||
println("DEBUG: Would log acceptance for completion ID: $it")
|
||||
// project.getService(NextEditService::class.java).acceptEdit(it)
|
||||
}
|
||||
|
||||
|
|
@ -1007,31 +915,6 @@ class NextEditWindowManager(private val project: Project) {
|
|||
hideAllNextEditWindows()
|
||||
currentCompletionId = null
|
||||
}
|
||||
|
||||
// fun registerSelectionChangeHandler() {
|
||||
// val selectionManager = project.getService(SelectionChangeManager::class.java)
|
||||
//
|
||||
// selectionManager.registerListener(
|
||||
// "nextEditWindowManager",
|
||||
// { event, state ->
|
||||
// handleSelectionChange(event, state)
|
||||
// },
|
||||
// HandlerPriority.HIGH
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// private suspend fun handleSelectionChange(
|
||||
// event: SelectionEvent,
|
||||
// state: StateSnapshot
|
||||
// ): Boolean {
|
||||
// // If window was just accepted, preserve the chain
|
||||
// if (state.nextEditWindowAccepted) {
|
||||
// println("Next edit window accepted, preserving chain")
|
||||
// return true
|
||||
// }
|
||||
//
|
||||
// return false
|
||||
// }
|
||||
}
|
||||
|
||||
enum class PopupAction {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue