Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(handler): introduce new elixir handler #75

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading