Build Rider and graph bridge slice
This commit is contained in:
parent
2901b51802
commit
afdfa230c7
25 changed files with 1421 additions and 28 deletions
|
|
@ -0,0 +1,69 @@
|
|||
package dev.epiphany.rider
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import java.io.File
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class EpiphanyBridgeClient(private val project: Project) {
|
||||
private val projectRoot: File = File(project.basePath ?: ".").absoluteFile
|
||||
private val epiphanyRoot: File = findEpiphanyRoot()
|
||||
|
||||
fun status(): String {
|
||||
return runBridge(listOf("status", "--project-root", projectRoot.absolutePath))
|
||||
}
|
||||
|
||||
fun captureContext(filePath: String, startLine: Int?, endLine: Int?): String {
|
||||
val args = mutableListOf(
|
||||
"context",
|
||||
"--project-root",
|
||||
projectRoot.absolutePath,
|
||||
"--file",
|
||||
filePath,
|
||||
)
|
||||
if (startLine != null) {
|
||||
args.add("--selection-start")
|
||||
args.add(startLine.toString())
|
||||
}
|
||||
if (endLine != null) {
|
||||
args.add("--selection-end")
|
||||
args.add(endLine.toString())
|
||||
}
|
||||
return runBridge(args)
|
||||
}
|
||||
|
||||
private fun runBridge(args: List<String>): String {
|
||||
val script = File(epiphanyRoot, "tools/epiphany_rider_bridge.py")
|
||||
val artifactRoot = System.getenv("EPIPHANY_RIDER_ARTIFACT_ROOT")
|
||||
?: File(epiphanyRoot, ".epiphany-gui/rider").absolutePath
|
||||
val command = mutableListOf(pythonPath(), script.absolutePath)
|
||||
command.addAll(args)
|
||||
command.add("--artifact-root")
|
||||
command.add(artifactRoot)
|
||||
|
||||
val process = ProcessBuilder(command)
|
||||
.directory(epiphanyRoot)
|
||||
.redirectErrorStream(true)
|
||||
.start()
|
||||
val output = process.inputStream.readBytes().toString(StandardCharsets.UTF_8)
|
||||
process.waitFor(30, TimeUnit.SECONDS)
|
||||
return output.ifBlank { "Epiphany bridge returned no output." }
|
||||
}
|
||||
|
||||
private fun pythonPath(): String {
|
||||
return System.getenv("EPIPHANY_PYTHON")
|
||||
?: "C:\\Users\\Meta\\.cache\\codex-runtimes\\codex-primary-runtime\\dependencies\\python\\python.exe"
|
||||
}
|
||||
|
||||
private fun findEpiphanyRoot(): File {
|
||||
System.getenv("EPIPHANY_REPO_ROOT")?.let { return File(it).absoluteFile }
|
||||
var cursor: File? = projectRoot
|
||||
while (cursor != null) {
|
||||
if (File(cursor, "tools/epiphany_rider_bridge.py").exists()) {
|
||||
return cursor
|
||||
}
|
||||
cursor = cursor.parentFile
|
||||
}
|
||||
return File("E:\\Projects\\EpiphanyAgent")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package dev.epiphany.rider
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.ui.Messages
|
||||
|
||||
class EpiphanyCaptureContextAction : AnAction() {
|
||||
override fun actionPerformed(event: AnActionEvent) {
|
||||
val project = event.project ?: return
|
||||
val editor = event.getData(CommonDataKeys.EDITOR)
|
||||
val file = event.getData(CommonDataKeys.VIRTUAL_FILE)
|
||||
if (file == null) {
|
||||
Messages.showWarningDialog(project, "No file is selected.", "Epiphany")
|
||||
return
|
||||
}
|
||||
|
||||
val document = editor?.document
|
||||
val selection = editor?.selectionModel
|
||||
val startLine = if (document != null && selection?.hasSelection() == true) {
|
||||
document.getLineNumber(selection.selectionStart) + 1
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val endLine = if (document != null && selection?.hasSelection() == true) {
|
||||
document.getLineNumber(selection.selectionEnd) + 1
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val output = EpiphanyBridgeClient(project).captureContext(file.path, startLine, endLine)
|
||||
Messages.showInfoMessage(project, output.take(1200), "Epiphany Context Captured")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package dev.epiphany.rider
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.wm.ToolWindow
|
||||
import com.intellij.openapi.wm.ToolWindowFactory
|
||||
import com.intellij.ui.content.ContentFactory
|
||||
import java.awt.BorderLayout
|
||||
import javax.swing.JButton
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.JScrollPane
|
||||
import javax.swing.JTextArea
|
||||
|
||||
class EpiphanyToolWindowFactory : ToolWindowFactory {
|
||||
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
|
||||
val output = JTextArea()
|
||||
output.isEditable = false
|
||||
output.lineWrap = true
|
||||
output.wrapStyleWord = true
|
||||
output.text = "Epiphany Rider bridge is ready. Click Refresh to capture a source-context status receipt."
|
||||
|
||||
val refresh = JButton("Refresh")
|
||||
refresh.addActionListener {
|
||||
output.text = EpiphanyBridgeClient(project).status()
|
||||
}
|
||||
|
||||
val panel = JPanel(BorderLayout(8, 8))
|
||||
panel.add(refresh, BorderLayout.NORTH)
|
||||
panel.add(JScrollPane(output), BorderLayout.CENTER)
|
||||
|
||||
val content = ContentFactory.getInstance().createContent(panel, "", false)
|
||||
toolWindow.contentManager.addContent(content)
|
||||
}
|
||||
}
|
||||
25
integrations/rider/src/main/resources/META-INF/plugin.xml
Normal file
25
integrations/rider/src/main/resources/META-INF/plugin.xml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<idea-plugin>
|
||||
<id>dev.epiphany.rider</id>
|
||||
<name>Epiphany</name>
|
||||
<vendor>GameCult</vendor>
|
||||
|
||||
<depends>com.intellij.modules.platform</depends>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<toolWindow
|
||||
id="Epiphany"
|
||||
anchor="right"
|
||||
factoryClass="dev.epiphany.rider.EpiphanyToolWindowFactory" />
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<action
|
||||
id="Epiphany.CaptureContext"
|
||||
class="dev.epiphany.rider.EpiphanyCaptureContextAction"
|
||||
text="Send Context to Epiphany"
|
||||
description="Write the current Rider file and selection as an Epiphany source-context artifact.">
|
||||
<add-to-group group-id="EditorPopupMenu" anchor="last" />
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl alt E" />
|
||||
</action>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
Reference in a new issue