Changesets · Branches · Tags · Compare
| Changeset | 44b2c1e0bb4571b9124addcec112610c7cdd190d9706258f99f07eec1c98d52b |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-21 22:00 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-21 22:00 -07:00 |
| Parents | 0e7f960647df, 05944493c70c |
6 files changed
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +13 −5
| @@ -8,12 +8,13 @@ | ||
| 8 | 8 | import com.github.continuedev.continueintellijextension.editor.EditorUtils |
| 9 | 9 | import com.github.continuedev.continueintellijextension.error.ContinueErrorService |
| 10 | 10 | import com.github.continuedev.continueintellijextension.protocol.* |
| 11 | -import com.github.continuedev.continueintellijextension.services.* | |
| 12 | -import com.github.continuedev.continueintellijextension.utils.* | |
| 11 | +import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings | |
| 12 | +import com.github.continuedev.continueintellijextension.services.ContinuePluginService | |
| 13 | +import com.github.continuedev.continueintellijextension.utils.getMachineUniqueID | |
| 14 | +import com.github.continuedev.continueintellijextension.utils.uuid | |
| 13 | 15 | import com.google.gson.Gson |
| 14 | 16 | import com.intellij.openapi.application.ApplicationManager |
| 15 | 17 | import com.intellij.openapi.command.WriteCommandAction |
| 16 | -import com.intellij.openapi.components.ServiceManager | |
| 17 | 18 | import com.intellij.openapi.components.service |
| 18 | 19 | import com.intellij.openapi.editor.SelectionModel |
| 19 | 20 | import com.intellij.openapi.fileEditor.FileEditorManager |
| @@ -21,7 +22,10 @@ | ||
| 21 | 22 | import com.intellij.openapi.project.Project |
| 22 | 23 | import com.intellij.openapi.vfs.VirtualFileManager |
| 23 | 24 | import com.intellij.openapi.wm.ToolWindowManager |
| 24 | -import kotlinx.coroutines.* | |
| 25 | +import kotlinx.coroutines.CoroutineScope | |
| 26 | +import kotlinx.coroutines.Dispatchers | |
| 27 | +import kotlinx.coroutines.ExperimentalCoroutinesApi | |
| 28 | +import kotlinx.coroutines.launch | |
| 25 | 29 | import java.awt.Toolkit |
| 26 | 30 | import java.awt.datatransfer.StringSelection |
| 27 | 31 | |
| @@ -323,7 +327,11 @@ | ||
| 323 | 327 | } |
| 324 | 328 | |
| 325 | 329 | "runCommand" -> { |
| 326 | - // Running commands not yet supported in JetBrains | |
| 330 | + val params = Gson().fromJson( | |
| 331 | + dataElement.toString(), | |
| 332 | + RunCommandParams::class.java | |
| 333 | + ) | |
| 334 | + ide.runCommand(params.command, params.options) | |
| 327 | 335 | respond(null) |
| 328 | 336 | } |
| 329 | 337 |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt +96 −11
| @@ -1,4 +1,3 @@ | ||
| 1 | - | |
| 2 | 1 | package com.github.continuedev.continueintellijextension.`continue` |
| 3 | 2 | |
| 4 | 3 | import com.github.continuedev.continueintellijextension.* |
| @@ -27,12 +26,14 @@ | ||
| 27 | 26 | import com.intellij.openapi.fileEditor.FileEditorManager |
| 28 | 27 | import com.intellij.openapi.project.Project |
| 29 | 28 | import com.intellij.openapi.project.guessProjectDir |
| 30 | -import com.intellij.openapi.util.IconLoader | |
| 31 | 29 | import com.intellij.openapi.vfs.LocalFileSystem |
| 32 | 30 | import com.intellij.openapi.vfs.VirtualFileManager |
| 31 | +import com.intellij.openapi.wm.ToolWindowManager | |
| 33 | 32 | import com.intellij.psi.PsiDocumentManager |
| 34 | 33 | import com.intellij.testFramework.LightVirtualFile |
| 35 | 34 | import kotlinx.coroutines.* |
| 35 | +import org.jetbrains.plugins.terminal.ShellTerminalWidget | |
| 36 | +import org.jetbrains.plugins.terminal.TerminalView | |
| 36 | 37 | import java.awt.Toolkit |
| 37 | 38 | import java.awt.datatransfer.DataFlavor |
| 38 | 39 | import java.io.BufferedReader |
| @@ -54,7 +55,7 @@ | ||
| 54 | 55 | init { |
| 55 | 56 | try { |
| 56 | 57 | val os = getOS() |
| 57 | - | |
| 58 | + | |
| 58 | 59 | if (os == OS.LINUX || os == OS.MAC) { |
| 59 | 60 | val file = File(ripgrep) |
| 60 | 61 | if (!file.canExecute()) { |
| @@ -135,7 +136,33 @@ | ||
| 135 | 136 | } |
| 136 | 137 | |
| 137 | 138 | override suspend fun getTerminalContents(): String { |
| 138 | - return "" | |
| 139 | + return withContext(Dispatchers.EDT) { | |
| 140 | + try { | |
| 141 | + val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Terminal") | |
| 142 | + | |
| 143 | + val terminalView = TerminalView.getInstance(project) | |
| 144 | + // Find the first terminal widget selected, whatever its state, running command or not. | |
| 145 | + val widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>().firstOrNull { | |
| 146 | + toolWindow?.getContentManager()?.getContent(it)?.isSelected ?: false | |
| 147 | + } | |
| 148 | + | |
| 149 | + if (widget != null) { | |
| 150 | + val textBuffer = widget.terminalTextBuffer | |
| 151 | + val stringBuilder = StringBuilder() | |
| 152 | + // Iterate through all lines in the buffer (history + screen) | |
| 153 | + for (i in 0 until textBuffer.historyLinesCount + textBuffer.screenLinesCount) { | |
| 154 | + stringBuilder.append(textBuffer.getLine(i).text).append('\n') | |
| 155 | + } | |
| 156 | + stringBuilder.toString() | |
| 157 | + } else { | |
| 158 | + "" // Return empty if no terminal is available | |
| 159 | + } | |
| 160 | + } catch (e: Exception) { | |
| 161 | + println("Error getting terminal contents: ${e.message}") | |
| 162 | + e.printStackTrace() | |
| 163 | + "" // Return empty on error | |
| 164 | + } | |
| 165 | + } | |
| 139 | 166 | } |
| 140 | 167 | |
| 141 | 168 | override suspend fun getDebugLocals(threadIndex: Int): String { |
| @@ -220,8 +247,65 @@ | ||
| 220 | 247 | } |
| 221 | 248 | } |
| 222 | 249 | |
| 223 | - override suspend fun runCommand(command: String) { | |
| 224 | - throw NotImplementedError("runCommand not implemented in IntelliJ") | |
| 250 | + override suspend fun runCommand(command: String, options: TerminalOptions?) { | |
| 251 | + val terminalOptions = | |
| 252 | + options ?: TerminalOptions(reuseTerminal = true, terminalName = null, waitForCompletion = false) | |
| 253 | + | |
| 254 | + ApplicationManager.getApplication().invokeLater { | |
| 255 | + try { | |
| 256 | + val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Terminal") | |
| 257 | + toolWindow?.activate({ | |
| 258 | + try { | |
| 259 | + val terminalView = TerminalView.getInstance(project) | |
| 260 | + var widget: ShellTerminalWidget? = null | |
| 261 | + | |
| 262 | + // 1. Handle reuseTerminal option | |
| 263 | + if (terminalOptions.reuseTerminal == true && terminalView.getWidgets().isNotEmpty()) { | |
| 264 | + // 2. Find by terminalName if provided | |
| 265 | + if (terminalOptions.terminalName != null) { | |
| 266 | + widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>() | |
| 267 | + .firstOrNull { | |
| 268 | + toolWindow.contentManager.getContent(it).tabName == terminalOptions.terminalName | |
| 269 | + && !it.hasRunningCommands() | |
| 270 | + } | |
| 271 | + } else { | |
| 272 | + // 3. Find active terminal, or fall back to the first one | |
| 273 | + widget = terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>() | |
| 274 | + .firstOrNull { toolWindow.contentManager.getContent(it).isSelected } | |
| 275 | + ?: terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>().firstOrNull { | |
| 276 | + !it.hasRunningCommands() | |
| 277 | + } | |
| 278 | + } | |
| 279 | + } | |
| 280 | + | |
| 281 | + // 4. Create a new terminal if needed | |
| 282 | + if (widget == null) { | |
| 283 | + widget = terminalView.createLocalShellWidget( | |
| 284 | + project.basePath, | |
| 285 | + terminalOptions.terminalName, | |
| 286 | + true | |
| 287 | + ) | |
| 288 | + } else { | |
| 289 | + // Ensure the found widget is visible | |
| 290 | + val content = toolWindow.contentManager.getContent(widget) | |
| 291 | + if (content != null) { | |
| 292 | + toolWindow.contentManager.setSelectedContent(content, true) | |
| 293 | + } | |
| 294 | + } | |
| 295 | + | |
| 296 | + // 5. Show and send text | |
| 297 | + widget.ttyConnector?.write(command) | |
| 298 | + | |
| 299 | + } catch (e: Exception) { | |
| 300 | + println("Error during terminal widget handling: ${e.message}") | |
| 301 | + e.printStackTrace() | |
| 302 | + } | |
| 303 | + }, true) | |
| 304 | + } catch (e: Exception) { | |
| 305 | + println("Error activating terminal tool window: ${e.message}") | |
| 306 | + e.printStackTrace() | |
| 307 | + } | |
| 308 | + } | |
| 225 | 309 | } |
| 226 | 310 | |
| 227 | 311 | override suspend fun saveFile(filepath: String) { |
| @@ -343,7 +427,7 @@ | ||
| 343 | 427 | } |
| 344 | 428 | |
| 345 | 429 | val command = GeneralCommandLine(commandArgs) |
| 346 | - | |
| 430 | + | |
| 347 | 431 | command.setWorkDirectory(project.basePath) |
| 348 | 432 | val results = ExecUtil.execAndGetOutput(command).stdout |
| 349 | 433 | return results.split("\n") |
| @@ -357,11 +441,12 @@ | ||
| 357 | 441 | throw NotImplementedError("Ripgrep not supported, this workspace is remote") |
| 358 | 442 | } |
| 359 | 443 | } |
| 444 | + | |
| 360 | 445 | override suspend fun getSearchResults(query: String, maxResults: Int?): String { |
| 361 | 446 | val ideInfo = this.getIdeInfo() |
| 362 | 447 | if (ideInfo.remoteName == "local") { |
| 363 | 448 | try { |
| 364 | - val commandArgs = mutableListOf( | |
| 449 | + val commandArgs = mutableListOf( | |
| 365 | 450 | ripgrep, |
| 366 | 451 | "-i", |
| 367 | 452 | "--ignore-file", |
| @@ -372,20 +457,20 @@ | ||
| 372 | 457 | "2", |
| 373 | 458 | "--heading" |
| 374 | 459 | ) |
| 375 | - | |
| 460 | + | |
| 376 | 461 | // Conditionally add maxResults flag |
| 377 | 462 | if (maxResults != null) { |
| 378 | 463 | commandArgs.add("-m") |
| 379 | 464 | commandArgs.add(maxResults.toString()) |
| 380 | 465 | } |
| 381 | - | |
| 466 | + | |
| 382 | 467 | // Add the search query and path |
| 383 | 468 | commandArgs.add("-e") |
| 384 | 469 | commandArgs.add(query) |
| 385 | 470 | commandArgs.add(".") |
| 386 | 471 | |
| 387 | 472 | val command = GeneralCommandLine(commandArgs) |
| 388 | - | |
| 473 | + | |
| 389 | 474 | command.setWorkDirectory(project.basePath) |
| 390 | 475 | return ExecUtil.execAndGetOutput(command).stdout |
| 391 | 476 | } catch (exception: Exception) { |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ide.kt +5 −2
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | package com.github.continuedev.continueintellijextension.protocol |
| 2 | 2 | |
| 3 | -import com.github.continuedev.continueintellijextension.* | |
| 3 | +import com.github.continuedev.continueintellijextension.Range | |
| 4 | +import com.github.continuedev.continueintellijextension.TerminalOptions | |
| 4 | 5 | |
| 5 | 6 | data class GetControlPlaneSessionInfoParams(val silent: Boolean, val useOnboarding: Boolean) |
| 6 | 7 | |
| @@ -59,4 +60,6 @@ | ||
| 59 | 60 | |
| 60 | 61 | data class ListDirParams(val dir: String) |
| 61 | 62 | |
| 62 | -data class GetFileStatsParams(val files: List<String>) | |
| No newline at the end of the file | ||
| 63 | +data class GetFileStatsParams(val files: List<String>) | |
| 64 | + | |
| 65 | +data class RunCommandParams(val command: String, val options: TerminalOptions?) |
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/types.kt +7 −2
| @@ -153,6 +153,11 @@ | ||
| 153 | 153 | val mergeBehavior: ConfigMergeType |
| 154 | 154 | ) |
| 155 | 155 | |
| 156 | +data class TerminalOptions( | |
| 157 | + val reuseTerminal: Boolean?, | |
| 158 | + val terminalName: String?, | |
| 159 | + val waitForCompletion: Boolean? | |
| 160 | +) | |
| 156 | 161 | |
| 157 | 162 | interface IDE { |
| 158 | 163 | suspend fun getIdeInfo(): IdeInfo |
| @@ -196,7 +201,7 @@ | ||
| 196 | 201 | |
| 197 | 202 | suspend fun openUrl(url: String) |
| 198 | 203 | |
| 199 | - suspend fun runCommand(command: String) | |
| 204 | + suspend fun runCommand(command: String, options: TerminalOptions?) | |
| 200 | 205 | |
| 201 | 206 | suspend fun saveFile(filepath: String) |
| 202 | 207 | |
| @@ -317,4 +322,4 @@ | ||
| 317 | 322 | sealed class FimResult { |
| 318 | 323 | data class FimEdit(val fimText: String) : FimResult() |
| 319 | 324 | object NotFimEdit : FimResult() |
| 320 | -} | |
| No newline at the end of the file | ||
| 325 | +} |
modified extensions/intellij/src/main/resources/META-INF/plugin.xml +1 −0
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | <![CDATA[View the latest release notes on <a href="https://github.com/continuedev/continue/releases">GitHub</a>]]></change-notes> |
| 8 | 8 | |
| 9 | 9 | <depends>com.intellij.modules.platform</depends> |
| 10 | + <depends>org.jetbrains.plugins.terminal</depends> | |
| 10 | 11 | |
| 11 | 12 | <!-- See here for why this is optional: https://github.com/continuedev/continue/issues/2775#issuecomment-2535620877--> |
| 12 | 13 | <depends optional="true" config-file="continueintellijextension-withJSON.xml"> |
modified gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/RunInTerminalButton.tsx +0 −6
| @@ -2,7 +2,6 @@ | ||
| 2 | 2 | import { useContext } from "react"; |
| 3 | 3 | import { lightGray, vscForeground } from "../.."; |
| 4 | 4 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 5 | -import { isJetBrains } from "../../../util"; | |
| 6 | 5 | import { extractCommand } from "../utils/commandExtractor"; |
| 7 | 6 | |
| 8 | 7 | interface RunInTerminalButtonProps { |
| @@ -12,11 +11,6 @@ | ||
| 12 | 11 | export function RunInTerminalButton({ command }: RunInTerminalButtonProps) { |
| 13 | 12 | const ideMessenger = useContext(IdeMessengerContext); |
| 14 | 13 | |
| 15 | - if (isJetBrains()) { | |
| 16 | - // JetBrains plugin doesn't currently have a way to run the command in the terminal for the user | |
| 17 | - return null; | |
| 18 | - } | |
| 19 | - | |
| 20 | 14 | function runInTerminal() { |
| 21 | 15 | // Extract just the command line |
| 22 | 16 | const extractedCommand = extractCommand(command); |