Skip to content

Commit

Permalink
docs(annotation): fix type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
bekaboo committed Aug 1, 2023
1 parent 7c8ac2a commit 758b52e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
32 changes: 27 additions & 5 deletions lua/dropbar/bar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end
---@field entry_idx integer? index of the symbol in the menu entry
---@field sibling_idx integer? index of the symbol in its siblings
---@field range dropbar_symbol_range_t?
---@field on_click fun(this: dropbar_symbol_t, min_width: integer?, n_clicks: integer?, button: string?, modifiers: string?)|false? force disable on_click when false
---@field on_click fun(this: dropbar_symbol_t, min_width: integer?, n_clicks: integer?, button: string?, modifiers: string?)|false|nil force disable on_click when false
---@field data table? any data associated with the symbol
---@field cache table caches string representation, length, etc. for the symbol
local dropbar_symbol_t = {}
Expand All @@ -62,19 +62,41 @@ function dropbar_symbol_t:__newindex(k, v)
end

---Create a new dropbar symbol instance with merged options
---@param opts dropbar_symbol_t
---@param opts dropbar_symbol_opts_t
---@return dropbar_symbol_t
function dropbar_symbol_t:merge(opts)
return dropbar_symbol_t:new(
setmetatable(
vim.tbl_deep_extend('force', self._, opts),
getmetatable(self._)
)
) --[[@as dropbar_symbol_opts_t]]
)
end

---@class dropbar_symbol_opts_t
---@field _ dropbar_symbol_t?
---@field name string?
---@field icon string?
---@field name_hl string?
---@field icon_hl string?
---@field win integer? the source window the symbol is shown in
---@field buf integer? the source buffer the symbol is defined in
---@field view table? original view of the source window
---@field bar dropbar_t? the winbar the symbol belongs to, if the symbol is shown inside a winbar
---@field menu dropbar_menu_t? menu associated with the winbar symbol, if the symbol is shown inside a winbar
---@field entry dropbar_menu_entry_t? the dropbar entry the symbol belongs to, if the symbol is shown inside a menu
---@field children dropbar_symbol_t[]? children of the symbol
---@field siblings dropbar_symbol_t[]? siblings of the symbol
---@field bar_idx integer? index of the symbol in the winbar
---@field entry_idx integer? index of the symbol in the menu entry
---@field sibling_idx integer? index of the symbol in its siblings
---@field range dropbar_symbol_range_t?
---@field on_click fun(this: dropbar_symbol_t, min_width: integer?, n_clicks: integer?, button: string?, modifiers: string?)|false|nil force disable on_click when false
---@field data table? any data associated with the symbol
---@field cache table? caches string representation, length, etc. for the symbol

---Create a dropbar symbol instance
---@param opts dropbar_symbol_t? dropbar symbol structure
---@param opts dropbar_symbol_opts_t? dropbar symbol structure
---@return dropbar_symbol_t
function dropbar_symbol_t:new(opts)
return setmetatable({
Expand Down Expand Up @@ -350,7 +372,7 @@ end
---@field string_cache string
---@field in_pick_mode boolean?
---@field symbol_on_hover dropbar_symbol_t?
---@field last_update_request_time float? timestamp of the last update request in ms, see :h uv.hrtime()
---@field last_update_request_time number? timestamp of the last update request in ms, see :h uv.hrtime()
local dropbar_t = {}
dropbar_t.__index = dropbar_t

Expand Down
32 changes: 27 additions & 5 deletions lua/dropbar/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ _G.dropbar.menus = {}
local dropbar_menu_entry_t = {}
dropbar_menu_entry_t.__index = dropbar_menu_entry_t

---@class dropbar_menu_entry_opts_t
---@field separator dropbar_symbol_t?
---@field padding {left: integer, right: integer}?
---@field components dropbar_symbol_t[]?
---@field menu dropbar_menu_t? the menu the entry belongs to
---@field idx integer? the index of the entry in the menu

---Create a dropbar menu entry instance
---@param opts dropbar_menu_entry_t?
---@param opts dropbar_menu_entry_opts_t?
---@return dropbar_menu_entry_t
function dropbar_menu_entry_t:new(opts)
local entry = setmetatable(
Expand Down Expand Up @@ -181,8 +188,23 @@ end
local dropbar_menu_t = {}
dropbar_menu_t.__index = dropbar_menu_t

---@class dropbar_menu_opts_t
---@field buf integer?
---@field win integer?
---@field is_opened boolean?
---@field entries dropbar_menu_entry_t[]?
---@field win_configs table? window configuration, value can be a function
---@field _win_configs table? evaluated window configuration
---@field cursor integer[]? initial cursor position
---@field prev_win integer? previous window, assigned when calling new() or automatically determined in open()
---@field sub_menu dropbar_menu_t? submenu, assigned when calling new() or automatically determined when a new menu opens
---@field prev_menu dropbar_menu_t? previous menu, assigned when calling new() or automatically determined in open()
---@field clicked_at integer[]? last position where the menu was clicked, byte-indexed, 1,0-indexed
---@field prev_cursor integer[]? previous cursor position
---@field symbol_previewed dropbar_symbol_t? symbol being previewed

---Create a dropbar menu instance
---@param opts dropbar_menu_t?
---@param opts dropbar_menu_opts_t?
---@return dropbar_menu_t
function dropbar_menu_t:new(opts)
local dropbar_menu = setmetatable(
Expand Down Expand Up @@ -460,7 +482,7 @@ function dropbar_menu_t:open_win()
end

---Override menu options
---@param opts dropbar_menu_t?
---@param opts dropbar_menu_opts_t?
---@return nil
function dropbar_menu_t:override(opts)
if not opts then
Expand All @@ -481,7 +503,7 @@ end

---Open the menu
---Side effect: change self.win and self.buf
---@param opts dropbar_menu_t?
---@param opts dropbar_menu_opts_t?
---@return nil
function dropbar_menu_t:open(opts)
if self.is_opened then
Expand Down Expand Up @@ -614,7 +636,7 @@ function dropbar_menu_t:quick_navigation(new_cursor)
end

---Toggle the menu
---@param opts dropbar_menu_t? menu options passed to self:open()
---@param opts dropbar_menu_opts_t? menu options passed to self:open()
---@return nil
function dropbar_menu_t:toggle(opts)
if self.is_opened then
Expand Down

0 comments on commit 758b52e

Please sign in to comment.