summaryrefslogtreecommitdiffhomepage
path: root/sdks/vscode/src
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-07-20 11:33:41 -0400
committerFrank <[email protected]>2025-07-20 11:33:44 -0400
commit0e1565449e4d89c0d7780436b2dd1d777e8447ba (patch)
treebf6b54652ac8c3eb74b601bfb484343837221b4a /sdks/vscode/src
parentf9a47fe5a387bc36f74a3af30638deda3a591259 (diff)
downloadopencode-0e1565449e4d89c0d7780436b2dd1d777e8447ba.tar.gz
opencode-0e1565449e4d89c0d7780436b2dd1d777e8447ba.zip
wip: vscode extension
Diffstat (limited to 'sdks/vscode/src')
-rw-r--r--sdks/vscode/src/extension.ts79
-rw-r--r--sdks/vscode/src/test/extension.test.ts15
2 files changed, 94 insertions, 0 deletions
diff --git a/sdks/vscode/src/extension.ts b/sdks/vscode/src/extension.ts
new file mode 100644
index 000000000..ce5cf5bf3
--- /dev/null
+++ b/sdks/vscode/src/extension.ts
@@ -0,0 +1,79 @@
+// This method is called when your extension is deactivated
+export function deactivate() {}
+
+import * as vscode from "vscode";
+
+export function activate(context: vscode.ExtensionContext) {
+ 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,
+ },
+ });
+
+ // Show the terminal
+ terminal.show();
+
+ // Send the opencode command to the terminal
+ terminal.sendText("opencode");
+ }
+ );
+
+ // Register command to add filepath to terminal
+ 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;
+ }
+
+ const document = activeEditor.document;
+ const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
+
+ 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}`;
+
+ // 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}`;
+ }
+ }
+
+ // Get or create terminal
+ let terminal = vscode.window.activeTerminal;
+ if (terminal?.name === TERMINAL_NAME) {
+ terminal.sendText(filepathWithAt);
+ terminal.show();
+ }
+ }
+ );
+
+ context.subscriptions.push(openTerminalDisposable, addFilepathDisposable);
+}
diff --git a/sdks/vscode/src/test/extension.test.ts b/sdks/vscode/src/test/extension.test.ts
new file mode 100644
index 000000000..4ca0ab419
--- /dev/null
+++ b/sdks/vscode/src/test/extension.test.ts
@@ -0,0 +1,15 @@
+import * as assert from 'assert';
+
+// You can import and use all API from the 'vscode' module
+// as well as import your extension to test it
+import * as vscode from 'vscode';
+// import * as myExtension from '../../extension';
+
+suite('Extension Test Suite', () => {
+ vscode.window.showInformationMessage('Start all tests.');
+
+ test('Sample test', () => {
+ assert.strictEqual(-1, [1, 2, 3].indexOf(5));
+ assert.strictEqual(-1, [1, 2, 3].indexOf(0));
+ });
+});