mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
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:
parent
5cf6c4d4eb
commit
cd1fc21df7
6 changed files with 29 additions and 22 deletions
1
.github/workflows/lua.yml
vendored
1
.github/workflows/lua.yml
vendored
|
@ -4,6 +4,7 @@ on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- stable
|
- stable
|
||||||
|
- dev
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
|
@ -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
|
||||||
|
|
31
dist/lua/annotations.lua
vendored
31
dist/lua/annotations.lua
vendored
|
@ -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 = {}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue