Changesets · Branches · Tags · Compare
| Changeset | ce2e334291621f5b3dcf12269e0cc0724f77f945a15d6058270b19ef9735e47f |
|---|---|
| Author | zimu <zimu@mgtv.com> · 2025-07-18 17:21 +08:00 |
| Committer | zimu <zimu@mgtv.com> · 2025-07-21 09:56 +08:00 |
| Parents | 9df0fa5d79c7 |
2 files changed
modified extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IntelliJIde.kt +33 −8
| @@ -27,12 +27,13 @@ | ||
| 27 | 27 | import com.intellij.openapi.fileEditor.FileEditorManager |
| 28 | 28 | import com.intellij.openapi.project.Project |
| 29 | 29 | import com.intellij.openapi.project.guessProjectDir |
| 30 | -import com.intellij.openapi.util.IconLoader | |
| 31 | 30 | import com.intellij.openapi.vfs.LocalFileSystem |
| 32 | 31 | import com.intellij.openapi.vfs.VirtualFileManager |
| 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,30 @@ | ||
| 135 | 136 | } |
| 136 | 137 | |
| 137 | 138 | override suspend fun getTerminalContents(): String { |
| 138 | - return "" | |
| 139 | + return withContext(Dispatchers.EDT) { | |
| 140 | + try { | |
| 141 | + val terminalView = TerminalView.getInstance(project) | |
| 142 | + // Find the first terminal widget available, whatever its state. | |
| 143 | + val widget = | |
| 144 | + terminalView.getWidgets().filterIsInstance<ShellTerminalWidget>().firstOrNull { it.isEnabled } | |
| 145 | + | |
| 146 | + if (widget != null) { | |
| 147 | + val textBuffer = widget.terminalTextBuffer | |
| 148 | + val stringBuilder = StringBuilder() | |
| 149 | + // Iterate through all lines in the buffer (history + screen) | |
| 150 | + for (i in 0 until textBuffer.historyLinesCount + textBuffer.screenLinesCount) { | |
| 151 | + stringBuilder.append(textBuffer.getLine(i).text).append('\n') | |
| 152 | + } | |
| 153 | + stringBuilder.toString() | |
| 154 | + } else { | |
| 155 | + "" // Return empty if no terminal is available | |
| 156 | + } | |
| 157 | + } catch (e: Exception) { | |
| 158 | + println("Error getting terminal contents: ${e.message}") | |
| 159 | + e.printStackTrace() | |
| 160 | + "" // Return empty on error | |
| 161 | + } | |
| 162 | + } | |
| 139 | 163 | } |
| 140 | 164 | |
| 141 | 165 | override suspend fun getDebugLocals(threadIndex: Int): String { |
| @@ -343,7 +367,7 @@ | ||
| 343 | 367 | } |
| 344 | 368 | |
| 345 | 369 | val command = GeneralCommandLine(commandArgs) |
| 346 | - | |
| 370 | + | |
| 347 | 371 | command.setWorkDirectory(project.basePath) |
| 348 | 372 | val results = ExecUtil.execAndGetOutput(command).stdout |
| 349 | 373 | return results.split("\n") |
| @@ -357,11 +381,12 @@ | ||
| 357 | 381 | throw NotImplementedError("Ripgrep not supported, this workspace is remote") |
| 358 | 382 | } |
| 359 | 383 | } |
| 384 | + | |
| 360 | 385 | override suspend fun getSearchResults(query: String, maxResults: Int?): String { |
| 361 | 386 | val ideInfo = this.getIdeInfo() |
| 362 | 387 | if (ideInfo.remoteName == "local") { |
| 363 | 388 | try { |
| 364 | - val commandArgs = mutableListOf( | |
| 389 | + val commandArgs = mutableListOf( | |
| 365 | 390 | ripgrep, |
| 366 | 391 | "-i", |
| 367 | 392 | "--ignore-file", |
| @@ -372,20 +397,20 @@ | ||
| 372 | 397 | "2", |
| 373 | 398 | "--heading" |
| 374 | 399 | ) |
| 375 | - | |
| 400 | + | |
| 376 | 401 | // Conditionally add maxResults flag |
| 377 | 402 | if (maxResults != null) { |
| 378 | 403 | commandArgs.add("-m") |
| 379 | 404 | commandArgs.add(maxResults.toString()) |
| 380 | 405 | } |
| 381 | - | |
| 406 | + | |
| 382 | 407 | // Add the search query and path |
| 383 | 408 | commandArgs.add("-e") |
| 384 | 409 | commandArgs.add(query) |
| 385 | 410 | commandArgs.add(".") |
| 386 | 411 | |
| 387 | 412 | val command = GeneralCommandLine(commandArgs) |
| 388 | - | |
| 413 | + | |
| 389 | 414 | command.setWorkDirectory(project.basePath) |
| 390 | 415 | return ExecUtil.execAndGetOutput(command).stdout |
| 391 | 416 | } catch (exception: Exception) { |
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"> |