Skip to content

Commit

Permalink
refactor: improve LuaLS generator (Chatterino#5283)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz authored Mar 30, 2024
1 parent d4b8fea commit c1bd5d1
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 164 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
- Dev: Added the ability to show `ChannelView`s without a `Split`. (#4747)
- Dev: Refactor Args to be less of a singleton. (#5041)
- Dev: Channels without any animated elements on screen will skip updates from the GIF timer. (#5042, #5043, #5045)
- Dev: Autogenerate docs/plugin-meta.lua. (#5055)
- Dev: Autogenerate docs/plugin-meta.lua. (#5055, #5283)
- Dev: Changed Ubuntu & AppImage builders to statically link Qt. (#5151)
- Dev: Refactor `NetworkPrivate`. (#5063)
- Dev: Refactor `Paths` & `Updates`, focusing on reducing their singletoniability. (#5092, #5102)
Expand Down
71 changes: 32 additions & 39 deletions docs/plugin-meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,46 @@

c2 = {}

---@class IWeakResource

--- Returns true if the channel this object points to is valid.
--- If the object expired, returns false
--- If given a non-Channel object, it errors.
---@return boolean
function IWeakResource:is_valid() end


---@alias LogLevel integer
---@type { Debug: LogLevel, Info: LogLevel, Warning: LogLevel, Critical: LogLevel }
---@alias c2.LogLevel integer
---@type { Debug: c2.LogLevel, Info: c2.LogLevel, Warning: c2.LogLevel, Critical: c2.LogLevel }
c2.LogLevel = {}

---@alias EventType integer
---@type { CompletionRequested: EventType }
---@alias c2.EventType integer
---@type { CompletionRequested: c2.EventType }
c2.EventType = {}

---@class CommandContext
---@field words string[] The words typed when executing the command. For example `/foo bar baz` will result in `{"/foo", "bar", "baz"}`.
---@field channel Channel The channel the command was executed in.

---@class CompletionList
---@field values string[] The completions
---@field hide_others boolean Whether other completions from Chatterino should be hidden/ignored.
-- Now including data from src/common/Channel.hpp.

---@class CompletionEvent
---@field query string The word being completed
---@field full_text_content string Content of the text input
---@field cursor_position integer Position of the cursor in the text input in unicode codepoints (not bytes)
---@field is_first_word boolean True if this is the first word in the input

-- Begin src/common/Channel.hpp

---@alias ChannelType integer
---@type { None: ChannelType }
---@type { None: ChannelType, Direct: ChannelType, Twitch: ChannelType, TwitchWhispers: ChannelType, TwitchWatching: ChannelType, TwitchMentions: ChannelType, TwitchLive: ChannelType, TwitchAutomod: ChannelType, TwitchEnd: ChannelType, Irc: ChannelType, Misc: ChannelType }
ChannelType = {}
-- Back to src/controllers/plugins/LuaAPI.hpp.
-- Now including data from src/controllers/plugins/api/ChannelRef.hpp.
--- This enum describes a platform for the purpose of searching for a channel.
--- Currently only Twitch is supported because identifying IRC channels is tricky.

-- End src/common/Channel.hpp

-- Begin src/controllers/plugins/api/ChannelRef.hpp

---@alias Platform integer
--- This enum describes a platform for the purpose of searching for a channel.
--- Currently only Twitch is supported because identifying IRC channels is tricky.
---@type { Twitch: Platform }
Platform = {}
---@class Channel: IWeakResource

---@class Channel
Channel = {}

--- Returns true if the channel this object points to is valid.
--- If the object expired, returns false
Expand Down Expand Up @@ -82,11 +85,9 @@ function Channel:add_system_message(message) end
--- Compares the channel Type. Note that enum values aren't guaranteed, just
--- that they are equal to the exposed enum.
---
---@return bool
---@return boolean
function Channel:is_twitch_channel() end

--- Twitch Channel specific functions

--- Returns a copy of the channel mode settings (subscriber only, r9k etc.)
---
---@return RoomModes
Expand Down Expand Up @@ -119,15 +120,10 @@ function Channel:is_mod() end
---@return boolean
function Channel:is_vip() end

--- Misc

---@return string
function Channel:__tostring() end

--- Static functions

--- Finds a channel by name.
---
--- Misc channels are marked as Twitch:
--- - /whispers
--- - /mentions
Expand All @@ -142,19 +138,15 @@ function Channel.by_name(name, platform) end

--- Finds a channel by the Twitch user ID of its owner.
---
---@param string id ID of the owner of the channel.
---@param id string ID of the owner of the channel.
---@return Channel?
function Channel.by_twitch_id(string) end
function Channel.by_twitch_id(id) end

---@class RoomModes
---@field unique_chat boolean You might know this as r9kbeta or robot9000.
---@field subscriber_only boolean
---@field emotes_only boolean Whether or not text is allowed in messages.

--- Note that "emotes" here only means Twitch emotes, not Unicode emoji, nor 3rd party text-based emotes

---@field unique_chat number? Time in minutes you need to follow to chat or nil.

---@field emotes_only boolean Whether or not text is allowed in messages. Note that "emotes" here only means Twitch emotes, not Unicode emoji, nor 3rd party text-based emotes
---@field follower_only number? Time in minutes you need to follow to chat or nil.
---@field slow_mode number? Time in seconds you need to wait before sending messages or nil.

---@class StreamStatus
Expand All @@ -164,7 +156,8 @@ function Channel.by_twitch_id(string) end
---@field title string Stream title or last stream title
---@field game_name string
---@field game_id string
-- Back to src/controllers/plugins/LuaAPI.hpp.

-- End src/controllers/plugins/api/ChannelRef.hpp

--- Registers a new command called `name` which when executed will call `handler`.
---
Expand All @@ -176,12 +169,12 @@ function c2.register_command(name, handler) end
--- Registers a callback to be invoked when completions for a term are requested.
---
---@param type "CompletionRequested"
---@param func fun(query: string, full_text_content: string, cursor_position: integer, is_first_word: boolean): CompletionList The callback to be invoked.
---@param func fun(event: CompletionEvent): CompletionList The callback to be invoked.
function c2.register_callback(type, func) end

--- Writes a message to the Chatterino log.
---
---@param level LogLevel The desired level.
---@param level c2.LogLevel The desired level.
---@param ... any Values to log. Should be convertible to a string with `tostring()`.
function c2.log(level, ...) end

Expand Down
Loading

0 comments on commit c1bd5d1

Please sign in to comment.