Skip to content

Commit

Permalink
updating types
Browse files Browse the repository at this point in the history
  • Loading branch information
clpi committed Dec 4, 2024
1 parent 498d243 commit ca9c154
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
40 changes: 19 additions & 21 deletions lua/word/mod/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Mod.__index = Mod
Mod.default_mod = function(name)
return {
setup = function()
---@type word.mod.setup
---@type word.mod.Setup
return {
loaded = true,
requires = {},
Expand Down Expand Up @@ -71,9 +71,9 @@ end

--- @param name string The name of the new init. Modake sure this is unique. The recommended naming convention is `category.modn` or `category.subcategory.modn`.
--- @param imports? string[] A list of imports to attach to the init. Import data is requestable via `init.required`. Use paths relative to the current init.
--- @return word.mod
--- @return word.Mod
function Mod.create(name, imports)
---@type word.mod
---@type word.Mod
local new_mod = Mod.default_mod(name)
if imports then
for _, imp in ipairs(imports) do
Expand Down Expand Up @@ -102,9 +102,9 @@ end
--- Constructs a metainit from a list of submod. Modetamod are mod that can autoload batches of mod at once.
--- @param name string The name of the new metainit. Modake sure this is unique. The recommended naming convention is `category.modn` or `category.subcategory.modn`.
--- @param ... string A list of init names to load.
--- @return word.mod
--- @return word.Mod
Mod.create_meta = function(name, ...)
---@type word.mod
---@type word.Mod
local m = Mod.create(name)

m.config.public.enable = { ... }
Expand Down Expand Up @@ -155,12 +155,12 @@ end
Mod.loaded_mod_count = 0

--- The table of currently loaded mod
--- @type { [string]: word.mod }
--- @type { [string]: word.Mod }
Mod.loaded_mod = {}

--- Loads and enables a init
--- Loads a specified init. If the init subscribes to any events then they will be activated too.
--- @param m word.mod The actual init to load.
--- @param m word.Mod The actual init to load.
--- @return boolean # Whether the init successfully loaded.
function Mod.load_mod_from_table(m)
log.info("Loading init with name" .. m.name)
Expand All @@ -172,7 +172,7 @@ function Mod.load_mod_from_table(m)
end

-- Invoke the setup function. This function returns whether or not the loading of the init was successful and some metadata.
---@type word.mod.setup
---@type word.mod.Setup
local mod_load = m.setup and m.setup()
or {
loaded = true,
Expand Down Expand Up @@ -406,8 +406,8 @@ function Mod.load_mod(modn, cfg)
end

--- Has the same principle of operation as load_mod_from_table(), except it then sets up the parent init's "required" table, allowing the parent to access the child as if it were a dependency.
--- @param md word.mod A valid table as returned by mod.create()
--- @param parent_mod string|word.mod If a string, then the parent is searched for in the loaded mod. If a table, then the init is treated as a valid init as returned by mod.create()
--- @param md word.Mod A valid table as returned by mod.create()
--- @param parent_mod string|word.Mod If a string, then the parent is searched for in the loaded mod. If a table, then the init is treated as a valid init as returned by mod.create()
function Mod.load_mod_as_dependency_from_table(md, parent_mod)
if Mod.load_mod_from_table(md) then
if type(parent_mod) == "string" then
Expand Down Expand Up @@ -528,9 +528,9 @@ function Mod.split_event_type(type)
end

--- Returns an event template defined in `init.events.defined`.
--- @param m word.mod A reference to the init invoking the function
--- @param m word.Mod A reference to the init invoking the function
--- @param type string A full path to a valid event type (e.g. `init.events.some_event`)
--- @return word.event?
--- @return word.Event?
function Mod.get_event_template(m, type)
-- You can't get the event template of a type if the type isn't loaded
if not Mod.is_mod_loaded(m.name) then
Expand All @@ -554,13 +554,13 @@ function Mod.get_event_template(m, type)
end

--- Creates a deep copy of the `mod.base_event` event and returns it with a custom type and referrer.
--- @param m word.mod A reference to the init invoking the function.
--- @param m word.Mod A reference to the init invoking the function.
--- @param name string A relative path to a valid event template.
--- @return word.event
--- @return word.Event
function Mod.define_event(m, name)
-- Create a copy of the base event and override the values with ones specified by the user

---@type word.event
---@type word.Event
local new_event = {
payload = nil,
topic = "base_event",
Expand All @@ -581,18 +581,16 @@ function Mod.define_event(m, name)
if name then
new_event.type = m.name .. ".events." .. name
end

new_event.referrer = m.name

return new_event
end

--- Returns a copy of the event template provided by a init.
--- @param init word.mod A reference to the init invoking the function
--- @param init word.Mod A reference to the init invoking the function
--- @param type string A full path to a valid .vent type (e.g. `init.events.some_event`)
--- @param content table|any? The content of the event, can be anything from a string to a table to whatever you please.
--- @param ev? table The original event data.
--- @return word.event? # New event.
--- @return word.Event? # New event.
function Mod.create_event(m, type, content, ev)
-- Get the init that contains the event
local modn = Mod.split_event_type(type)[1]
Expand Down Expand Up @@ -636,7 +634,7 @@ function Mod.create_event(m, type, content, ev)
end

--- Sends an event to all subscribed mod. The event contains the filename, filehead, cursor position and line content as a bonus.
--- @param event word.event An event, usually created by `mod.create_event()`.
--- @param event word.Event An event, usually created by `mod.create_event()`.
--- @param callback function? A callback to be invoked after all events have been asynchronously broadcast
function Mod.broadcast_event(event, callback)
-- Broadcast the event to all mod
Expand Down Expand Up @@ -666,7 +664,7 @@ function Mod.broadcast_event(event, callback)
end

--- @param recv string The name of a loaded init that will be the recipient of the event.
--- @param ev word.event An event, usually created by `mod.create_event()`.
--- @param ev word.Event An event, usually created by `mod.create_event()`.
--- @return nil
function Mod.send_event(recv, ev)
if not Mod.is_mod_loaded(recv) then
Expand Down
16 changes: 16 additions & 0 deletions lua/word/mod/lsp/notify/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local N = require("word.mod").create("lsp.notify")

N.setup = function()
return {
requires = {
"workspace",
},
loaded = true,
}
end

---@class lsp.notify.Data
N.data = {
}

return N
6 changes: 6 additions & 0 deletions lua/word/types/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
--- @field ['data.export']? data.export.Data
--- @field ['data.encrypt']? data.encrypt.Data
--- @field ['data.metadata']? data.metadata.Data
--- @field ['data.syntax']? data.syntax.Data
--- @field ['data.toc']? data.toc.Data
--- @field ['edit.parse']? edit.parse.Data
--- @field ['data.log']? data.log.Data
--- @field ['data.link']? data.link.Data
Expand All @@ -36,6 +38,10 @@
--- @field ['data.mod']? data.mod.Data
--- @field ['data.code']? data.code.Data
--- @field ['data.todo']? data.todo.Data
--- @field ['edit.todo']? edit.todo.Data
--- @field ['edit.cursor']? edit.cursor.Data
--- @field ['edit.find']? edit.find.Data
--- @field ['edit.indent']? edit.indent.Data
--- @field ui? ui.Data
--- @field ['data.template']? data.template.Data
--- @field ["data.code.snippet"]? data.code.snippet.Data
Expand Down

0 comments on commit ca9c154

Please sign in to comment.