Changesets · Branches · Tags · Compare
| Changeset | 74029cf4f4f0bd61d6697b99e59f8970d53893e756f5e5e6572d92069fd6a028 |
|---|---|
| Author | zimu <zimu@mgtv.com> · 2025-07-18 21:25 +08:00 |
| Committer | zimu <zimu@mgtv.com> · 2025-07-21 09:58 +08:00 |
| Parents | d9595d31f99e |
3 files changed
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt +37 −18
| @@ -248,43 +248,62 @@ | ||
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - override suspend fun runCommand(command: String, options: TerminalOptions) { | |
| 252 | - println("Continue-Debug: runCommand called with command: $command") | |
| 251 | + override suspend fun runCommand(command: String, options: TerminalOptions?) { | |
| 252 | + val terminalOptions = | |
| 253 | + options ?: TerminalOptions(reuseTerminal = true, terminalName = null, waitForCompletion = false) | |
| 254 | + | |
| 253 | 255 | ApplicationManager.getApplication().invokeLater { |
| 254 | 256 | try { |
| 255 | - println("Continue-Debug: Activating Terminal tool window.") | |
| 256 | 257 | val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Terminal") |
| 257 | 258 | toolWindow?.activate({ |
| 258 | 259 | try { |
| 259 | 260 | val terminalView = TerminalView.getInstance(project) |
| 260 | - println("Continue-Debug: Searching for an existing, non-busy terminal widget.") | |
| 261 | - | |
| 262 | - var widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>() | |
| 263 | - .firstOrNull { !it.hasRunningCommands() } | |
| 261 | + var widget: ShellTerminalWidget? = null | |
| 262 | + | |
| 263 | + // 1. Handle reuseTerminal option | |
| 264 | + if (terminalOptions.reuseTerminal == true && terminalView.getWidgets().isNotEmpty()) { | |
| 265 | + // 2. Find by terminalName if provided | |
| 266 | + if (terminalOptions.terminalName != null) { | |
| 267 | + widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>() | |
| 268 | + .firstOrNull { | |
| 269 | + toolWindow.contentManager.getContent(it).tabName == terminalOptions.terminalName | |
| 270 | + && !it.hasRunningCommands() | |
| 271 | + } | |
| 272 | + } else { | |
| 273 | + // 3. Find active terminal, or fall back to the first one | |
| 274 | + widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>() | |
| 275 | + .firstOrNull { toolWindow.contentManager.getContent(it).isSelected } | |
| 276 | + ?: terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>().firstOrNull { | |
| 277 | + !it.hasRunningCommands() | |
| 278 | + } | |
| 279 | + } | |
| 280 | + } | |
| 264 | 281 | |
| 282 | + // 4. Create a new terminal if needed | |
| 265 | 283 | if (widget == null) { |
| 266 | - println("Continue-Debug: No non-busy widget found. Creating a new one.") | |
| 267 | - widget = terminalView.createLocalShellWidget(project.basePath, "Continue Terminal", true) | |
| 284 | + widget = terminalView.createLocalShellWidget( | |
| 285 | + project.basePath, | |
| 286 | + terminalOptions.terminalName, | |
| 287 | + true | |
| 288 | + ) | |
| 268 | 289 | } else { |
| 269 | - println("Continue-Debug: Found an existing widget. Bringing it to the front.") | |
| 270 | - val contentManager = toolWindow.contentManager | |
| 271 | - val content = contentManager.getContent(widget) | |
| 290 | + // Ensure the found widget is visible | |
| 291 | + val content = toolWindow.contentManager.getContent(widget) | |
| 272 | 292 | if (content != null) { |
| 273 | - contentManager.setSelectedContent(content, true) | |
| 293 | + toolWindow.contentManager.setSelectedContent(content, true) | |
| 274 | 294 | } |
| 275 | 295 | } |
| 276 | 296 | |
| 277 | - println("Continue-Debug: Writing command to terminal: $command") | |
| 297 | + // 5. Show and send text | |
| 278 | 298 | widget.ttyConnector?.write(command) |
| 279 | - println("Continue-Debug: Command successfully written to terminal.") | |
| 280 | 299 | |
| 281 | 300 | } catch (e: Exception) { |
| 282 | - println("Continue-Debug: Error during terminal widget handling: ${e.message}") | |
| 301 | + println("Error during terminal widget handling: ${e.message}") | |
| 283 | 302 | e.printStackTrace() |
| 284 | 303 | } |
| 285 | 304 | }, true) |
| 286 | 305 | } catch (e: Exception) { |
| 287 | - println("Continue-Debug: Error activating terminal tool window: ${e.message}") | |
| 306 | + println("Error activating terminal tool window: ${e.message}") | |
| 288 | 307 | e.printStackTrace() |
| 289 | 308 | } |
| 290 | 309 | } |
| @@ -666,7 +685,7 @@ | ||
| 666 | 685 | } |
| 667 | 686 | |
| 668 | 687 | private fun setFileOpen(filepath: String, open: Boolean = true) { |
| 669 | - val file = LocalFileSystem.getInstance().findFileByPath(UriUtils.uriToFile(filepath).path) | |
| 688 | + val file = LocalFileSystem.getInstance().findFileByPath(UriUtils.parseUri(filepath).path) | |
| 670 | 689 | |
| 671 | 690 | file?.let { |
| 672 | 691 | if (open) { |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ide.kt +1 −1
| @@ -62,4 +62,4 @@ | ||
| 62 | 62 | |
| 63 | 63 | data class GetFileStatsParams(val files: List<String>) |
| 64 | 64 | |
| 65 | -data class RunCommandParams(val command: String, val options: TerminalOptions) | |
| 65 | +data class RunCommandParams(val command: String, val options: TerminalOptions?) |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt +4 −4
| @@ -92,9 +92,9 @@ | ||
| 92 | 92 | ) |
| 93 | 93 | |
| 94 | 94 | data class TerminalOptions( |
| 95 | - val reuseTerminal: Boolean, | |
| 96 | - val terminalName: String, | |
| 97 | - val waitForCompletion: Boolean | |
| 95 | + val reuseTerminal: Boolean?, | |
| 96 | + val terminalName: String?, | |
| 97 | + val waitForCompletion: Boolean? | |
| 98 | 98 | ) |
| 99 | 99 | |
| 100 | 100 | interface IDE { |
| @@ -139,7 +139,7 @@ | ||
| 139 | 139 | |
| 140 | 140 | suspend fun openUrl(url: String) |
| 141 | 141 | |
| 142 | - suspend fun runCommand(command: String, options: TerminalOptions) | |
| 142 | + suspend fun runCommand(command: String, options: TerminalOptions?) | |
| 143 | 143 | |
| 144 | 144 | suspend fun saveFile(filepath: String) |
| 145 | 145 |