Skip to content

Commit

Permalink
fix(typings): make it useful for diagnoistics
Browse files Browse the repository at this point in the history
  • Loading branch information
phanen committed Aug 6, 2024
1 parent d921f21 commit a65e6cc
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 12 deletions.
10 changes: 7 additions & 3 deletions lua/gx/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ local search_handler = require("gx.handlers.search")

local M = {}

---@param handlers table<string, boolean|GxHandler>
---@param handler boolean|GxHandler
---@param active boolean
local function add_handler(handlers, handler, active)
if
active == false
Expand All @@ -23,7 +26,7 @@ local function add_handler(handlers, handler, active)
handlers[#handlers + 1] = handler
end

---@param handlers { [string]: (boolean | GxHandler)[] }
---@param handlers table<string, boolean|GxHandler>
---@return GxHandler[]
local function resolve_handlers(handlers)
local resolved = {}
Expand Down Expand Up @@ -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<string, boolean|GxHandler>
---@param handler_options GxHandlerOptions
---@return GxSelection[]
function M.get_url(mode, line, configured_handlers, handler_options)
local detected_urls_set = {}
local detected_urls = {}
Expand Down
1 change: 1 addition & 0 deletions lua/gx/handlers/brewfile.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local helper = require("gx.helper")

---@type GxHandler
local M = {
-- only Brewfile
name = "brewfile",
Expand Down
3 changes: 2 additions & 1 deletion lua/gx/handlers/commit.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local helper = require("gx.helper")

---@type GxHandler
local M = {
-- every filetype and filename
name = "commit",
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/gx/handlers/cve.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local helper = require("gx.helper")

---@type GxHandler
local M = {
-- every filetype and filename
name = "cve",
Expand Down
3 changes: 2 additions & 1 deletion lua/gx/handlers/github.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local helper = require("gx.helper")

---@type GxHandler
local M = {
-- every filetype and filename
name = "github",
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/gx/handlers/go.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@type GxHandler
local M = {
-- every filetype and filename
name = "go",
Expand Down
1 change: 1 addition & 0 deletions lua/gx/handlers/markdown.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local helper = require("gx.helper")

---@type GxHandler
local M = {
-- every filetype and filename
name = "markdown",
Expand Down
1 change: 1 addition & 0 deletions lua/gx/handlers/package_json.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local helper = require("gx.helper")

---@type GxHandler
local M = {
-- only package.json
name = "package_json",
Expand Down
17 changes: 10 additions & 7 deletions lua/gx/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean|GxHandler>
---@field handler_options GxHandlerOptions

---@class GxSelection
---@field name string | nil
---@field name string?
---@field url string

-- search for url with handler
Expand Down Expand Up @@ -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 {}
Expand Down

0 comments on commit a65e6cc

Please sign in to comment.