mirror of
https://github.com/hexedtech/codemp-intellij.git
synced 2024-12-18 02:44:53 +01:00
chore: removed snapshot, fixed cargo, periodic fetch in glue
Co-authored-by: alemi <me@alemi.dev>
This commit is contained in:
parent
5a42577a1f
commit
0719ac84f4
3 changed files with 20 additions and 13 deletions
|
@ -17,7 +17,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WorkspaceFileOpenedListener implements FileOpenedSyncListener {
|
public class WorkspaceFileOpenedListener implements FileOpenedSyncListener {
|
||||||
|
|
||||||
private final WorkspaceHandler handler;
|
private final WorkspaceHandler handler;
|
||||||
private final BufferEventAwaiterTask task;
|
private final BufferEventAwaiterTask task;
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,8 @@ public class FileUtil {
|
||||||
public static Editor getActiveEditorByPath(Project project, String path) {
|
public static Editor getActiveEditorByPath(Project project, String path) {
|
||||||
return Arrays.stream(FileEditorManager.getInstance(project).getAllEditors())
|
return Arrays.stream(FileEditorManager.getInstance(project).getAllEditors())
|
||||||
.filter(fe -> fe instanceof TextEditor)
|
.filter(fe -> fe instanceof TextEditor)
|
||||||
.map(fe -> {
|
.map(fe -> ((TextEditor) fe).getEditor())
|
||||||
TextEditor te = (TextEditor) fe;
|
.filter(editor -> path.equals(FileUtil.getRelativePath(editor.getProject(), editor.getVirtualFile())))
|
||||||
return te.getEditor();
|
|
||||||
}).filter(editor -> path.equals(FileUtil.getRelativePath(editor.getProject(), editor.getVirtualFile())))
|
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,14 +38,20 @@ impl ClientHandler {
|
||||||
/// create a new workspace
|
/// create a new workspace
|
||||||
fn create_workspace(&mut self, workspace_id: &str) -> CodempResult<WorkspaceHandler> {
|
fn create_workspace(&mut self, workspace_id: &str) -> CodempResult<WorkspaceHandler> {
|
||||||
RT.block_on(self.client.create_workspace(workspace_id))
|
RT.block_on(self.client.create_workspace(workspace_id))
|
||||||
.map(|workspace| WorkspaceHandler { workspace })
|
.map(|workspace| {
|
||||||
|
Self::spawn_updater(workspace.clone());
|
||||||
|
WorkspaceHandler { workspace }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
/// join a workspace by name
|
/// join a workspace by name
|
||||||
fn join_workspace(&mut self, workspace_id: &str) -> CodempResult<WorkspaceHandler> {
|
fn join_workspace(&mut self, workspace_id: &str) -> CodempResult<WorkspaceHandler> {
|
||||||
RT.block_on(self.client.join_workspace(workspace_id))
|
RT.block_on(self.client.join_workspace(workspace_id))
|
||||||
.map(|workspace| WorkspaceHandler { workspace })
|
.map(|workspace| {
|
||||||
|
Self::spawn_updater(workspace.clone());
|
||||||
|
WorkspaceHandler { workspace }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
|
@ -54,6 +60,16 @@ impl ClientHandler {
|
||||||
RT.block_on(self.client.leave_workspace(workspace_id))
|
RT.block_on(self.client.leave_workspace(workspace_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn spawn_updater(workspace: Arc<RwLock<CodempWorkspace>>) {
|
||||||
|
tokio::spawn(async move {
|
||||||
|
loop {
|
||||||
|
tokio::time::sleep(Duration::from_secs(60)).await;
|
||||||
|
workspace.write().await.fetch_buffers().await.unwrap();
|
||||||
|
workspace.write().await.fetch_users().await.unwrap();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
/// get the url you are currently connected to
|
/// get the url you are currently connected to
|
||||||
fn get_url(&self) -> String {
|
fn get_url(&self) -> String {
|
||||||
|
@ -88,12 +104,6 @@ impl WorkspaceHandler {
|
||||||
.map(|buffer| BufferHandler { buffer })
|
.map(|buffer| BufferHandler { buffer })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[generate_interface]
|
|
||||||
/// get a buffer's contents as a flat string
|
|
||||||
fn get_buffer_snapshot(&self , path: &str) -> CodempResult<String> {
|
|
||||||
RT.block_on(RT.block_on(self.workspace.read()).snapshot(path))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[generate_interface]
|
#[generate_interface]
|
||||||
/// updates the local list of the workspace's buffers
|
/// updates the local list of the workspace's buffers
|
||||||
fn fetch_buffers(&mut self) -> CodempResult<()> {
|
fn fetch_buffers(&mut self) -> CodempResult<()> {
|
||||||
|
|
Loading…
Reference in a new issue