diff --git a/.gitignore b/.gitignore index 6b2fb8c..2339481 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ Cargo.lock /client/vscode/*.vsix /client/vscode/codemp.node -.cargo \ No newline at end of file +.cargo + +.vscode/ \ No newline at end of file diff --git a/proto/buffer_service.proto b/proto/buffer_service.proto index d7d989f..0e6e0ca 100644 --- a/proto/buffer_service.proto +++ b/proto/buffer_service.proto @@ -20,6 +20,7 @@ message Operation { message SnapshotRequest { required string path = 1; } + message SnapshotResponse { required string content = 1; } \ No newline at end of file diff --git a/proto/workspace.proto b/proto/workspace.proto index d4c1a01..3bb467d 100644 --- a/proto/workspace.proto +++ b/proto/workspace.proto @@ -16,7 +16,7 @@ message WorkspaceUserList { } message WorkspaceMessage { - required int32 id = 1; //unused??? + required string id = 1; //unused??? } message JoinRequest { @@ -25,7 +25,7 @@ message JoinRequest { } message AttachRequest { - required string id = 1; + required string path = 1; } message Token { diff --git a/src/workspace.rs b/src/workspace.rs index d03e43a..4e84326 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -2,7 +2,7 @@ use std::{collections::{BTreeMap, BTreeSet}, sync::Arc}; use tokio::sync::mpsc; use uuid::Uuid; use crate::{ - proto::{user::UserIdentity, workspace::{AttachRequest, BufferListRequest, BufferPayload, Token, UserListRequest}}, + proto::{buffer_service::SnapshotRequest, user::UserIdentity, workspace::{AttachRequest, BufferListRequest, BufferPayload, Token, UserListRequest}}, api::controller::ControllerWorker, buffer::{self, worker::BufferWorker}, client::Services, @@ -42,6 +42,7 @@ pub struct Workspace { } impl Workspace { + /// create a new buffer and perform initial fetch operations pub(crate) async fn new( id: String, user_id: Uuid, @@ -86,7 +87,7 @@ impl Workspace { pub async fn attach(&mut self, path: &str) -> crate::Result> { let mut worskspace_client = self.services.workspace.clone(); self.token.send(worskspace_client.attach( - tonic::Request::new(AttachRequest { id: path.to_string() }) + tonic::Request::new(AttachRequest { path: path.to_string() }) ).await?.into_inner())?; let (tx, rx) = mpsc::channel(10); @@ -108,6 +109,16 @@ impl Workspace { Ok(controller) } + /// get a snapshot of a buffer (meaning its contents as a flat string) + pub async fn snapshot(&mut self, path: &str) -> crate::Result { + let mut buffer_client = self.services.buffer.clone(); + let contents = buffer_client.snapshot( + tonic::Request::new(SnapshotRequest { path: path.to_string() }) + ).await?.into_inner().content; + + Ok(contents) + } + /// fetch a list of all buffers in a workspace pub async fn fetch_buffers(&mut self) -> crate::Result<()> { let mut workspace_client = self.services.workspace.clone(); @@ -173,6 +184,7 @@ impl Workspace { Ok(()) } + /// get the id of the workspace pub fn id(&self) -> String { self.id.clone() } /// return a reference to current cursor controller, if currently in a workspace @@ -182,4 +194,9 @@ impl Workspace { pub fn buffer_by_name(&self, path: &str) -> Option> { self.buffers.get(path).cloned() } + + /// get the currently cached "filetree" + pub fn filetree(&self) -> Vec { + self.filetree.iter().map(|f| f.clone()).collect() + } } \ No newline at end of file