diff options
| author | David Hill <[email protected]> | 2025-11-10 13:44:12 +0000 |
|---|---|---|
| committer | David Hill <[email protected]> | 2025-11-10 13:44:12 +0000 |
| commit | c6e830c954418808dc39284a1c073aa63a6d4d21 (patch) | |
| tree | 9c3052e0509115188768a553c0be5a8441ebdd96 /sdks | |
| parent | 7088bfabd773e2f076aab1c9d2468c04feff0570 (diff) | |
| parent | fc78c28df64383a9f99382093f61fc28caf6569f (diff) | |
| download | opencode-c6e830c954418808dc39284a1c073aa63a6d4d21.tar.gz opencode-c6e830c954418808dc39284a1c073aa63a6d4d21.zip | |
Merge branch 'dev' of https://github.com/sst/opencode into dev
Diffstat (limited to 'sdks')
| -rw-r--r-- | sdks/vscode/package.json | 2 | ||||
| -rw-r--r-- | sdks/vscode/src/extension.ts | 106 | ||||
| -rw-r--r-- | sdks/vscode/sst-env.d.ts | 2 |
3 files changed, 60 insertions, 50 deletions
diff --git a/sdks/vscode/package.json b/sdks/vscode/package.json index 6a8ed497a..80ac0922a 100644 --- a/sdks/vscode/package.json +++ b/sdks/vscode/package.json @@ -2,7 +2,7 @@ "name": "opencode", "displayName": "opencode", "description": "opencode for VS Code", - "version": "1.0.23", + "version": "1.0.55", "publisher": "sst-dev", "repository": { "type": "git", diff --git a/sdks/vscode/src/extension.ts b/sdks/vscode/src/extension.ts index 77c70513f..63d8d332e 100644 --- a/sdks/vscode/src/extension.ts +++ b/sdks/vscode/src/extension.ts @@ -1,46 +1,50 @@ // This method is called when your extension is deactivated export function deactivate() {} -import * as vscode from "vscode"; +import * as vscode from "vscode" -const TERMINAL_NAME = "opencode"; +const TERMINAL_NAME = "opencode" export function activate(context: vscode.ExtensionContext) { let openNewTerminalDisposable = vscode.commands.registerCommand("opencode.openNewTerminal", async () => { - await openTerminal(); - }); + await openTerminal() + }) let openTerminalDisposable = vscode.commands.registerCommand("opencode.openTerminal", async () => { // An opencode terminal already exists => focus it - const existingTerminal = vscode.window.terminals.find((t) => t.name === TERMINAL_NAME); + const existingTerminal = vscode.window.terminals.find((t) => t.name === TERMINAL_NAME) if (existingTerminal) { - existingTerminal.show(); - return; + existingTerminal.show() + return } - await openTerminal(); - }); + await openTerminal() + }) let addFilepathDisposable = vscode.commands.registerCommand("opencode.addFilepathToTerminal", async () => { - const fileRef = getActiveFile(); - if (!fileRef) {return;} + const fileRef = getActiveFile() + if (!fileRef) { + return + } - const terminal = vscode.window.activeTerminal; - if (!terminal) {return;} + const terminal = vscode.window.activeTerminal + if (!terminal) { + return + } if (terminal.name === TERMINAL_NAME) { // @ts-ignore - const port = terminal.creationOptions.env?.["_EXTENSION_OPENCODE_PORT"]; - port ? await appendPrompt(parseInt(port), fileRef) : terminal.sendText(fileRef); - terminal.show(); + const port = terminal.creationOptions.env?.["_EXTENSION_OPENCODE_PORT"] + port ? await appendPrompt(parseInt(port), fileRef) : terminal.sendText(fileRef) + terminal.show() } - }); + }) - context.subscriptions.push(openTerminalDisposable, addFilepathDisposable); + context.subscriptions.push(openTerminalDisposable, addFilepathDisposable) async function openTerminal() { // Create a new terminal in split screen - const port = Math.floor(Math.random() * (65535 - 16384 + 1)) + 16384; + const port = Math.floor(Math.random() * (65535 - 16384 + 1)) + 16384 const terminal = vscode.window.createTerminal({ name: TERMINAL_NAME, iconPath: { @@ -55,32 +59,34 @@ export function activate(context: vscode.ExtensionContext) { _EXTENSION_OPENCODE_PORT: port.toString(), OPENCODE_CALLER: "vscode", }, - }); + }) - terminal.show(); - terminal.sendText(`opencode --port ${port}`); + terminal.show() + terminal.sendText(`opencode --port ${port}`) - const fileRef = getActiveFile(); - if (!fileRef) {return;} + const fileRef = getActiveFile() + if (!fileRef) { + return + } // Wait for the terminal to be ready - let tries = 10; - let connected = false; + let tries = 10 + let connected = false do { - await new Promise((resolve) => setTimeout(resolve, 200)); + await new Promise((resolve) => setTimeout(resolve, 200)) try { - await fetch(`http://localhost:${port}/app`); - connected = true; - break; + await fetch(`http://localhost:${port}/app`) + connected = true + break } catch (e) {} - tries--; - } while (tries > 0); + tries-- + } while (tries > 0) // If connected, append the prompt to the terminal if (connected) { - await appendPrompt(port, `In ${fileRef}`); - terminal.show(); + await appendPrompt(port, `In ${fileRef}`) + terminal.show() } } @@ -91,37 +97,41 @@ export function activate(context: vscode.ExtensionContext) { "Content-Type": "application/json", }, body: JSON.stringify({ text }), - }); + }) } function getActiveFile() { - const activeEditor = vscode.window.activeTextEditor; - if (!activeEditor) {return;} + const activeEditor = vscode.window.activeTextEditor + if (!activeEditor) { + return + } - const document = activeEditor.document; - const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri); - if (!workspaceFolder) {return;} + const document = activeEditor.document + const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri) + if (!workspaceFolder) { + return + } // Get the relative path from workspace root - const relativePath = vscode.workspace.asRelativePath(document.uri); - let filepathWithAt = `@${relativePath}`; + const relativePath = vscode.workspace.asRelativePath(document.uri) + let filepathWithAt = `@${relativePath}` // Check if there's a selection and add line numbers - const selection = activeEditor.selection; + const selection = activeEditor.selection if (!selection.isEmpty) { // Convert to 1-based line numbers - const startLine = selection.start.line + 1; - const endLine = selection.end.line + 1; + const startLine = selection.start.line + 1 + const endLine = selection.end.line + 1 if (startLine === endLine) { // Single line selection - filepathWithAt += `#L${startLine}`; + filepathWithAt += `#L${startLine}` } else { // Multi-line selection - filepathWithAt += `#L${startLine}-${endLine}`; + filepathWithAt += `#L${startLine}-${endLine}` } } - return filepathWithAt; + return filepathWithAt } } diff --git a/sdks/vscode/sst-env.d.ts b/sdks/vscode/sst-env.d.ts index b6a7e9066..0397645b5 100644 --- a/sdks/vscode/sst-env.d.ts +++ b/sdks/vscode/sst-env.d.ts @@ -6,4 +6,4 @@ /// <reference path="../../sst-env.d.ts" /> import "sst" -export {}
\ No newline at end of file +export {} |
