New features: attaching to buffers

This commit is contained in:
frelodev 2023-10-01 10:54:08 +02:00
parent ed859f0630
commit 3f56943f01
2 changed files with 25 additions and 0 deletions

View file

@ -27,6 +27,10 @@
"command": "codempvscode.createBuffer", "command": "codempvscode.createBuffer",
"title": "create a codemp buffer" "title": "create a codemp buffer"
}, },
{
"command": "codempvscode.attach",
"title": "attach to a codemp workspace"
},
{ {
"command": "codempvscode.helloWorld", "command": "codempvscode.helloWorld",
"title": "Hello World (debug)" "title": "Hello World (debug)"

View file

@ -27,9 +27,11 @@ export function activate(context: vscode.ExtensionContext) {
}); });
let connectCommand = vscode.commands.registerCommand('codempvscode.connect', connect); let connectCommand = vscode.commands.registerCommand('codempvscode.connect', connect);
let joinCommand = vscode.commands.registerCommand('codempvscode.join', join); let joinCommand = vscode.commands.registerCommand('codempvscode.join', join);
let attachCommand = vscode.commands.registerCommand('codempvscode.attach', attach);
let createBufferCommand = vscode.commands.registerCommand('codempvscode.createBuffer', createBuffer); let createBufferCommand = vscode.commands.registerCommand('codempvscode.createBuffer', createBuffer);
context.subscriptions.push(connectCommand); context.subscriptions.push(connectCommand);
context.subscriptions.push(joinCommand); context.subscriptions.push(joinCommand);
context.subscriptions.push(attachCommand);
context.subscriptions.push(createBufferCommand); context.subscriptions.push(createBufferCommand);
context.subscriptions.push(disposable); 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}]`);
}