Skip to content

Commit 2a7a3b8

Browse files
committed
feat: BufferAttributes (and event)
1 parent 97e127f commit 2a7a3b8

File tree

10 files changed

+43
-27
lines changed

10 files changed

+43
-27
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ thiserror = "2.0"
3131
# crdt
3232
diamond-types = "1.0"
3333
# proto
34-
codemp-proto = { git = "https://github.com/hexedtech/codemp-proto", rev = "29fb391b4857ac2e3bd2f60ddebcc79494c77953", features = ["client"] }
34+
codemp-proto = { git = "https://github.com/hexedtech/codemp-proto", rev = "0e3af02296d33563dde6fe4caf7fd8df237c9357", features = ["client"] }
3535
uuid = { version = "1.17", features = ["v4"] }
3636
tonic = { version = "0.14", features = ["tls-native-roots"] }
3737
# api

dist/lua/annotations.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,14 @@ function Client:callback(cb) end
362362
---@field user string username of workspace owner
363363
---@field workspace string workspace name
364364

365+
---@class BufferAttributes
366+
---attributes and properties of a buffer
367+
---@field ephemeral boolean wheter this buffer is ephemeral
368+
365369
---@class BufferNode
366370
---represents a buffer and holds wheter it is ephemeral
367371
---@field path string buffer path
368-
---@field ephemeral boolean wheter this buffer is ephemeral
372+
---@field attributes BufferAttributes attributes of this buffer
369373

370374

371375

dist/lua/enums.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local WorkspaceEventKind = {
1616
FileDelete = 5,
1717
UserJoinBuffer = 6,
1818
UserLeaveBuffer = 7,
19+
FileAttrsUpdated = 8,
1920
}
2021

2122
return {

src/ffi/java/workspace.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
errors::{ConnectionError, ControllerError, RemoteError},
55
proto::{common::UserInfo, session::WorkspaceIdentifier, workspace::WorkspaceEvent}
66
};
7-
use codemp_proto::files::BufferNode;
7+
use codemp_proto::files::{BufferAttributes, BufferNode};
88
use jni::{Env, objects::JObject};
99
use jni_toolbox::jni;
1010

