mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-15 12:41:37 +03:00
fix(vscode): launch the V2 CLI without --port (#49084)
Co-authored-by: uyencss <uyencss@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
22326d4bc3
commit
80fb31ebb7
@@ -33,9 +33,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
|
||||
if (terminal.name === TERMINAL_NAME) {
|
||||
// @ts-ignore
|
||||
const port = terminal.creationOptions.env?.["_EXTENSION_OPENCODE_PORT"]
|
||||
port ? await appendPrompt(parseInt(port), fileRef) : terminal.sendText(fileRef, false)
|
||||
terminal.sendText(fileRef, false)
|
||||
terminal.show()
|
||||
}
|
||||
})
|
||||
@@ -44,7 +42,6 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
async function openTerminal() {
|
||||
// Create a new terminal in split screen
|
||||
const port = Math.floor(Math.random() * (65535 - 16384 + 1)) + 16384
|
||||
const terminal = vscode.window.createTerminal({
|
||||
name: TERMINAL_NAME,
|
||||
iconPath: {
|
||||
@@ -56,48 +53,12 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
preserveFocus: false,
|
||||
},
|
||||
env: {
|
||||
_EXTENSION_OPENCODE_PORT: port.toString(),
|
||||
OPENCODE_CALLER: "vscode",
|
||||
},
|
||||
})
|
||||
|
||||
terminal.show()
|
||||
terminal.sendText(`opencode --port ${port}`)
|
||||
|
||||
const fileRef = getActiveFile()
|
||||
if (!fileRef) {
|
||||
return
|
||||
}
|
||||
|
||||
// Wait for the terminal to be ready
|
||||
let tries = 10
|
||||
let connected = false
|
||||
do {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200))
|
||||
try {
|
||||
await fetch(`http://localhost:${port}/app`)
|
||||
connected = true
|
||||
break
|
||||
} catch {}
|
||||
|
||||
tries--
|
||||
} while (tries > 0)
|
||||
|
||||
// If connected, append the prompt to the terminal
|
||||
if (connected) {
|
||||
await appendPrompt(port, `In ${fileRef}`)
|
||||
terminal.show()
|
||||
}
|
||||
}
|
||||
|
||||
async function appendPrompt(port: number, text: string) {
|
||||
await fetch(`http://localhost:${port}/tui/append-prompt`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ text }),
|
||||
})
|
||||
terminal.sendText("opencode")
|
||||
}
|
||||
|
||||
function getActiveFile() {
|
||||
|
||||
Reference in New Issue
Block a user