From 44c464490c28020fc467e9f97e0b557ac9cddb1b Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Tue, 6 Aug 2024 19:08:47 +0800 Subject: [PATCH] fix(typings): make it useful for diagnoistics (#68) --- lua/gx/handler.lua | 10 +++++++--- lua/gx/handlers/brewfile.lua | 1 + lua/gx/handlers/commit.lua | 3 ++- lua/gx/handlers/cve.lua | 1 + lua/gx/handlers/github.lua | 3 ++- lua/gx/handlers/go.lua | 1 + lua/gx/handlers/markdown.lua | 1 + lua/gx/handlers/package_json.lua | 1 + lua/gx/handlers/plugin.lua | 1 + lua/gx/handlers/search.lua | 1 + lua/gx/handlers/url.lua | 1 + lua/gx/init.lua | 17 ++++++++++------- 12 files changed, 29 insertions(+), 12 deletions(-) diff --git a/lua/gx/handler.lua b/lua/gx/handler.lua index e443826..a46eb9c 100644 --- a/lua/gx/handler.lua +++ b/lua/gx/handler.lua @@ -12,6 +12,9 @@ local search_handler = require("gx.handlers.search") local M = {} +---@param handlers table +---@param handler boolean|GxHandler +---@param active boolean local function add_handler(handlers, handler, active) if active == false @@ -23,7 +26,7 @@ local function add_handler(handlers, handler, active) handlers[#handlers + 1] = handler end ----@param handlers { [string]: (boolean | GxHandler)[] } +---@param handlers table ---@return GxHandler[] local function resolve_handlers(handlers) local resolved = {} @@ -55,8 +58,9 @@ end -- handler function ---@param mode string ---@param line string ----@param configured_handlers { [string]: (boolean | GxHandler)[] } ----@return { [number]: GxSelection } +---@param configured_handlers table +---@param handler_options GxHandlerOptions +---@return GxSelection[] function M.get_url(mode, line, configured_handlers, handler_options) local detected_urls_set = {} local detected_urls = {} diff --git a/lua/gx/handlers/brewfile.lua b/lua/gx/handlers/brewfile.lua index d14d7c4..b9f986e 100644 --- a/lua/gx/handlers/brewfile.lua +++ b/lua/gx/handlers/brewfile.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- only Brewfile name = "brewfile", diff --git a/lua/gx/handlers/commit.lua b/lua/gx/handlers/commit.lua index bcfe49b..d3f626a 100644 --- a/lua/gx/handlers/commit.lua +++ b/lua/gx/handlers/commit.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- every filetype and filename name = "commit", @@ -20,7 +21,7 @@ function M.handle(mode, line, handler_options) remotes = remotes(vim.fn.expand("%:p")) end - local push = handler_options.push + local push = handler_options.git_remote_push if type(push) == "function" then push = push(vim.fn.expand("%:p")) end diff --git a/lua/gx/handlers/cve.lua b/lua/gx/handlers/cve.lua index 582391d..e868f6f 100644 --- a/lua/gx/handlers/cve.lua +++ b/lua/gx/handlers/cve.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- every filetype and filename name = "cve", diff --git a/lua/gx/handlers/github.lua b/lua/gx/handlers/github.lua index 689690d..bd72b34 100644 --- a/lua/gx/handlers/github.lua +++ b/lua/gx/handlers/github.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- every filetype and filename name = "github", @@ -26,7 +27,7 @@ function M.handle(mode, line, handler_options) remotes = remotes(vim.fn.expand("%:p")) end - local push = handler_options.push + local push = handler_options.git_remote_push if type(push) == "function" then push = push(vim.fn.expand("%:p")) end diff --git a/lua/gx/handlers/go.lua b/lua/gx/handlers/go.lua index 1fd4224..ebde012 100644 --- a/lua/gx/handlers/go.lua +++ b/lua/gx/handlers/go.lua @@ -1,3 +1,4 @@ +---@type GxHandler local M = { -- every filetype and filename name = "go", diff --git a/lua/gx/handlers/markdown.lua b/lua/gx/handlers/markdown.lua index 7c4cc7f..1ecaba1 100644 --- a/lua/gx/handlers/markdown.lua +++ b/lua/gx/handlers/markdown.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- every filetype and filename name = "markdown", diff --git a/lua/gx/handlers/package_json.lua b/lua/gx/handlers/package_json.lua index 5f0ff87..c8b76f0 100644 --- a/lua/gx/handlers/package_json.lua +++ b/lua/gx/handlers/package_json.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- only package.json name = "package_json", diff --git a/lua/gx/handlers/plugin.lua b/lua/gx/handlers/plugin.lua index 0020ad6..4b95fe0 100644 --- a/lua/gx/handlers/plugin.lua +++ b/lua/gx/handlers/plugin.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- every filename but only lua name = "nvim-plugin", diff --git a/lua/gx/handlers/search.lua b/lua/gx/handlers/search.lua index 30462ed..724e44b 100644 --- a/lua/gx/handlers/search.lua +++ b/lua/gx/handlers/search.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- every filetype and filename name = "search", diff --git a/lua/gx/handlers/url.lua b/lua/gx/handlers/url.lua index 7664729..9d924ee 100644 --- a/lua/gx/handlers/url.lua +++ b/lua/gx/handlers/url.lua @@ -1,5 +1,6 @@ local helper = require("gx.helper") +---@type GxHandler local M = { -- every filetype name = "url", diff --git a/lua/gx/init.lua b/lua/gx/init.lua index 82add5d..12272d4 100644 --- a/lua/gx/init.lua +++ b/lua/gx/init.lua @@ -6,22 +6,24 @@ local M = {} ---@class GxHandlerOptions ---@field search_engine string ----@field select_for_search string +---@field select_for_search boolean +---@field git_remotes string[] +---@field git_remote_push boolean ---@class GxHandler ---@field name string ----@field filetypes string[] | nil ----@field filename string | nil ----@field handle fun(mode: string, line: string, handler_options: GxHandlerOptions | nil) +---@field filetype string[]? +---@field filename string? +---@field handle fun(mode: string, line: string, handler_options: GxHandlerOptions): string? ---@class GxOptions ---@field open_browser_app string ---@field open_browser_args string[] ----@field handlers (boolean | GxHandler)[] ----@field handler_options GxHandlerOptions | nil +---@field handlers table +---@field handler_options GxHandlerOptions ---@class GxSelection ----@field name string | nil +---@field name string? ---@field url string -- search for url with handler @@ -87,6 +89,7 @@ local function get_open_browser_args() return args end +---@param options GxOptions local function with_defaults(options) options = options or {} options.handler_options = options.handler_options or {}