@@ -46,8 +46,8 @@ fn user_list(workspace: &mut Workspace) -> Vec<UserInfo> {
4646

4747
/// Create a new buffer.
4848
#[jni(package = "mp.code", class = "Workspace")]
49-
fn create_buffer(workspace: &mut Workspace, path: String, ephemeral: bool) -> Result<(), RemoteError> {
50-
super::tokio().block_on(workspace.create_buffer(path, ephemeral))
49+
fn create_buffer(workspace: &mut Workspace, path: String, attributes: Option<BufferAttributes>) -> Result<(), RemoteError> {
50+
super::tokio().block_on(workspace.create_buffer(path, attributes))
5151
}
5252

5353
/// Pins an ephemeral buffer.

src/ffi/js/workspace.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use codemp_proto::{common::UserInfo, files::BufferNode, session::WorkspaceIdentifier, workspace::WorkspaceEvent};
1+
use codemp_proto::{common::UserInfo, files::{BufferAttributes, BufferNode}, session::WorkspaceIdentifier, workspace::WorkspaceEvent};
22
use crate::{api::AsyncReceiver, buffer::controller::BufferController, cursor::controller::CursorController};
33
use napi::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode};
44
use napi_derive::napi;
@@ -45,8 +45,8 @@ impl Workspace {
4545

4646
/// Create a new buffer in the current workspace
4747
#[napi(js_name = "createBuffer")]
48-
pub async fn js_create_buffer(&self, path: String, ephemeral: bool) -> napi::Result<()> {
49-
Ok(self.create_buffer(&path, ephemeral).await?)
48+
pub async fn js_create_buffer(&self, path: String, attributes: Option<BufferAttributes>) -> napi::Result<()> {
49+
Ok(self.create_buffer(&path, attributes).await?)
5050
}
5151

5252
/// Attach to a workspace buffer, starting a BufferController

src/ffi/lua/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl LuaUserData for CodempWorkspace {
1010
});
1111
methods.add_method(
1212
"create_buffer",
13-
|_, this, (name, ephemeral): (String, bool)| a_sync! { this => this.create_buffer(name, ephemeral).await? },
13+
|_, this, (name, attrs): (String, Option<CodempBufferAttributes>)| a_sync! { this => this.create_buffer(name, attrs).await? },
1414
);
1515

1616
methods.add_method("pin_buffer", |_, this, (path,): (String,)| {

src/ffi/python/workspace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use super::a_sync_detach;
99
impl CodempWorkspace {
1010
// join a workspace
1111
#[pyo3(name = "create_buffer")]
12-
fn pycreate_buffer(&self, py: Python, path: String, ephemeral: bool) -> PyResult<Promise> {
12+
fn pycreate_buffer(&self, py: Python, path: String, attrs: Option<CodempBufferAttributes>) -> PyResult<Promise> {
1313
let this = self.clone();
14-
a_sync_detach!(py, this.create_buffer(path.as_str(), ephemeral).await)
14+
a_sync_detach!(py, this.create_buffer(path.as_str(), attrs).await)
1515
}
1616

1717
#[pyo3(name = "pin_buffer")]

src/prelude.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ pub use crate::api::{
99
};
1010

1111
pub use crate::proto::{
12-
files::BufferNode as CodempBufferNode, buffer::BufferEvent as CodempBufferEvent,
12+
common::UserInfo as CodempUserInfo,
13+
files::BufferNode as CodempBufferNode, files::BufferAttributes as CodempBufferAttributes,
14+
buffer::BufferEvent as CodempBufferEvent,
1315
cursor::CursorEvent as CodempCursorEvent, cursor::CursorUpdate as CodempCursorUpdate,
1416
cursor::CursorPosition as CodempCursorPosition, cursor::RowCol as CodempRowCol,
15-
session::SessionEvent as CodempSessionEvent, workspace::WorkspaceEvent as CodempWorkspaceEvent,
16-
session::WorkspaceIdentifier as CodempWorkspaceIdentifier, common::UserInfo as CodempUserInfo,
17+
session::SessionEvent as CodempSessionEvent, session::WorkspaceIdentifier as CodempWorkspaceIdentifier,
18+
workspace::WorkspaceEvent as CodempWorkspaceEvent,
1719
};
1820

1921
pub use crate::{

src/workspace.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515

1616
use codemp_proto::{
1717
common::Empty,
18-
files::{BufferNode, BufferPath},
18+
files::{BufferAttributes, BufferNode, BufferPath},
1919
workspace::{WorkspaceEvent, WorkspaceEventKind},
2020
};
2121

@@ -48,7 +48,7 @@ pub(crate) struct WorkspaceInner {
4848
cursor: cursor::Controller,
4949
buffers: DashMap<String, buffer::Controller>,
5050
services: Services,
51-
filetree: DashMap<String, crate::proto::files::BufferNode>,
51+
filetree: DashMap<String, BufferNode>,
5252
buffer_users: DashMap<String, Vec<String>>,
5353
users: Arc<DashMap<String, codemp_proto::common::UserInfo>>,
5454
events: tokio::sync::Mutex<mpsc::UnboundedReceiver<WorkspaceEvent>>,
@@ -158,22 +158,23 @@ impl Workspace {
158158
}
159159

160160
/// Create a new buffer in the current workspace.
161-
pub async fn create_buffer(&self, path: impl ToString, ephemeral: bool) -> RemoteResult<()> {
161+
pub async fn create_buffer(&self, path: impl ToString, attributes: Option<BufferAttributes>) -> RemoteResult<()> {
162162
let mut workspace_client = self.0.services.ws();
163163
let path = path.to_string();
164+
let attributes = attributes.unwrap_or_default();
164165
workspace_client
165166
.create_buffer(tonic::Request::new(BufferNode {
166-
path: crate::proto::files::BufferPath::from(&path),
167-
ephemeral,
167+
path: BufferPath::from(&path),
168+
attributes,
168169
}))
169170
.await?;
170171

171172
// add to filetree, not really necessary as we will get an event for it
172173
self.0.filetree.insert(
173174
path.clone(),
174-
crate::proto::files::BufferNode {
175-
path: crate::proto::files::BufferPath::from(&path),
176-
ephemeral,
175+
BufferNode {
176+
path: BufferPath::from(&path),
177+
attributes,
177178
},
178179
);
179180

@@ -467,11 +468,11 @@ impl WorkspaceWorker {
467468
},
468469

469470
WorkspaceEventKind::FileCreate => {
470-
if let (Some(path), Some(ephemeral)) = (event.path, event.ephemeral) {
471+
if let (Some(path), Some(attributes)) = (event.path, event.attributes) {
471472
inner.buffer_users.insert(path.clone(), Vec::new());
472-
inner.filetree.insert(path.clone(), crate::proto::files::BufferNode {
473-
path: crate::proto::files::BufferPath::from(&path),
474-
ephemeral
473+
inner.filetree.insert(path.clone(), BufferNode {
474+
path: BufferPath::from(&path),
475+
attributes
475476
});
476477
}
477478
}
@@ -495,6 +496,14 @@ impl WorkspaceWorker {
495496
let _ = inner.buffers.remove(&path);
496497
}
497498
}
499+
WorkspaceEventKind::FileAttrsUpdated => {
500+
if let (Some(path), Some(attributes)) = (event.path, event.attributes) {
501+
if let Some(mut r) = inner.filetree.get_mut(&path) {
502+
r.attributes = attributes;
503+
}
504+
}
505+
}
506+
498507
}
499508

500509
if self.events.send(_event).is_err() {

0 commit comments

Comments
 (0)