From 3f56943f0155db8a4b787e726c497ecc55c9fcd1 Mon Sep 17 00:00:00 2001 From: frelodev Date: Sun, 1 Oct 2023 10:54:08 +0200 Subject: [PATCH] New features: attaching to buffers --- package.json | 4 ++++ src/extension.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/package.json b/package.json index 384192b..096e8f2 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,10 @@ "command": "codempvscode.createBuffer", "title": "create a codemp buffer" }, + { + "command": "codempvscode.attach", + "title": "attach to a codemp workspace" + }, { "command": "codempvscode.helloWorld", "title": "Hello World (debug)" diff --git a/src/extension.ts b/src/extension.ts index dfd2253..f0ad268 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -27,9 +27,11 @@ export function activate(context: vscode.ExtensionContext) { }); let connectCommand = vscode.commands.registerCommand('codempvscode.connect', connect); let joinCommand = vscode.commands.registerCommand('codempvscode.join', join); + let attachCommand = vscode.commands.registerCommand('codempvscode.attach', attach); let createBufferCommand = vscode.commands.registerCommand('codempvscode.createBuffer', createBuffer); context.subscriptions.push(connectCommand); context.subscriptions.push(joinCommand); + context.subscriptions.push(attachCommand); context.subscriptions.push(createBufferCommand); context.subscriptions.push(disposable); @@ -128,6 +130,25 @@ async function createBuffer(){ +async function attach() { + let workspace="test"; + let buffer = await codemp.attach(workspace); + + let editor = vscode.window.activeTextEditor; + + if (editor === undefined) { return } // TODO say something!!!!!! + + let range = new vscode.Range( + editor.document.positionAt(0), + editor.document.positionAt(editor.document.getText().length) + ) + await editor.edit(editBuilder => editBuilder.replace(range, buffer.content())) + + console.log("Buffer = ", buffer, "\n"); + vscode.window.showInformationMessage(`Connected to codemp workspace buffer @[${workspace}]`); + +} +