Skip to content

Commit 13def91

Browse files
author
Frank
committed
wip: vscode extension
1 parent 26a4061 commit 13def91

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

sdks/vscode/src/extension.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ export function deactivate() {}
44
import * as vscode from "vscode"
55

66
export function activate(context: vscode.ExtensionContext) {
7+
const TERMINAL_NAME = "opencode"
8+
79
// Register command to open terminal in split screen and run opencode
810
let openTerminalDisposable = vscode.commands.registerCommand("opencode.openTerminal", async () => {
911
// Create a new terminal in split screen
1012
const port = Math.floor(Math.random() * (65535 - 16384 + 1)) + 16384
1113
const terminal = vscode.window.createTerminal({
12-
name: "opencode",
14+
name: TERMINAL_NAME,
1315
iconPath: {
1416
light: vscode.Uri.file(context.asAbsolutePath("images/button-dark.svg")),
1517
dark: vscode.Uri.file(context.asAbsolutePath("images/button-light.svg")),
@@ -23,7 +25,7 @@ export function activate(context: vscode.ExtensionContext) {
2325
},
2426
})
2527

26-
terminal.show(false)
28+
terminal.show()
2729
terminal.sendText(`OPENCODE_THEME=system OPENCODE_CALLER=vscode opencode --port ${port}`)
2830

2931
const fileRef = getActiveFile()
@@ -46,6 +48,7 @@ export function activate(context: vscode.ExtensionContext) {
4648
// If connected, append the prompt to the terminal
4749
if (connected) {
4850
await appendPrompt(port, `In ${fileRef}`)
51+
terminal.show()
4952
}
5053
})
5154

@@ -57,12 +60,12 @@ export function activate(context: vscode.ExtensionContext) {
5760
const terminal = vscode.window.activeTerminal
5861
if (!terminal) return
5962

60-
// @ts-ignore
61-
const port = terminal.creationOptions.env?.["_EXTENSION_OPENCODE_PORT"]
62-
if (!port) return
63-
64-
await appendPrompt(parseInt(port), fileRef)
65-
terminal.show()
63+
if (terminal.name === TERMINAL_NAME) {
64+
// @ts-ignore
65+
const port = terminal.creationOptions.env?.["_EXTENSION_OPENCODE_PORT"]
66+
port ? await appendPrompt(parseInt(port), fileRef) : terminal.sendText(fileRef)
67+
terminal.show()
68+
}
6669
})
6770

6871
context.subscriptions.push(openTerminalDisposable, addFilepathDisposable)

0 commit comments

Comments
 (0)