Changesets · Branches · Tags · Compare
| Changeset | e841ee848161a20aaabd2af514de0f671bcd63b1b2e1b7e46a78f7ce0d34a9c8 |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-30 13:37 -07:00 |
| Committer | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-06-30 13:37 -07:00 |
| Parents | 62c4c3e6fad7 |
4 files changed
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ApplyToFileHandler.kt +50 −28
| @@ -44,6 +44,12 @@ | ||
| 44 | 44 | return |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | + // Handle search/replace mode | |
| 48 | + if (params.isSearchReplace == true) { | |
| 49 | + handleSearchReplace(editorUtils) | |
| 50 | + return | |
| 51 | + } | |
| 52 | + | |
| 47 | 53 | // Get the LLM configuration for applying edits |
| 48 | 54 | val llm = fetchApplyLLMConfig() ?: run { |
| 49 | 55 | ide.showToast(ToastType.ERROR, "Failed to fetch model configuration") |
| @@ -54,6 +60,40 @@ | ||
| 54 | 60 | setupAndStreamDiffs(editorUtils, llm) |
| 55 | 61 | } |
| 56 | 62 | |
| 63 | + /** | |
| 64 | + * Handle search and replace operations | |
| 65 | + * | |
| 66 | + * For search/replace, we always get a full file rewrite of the contents. | |
| 67 | + * We just need to generate diff lines between the current content and new content, | |
| 68 | + * then stream them through the existing infrastructure. | |
| 69 | + */ | |
| 70 | + private fun handleSearchReplace(editorUtils: EditorUtils) { | |
| 71 | + // Clear all diff blocks before running the diff stream | |
| 72 | + diffStreamService.reject(editorUtils.editor) | |
| 73 | + | |
| 74 | + // Get current file content and the new content (full rewrite) | |
| 75 | + val currentContent = editorUtils.getDocumentText() | |
| 76 | + val newContent = params.text | |
| 77 | + | |
| 78 | + // Work with the entire document | |
| 79 | + val startLine = 0 | |
| 80 | + val endLine = editorUtils.getLineCount() - 1 | |
| 81 | + // Create and register the diff stream handler | |
| 82 | + val diffStreamHandler = createDiffStreamHandler(editorUtils.editor, startLine, endLine) | |
| 83 | + diffStreamService.register(diffStreamHandler, editorUtils.editor) | |
| 84 | + | |
| 85 | + // Stream the diffs between current and new content | |
| 86 | + // For search/replace, we pass the new content as "input" and current as "highlighted" | |
| 87 | + diffStreamHandler.streamDiffLinesToEditor( | |
| 88 | + input = newContent, // The new content (full rewrite) | |
| 89 | + prefix = "", // No prefix since we're rewriting the whole file | |
| 90 | + highlighted = currentContent, // Current file content | |
| 91 | + suffix = "", // No suffix since we're rewriting the whole file | |
| 92 | + modelTitle = null, // No model needed for search/replace instant apply | |
| 93 | + includeRulesInSystemMessage = false // No LLM involved, just diff generation | |
| 94 | + ) | |
| 95 | + } | |
| 96 | + | |
| 57 | 97 | private fun notifyStreamStarted() { |
| 58 | 98 | sendApplyStateUpdate(ApplyStateStatus.STREAMING) |
| 59 | 99 | } |
| @@ -61,10 +101,8 @@ | ||
| 61 | 101 | private fun notifyStreamClosed(numDiffs: Int? = 0) { |
| 62 | 102 | sendApplyStateUpdate(ApplyStateStatus.CLOSED, numDiffs) |
| 63 | 103 | } |
| 64 | - | |
| 65 | 104 | private fun sendApplyStateUpdate( |
| 66 | - status: ApplyStateStatus, | |
| 67 | - numDiffs: Int? = null | |
| 105 | + status: ApplyStateStatus, numDiffs: Int? = null | |
| 68 | 106 | ) { |
| 69 | 107 | val payload = ApplyState( |
| 70 | 108 | streamId = params.streamId, |
| @@ -82,16 +120,11 @@ | ||
| 82 | 120 | return try { |
| 83 | 121 | suspendCancellableCoroutine { continuation -> |
| 84 | 122 | continuePluginService.coreMessenger?.request( |
| 85 | - "config/getSerializedProfileInfo", | |
| 86 | - null, | |
| 87 | - null | |
| 123 | + "config/getSerializedProfileInfo", null, null | |
| 88 | 124 | ) { response -> |
| 89 | 125 | try { |
| 90 | 126 | val selectedModels = response.castNestedOrNull<Map<String, Any>>( |
| 91 | - "content", | |
| 92 | - "result", | |
| 93 | - "config", | |
| 94 | - "selectedModelByRole" | |
| 127 | + "content", "result", "config", "selectedModelByRole" | |
| 95 | 128 | ) |
| 96 | 129 | |
| 97 | 130 | // If "apply" role model is not found, try "chat" role |
| @@ -143,9 +176,7 @@ | ||
| 143 | 176 | } |
| 144 | 177 | |
| 145 | 178 | private fun createDiffStreamHandler( |
| 146 | - editor: Editor, | |
| 147 | - startLine: Int, | |
| 148 | - endLine: Int | |
| 179 | + editor: Editor, startLine: Int, endLine: Int | |
| 149 | 180 | ): DiffStreamHandler { |
| 150 | 181 | return DiffStreamHandler( |
| 151 | 182 | project, |
| @@ -164,28 +195,19 @@ | ||
| 164 | 195 | * Factory method to create and execute a new handler for a single apply-to-file operation |
| 165 | 196 | */ |
| 166 | 197 | suspend fun apply( |
| 167 | - project: Project, | |
| 168 | - continuePluginService: ContinuePluginService, | |
| 169 | - ide: IDE, | |
| 170 | - params: ApplyToFileParams | |
| 198 | + project: Project, continuePluginService: ContinuePluginService, ide: IDE, params: ApplyToFileParams | |
| 171 | 199 | ) { |
| 172 | - val editorUtils = if (EditorUtils.editorFileExist(params.filepath)) | |
| 173 | - EditorUtils.getOrOpenEditor(project, params.filepath) | |
| 174 | - else | |
| 175 | - EditorUtils.getEditorByCreateFile(project, params.filepath) | |
| 200 | + val editorUtils = | |
| 201 | + if (EditorUtils.editorFileExist(params.filepath)) EditorUtils.getOrOpenEditor(project, params.filepath) | |
| 202 | + else EditorUtils.getEditorByCreateFile(project, params.filepath) | |
| 176 | 203 | |
| 177 | 204 | val diffStreamService = project.getService(DiffStreamService::class.java) |
| 178 | 205 | |
| 179 | 206 | val handler = ApplyToFileHandler( |
| 180 | - project, | |
| 181 | - continuePluginService, | |
| 182 | - ide, | |
| 183 | - params, | |
| 184 | - editorUtils, | |
| 185 | - diffStreamService | |
| 207 | + project, continuePluginService, ide, params, editorUtils, diffStreamService | |
| 186 | 208 | ) |
| 187 | 209 | |
| 188 | 210 | handler.handleApplyToFile() |
| 189 | 211 | } |
| 190 | 212 | } |
| 191 | -} | |
| No newline at the end of the file | ||
| 213 | +} |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/DiffStreamHandler.kt +1 −1
| @@ -96,7 +96,7 @@ | ||
| 96 | 96 | prefix: String, |
| 97 | 97 | highlighted: String, |
| 98 | 98 | suffix: String, |
| 99 | - modelTitle: String, | |
| 99 | + modelTitle: String?, | |
| 100 | 100 | includeRulesInSystemMessage: Boolean |
| 101 | 101 | ) { |
| 102 | 102 | isRunning = true |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/EditorUtils.kt +7 −2
| @@ -46,6 +46,13 @@ | ||
| 46 | 46 | return editor.document.lineCount |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + /** | |
| 50 | + * Gets the full text content of the document | |
| 51 | + */ | |
| 52 | + fun getDocumentText(): String { | |
| 53 | + return editor.document.text | |
| 54 | + } | |
| 55 | + | |
| 49 | 56 | /** |
| 50 | 57 | * Inserts text at the specified position in the document |
| 51 | 58 | */ |
| @@ -62,7 +69,6 @@ | ||
| 62 | 69 | insertTextAtPos(0, text) |
| 63 | 70 | } |
| 64 | 71 | |
| 65 | - | |
| 66 | 72 | /** |
| 67 | 73 | * Scrolls the editor to make the specified line visible |
| 68 | 74 | */ |
| @@ -165,7 +171,6 @@ | ||
| 165 | 171 | } |
| 166 | 172 | } |
| 167 | 173 | } |
| 168 | - | |
| 169 | 174 | val editor = FileEditorManager.getInstance(project).selectedTextEditor ?: return null |
| 170 | 175 | return EditorUtils(editor) |
| 171 | 176 | } |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ideWebview.kt +2 −2
| @@ -8,10 +8,10 @@ | ||
| 8 | 8 | val text: String, |
| 9 | 9 | val streamId: String, |
| 10 | 10 | val filepath: String?, |
| 11 | - val toolCallId: String? | |
| 11 | + val toolCallId: String?, | |
| 12 | + val isSearchReplace: Boolean? = null | |
| 12 | 13 | ) |
| 13 | 14 | |
| 14 | 15 | data class InsertAtCursorParams( |
| 15 | 16 | val text: String |
| 16 | 17 | ) |
| 17 | - |