mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 07:24:49 +01:00
chore: code cleanup
This commit is contained in:
parent
ac3bac3730
commit
1a1c6b007b
2 changed files with 6 additions and 31 deletions
|
@ -1,5 +1,5 @@
|
||||||
import * as vscode from 'vscode';
|
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 * as mapping from "./mapping";
|
||||||
import { LOGGER } from './extension';
|
import { LOGGER } from './extension';
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ export async function join() {
|
||||||
vscode.window.onDidChangeTextEditorSelection(async (event: vscode.TextEditorSelectionChangeEvent) => {
|
vscode.window.onDidChangeTextEditorSelection(async (event: vscode.TextEditorSelectionChangeEvent) => {
|
||||||
if (event.kind == vscode.TextEditorSelectionChangeKind.Command) return; // TODO commands might move cursor too
|
if (event.kind == vscode.TextEditorSelectionChangeKind.Command) return; // TODO commands might move cursor too
|
||||||
let buf = event.textEditor.document.uri;
|
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 anchor: [number, number] = [selection.anchor.line, selection.anchor.character];
|
||||||
let position: [number, number] = [selection.active.line, selection.active.character + 1];
|
let position: [number, number] = [selection.active.line, selection.active.character + 1];
|
||||||
let buffer = mapping.bufferMapper.by_editor(buf)
|
let buffer = mapping.bufferMapper.by_editor(buf)
|
||||||
|
@ -65,9 +65,7 @@ export async function join() {
|
||||||
buffer: buffer,
|
buffer: buffer,
|
||||||
user: undefined,
|
user: undefined,
|
||||||
}
|
}
|
||||||
console.log("Sending Cursor");
|
await controller.send(cursor);
|
||||||
//await controller.send(cursor);
|
|
||||||
console.log("Cursor sent");
|
|
||||||
});
|
});
|
||||||
vscode.window.showInformationMessage("Connected to workspace");
|
vscode.window.showInformationMessage("Connected to workspace");
|
||||||
}
|
}
|
||||||
|
@ -95,23 +93,16 @@ export async function attach() {
|
||||||
let fileUri = buffer_name;
|
let fileUri = buffer_name;
|
||||||
let random = (Math.random() + 1).toString(36).substring(2);
|
let random = (Math.random() + 1).toString(36).substring(2);
|
||||||
const fileName = '' + random;
|
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: "" });
|
const newFileUri = vscode.Uri.file(fileName).with({ scheme: 'untitled', path: "" });
|
||||||
//vscode.workspace.openTextDocument()
|
|
||||||
await vscode.workspace.openTextDocument(newFileUri);
|
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.commands.executeCommand('vscode.open', newFileUri);
|
||||||
//vscode.window.showInformationMessage(`Open a file first`);
|
|
||||||
//return;
|
|
||||||
}
|
}
|
||||||
editor = vscode.window.activeTextEditor!;
|
editor = vscode.window.activeTextEditor!;
|
||||||
//console.log("Buffer = ", buffer, "\n");
|
|
||||||
vscode.window.showInformationMessage(`Connected to codemp workspace buffer @[${buffer_name}]`);
|
vscode.window.showInformationMessage(`Connected to codemp workspace buffer @[${buffer_name}]`);
|
||||||
|
|
||||||
let file_uri: vscode.Uri = editor.document.uri;
|
let file_uri: vscode.Uri = editor.document.uri;
|
||||||
mapping.bufferMapper.register(buffer.get_name(), editor);
|
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(
|
let range = new vscode.Range(
|
||||||
|
@ -127,9 +118,7 @@ export async function attach() {
|
||||||
if(mine) { return }
|
if(mine) { return }
|
||||||
if (event.document.uri !== file_uri) return; // ?
|
if (event.document.uri !== file_uri) return; // ?
|
||||||
for (let change of event.contentChanges) {
|
for (let change of event.contentChanges) {
|
||||||
let tmp = CACHE.get(buffer_name, change.rangeOffset, change.text, change.rangeOffset + change.rangeLength)
|
if (CACHE.get(buffer_name, change.rangeOffset, change.text, change.rangeOffset + change.rangeLength)) continue;
|
||||||
console.log("CACHE DUMPP", tmp);
|
|
||||||
if (tmp) continue; // Remove TMP is for debug
|
|
||||||
LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
LOGGER.info(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
||||||
console.log("Sending buffer event");
|
console.log("Sending buffer event");
|
||||||
await buffer.send({
|
await buffer.send({
|
||||||
|
@ -153,7 +142,6 @@ export async function attach() {
|
||||||
editor.document.positionAt(event.end)
|
editor.document.positionAt(event.end)
|
||||||
)
|
)
|
||||||
mine = true
|
mine = true
|
||||||
//Study more on this maybe it locks it
|
|
||||||
await editor.edit(editBuilder => {
|
await editor.edit(editBuilder => {
|
||||||
editBuilder
|
editBuilder
|
||||||
.replace(range, event.content)
|
.replace(range, event.content)
|
||||||
|
@ -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
|
// This method is called when your extension is deactivated
|
||||||
export function deactivate() {
|
export function deactivate() {
|
||||||
//Maybe i should disconnect from every workspace and buffer ??? // TODO
|
//Maybe i should disconnect from every workspace and buffer ??? // TODO
|
||||||
|
|
|
@ -14,7 +14,6 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
|
|
||||||
// register commands: the commandId parameter must match the command field in package.json
|
// register commands: the commandId parameter must match the command field in package.json
|
||||||
for (let cmd of [
|
for (let cmd of [
|
||||||
vscode.commands.registerCommand('codemp.helloWorld', codemplogic.helloWorld),
|
|
||||||
vscode.commands.registerCommand('codemp.connect', codemplogic.connect),
|
vscode.commands.registerCommand('codemp.connect', codemplogic.connect),
|
||||||
vscode.commands.registerCommand('codemp.join', codemplogic.join),
|
vscode.commands.registerCommand('codemp.join', codemplogic.join),
|
||||||
vscode.commands.registerCommand('codemp.attach', codemplogic.attach),
|
vscode.commands.registerCommand('codemp.attach', codemplogic.attach),
|
||||||
|
@ -22,9 +21,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
vscode.commands.registerCommand('codemp.listWorkspaces', codemplogic.listWorkspaces),
|
vscode.commands.registerCommand('codemp.listWorkspaces', codemplogic.listWorkspaces),
|
||||||
vscode.commands.registerCommand('codemp.createBuffer', codemplogic.createBuffer),
|
vscode.commands.registerCommand('codemp.createBuffer', codemplogic.createBuffer),
|
||||||
vscode.commands.registerCommand('codemp.listBuffers', codemplogic.listBuffers),
|
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.sync', codemplogic.sync),
|
||||||
vscode.commands.registerCommand('codemp.printOpCache', codemplogic.printOpCache)
|
|
||||||
]) {
|
]) {
|
||||||
context.subscriptions.push(cmd);
|
context.subscriptions.push(cmd);
|
||||||
console.log("registered all commands and pushed them");
|
console.log("registered all commands and pushed them");
|
||||||
|
|
Loading…
Reference in a new issue