Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
frelodev committed Sep 6, 2024
1 parent ac3bac3 commit 1a1c6b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
34 changes: 6 additions & 28 deletions src/codemp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +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 codemp from '@codemp/codemp';
import * as mapping from "./mapping";
import { LOGGER } from './extension';

Expand Down Expand Up @@ -52,7 +52,7 @@ export async function join() {
vscode.window.onDidChangeTextEditorSelection(async (event: vscode.TextEditorSelectionChangeEvent) => {
if (event.kind == vscode.TextEditorSelectionChangeKind.Command) return; // TODO commands might move cursor too
let buf = event.textEditor.document.uri;
let selection: vscode.Selection = event.selections[0] // TODO there may be more than one cursor!!
let selection: vscode.Selection = event.selections[0]
let anchor: [number, number] = [selection.anchor.line, selection.anchor.character];
let position: [number, number] = [selection.active.line, selection.active.character + 1];
let buffer = mapping.bufferMapper.by_editor(buf)
Expand All @@ -65,9 +65,7 @@ export async function join() {
buffer: buffer,
user: undefined,
}
console.log("Sending Cursor");
//await controller.send(cursor);
console.log("Cursor sent");
await controller.send(cursor);
});
vscode.window.showInformationMessage("Connected to workspace");
}
Expand Down Expand Up @@ -95,23 +93,16 @@ export async function attach() {
let fileUri = buffer_name;
let random = (Math.random() + 1).toString(36).substring(2);
const fileName = '' + random;
//const newFileUri = vscode.Uri.file(fileName).with({ scheme: 'untitled', path: fileName });

//Create a document not a file so it's temp and it doesn't get saved
const newFileUri = vscode.Uri.file(fileName).with({ scheme: 'untitled', path: "" });
//vscode.workspace.openTextDocument()
await vscode.workspace.openTextDocument(newFileUri);
vscode.commands.executeCommand('vscode.open', newFileUri); //It should already be opened with the api command above idk why i do this?
//vscode.window.showInformationMessage(`Open a file first`);
//return;
vscode.commands.executeCommand('vscode.open', newFileUri);
}
editor = vscode.window.activeTextEditor!;
//console.log("Buffer = ", buffer, "\n");
vscode.window.showInformationMessage(`Connected to codemp workspace buffer @[${buffer_name}]`);

let file_uri: vscode.Uri = editor.document.uri;
mapping.bufferMapper.register(buffer.get_name(), editor);
let bufferContent = await buffer.content(); //Temp fix for content not being applied when attached
let bufferContent = await buffer.content();


let range = new vscode.Range(
Expand All @@ -127,9 +118,7 @@ export async function attach() {
if(mine) { return }
if (event.document.uri !== file_uri) return; // ?
for (let change of event.contentChanges) {
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
if (CACHE.get(buffer_name, change.rangeOffset, change.text, change.rangeOffset + change.rangeLength)) continue;
LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
console.log("Sending buffer event");
await buffer.send({
Expand All @@ -153,7 +142,6 @@ export async function attach() {
editor.document.positionAt(event.end)
)
mine = true
//Study more on this maybe it locks it
await editor.edit(editBuilder => {
editBuilder
.replace(range, event.content)
Expand Down Expand Up @@ -217,16 +205,6 @@ export async function listWorkspaces(){



export async function helloWorld() {
vscode.window.showInformationMessage("Hello World");
}


export function printOpCache() {
console.log("CACHE\n");
console.log(CACHE.toString());
}

// This method is called when your extension is deactivated
export function deactivate() {
//Maybe i should disconnect from every workspace and buffer ??? // TODO
Expand Down
3 changes: 0 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ export function activate(context: vscode.ExtensionContext) {

// register commands: the commandId parameter must match the command field in package.json
for (let cmd of [
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.createWorkspace', codemplogic.createWorkspace),
vscode.commands.registerCommand('codemp.listWorkspaces', codemplogic.listWorkspaces),
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");
Expand Down

0 comments on commit 1a1c6b0

Please sign in to comment.