feat(lua): alternative getters, annotations

also cleaned up features a bit and updated annotations
oh and run CI too once
This commit is contained in:
əlemi 2024-09-16 18:23:19 +02:00
parent 5cf6c4d4eb
commit cd1fc21df7
Signed by: alemi
GPG key ID: A4895B84D311642C
6 changed files with 29 additions and 22 deletions

View file

@ -4,6 +4,7 @@ on:
push: push:
branches: branches:
- stable - stable
- dev
permissions: permissions:
contents: read contents: read

View file

@ -72,8 +72,9 @@ rust = [] # used for ci matrix
java = ["lazy_static", "jni", "tracing-subscriber"] java = ["lazy_static", "jni", "tracing-subscriber"]
js = ["napi-build", "tracing-subscriber", "napi", "napi-derive"] js = ["napi-build", "tracing-subscriber", "napi", "napi-derive"]
py = ["pyo3", "tracing-subscriber", "pyo3-build-config"] py = ["pyo3", "tracing-subscriber", "pyo3-build-config"]
lua = ["mlua-codemp-patch", "tracing-subscriber", "lazy_static", "serialize", "mlua-codemp-patch/lua54"] lua = ["mlua-codemp-patch", "tracing-subscriber", "lazy_static", "serialize"]
luajit = ["mlua-codemp-patch", "tracing-subscriber", "lazy_static", "serialize", "mlua-codemp-patch/luajit"] lua54 =["lua", "mlua-codemp-patch/lua54"]
luajit = ["lua", "mlua-codemp-patch/luajit"]
[package.metadata.docs.rs] # enabled features when building on docs.rs [package.metadata.docs.rs] # enabled features when building on docs.rs

View file

@ -121,14 +121,14 @@ local Workspace = {}
---@async ---@async
---@nodiscard ---@nodiscard
---create a new empty buffer ---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 ---@param path string relative path ("name") of buffer to delete
---@return NilPromise ---@return NilPromise
---@async ---@async
---@nodiscard ---@nodiscard
---delete buffer from workspace ---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 ---@param path string relative path ("name") of buffer to get
---@return BufferController? ---@return BufferController?
@ -140,15 +140,15 @@ function Workspace:get_buffer(path) end
---@async ---@async
---@nodiscard ---@nodiscard
---attach to a remote buffer, synching content and changes and returning its controller ---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 ---@param path string relative path ("name") of buffer to detach from
---@return boolean ---@return boolean
---detach from an active buffer, closing all streams. returns false if buffer was no longer active ---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 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 string[]
---return the list of available buffers in this workspace, as relative paths from workspace root ---return the list of available buffers in this workspace, as relative paths from workspace root
function Workspace:filetree(filter, strict) end function Workspace:filetree(filter, strict) end
@ -184,10 +184,14 @@ local BufferController = {}
---@class TextChange ---@class TextChange
---@field content string text content of change ---@field content string text content of change
---@field first integer start index of change ---@field start integer start index of change
---@field last integer end 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 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 ---@param change TextChange text change to broadcast
---@return NilPromise ---@return NilPromise
@ -238,16 +242,11 @@ function BufferController:content() end
---handle to a workspace's cursor channel, allowing send/recv operations ---handle to a workspace's cursor channel, allowing send/recv operations
local CursorController = {} local CursorController = {}
---@class RowCol
---@field row integer row number
---@field col integer column number
---row and column tuple
---@class Cursor ---@class Cursor
---@field user string? id of user owning this cursor ---@field user string? id of user owning this cursor
---@field buffer string relative path ("name") of buffer on which this cursor is ---@field buffer string relative path ("name") of buffer on which this cursor is
---@field start RowCol cursor start position ---@field start [integer, integer] cursor start position
---@field finish RowCol cursor end position ---@field finish [integer, integer] cursor end position
---a cursor position ---a cursor position
---@param cursor Cursor cursor event to broadcast ---@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 port integer | nil port to connect to, default 50053
---@field tls boolean | nil enable or disable tls, default true ---@field tls boolean | nil enable or disable tls, default true
---@class (exact) Codemp ---@class Codemp
---the codemp shared library ---the codemp shared library
local Codemp = {} local Codemp = {}

View file

@ -28,6 +28,7 @@ pub struct TextChange {
/// Range start of text change, as char indexes in buffer previous state. /// Range start of text change, as char indexes in buffer previous state.
pub start: u32, pub start: u32,
/// Range end of text change, as char indexes in buffer previous state. /// 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, pub end: u32,
/// New content of text inside span. /// New content of text inside span.
pub content: String, pub content: String,

View file

@ -13,6 +13,7 @@ pub struct Cursor {
/// Cursor start position in buffer, as 0-indexed row-column tuple. /// Cursor start position in buffer, as 0-indexed row-column tuple.
pub start: (i32, i32), pub start: (i32, i32),
/// Cursor end position in buffer, as 0-indexed row-column tuple. /// 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), pub end: (i32, i32),
/// Path of buffer this cursor is on. /// Path of buffer this cursor is on.
pub buffer: String, pub buffer: String,

View file

@ -294,8 +294,8 @@ impl LuaUserData for CodempWorkspace {
// Ok(()) // Ok(())
// }); // });
methods.add_method("filetree", |_, this, (filter, strict,):(Option<String>, bool,)| methods.add_method("filetree", |_, this, (filter, strict,):(Option<String>, Option<bool>,)|
Ok(this.filetree(filter.as_deref(), strict)) 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("user", |_, this| Ok(this.user.clone()));
fields.add_field_method_get("buffer", |_, this| Ok(this.buffer.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("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))); fields.add_field_method_get("finish", |_, this| Ok(RowCol::from(this.end)));
} }
} }
@ -414,9 +416,11 @@ from_lua_serde! { CodempTextChange }
impl LuaUserData for CodempTextChange { impl LuaUserData for CodempTextChange {
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) { fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {
fields.add_field_method_get("content", |_, this| Ok(this.content.clone())); 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("start", |_, this| Ok(this.start));
fields.add_field_method_get("last", |_, this| Ok(this.end)); fields.add_field_method_get("end", |_, this| Ok(this.end));
fields.add_field_method_get("hash", |_, this| Ok(this.hash)); 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<M: LuaUserDataMethods<Self>>(methods: &mut M) { fn add_methods<M: LuaUserDataMethods<Self>>(methods: &mut M) {