mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 07:24:49 +01:00
feat: updated callback according to new API and added debug console logs
This commit is contained in:
parent
f5261b6a71
commit
3dca7476a7
3 changed files with 144 additions and 96 deletions
30
package.json
30
package.json
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"name": "codempvscode",
|
||||
"displayName": "codempvscode",
|
||||
"name": "codemp",
|
||||
"displayName": "codemp",
|
||||
"description": "",
|
||||
"repository": "https://github.com/codewithotherpeopleandchangenamelater/codemp-vscode",
|
||||
"repository": "",
|
||||
"version": "0.0.1",
|
||||
"napi": {
|
||||
"name": "index"
|
||||
|
@ -20,35 +20,39 @@
|
|||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "codempvscode.connect",
|
||||
"command": "codemp.connect",
|
||||
"title": "Connect to a codemp host"
|
||||
},
|
||||
{
|
||||
"command": "codempvscode.createBuffer",
|
||||
"command": "codemp.join",
|
||||
"title": "Join a codemp Workspace"
|
||||
},
|
||||
{
|
||||
"command": "codemp.createBuffer",
|
||||
"title": "Create a codemp buffer"
|
||||
},
|
||||
{
|
||||
"command": "codempvscode.listBuffers",
|
||||
"command": "codemp.listBuffers",
|
||||
"title": "List all buffers of joined Workspace"
|
||||
},
|
||||
{
|
||||
"command": "codempvscode.attach",
|
||||
"command": "codemp.attach",
|
||||
"title": "attach to a codemp workspace"
|
||||
},
|
||||
{
|
||||
"command": "codempvscode.disconnectBuffer",
|
||||
"command": "codemp.disconnectBuffer",
|
||||
"title": "disconnect from a codemp Buffer (unused)"
|
||||
},
|
||||
{
|
||||
"command": "codempvscode.sync",
|
||||
"command": "codemp.sync",
|
||||
"title": "Sync the current buffer"
|
||||
},
|
||||
{
|
||||
"command": "codempvscode.printOpCache",
|
||||
"command": "codemp.printOpCache",
|
||||
"title": "Print current OpCache"
|
||||
},
|
||||
{
|
||||
"command": "codempvscode.helloWorld",
|
||||
"command": "codemp.helloWorld",
|
||||
"title": "Hello World (debug)"
|
||||
}
|
||||
]
|
||||
|
@ -76,8 +80,8 @@
|
|||
"typescript": "^5.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemp/codemp" : "0.0.4",
|
||||
"@vscode/vsce": "^2.22.0",
|
||||
"@codemp/codemp": "0.0.8-debug",
|
||||
"@vscode/vsce": "^2.32.0",
|
||||
"npx": "^10.2.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as codemp from '@codemp/codemp'; // TODO why won't it work with a custom name???
|
||||
import * as mapping from "./mapping";
|
||||
|
@ -9,9 +11,7 @@ let MAPPINGS = new mapping.BufferMappingContainer();
|
|||
let smallNumberDecorationType = vscode.window.createTextEditorDecorationType({});
|
||||
let client: codemp.Client | null = null;
|
||||
let workspace: codemp.Workspace | null = null;
|
||||
let username : string;
|
||||
|
||||
|
||||
let username: string = "";
|
||||
|
||||
export async function connect() {
|
||||
let username = await vscode.window.showInputBox({ prompt: "enter username" });
|
||||
|
@ -24,13 +24,18 @@ export async function join() {
|
|||
let workspace_id = await vscode.window.showInputBox({ prompt: "workspace to attach (default to default)" });
|
||||
//let editor = vscode.window.activeTextEditor;
|
||||
if (workspace_id === undefined) return // user cancelled with ESC
|
||||
if (workspace_id.length == 0) workspace_id = "asd"
|
||||
if (workspace_id.length == 0) workspace_id = "diamond"
|
||||
|
||||
|
||||
if (client === null) throw "connect first";
|
||||
workspace = await client.join_workspace(workspace_id)
|
||||
let controller = workspace.cursor();
|
||||
controller.callback((event: codemp.Cursor) => {
|
||||
controller.callback(async function (controller: codemp.CursorController) {
|
||||
while (true) {
|
||||
console.log("debug 12");
|
||||
let event = await controller.try_recv();
|
||||
console.log("debug 13");
|
||||
if (event === null) break;
|
||||
let range_start: vscode.Position = new vscode.Position(event.startRow, event.startCol); // -1?
|
||||
let range_end: vscode.Position = new vscode.Position(event.endRow, event.endCol); // -1? idk if this works it's kinda funny, should test with someone with a working version of codemp
|
||||
const decorationRange = new vscode.Range(range_start, range_end);
|
||||
|
@ -49,10 +54,12 @@ export async function join() {
|
|||
borderColor: 'lightblue' //should create this color based on event.user (uuid)
|
||||
}
|
||||
});
|
||||
console.log("debug 14");
|
||||
|
||||
let m = MAPPINGS.get_by_buffer(event.buffer);
|
||||
if (m === null) return;
|
||||
m.editor.setDecorations(smallNumberDecorationType, [decorationRange]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
@ -72,6 +79,7 @@ export async function join() {
|
|||
buffer: n.buffer.get_name(),
|
||||
user: username
|
||||
}
|
||||
console.log("Crashing?")
|
||||
controller.send(cursor);
|
||||
});
|
||||
console.log("workspace id \n");
|
||||
|
@ -98,8 +106,9 @@ export async function attach() {
|
|||
console.log("attached to buffer", buffer_name);
|
||||
console.log("buffer", buffer);
|
||||
let editor = vscode.window.activeTextEditor;
|
||||
|
||||
console.log("debug 1");
|
||||
if (editor === undefined) {
|
||||
console.log("debug 2");
|
||||
let fileUri = buffer_name;
|
||||
let random = (Math.random() + 1).toString(36).substring(2);
|
||||
const fileName = '' + random;
|
||||
|
@ -113,30 +122,56 @@ export async function attach() {
|
|||
//vscode.window.showInformationMessage(`Open a file first`);
|
||||
//return;
|
||||
}
|
||||
console.log("debug 3");
|
||||
editor = vscode.window.activeTextEditor!;
|
||||
console.log("debug 4");
|
||||
//console.log("Buffer = ", buffer, "\n");
|
||||
vscode.window.showInformationMessage(`Connected to codemp workspace buffer @[${buffer_name}]`);
|
||||
|
||||
let file_uri: vscode.Uri = editor.document.uri;
|
||||
MAPPINGS.put(new mapping.BufferMapping(buffer, editor));
|
||||
console.log("debug 5");
|
||||
let bufferContent = await buffer.content(); //Temp fix for content not being applied when attached
|
||||
console.log("Crashed after content ")
|
||||
|
||||
|
||||
let range = new vscode.Range(
|
||||
editor.document.positionAt(0),
|
||||
editor.document.positionAt(0)
|
||||
);
|
||||
CACHE.put(buffer_name, 0, bufferContent, 0)
|
||||
editor.edit(editBuilder => {
|
||||
editBuilder
|
||||
.replace(range, bufferContent)
|
||||
});
|
||||
|
||||
vscode.workspace.onDidChangeTextDocument((event: vscode.TextDocumentChangeEvent) => {
|
||||
console.log("debug 6");
|
||||
if (event.document.uri != file_uri) return; // ?
|
||||
for (let change of event.contentChanges) {
|
||||
if (CACHE.get(buffer_name, change.rangeOffset, change.text, change.rangeOffset + change.rangeLength)) continue;
|
||||
let tmp = CACHE.get(buffer_name, change.rangeOffset, change.text, change.rangeOffset + change.rangeLength)
|
||||
console.log("CACHE DUMPP", tmp);
|
||||
if (tmp) continue; // Remove TMP is for debug
|
||||
console.log("debug 7");
|
||||
LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
||||
buffer.send({
|
||||
start: change.rangeOffset,
|
||||
end: change.rangeOffset + change.rangeLength,
|
||||
content: change.text
|
||||
});
|
||||
console.log("debug 8");
|
||||
}
|
||||
});
|
||||
|
||||
buffer.callback((event: codemp.TextChange) => {
|
||||
buffer.callback(async function (controller: codemp.BufferController) {
|
||||
while (true) {
|
||||
console.log("debug 9");
|
||||
let event = await controller.try_recv();
|
||||
if (event === null) break;
|
||||
LOGGER.info(`buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
||||
console.log(`console log buffer.callback(event: [${event.start}, ${event.content}, ${event.end}])`)
|
||||
CACHE.put(buffer_name, event.start, event.content, event.end);
|
||||
|
||||
console.log("debug 10");
|
||||
if (editor === undefined) { throw "Open an editor first" }
|
||||
let range = new vscode.Range(
|
||||
editor.document.positionAt(event.start),
|
||||
|
@ -146,7 +181,10 @@ export async function attach() {
|
|||
editBuilder
|
||||
.replace(range, event.content)
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/*export async function disconnectBuffer() { TODO i should just set buffer=null
|
||||
|
@ -181,6 +219,10 @@ export async function listBuffers(){
|
|||
console.log(buffers); // improve UX
|
||||
}
|
||||
|
||||
export async function helloWorld() {
|
||||
vscode.window.showInformationMessage("Hello World");
|
||||
}
|
||||
|
||||
// This method is called when your extension is deactivated
|
||||
export function deactivate() {
|
||||
//Maybe i should disconnect from every workspace and buffer ??? // TODO
|
||||
|
|
|
@ -7,23 +7,25 @@ export let LOGGER = vscode.window.createOutputChannel("codemp", {log: true});
|
|||
// extension is activated the very first time the command is executed
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||||
console.log('Congratulations, your extension "codempvscode" is now active!');
|
||||
console.log('Congratulations, your extension "codemp" is now active!');
|
||||
|
||||
// start codemp log poller
|
||||
log_poller_task(new codemp.JsLogger(true)); // don't await it! run it in background forever
|
||||
log_poller_task(new codemp.JsLogger()); // don't await it! run it in background forever
|
||||
|
||||
// register commands: the commandId parameter must match the command field in package.json
|
||||
for (let cmd of [
|
||||
vscode.commands.registerCommand('codempvscode.connect', codemplogic.connect),
|
||||
vscode.commands.registerCommand('codempvscode.join', codemplogic.join),
|
||||
vscode.commands.registerCommand('codempvscode.attach', codemplogic.attach),
|
||||
vscode.commands.registerCommand('codempvscode.createBuffer', codemplogic.createBuffer),
|
||||
vscode.commands.registerCommand('codempvscode.listBuffers', codemplogic.listBuffers),
|
||||
// vscode.commands.registerCommand('codempvscode.disconnectBuffer', codemplogic.disconnectBuffer),
|
||||
vscode.commands.registerCommand('codempvscode.sync', codemplogic.sync),
|
||||
vscode.commands.registerCommand('codempvscode.printOpCache', codemplogic.printOpCache)
|
||||
vscode.commands.registerCommand('codemp.helloWorld', codemplogic.helloWorld),
|
||||
vscode.commands.registerCommand('codemp.connect', codemplogic.connect),
|
||||
vscode.commands.registerCommand('codemp.join', codemplogic.join),
|
||||
vscode.commands.registerCommand('codemp.attach', codemplogic.attach),
|
||||
vscode.commands.registerCommand('codemp.createBuffer', codemplogic.createBuffer),
|
||||
vscode.commands.registerCommand('codemp.listBuffers', codemplogic.listBuffers),
|
||||
// vscode.commands.registerCommand('codemp.disconnectBuffer', codemplogic.disconnectBuffer),
|
||||
vscode.commands.registerCommand('codemp.sync', codemplogic.sync),
|
||||
vscode.commands.registerCommand('codemp.printOpCache', codemplogic.printOpCache)
|
||||
]) {
|
||||
context.subscriptions.push(cmd);
|
||||
console.log("registered all commands and pushed them");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue