mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 07:24:49 +01:00
fixed opcache?
This commit is contained in:
parent
bec5a3d39c
commit
55a4cf111d
2 changed files with 63 additions and 25 deletions
|
@ -1,16 +1,12 @@
|
||||||
// The module 'vscode' contains the VS Code extensibility API
|
// The module 'vscode' contains the VS Code extensibility API
|
||||||
// Import the module and reference it with the alias vscode in your code below
|
// Import the module and reference it with the alias vscode in your code below
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { JsTextChange } from '..';
|
import * as codemp from '../index'; // TODO why won't it work with a custom name???
|
||||||
//import * as types from 'index';
|
|
||||||
//import * as codemp from '..';
|
|
||||||
//import * as codemp from '/home/***REMOVED***/projects/codemp/mine/codempvscode/codemp.node';
|
|
||||||
const codemp = require("/home/***REMOVED***/projects/codemp/mine/codempvscode/codemp.node");
|
|
||||||
|
|
||||||
var CACHE : string = "";
|
|
||||||
var BUFFERS : any = [];
|
var CACHE = new codemp.OpCache();
|
||||||
|
var BUFFERS : string[][] = [];
|
||||||
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";
|
|
||||||
|
|
||||||
// This method is called when your extension is activated
|
// This method is called when your extension is activated
|
||||||
// Your extension is activated the very first time the command is executed
|
// Your extension is activated the very first time the command is executed
|
||||||
|
@ -156,12 +152,13 @@ async function attach() {
|
||||||
console.log("attached to buffer", buffer_name);
|
console.log("attached to buffer", buffer_name);
|
||||||
console.log("buffer", buffer);
|
console.log("buffer", buffer);
|
||||||
|
|
||||||
|
// let fileUri = buffer_name;
|
||||||
|
// const fileName = 'untitled-1';
|
||||||
|
// const newFileUri = vscode.Uri.file(fileName).with({ scheme: 'untitled', path: fileName });
|
||||||
|
// vscode.workspace.openTextDocument()
|
||||||
|
// await vscode.workspace.openTextDocument(newFileUri);
|
||||||
|
// vscode.commands.executeCommand('vscode.open', newFileUri);
|
||||||
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) {
|
if (editor === undefined) {
|
||||||
vscode.window.showInformationMessage(`Open a file first`);
|
vscode.window.showInformationMessage(`Open a file first`);
|
||||||
|
@ -178,7 +175,7 @@ async function attach() {
|
||||||
console.log(event.reason);
|
console.log(event.reason);
|
||||||
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) {
|
||||||
if (`${change.rangeOffset}${change.text}${change.rangeOffset+change.rangeLength}` === CACHE) continue; // LMAO
|
if (CACHE.get(buffer_name, change.rangeOffset, change.text, change.rangeOffset + change.rangeLength)) continue;
|
||||||
buffer.send({
|
buffer.send({
|
||||||
span: {
|
span: {
|
||||||
start: change.rangeOffset,
|
start: change.rangeOffset,
|
||||||
|
@ -193,30 +190,36 @@ async function attach() {
|
||||||
console.log("test");
|
console.log("test");
|
||||||
|
|
||||||
buffer.callback((event: any) => {
|
buffer.callback((event: any) => {
|
||||||
CACHE = `${event.span.start}${event.content}${event.span.end}`; //what's the difference between e.text and e.content like it's on lib.rs?
|
CACHE.put(buffer_name, event.span.start, event.content, event.span.end); //what's the difference between e.text and e.content like it's on lib.rs?
|
||||||
|
|
||||||
if (editor === undefined) { return } // TODO say something!!!!!!
|
if (editor === undefined) { return } // TODO say something!!!!!!
|
||||||
let range = new vscode.Range(
|
let range = new vscode.Range(
|
||||||
editor.document.positionAt(event.span.start),
|
editor.document.positionAt(event.span.start),
|
||||||
editor.document.positionAt(event.span.end)
|
editor.document.positionAt(event.span.end)
|
||||||
)
|
)
|
||||||
editor.edit(editBuilder => editBuilder.replace(range, event.content))
|
editor.edit(editBuilder => {
|
||||||
|
editBuilder
|
||||||
|
.replace(range, event.content)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function disconnectBuffer() {
|
async function disconnectBuffer() {
|
||||||
let buffer : string = (await vscode.window.showInputBox({prompt: "buffer name for the file to disconnect from"}))!;
|
let buffer : string = (await vscode.window.showInputBox({prompt: "buffer name for the file to disconnect from"}))!;
|
||||||
codemp.disconnect(buffer);
|
codemp.disconnectBuffer(buffer);
|
||||||
vscode.window.showInformationMessage(`Disconnected from codemp workspace buffer @[${buffer}]`);
|
vscode.window.showInformationMessage(`Disconnected from codemp workspace buffer @[${buffer}]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sync() {
|
async function sync() {
|
||||||
let editor = vscode.window.activeTextEditor;
|
let editor = vscode.window.activeTextEditor;
|
||||||
if (editor === undefined) { return }
|
if (editor === undefined) { return }
|
||||||
for (let tuple of BUFFERS) {
|
for (let tuple of BUFFERS) {
|
||||||
if (tuple[0] == editor?.document.uri) {
|
console.log(tuple[0]);
|
||||||
|
console.log("\n");
|
||||||
|
console.log(editor?.document.uri.toString());
|
||||||
|
if (tuple[0] === editor?.document.uri.toString()) {
|
||||||
|
|
||||||
let buffer = codemp.getBuffer(tuple[1]);
|
let buffer = await codemp.getBuffer(tuple[1]);
|
||||||
if (buffer==null) {
|
if (buffer==null) {
|
||||||
vscode.window.showErrorMessage("This buffer does not exist anymore");
|
vscode.window.showErrorMessage("This buffer does not exist anymore");
|
||||||
return;
|
return;
|
||||||
|
@ -224,10 +227,10 @@ function sync() {
|
||||||
let range = new vscode.Range(
|
let range = new vscode.Range(
|
||||||
editor.document.positionAt(0),
|
editor.document.positionAt(0),
|
||||||
editor.document.positionAt(editor.document.getText().length)
|
editor.document.positionAt(editor.document.getText().length)
|
||||||
)
|
);
|
||||||
let content = buffer.content()
|
let content = buffer.content();
|
||||||
CACHE = `${range.start}${content}${range.end}`;
|
CACHE.put(tuple[1],0,content,editor.document.getText().length);
|
||||||
editor.edit(editBuilder => editBuilder.replace(range, content))
|
editor.edit(editBuilder => editBuilder.replace(range, content));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
use std::sync::Arc;
|
use std::{sync::Arc, collections::HashSet};
|
||||||
use codemp::{
|
use codemp::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
proto::{RowCol, CursorEvent},
|
proto::{RowCol, CursorEvent},
|
||||||
|
@ -10,7 +10,41 @@ use napi::tokio;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct JsCodempError(CodempError);
|
struct JsCodempError(CodempError);
|
||||||
|
|
||||||
|
pub type OpTuple = (String, u32, String, u32);
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
pub struct OpCache {
|
||||||
|
store: HashSet<OpTuple>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
impl OpCache {
|
||||||
|
#[napi(constructor)]
|
||||||
|
pub fn new() -> Self {
|
||||||
|
OpCache {
|
||||||
|
store: HashSet::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
pub fn put(&mut self, buf: String, start: u32, text: String, end: u32) -> bool {
|
||||||
|
let op = (buf, start, text, end);
|
||||||
|
let res = self.store.contains(&op);
|
||||||
|
self.store.insert(op);
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
pub fn get(&mut self, buf: String, start: u32, text: String, end: u32) -> bool {
|
||||||
|
let op = (buf, start, text, end);
|
||||||
|
if self.store.contains(&op) {
|
||||||
|
self.store.remove(&op);
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,6 +87,7 @@ pub async fn disconnect_buffer(path: String) -> Result<bool, napi::Error> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// CURSOR
|
/// CURSOR
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
|
|
Loading…
Reference in a new issue