feat(lua): pass logs via callback channel, fix hints

This commit is contained in:
əlemi 2024-09-17 18:53:52 +02:00
parent 6e63468e48
commit 7d53f61f0a
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 99 additions and 27 deletions

View file

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

View file

@ -13,48 +13,116 @@
---@field ready boolean true if promise completed ---@field ready boolean true if promise completed
---@class (exact) NilPromise : Promise ---@class (exact) NilPromise : Promise
---@field await fun(self: NilPromise): nil block until promise is ready local NilPromise = {}
---@field and_then fun(self: NilPromise, cb: fun(x: nil)): nil run callback after promise is complete
--- block until promise is ready
function NilPromise:await() end
---@param cb fun() callback to invoke
---invoke callback asynchronously as soon as promise is ready
function NilPromise:and_then(cb) end
---@class (exact) StringPromise : Promise ---@class (exact) StringPromise : Promise
---@field await fun(self: StringPromise): string block until promise is ready and return value local StringPromise = {}
---@field and_then fun(self: StringPromise, cb: fun(x: string)): nil run callback after promise is complete
--- block until promise is ready and return value
--- @return string
function StringPromise:await() end
---@param cb fun(x: string) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function StringPromise:and_then(cb) end
---@class (exact) StringArrayPromise : Promise ---@class (exact) StringArrayPromise : Promise
---@field await fun(self: StringArrayPromise): string[] block until promise is ready and return value local StringArrayPromise = {}
---@field and_then fun(self: StringArrayPromise, cb: fun(x: string[])): nil run callback after promise is complete --- block until promise is ready and return value
--- @return string[]
function StringArrayPromise:await() end
---@param cb fun(x: string[]) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function StringArrayPromise:and_then(cb) end
---@class (exact) ClientPromise : Promise ---@class (exact) ClientPromise : Promise
---@field await fun(self: ClientPromise): Client block until promise is ready and return value local ClientPromise = {}
---@field and_then fun(self: ClientPromise, cb: fun(x: Client)): nil run callback after promise is complete --- block until promise is ready and return value
--- @return Client
function ClientPromise:await() end
---@param cb fun(x: Client) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function ClientPromise:and_then(cb) end
---@class (exact) WorkspacePromise : Promise ---@class (exact) WorkspacePromise : Promise
---@field await fun(self: WorkspacePromise): Workspace block until promise is ready and return value local WorkspacePromise = {}
---@field and_then fun(self: WorkspacePromise, cb: fun(x: Workspace)): nil run callback after promise is complete --- block until promise is ready and return value
--- @return Workspace
function WorkspacePromise:await() end
---@param cb fun(x: Workspace) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function WorkspacePromise:and_then(cb) end
---@class (exact) WorkspaceEventPromise : Promise ---@class (exact) WorkspaceEventPromise : Promise
---@field await fun(self: WorkspaceEventPromise): WorkspaceEvent block until promise is ready and return value local WorkspaceEventPromise = {}
---@field and_then fun(self: WorkspaceEventPromise, cb: fun(x: WorkspaceEvent)): nil run callback after promise is complete --- block until promise is ready and return value
--- @return WorkspaceEvent
function WorkspaceEventPromise:await() end
---@param cb fun(x: WorkspaceEvent) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function WorkspaceEventPromise:and_then(cb) end
---@class (exact) BufferControllerPromise : Promise ---@class (exact) BufferControllerPromise : Promise
---@field await fun(self: BufferControllerPromise): BufferController block until promise is ready and return value local BufferControllerPromise = {}
---@field and_then fun(self: BufferControllerPromise, cb: fun(x: BufferController)): nil run callback after promise is complete --- block until promise is ready and return value
--- @return BufferController
function BufferControllerPromise:await() end
---@param cb fun(x: BufferController) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function BufferControllerPromise:and_then(cb) end
---@class (exact) CursorPromise : Promise ---@class (exact) CursorPromise : Promise
---@field await fun(self: CursorPromise): Cursor block until promise is ready and return value local CursorPromise = {}
---@field and_then fun(self: CursorPromise, cb: fun(x: Cursor)): nil run callback after promise is complete --- block until promise is ready and return value
--- @return Cursor
function CursorPromise:await() end
---@param cb fun(x: Cursor) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function CursorPromise:and_then(cb) end
---@class (exact) MaybeCursorPromise : Promise ---@class (exact) MaybeCursorPromise : Promise
---@field await fun(self: MaybeCursorPromise): Cursor? block until promise is ready and return value local MaybeCursorPromise = {}
---@field and_then fun(self: MaybeCursorPromise, cb: fun(x: Cursor | nil)): nil run callback after promise is complete --- block until promise is ready and return value
--- @return Cursor | nil
function MaybeCursorPromise:await() end
---@param cb fun(x: Cursor | nil) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function MaybeCursorPromise:and_then(cb) end
---@class (exact) TextChangePromise : Promise ---@class (exact) TextChangePromise : Promise
---@field await fun(self: TextChangePromise): TextChange block until promise is ready and return value local TextChangePromise = {}
---@field and_then fun(self: TextChangePromise, cb: fun(x: TextChange)): nil run callback after promise is complete --- block until promise is ready and return value
--- @return TextChange
function TextChangePromise:await() end
---@param cb fun(x: TextChange) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function TextChangePromise:and_then(cb) end
---@class (exact) MaybeTextChangePromise : Promise ---@class (exact) MaybeTextChangePromise : Promise
---@field await fun(self: MaybeTextChangePromise): TextChange? block until promise is ready and return value local MaybeTextChangePromise = {}
---@field and_then fun(self: MaybeTextChangePromise, cb: fun(x: TextChange | nil)): nil run callback after promise is complete --- block until promise is ready and return value
--- @return TextChange | nil
function MaybeTextChangePromise:await() end
---@param cb fun(x: TextChange | nil) callback to invoke
---invoke callback asynchronously as soon as promise is ready
function MaybeTextChangePromise:and_then(cb) end
-- [[ END ASYNC STUFF ]] -- [[ END ASYNC STUFF ]]
@ -329,14 +397,18 @@ function Codemp.poll_callback() end
function Codemp.hash(data) end function Codemp.hash(data) end
---@class (exact) RuntimeDriver ---@class (exact) RuntimeDriver
---@field stop fun(self: RuntimeDriver): boolean stops the runtime thread without deleting the runtime itself, returns false if driver was already stopped local RuntimeDriver = {}
---@return boolean
---stops the runtime thread, returns false if driver was already stopped
function RuntimeDriver:stop() end
---@return RuntimeDriver ---@return RuntimeDriver
---spawns a background thread and uses it to run the codemp runtime ---spawns a background thread and uses it to run the codemp runtime
function Codemp.spawn_runtime_driver() end function Codemp.spawn_runtime_driver() end
---@param printer? string | fun(string) log sink used for printing, if string will go to file, otherwise use given function ---@param printer? string | fun(string) | nil log sink used for printing, if string will go to file, otherwise use given function
---@param debug boolean? show more verbose debug logs, default false ---@param debug? boolean show more verbose debug logs, default false
---@return boolean true if logger was setup correctly, false otherwise ---@return boolean true if logger was setup correctly, false otherwise
---setup a global logger for codemp, note that can only be done once ---setup a global logger for codemp, note that can only be done once
function Codemp.logger(printer, debug) end function Codemp.logger(printer, debug) end

View file

@ -515,8 +515,7 @@ fn logger(_: &Lua, (printer, debug): (LuaValue, Option<bool>)) -> LuaResult<bool
if res { if res {
tokio().spawn(async move { tokio().spawn(async move {
while let Some(msg) = rx.recv().await { while let Some(msg) = rx.recv().await {
let _ = cb.call::<()>((msg,)); CHANNEL.send(cb.clone(), msg);
// if the logger fails logging who logs it?
} }
}); });
} }