Skip to content

Commit a140fb6

Browse files
committed
feat(lua): updated methods
1 parent c403fb5 commit a140fb6

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

src/ffi/lua/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use mlua::prelude::*;
33

44
use super::ext::a_sync::a_sync;
55

6-
super::ext::impl_lua_serde! { CodempTextChange CodempBufferUpdate }
6+
super::ext::impl_lua_serde! { CodempTextChange CodempBufferUpdate CodempBufferNode }
77

88
impl LuaUserData for CodempBufferController {
99
fn add_methods<M: LuaUserDataMethods<Self>>(methods: &mut M) {

src/ffi/lua/client.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ impl LuaUserData for CodempClient {
2525

2626
methods.add_method(
2727
"attach_workspace",
28-
|_, this, (ws,): (String,)| a_sync! { this => this.attach_workspace(ws).await? },
28+
|_, this, (ws,): (String,)| {
29+
let ws_id = super::ext::lua_parse_uuid(&ws, 1, "ws")?;
30+
a_sync! { this => this.attach_workspace(ws_id).await? }
31+
},
2932
);
3033

3134
methods.add_method(
@@ -53,11 +56,13 @@ impl LuaUserData for CodempClient {
5356
);
5457

5558
methods.add_method("leave_workspace", |_, this, (ws,): (String,)| {
56-
Ok(this.leave_workspace(&ws))
59+
let ws_id = super::ext::lua_parse_uuid(&ws, 1, "ws")?;
60+
Ok(this.leave_workspace(ws_id))
5761
});
5862

5963
methods.add_method("get_workspace", |_, this, (ws,): (String,)| {
60-
Ok(this.get_workspace(&ws))
64+
let ws_id = super::ext::lua_parse_uuid(&ws, 1, "ws")?;
65+
Ok(this.get_workspace(ws_id))
6166
});
6267
}
6368
}

src/ffi/lua/ext/callback.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,18 @@ callback_args! {
123123
CursorController: CodempCursorController,
124124
BufferController: CodempBufferController,
125125
Workspace: CodempWorkspace,
126+
WorkspaceInfo: CodempWorkspaceInfo,
127+
VecWorkspaceInfo: Vec<CodempWorkspaceInfo>,
126128
Event: CodempEvent,
127129
MaybeEvent: Option<CodempEvent>,
128130
Cursor: CodempCursor,
129131
MaybeCursor: Option<CodempCursor>,
130132
Selection: CodempSelection,
133+
VecSelection: Vec<CodempSelection>,
131134
MaybeSelection: Option<CodempSelection>,
132135
TextChange: CodempTextChange,
133136
MaybeTextChange: Option<CodempTextChange>,
134137
BufferUpdate: CodempBufferUpdate,
135138
MaybeBufferUpdate: Option<CodempBufferUpdate>,
139+
BufferNode: CodempBufferNode,
136140
}

src/ffi/lua/ext/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ pub mod log;
55
pub(crate) use a_sync::tokio;
66
pub(crate) use callback::callback;
77

8+
pub(crate) fn lua_parse_uuid(uuid: &str, pos: usize, name: &str) -> mlua::Result<uuid::Uuid> {
9+
use std::str::FromStr;
10+
match uuid::Uuid::from_str(uuid) {
11+
Ok(x) => Ok(x),
12+
Err(e) => Err(mlua::Error::BadArgument {
13+
pos,
14+
name: Some(name.to_string()),
15+
to: Some("Uuid::from_str".to_string()),
16+
cause: std::sync::Arc::new(mlua::Error::FromLuaConversionError {
17+
from: "string",
18+
to: "Uuid".to_string(),
19+
message: Some(e.to_string()),
20+
}),
21+
}),
22+
}
23+
}
24+
825
macro_rules! impl_lua_serde {
926
($($t:ty)*) => {
1027
$(
@@ -24,3 +41,4 @@ macro_rules! impl_lua_serde {
2441
}
2542

2643
pub(crate) use impl_lua_serde;
44+

src/ffi/lua/workspace.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use mlua::prelude::*;
33

44
use super::ext::a_sync::a_sync;
55

6-
super::ext::impl_lua_serde! { CodempEvent }
6+
super::ext::impl_lua_serde! { CodempEvent CodempWorkspaceInfo }
77

88
impl LuaUserData for CodempWorkspace {
99
fn add_methods<M: LuaUserDataMethods<Self>>(methods: &mut M) {
@@ -12,7 +12,7 @@ impl LuaUserData for CodempWorkspace {
1212
});
1313
methods.add_method(
1414
"create_buffer",
15-
|_, this, (name,): (String,)| a_sync! { this => this.create_buffer(&name).await? },
15+
|_, this, (name, ephemeral): (String, bool)| a_sync! { this => this.create_buffer(&name, ephemeral).await? },
1616
);
1717

1818
methods.add_method(
@@ -34,25 +34,25 @@ impl LuaUserData for CodempWorkspace {
3434
});
3535

3636
methods.add_method(
37-
"fetch_buffers",
38-
|_, this, ()| a_sync! { this => this.fetch_buffers().await? },
37+
"list_buffers",
38+
|_, this, (filter,): (String,)| a_sync! { this => this.list_buffers(filter).await? },
3939
);
4040
methods.add_method(
41-
"fetch_users",
42-
|_, this, ()| a_sync! { this => this.fetch_users().await? },
41+
"list_users",
42+
|_, this, ()| a_sync! { this => this.list_users().await? },
4343
);
4444

4545
methods.add_method("search_buffers", |_, this, (filter,): (Option<String>,)| {
4646
Ok(this.search_buffers(filter.as_deref()))
4747
});
4848

49-
methods.add_method("fetch_buffer_users", |_, this, (path,): (String,)| {
49+
methods.add_method("list_buffer_users", |_, this, (path,): (String,)| {
5050
a_sync! {
51-
this => this.fetch_buffer_users(&path).await?
51+
this => this.list_buffer_users(&path).await?
5252
}
5353
});
5454

55-
methods.add_method("id", |_, this, ()| Ok(this.id()));
55+
methods.add_method("id", |_, this, ()| Ok(this.id().to_string()));
5656
methods.add_method("cursor", |_, this, ()| Ok(this.cursor()));
5757
methods.add_method("active_buffers", |_, this, ()| Ok(this.active_buffers()));
5858
methods.add_method("user_list", |_, this, ()| Ok(this.user_list()));

0 commit comments

Comments
 (0)