Skip to content

Commit 80fb31e

Browse files
fix(vscode): launch the V2 CLI without --port (#49084)
Co-authored-by: uyencss <[email protected]> Co-authored-by: Aiden Cline <[email protected]>
1 parent 22326d4 commit 80fb31e

1 file changed

Lines changed: 2 additions & 41 deletions

File tree

‎sdks/vscode/src/extension.ts‎

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ export function activate(context: vscode.ExtensionContext) {
3333
}
3434

3535
if (terminal.name === TERMINAL_NAME) {
36-
// @ts-ignore
37-
const port = terminal.creationOptions.env?.["_EXTENSION_OPENCODE_PORT"]
38-
port ? await appendPrompt(parseInt(port), fileRef) : terminal.sendText(fileRef, false)
36+
terminal.sendText(fileRef, false)
3937
terminal.show()
4038
}
4139
})
@@ -44,7 +42,6 @@ export function activate(context: vscode.ExtensionContext) {
4442

4543
async function openTerminal() {
4644
// Create a new terminal in split screen
47-
const port = Math.floor(Math.random() * (65535 - 16384 + 1)) + 16384
4845
const terminal = vscode.window.createTerminal({
4946
name: TERMINAL_NAME,
5047
iconPath: {
@@ -56,48 +53,12 @@ export function activate(context: vscode.ExtensionContext) {
5653
preserveFocus: false,
5754
},
5855
env: {
59-
_EXTENSION_OPENCODE_PORT: port.toString(),
6056
OPENCODE_CALLER: "vscode",
6157
},
6258
})
6359

6460
terminal.show()
65-
terminal.sendText(`opencode --port ${port}`)
66-
67-
const fileRef = getActiveFile()
68-
if (!fileRef) {
69-
return
70-
}
71-
72-
// Wait for the terminal to be ready
73-
let tries = 10
74-
let connected = false
75-
do {
76-
await new Promise((resolve) => setTimeout(resolve, 200))
77-
try {
78-
await fetch(`http://localhost:${port}/app`)
79-
connected = true
80-
break
81-
} catch {}
82-
83-
tries--
84-
} while (tries > 0)
85-
86-
// If connected, append the prompt to the terminal
87-
if (connected) {
88-
await appendPrompt(port, `In ${fileRef}`)
89-
terminal.show()
90-
}
91-
}
92-
93-
async function appendPrompt(port: number, text: string) {
94-
await fetch(`http://localhost:${port}/tui/append-prompt`, {
95-
method: "POST",
96-
headers: {
97-
"Content-Type": "application/json",
98-
},
99-
body: JSON.stringify({ text }),
100-
})
61+
terminal.sendText("opencode")
10162
}
10263

10364
function getActiveFile() {

0 commit comments

Comments
 (0)