~tomleb/repo-url.nvim

a894a94c99d119c6d27bdd8b378dac11a50c63d0 — Tom Lebreux 6 months ago 6cdff24
Add slow fallback for getting go mod info
2 files changed, 18 insertions(+), 0 deletions(-)

M lua/repo-url/health.lua
M lua/repo-url/init.lua
M lua/repo-url/health.lua => lua/repo-url/health.lua +1 -0
@@ 16,5 16,6 @@ return {

    check_executable('git', false)
    check_executable('go', true)
    check_executable('env', true)
  end,
}

M lua/repo-url/init.lua => lua/repo-url/init.lua +17 -0
@@ 13,6 13,8 @@ local M = {}
--- @field history_url (fun(RepoUrl.InfoOpts): string)?
--- @field raw_url (fun(RepoUrl.InfoOpts): string)?

local fallback_gocache_dir = nil

--- @type fun(RepoUrl.InfoOpts, string, string?): string
local pos_to_path = function(opts, format1, format2)
  if opts == nil or opts.line1 == nil then


@@ 148,6 150,21 @@ local function go_modcache_info(filename)
    return false
  end

  if not json.Origin then
    -- XXX: This will be super slow in most cases. Need to find a better way and
    -- potentially make everything async..
    output = vim.fn.system { 'env', 'GOPROXY=direct', 'GOMODCACHE=' .. fallback_gocache_dir, 'go', 'mod', 'download', '-json', module }
    if output == '' then
      return false
    end

    json = vim.fn.json_decode(output)
    if not json then
      return false
    end
    return false
  end

  if not json.Origin or json.Origin.VCS ~= 'git' then
    return false
  end