mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-12-22 20:44:53 +01:00
fix: removed tonioware
also moved select_buffer locally for testing, until it's stable
This commit is contained in:
parent
7ae82c83c0
commit
878df9716f
3 changed files with 34 additions and 14 deletions
|
@ -4,11 +4,12 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "0.5.0", features = ["global", "sync"] }
|
||||
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.5.0", features = ["global", "sync"] }
|
||||
jni = { version = "0.21.1", features = ["invocation"] }
|
||||
jni-sys = "0.3.0"
|
||||
log = "0.4.20"
|
||||
rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7"}
|
||||
tokio = "1.34.0"
|
||||
|
||||
[build-dependencies]
|
||||
flapigen = "0.6.0"
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
public class BufferEventAwaiterTask extends Task.Backgroundable implements Disposable {
|
||||
private final Map<String, Disposable> bufferListeners = new ConcurrentHashMap<>();
|
||||
private final Set<String> initialisedBuffers = Collections.newSetFromMap(new ConcurrentHashMap<>()); //also tonioware
|
||||
|
||||
public BufferEventAwaiterTask(@NotNull Project project) {
|
||||
super(project, "Awaiting CodeMP buffer events", false);
|
||||
|
@ -44,7 +43,6 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
|
||||
public void unregisterListener(String name) {
|
||||
CodeMP.ACTIVE_BUFFERS_REVERSE.remove(CodeMP.ACTIVE_BUFFERS.remove(name));
|
||||
this.initialisedBuffers.remove(name);
|
||||
Disposable listener = this.bufferListeners.remove(name);
|
||||
if(listener != null)
|
||||
listener.dispose();
|
||||
|
@ -54,7 +52,7 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
public void dispose() {}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"InfiniteLoopStatement", "UnstableApiUsage", "BusyWait"})
|
||||
@SuppressWarnings({"InfiniteLoopStatement", "UnstableApiUsage"})
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
try {
|
||||
while(true) {
|
||||
|
@ -66,13 +64,6 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
|
|||
continue;
|
||||
String buffer = bufferOptional.get();
|
||||
|
||||
if(!this.initialisedBuffers.contains(buffer)) { //tonioware
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch(InterruptedException ignored) {}
|
||||
this.initialisedBuffers.add(buffer);
|
||||
}
|
||||
|
||||
BufferHandler handler = CodeMPHandler.getBuffer(buffer);
|
||||
|
||||
List<TextChangeWrapper> changeList = new ArrayList<>();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use codemp::prelude::*;
|
||||
use codemp::tools;
|
||||
use rifgen::rifgen_attr::{generate_access_methods, generate_interface, generate_interface_doc};
|
||||
|
||||
pub mod glue { //rifgen generated code
|
||||
|
@ -76,8 +75,37 @@ impl CodeMPHandler {
|
|||
Err(_) => continue
|
||||
}
|
||||
}
|
||||
CODEMP_INSTANCE.rt().block_on(
|
||||
tools::select_buffer_timeout(&buffers, Duration::from_millis(timeout as u64)))
|
||||
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
let mut tasks = Vec::new();
|
||||
for buffer in buffers {
|
||||
let _tx = tx.clone();
|
||||
let _buffer = buffer.clone();
|
||||
tasks.push(CODEMP_INSTANCE.rt().spawn(async move {
|
||||
match _buffer.poll().await {
|
||||
Ok(()) => _tx.send(Ok(Some(_buffer.name.clone()))),
|
||||
Err(_) => _tx.send(Err(CodempError::Channel { send: true })),
|
||||
}
|
||||
}))
|
||||
}
|
||||
let _tx = tx.clone();
|
||||
tasks.push(CODEMP_INSTANCE.rt().spawn(async move {
|
||||
tokio::time::sleep(Duration::from_millis(timeout as u64)).await;
|
||||
_tx.send(Ok(None))
|
||||
}));
|
||||
loop {
|
||||
match CODEMP_INSTANCE.rt().block_on(rx.recv()) {
|
||||
None => return Err(CodempError::Channel { send: false }),
|
||||
Some(Err(_)) => continue,
|
||||
Some(Ok(None)) => return Ok(None),
|
||||
Some(Ok(Some(x))) => {
|
||||
for t in tasks {
|
||||
t.abort();
|
||||
}
|
||||
return Ok(Some(x.clone()));
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue