mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 15:34:49 +01:00
updated to v0.5.1
This commit is contained in:
parent
aca8d31e1e
commit
ffa86902d7
4 changed files with 69 additions and 8 deletions
|
@ -9,7 +9,7 @@ crate-type = ["cdylib"]
|
||||||
path = "src/rust/lib.rs"
|
path = "src/rust/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", rev = "7fc03e3fd936240fdbadd368bfce38832ce34767", features = ["global"] }
|
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag="v0.5.1", features = ["global"] }
|
||||||
#codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", features = ["global"] }
|
#codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", features = ["global"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = "0.3.17"
|
tracing-subscriber = "0.3.17"
|
||||||
|
|
|
@ -35,6 +35,10 @@
|
||||||
"command": "codempvscode.disconnectBuffer",
|
"command": "codempvscode.disconnectBuffer",
|
||||||
"title": "disconnect from a codemp Buffer"
|
"title": "disconnect from a codemp Buffer"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "codempvscode.sync",
|
||||||
|
"title": "Sync the current buffer"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "codempvscode.helloWorld",
|
"command": "codempvscode.helloWorld",
|
||||||
"title": "Hello World (debug)"
|
"title": "Hello World (debug)"
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { JsTextChange } from '..';
|
||||||
const codemp = require("/home/***REMOVED***/projects/codemp/mine/codempvscode/codemp.node");
|
const codemp = require("/home/***REMOVED***/projects/codemp/mine/codempvscode/codemp.node");
|
||||||
|
|
||||||
var CACHE : string = "";
|
var CACHE : string = "";
|
||||||
|
var BUFFERS : any = [];
|
||||||
let smallNumberDecorationType = vscode.window.createTextEditorDecorationType({});
|
let smallNumberDecorationType = vscode.window.createTextEditorDecorationType({});
|
||||||
//import * as codemp from "/home/***REMOVED***/projects/codemp/mine/vscode/target/debug/libcodemp_vscode.node";
|
//import * as codemp from "/home/***REMOVED***/projects/codemp/mine/vscode/target/debug/libcodemp_vscode.node";
|
||||||
|
|
||||||
|
@ -32,13 +33,16 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
let attachCommand = vscode.commands.registerCommand('codempvscode.attach', attach);
|
let attachCommand = vscode.commands.registerCommand('codempvscode.attach', attach);
|
||||||
let createBufferCommand = vscode.commands.registerCommand('codempvscode.createBuffer', createBuffer);
|
let createBufferCommand = vscode.commands.registerCommand('codempvscode.createBuffer', createBuffer);
|
||||||
let disconnectBufferCommand = vscode.commands.registerCommand('codempvscode.disconnectBuffer', disconnectBuffer);
|
let disconnectBufferCommand = vscode.commands.registerCommand('codempvscode.disconnectBuffer', disconnectBuffer);
|
||||||
|
let syncBufferCommand = vscode.commands.registerCommand('codempvscode.sync', sync);
|
||||||
context.subscriptions.push(connectCommand);
|
context.subscriptions.push(connectCommand);
|
||||||
context.subscriptions.push(joinCommand);
|
context.subscriptions.push(joinCommand);
|
||||||
context.subscriptions.push(attachCommand);
|
context.subscriptions.push(attachCommand);
|
||||||
context.subscriptions.push(createBufferCommand);
|
context.subscriptions.push(createBufferCommand);
|
||||||
context.subscriptions.push(disconnectBufferCommand)
|
context.subscriptions.push(disconnectBufferCommand);
|
||||||
|
context.subscriptions.push(syncBufferCommand);
|
||||||
context.subscriptions.push(disposable);
|
context.subscriptions.push(disposable);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,7 +65,7 @@ async function join() {
|
||||||
if (workspace.length == 0) workspace = "default"
|
if (workspace.length == 0) workspace = "default"
|
||||||
|
|
||||||
if (buffer === undefined) return // user cancelled with ESC
|
if (buffer === undefined) return // user cancelled with ESC
|
||||||
if (buffer.length == 0) {workspace = "test"; buffer="test"; }
|
if (buffer.length == 0) {workspace = "default"; buffer="fucl"; }
|
||||||
|
|
||||||
let controller = await codemp.join(workspace)
|
let controller = await codemp.join(workspace)
|
||||||
try{
|
try{
|
||||||
|
@ -147,18 +151,32 @@ async function createBuffer() {
|
||||||
|
|
||||||
|
|
||||||
async function attach() {
|
async function attach() {
|
||||||
let workspace="test";
|
let buffer_name : any = (await vscode.window.showInputBox({prompt: "buffer to attach to"}))!;
|
||||||
let buffer = await codemp.attach(workspace);
|
let buffer = await codemp.attach(buffer_name);
|
||||||
|
console.log("attached to buffer", buffer_name);
|
||||||
|
console.log("buffer", buffer);
|
||||||
|
|
||||||
let editor = vscode.window.activeTextEditor;
|
let editor = vscode.window.activeTextEditor;
|
||||||
|
let fileUri = buffer_name;
|
||||||
|
const fileName = 'untitled-1';
|
||||||
|
const newFileUri = vscode.Uri.file(fileName).with({ scheme: 'untitled', path: fileName });
|
||||||
|
await vscode.workspace.openTextDocument(newFileUri);
|
||||||
|
vscode.commands.executeCommand('vscode.open', newFileUri);
|
||||||
|
|
||||||
if (editor === undefined) { return } // TODO say something!!!!!!
|
if (editor === undefined) {
|
||||||
|
vscode.window.showInformationMessage(`Open a file first`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editor = vscode.window.activeTextEditor!;
|
||||||
console.log("Buffer = ", buffer, "\n");
|
console.log("Buffer = ", buffer, "\n");
|
||||||
vscode.window.showInformationMessage(`Connected to codemp workspace buffer @[${workspace}]`);
|
vscode.window.showInformationMessage(`Connected to codemp workspace buffer @[${buffer_name}]`);
|
||||||
|
|
||||||
|
let file_uri = editor.document.uri;
|
||||||
|
BUFFERS.push([file_uri, buffer_name]);
|
||||||
|
|
||||||
vscode.workspace.onDidChangeTextDocument((event:vscode.TextDocumentChangeEvent) => {
|
vscode.workspace.onDidChangeTextDocument((event:vscode.TextDocumentChangeEvent) => {
|
||||||
console.log(event.reason);
|
console.log(event.reason);
|
||||||
|
if (event.document.uri != file_uri) return; // ?
|
||||||
for (let change of event.contentChanges) {
|
for (let change of event.contentChanges) {
|
||||||
if (`${change.rangeOffset}${change.text}${change.rangeOffset+change.rangeLength}` === CACHE) continue; // LMAO
|
if (`${change.rangeOffset}${change.text}${change.rangeOffset+change.rangeLength}` === CACHE) continue; // LMAO
|
||||||
buffer.send({
|
buffer.send({
|
||||||
|
@ -192,6 +210,30 @@ async function disconnectBuffer() {
|
||||||
vscode.window.showInformationMessage(`Disconnected from codemp workspace buffer @[${buffer}]`);
|
vscode.window.showInformationMessage(`Disconnected from codemp workspace buffer @[${buffer}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sync() {
|
||||||
|
let editor = vscode.window.activeTextEditor;
|
||||||
|
if (editor === undefined) { return }
|
||||||
|
for (let tuple of BUFFERS) {
|
||||||
|
if (tuple[0] == editor?.document.uri) {
|
||||||
|
|
||||||
|
let buffer = codemp.getBuffer(tuple[1]);
|
||||||
|
if (buffer==null) {
|
||||||
|
vscode.window.showErrorMessage("This buffer does not exist anymore");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let range = new vscode.Range(
|
||||||
|
editor.document.positionAt(0),
|
||||||
|
editor.document.positionAt(editor.document.getText().length)
|
||||||
|
)
|
||||||
|
let content = buffer.content()
|
||||||
|
CACHE = `${range.start}${content}${range.end}`;
|
||||||
|
editor.edit(editBuilder => editBuilder.replace(range, content))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vscode.window.showErrorMessage("This buffer is not managed by codemp");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,13 @@ pub async fn connect(addr: String) -> napi::Result<()> {
|
||||||
.map_err(|e| JsCodempError(e).into())
|
.map_err(|e| JsCodempError(e).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
pub async fn get_buffer(path: String) -> Option<JsBufferController> {
|
||||||
|
let x = CODEMP_INSTANCE.get_buffer(&path)
|
||||||
|
.await
|
||||||
|
.ok()?;
|
||||||
|
Some(JsBufferController(x))
|
||||||
|
}
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
pub async fn leave_workspace() -> Result<(), napi::Error> {
|
pub async fn leave_workspace() -> Result<(), napi::Error> {
|
||||||
|
@ -237,6 +244,14 @@ impl JsBufferController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
pub fn content(&self) -> napi::Result<String> {
|
||||||
|
Ok(self.0.content())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
pub async fn recv(&self) -> napi::Result<JsTextChange> {
|
pub async fn recv(&self) -> napi::Result<JsTextChange> {
|
||||||
Ok(
|
Ok(
|
||||||
|
|
Loading…
Reference in a new issue