From 758b52e76a2ed3a2666e8ab9e529f4f9c5dbf8c2 Mon Sep 17 00:00:00 2001 From: bekaboo <18127878294@qq.com> Date: Tue, 1 Aug 2023 12:53:15 +0800 Subject: [PATCH] docs(annotation): fix type annotations --- lua/dropbar/bar.lua | 32 +++++++++++++++++++++++++++----- lua/dropbar/menu.lua | 32 +++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/lua/dropbar/bar.lua b/lua/dropbar/bar.lua index bcc9acd7..f98287ba 100644 --- a/lua/dropbar/bar.lua +++ b/lua/dropbar/bar.lua @@ -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 = {} @@ -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({ @@ -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 diff --git a/lua/dropbar/menu.lua b/lua/dropbar/menu.lua index 2e1787a8..6e6e335f 100644 --- a/lua/dropbar/menu.lua +++ b/lua/dropbar/menu.lua @@ -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( @@ -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( @@ -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 @@ -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 @@ -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