Skip to content

Commit

Permalink
fix: don't suggest use_git_source action when git key is present
Browse files Browse the repository at this point in the history
  • Loading branch information
saecki committed Aug 2, 2024
1 parent d1be10c commit c3f4f70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions lua/crates/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function M.use_git_source()
local crates = util.get_line_crates(buf, Span.pos(line))
local _, crate = next(crates)

if crate and crate.vers then
if crate and crate.vers and not crate.git then
local api_crate = state.api_cache[crate:package()]
if api_crate and api_crate.repository then
edit.use_git_source(buf, crate, api_crate.repository)
Expand Down Expand Up @@ -324,10 +324,12 @@ function M.get_actions()
})
end

table.insert(actions, {
name = "use_git_source",
action = M.use_git_source,
})
if crate.vers and not crate.git then
table.insert(actions, {
name = "use_git_source",
action = M.use_git_source,
})
end

table.insert(actions, {
name = "open_documentation",
Expand Down
4 changes: 2 additions & 2 deletions lua/crates/edit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ end
---@param crate TomlCrate
---@param repo_url string
function M.use_git_source(buf, crate, repo_url)
if not (repo_url and crate.vers) then
if not (repo_url and crate.vers and not crate.git) then
return
end

Expand All @@ -310,7 +310,7 @@ function M.use_git_source(buf, crate, repo_url)
local t = '{ git = "' .. repo_url .. '" }'
local line = crate.vers.line
vim.api.nvim_buf_set_text(
buf, line, crate.vers.col.s - 1, line, end_col, { t }
buf, line, crate.vers.col.s - 1, line, end_col, { t }
)
return
elseif crate.syntax == TomlCrateSyntax.INLINE_TABLE then
Expand Down

0 comments on commit c3f4f70

Please sign in to comment.