summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-07-21 15:48:42 -0400
committerFrank <[email protected]>2025-07-21 15:48:46 -0400
commit0bd8b2c72f0ef91e18377550f118d0b1b1ef928b (patch)
tree6d4790406eda1d6434a8983ac8d27a3988bd8237
parent5550ce47e14025c8b040e4df91fa6368233839dd (diff)
downloadopencode-0bd8b2c72f0ef91e18377550f118d0b1b1ef928b.tar.gz
opencode-0bd8b2c72f0ef91e18377550f118d0b1b1ef928b.zip
wip: vscode extension
-rw-r--r--sdks/vscode/src/extension.ts107
1 files changed, 49 insertions, 58 deletions
diff --git a/sdks/vscode/src/extension.ts b/sdks/vscode/src/extension.ts
index ce5cf5bf3..a183ef09a 100644
--- a/sdks/vscode/src/extension.ts
+++ b/sdks/vscode/src/extension.ts
@@ -1,79 +1,70 @@
// This method is called when your extension is deactivated
export function deactivate() {}
-import * as vscode from "vscode";
+import * as vscode from "vscode"
export function activate(context: vscode.ExtensionContext) {
- const TERMINAL_NAME = "opencode Terminal";
+ const TERMINAL_NAME = "opencode Terminal"
// Register command to open terminal in split screen and run opencode
- let openTerminalDisposable = vscode.commands.registerCommand(
- "opencode.openTerminal",
- async () => {
- // Create a new terminal in split screen
- const terminal = vscode.window.createTerminal({
- name: TERMINAL_NAME,
- location: {
- viewColumn: vscode.ViewColumn.Beside,
- preserveFocus: false,
- },
- });
+ let openTerminalDisposable = vscode.commands.registerCommand("opencode.openTerminal", async () => {
+ // Create a new terminal in split screen
+ const terminal = vscode.window.createTerminal({
+ name: TERMINAL_NAME,
+ location: {
+ viewColumn: vscode.ViewColumn.Beside,
+ preserveFocus: false,
+ },
+ })
- // Show the terminal
- terminal.show();
-
- // Send the opencode command to the terminal
- terminal.sendText("opencode");
- }
- );
+ terminal.show()
+ terminal.sendText("OPENCODE_THEME=system OPENCODE_CALLER=vscode opencode")
+ })
// Register command to add filepath to terminal
- let addFilepathDisposable = vscode.commands.registerCommand(
- "opencode.addFilepathToTerminal",
- async () => {
- const activeEditor = vscode.window.activeTextEditor;
+ let addFilepathDisposable = vscode.commands.registerCommand("opencode.addFilepathToTerminal", async () => {
+ const activeEditor = vscode.window.activeTextEditor
- if (!activeEditor) {
- vscode.window.showInformationMessage("No active file to get path from");
- return;
- }
+ if (!activeEditor) {
+ vscode.window.showInformationMessage("No active file to get path from")
+ return
+ }
- const document = activeEditor.document;
- const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
+ const document = activeEditor.document
+ const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri)
- if (!workspaceFolder) {
- vscode.window.showInformationMessage("File is not in a workspace");
- return;
- }
+ if (!workspaceFolder) {
+ vscode.window.showInformationMessage("File is not in a workspace")
+ return
+ }
- // Get the relative path from workspace root
- const relativePath = vscode.workspace.asRelativePath(document.uri);
- let filepathWithAt = `@${relativePath}`;
+ // Get the relative path from workspace root
+ const relativePath = vscode.workspace.asRelativePath(document.uri)
+ let filepathWithAt = `@${relativePath}`
- // Check if there's a selection and add line numbers
- 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;
+ // Check if there's a selection and add line numbers
+ 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
- if (startLine === endLine) {
- // Single line selection
- filepathWithAt += `#L${startLine}`;
- } else {
- // Multi-line selection
- filepathWithAt += `#L${startLine}-${endLine}`;
- }
+ if (startLine === endLine) {
+ // Single line selection
+ filepathWithAt += `#L${startLine}`
+ } else {
+ // Multi-line selection
+ filepathWithAt += `#L${startLine}-${endLine}`
}
+ }
- // Get or create terminal
- let terminal = vscode.window.activeTerminal;
- if (terminal?.name === TERMINAL_NAME) {
- terminal.sendText(filepathWithAt);
- terminal.show();
- }
+ // Get or create terminal
+ let terminal = vscode.window.activeTerminal
+ if (terminal?.name === TERMINAL_NAME) {
+ terminal.sendText(filepathWithAt)
+ terminal.show()
}
- );
+ })
- context.subscriptions.push(openTerminalDisposable, addFilepathDisposable);
+ context.subscriptions.push(openTerminalDisposable, addFilepathDisposable)
}