diff --git a/.github/workflows/lua.yml b/.github/workflows/lua.yml index 1d33d9c..0d0be3d 100644 --- a/.github/workflows/lua.yml +++ b/.github/workflows/lua.yml @@ -4,6 +4,7 @@ on: push: branches: - stable + - dev permissions: contents: read diff --git a/Cargo.toml b/Cargo.toml index 4ca0a86..1d139a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,8 +72,9 @@ rust = [] # used for ci matrix java = ["lazy_static", "jni", "tracing-subscriber"] js = ["napi-build", "tracing-subscriber", "napi", "napi-derive"] py = ["pyo3", "tracing-subscriber", "pyo3-build-config"] -lua = ["mlua-codemp-patch", "tracing-subscriber", "lazy_static", "serialize", "mlua-codemp-patch/lua54"] -luajit = ["mlua-codemp-patch", "tracing-subscriber", "lazy_static", "serialize", "mlua-codemp-patch/luajit"] +lua = ["mlua-codemp-patch", "tracing-subscriber", "lazy_static", "serialize"] +lua54 =["lua", "mlua-codemp-patch/lua54"] +luajit = ["lua", "mlua-codemp-patch/luajit"] [package.metadata.docs.rs] # enabled features when building on docs.rs diff --git a/dist/lua/annotations.lua b/dist/lua/annotations.lua index 8e19337..07029e5 100644 --- a/dist/lua/annotations.lua +++ b/dist/lua/annotations.lua @@ -121,14 +121,14 @@ local Workspace = {} ---@async ---@nodiscard ---create a new empty buffer -function Workspace:create_buffer(path) end +function Workspace:create(path) end ---@param path string relative path ("name") of buffer to delete ---@return NilPromise ---@async ---@nodiscard ---delete buffer from workspace -function Workspace:delete_buffer(path) end +function Workspace:delete(path) end ---@param path string relative path ("name") of buffer to get ---@return BufferController? @@ -140,15 +140,15 @@ function Workspace:get_buffer(path) end ---@async ---@nodiscard ---attach to a remote buffer, synching content and changes and returning its controller -function Workspace:attach_buffer(path) end +function Workspace:attach(path) end ---@param path string relative path ("name") of buffer to detach from ---@return boolean ---detach from an active buffer, closing all streams. returns false if buffer was no longer active -function Workspace:detach_buffer(path) end +function Workspace:detach(path) end ---@param filter? string apply a filter to the return elements ----@param strict boolean whether to strictly match or just check whether it starts with it +---@param strict? boolean whether to strictly match or just check whether it starts with it ---@return string[] ---return the list of available buffers in this workspace, as relative paths from workspace root function Workspace:filetree(filter, strict) end @@ -184,10 +184,14 @@ local BufferController = {} ---@class TextChange ---@field content string text content of change ----@field first integer start index of change ----@field last integer end index of change +---@field start integer start index of change +---@field finish integer end index of change ---@field hash integer? optional hash of text buffer after this change, for sync checks ----@field apply fun(self: TextChange, other: string): string apply this text change to a string +local TextChange = {} + +---@param other string text to apply change to +---apply this text change to a string, returning the result +function TextChange:apply(other) end ---@param change TextChange text change to broadcast ---@return NilPromise @@ -238,16 +242,11 @@ function BufferController:content() end ---handle to a workspace's cursor channel, allowing send/recv operations local CursorController = {} ----@class RowCol ----@field row integer row number ----@field col integer column number ----row and column tuple - ---@class Cursor ---@field user string? id of user owning this cursor ---@field buffer string relative path ("name") of buffer on which this cursor is ----@field start RowCol cursor start position ----@field finish RowCol cursor end position +---@field start [integer, integer] cursor start position +---@field finish [integer, integer] cursor end position ---a cursor position ---@param cursor Cursor cursor event to broadcast @@ -297,7 +296,7 @@ function CursorController:callback(cb) end ---@field port integer | nil port to connect to, default 50053 ---@field tls boolean | nil enable or disable tls, default true ----@class (exact) Codemp +---@class Codemp ---the codemp shared library local Codemp = {} diff --git a/src/api/change.rs b/src/api/change.rs index 6e0aa1c..9c04aad 100644 --- a/src/api/change.rs +++ b/src/api/change.rs @@ -28,6 +28,7 @@ pub struct TextChange { /// Range start of text change, as char indexes in buffer previous state. pub start: u32, /// Range end of text change, as char indexes in buffer previous state. + #[cfg_attr(feature = "serialize", serde(alias = "finish"))] // Lua uses `end` as keyword pub end: u32, /// New content of text inside span. pub content: String, diff --git a/src/api/cursor.rs b/src/api/cursor.rs index 06b6b94..1016ca5 100644 --- a/src/api/cursor.rs +++ b/src/api/cursor.rs @@ -13,6 +13,7 @@ pub struct Cursor { /// Cursor start position in buffer, as 0-indexed row-column tuple. pub start: (i32, i32), /// Cursor end position in buffer, as 0-indexed row-column tuple. + #[cfg_attr(feature = "serialize", serde(alias = "finish"))] // Lua uses `end` as keyword pub end: (i32, i32), /// Path of buffer this cursor is on. pub buffer: String, diff --git a/src/ffi/lua.rs b/src/ffi/lua.rs index 4a80bab..1150555 100644 --- a/src/ffi/lua.rs +++ b/src/ffi/lua.rs @@ -294,8 +294,8 @@ impl LuaUserData for CodempWorkspace { // Ok(()) // }); - methods.add_method("filetree", |_, this, (filter, strict,):(Option, bool,)| - Ok(this.filetree(filter.as_deref(), strict)) + methods.add_method("filetree", |_, this, (filter, strict,):(Option, Option,)| + Ok(this.filetree(filter.as_deref(), strict.unwrap_or(false))) ); } @@ -359,6 +359,8 @@ impl LuaUserData for Cursor { fields.add_field_method_get("user", |_, this| Ok(this.user.clone())); fields.add_field_method_get("buffer", |_, this| Ok(this.buffer.clone())); fields.add_field_method_get("start", |_, this| Ok(RowCol::from(this.start))); + fields.add_field_method_get("end", |_, this| Ok(RowCol::from(this.end))); + // add a 'finish' accessor too because in Lua 'end' is reserved fields.add_field_method_get("finish", |_, this| Ok(RowCol::from(this.end))); } } @@ -414,9 +416,11 @@ from_lua_serde! { CodempTextChange } impl LuaUserData for CodempTextChange { fn add_fields>(fields: &mut F) { fields.add_field_method_get("content", |_, this| Ok(this.content.clone())); - fields.add_field_method_get("first", |_, this| Ok(this.start)); - fields.add_field_method_get("last", |_, this| Ok(this.end)); + fields.add_field_method_get("start", |_, this| Ok(this.start)); + fields.add_field_method_get("end", |_, this| Ok(this.end)); fields.add_field_method_get("hash", |_, this| Ok(this.hash)); + // add a 'finish' accessor too because in Lua 'end' is reserved + fields.add_field_method_get("finish", |_, this| Ok(this.end)); } fn add_methods>(methods: &mut M) {