Skip to content

Commit

Permalink
feature(handler): introduce new elixir handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-carter committed Dec 16, 2024
1 parent b01db72 commit a4bf815
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lua/gx/handlers/elixir.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
local helper = require("gx.helper")

---@type GxHandler
local M = {
-- every filetype and filename
name = "elixir",
filetype = { "exs" },
filename = nil,
}

-- hex.pm pattern: https://hex.pm/packages/<package>/<version>
local hex_url = "https://hex.pm/packages/"
local pattern = '{:([%l_]*),%s[~>=]-%s"([%d.]*)"[^}]*}'

-- matches package and version from line, e.g. {:dep, ~> "1.0.0"} => "dep", "1.0.0"
function M.handle(_, line, _)
local package_name, version = string.match(line, pattern)
package_name = package_name ~= "" and package_name or nil
version = version ~= "" and version or nil

local hex_path = package_name and version and (package_name .. "/" .. version)
or package_name
or nil

return hex_path and (hex_url .. hex_path) or nil
end

return M

0 comments on commit a4bf815

Please sign in to comment.