Skip to content

feat(credo): auto install latest version #114

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

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion bin/credo-language-server
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

System.no_halt(true)

Mix.install([ {:credo_language_server, System.get_env("CREDO_LSP_VERSION")}, ])
Mix.install([{:credo_language_server, System.get_env("CREDO_LSP_VERSION")}])

Application.ensure_all_started(:credo_language_server)
5 changes: 2 additions & 3 deletions lua/elixir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local elixirls = require("elixir.elixirls")
local credo = require("elixir.credo")
local mix = require("elixir.mix")
local projectionist = require("elixir.projectionist")
local utils = require("elixir.utils")

local M = {}

Expand All @@ -16,8 +17,6 @@ M.credo.default_bin = (
vim.fn.fnamemodify(debug.getinfo(1).source, ":h") .. "/../../bin/credo-language-server"
):gsub("^@", "")

M.credo.default_version = "0.0.5"

local enabled = function(value)
return value == nil or value == true
end
Expand All @@ -33,7 +32,7 @@ function M.setup(opts)
end

if not opts.credo.version then
opts.credo.version = M.credo.default_version
opts.credo.version = utils.latest_release("elixir-tools", "credo-language-server")
end

mix.setup()
Expand Down
11 changes: 11 additions & 0 deletions lua/elixir/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ function M.root_dir(fname)
return vim.fs.dirname(maybe_umbrella_path or child_or_root_path)
end

function M.latest_release(owner, repo)
local curl = string.format(
[[curl --silent -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/%s/%s/releases/latest]],
owner,
repo
)
local resp = vim.json.decode(vim.fn.system(curl))

return resp and resp.tag_name or nil
end

return M