Skip to content

Commit

Permalink
fix: use git source end_col calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
saecki committed Jul 1, 2024
1 parent 82f8e0a commit 5bb3c9e
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions lua/crates/edit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,32 +306,35 @@ end
---@param crate TomlCrate
---@param repo_url string
function M.use_git_source(buf, crate, repo_url)
if not repo_url then
if not (repo_url and crate.vers) then
return
end

if crate.vers then
if crate.syntax == TomlCrateSyntax.PLAIN then
local t = '{ git = "' .. repo_url .. '" }'
local line = crate.vers.line
vim.api.nvim_buf_set_text(
buf, line, crate.vers.col.s - 1, line, crate.vers.col.e + 1, { t }
)
return
elseif crate.syntax == TomlCrateSyntax.INLINE_TABLE then
local line = crate.vers.line
local text = ' git = "' .. repo_url .. '"'
vim.api.nvim_buf_set_text(
buf, line, crate.vers.decl_col.s, line, crate.vers.col.e + 1, { text }
)
return
else
local line = crate.vers.line
local text = 'git = "' .. repo_url .. '"'
vim.api.nvim_buf_set_text(
buf, line, crate.vers.decl_col.s, line, crate.vers.col.e + 1, { text }
)
end
local end_col = crate.vers.col.e
if crate.vers.quote.e then
end_col = end_col + 1
end

if crate.syntax == TomlCrateSyntax.PLAIN then
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 }
)
return
elseif crate.syntax == TomlCrateSyntax.INLINE_TABLE then
local line = crate.vers.line
local text = ' git = "' .. repo_url .. '"'
vim.api.nvim_buf_set_text(
buf, line, crate.vers.decl_col.s, line, end_col, { text }
)
return
else
local line = crate.vers.line
local text = 'git = "' .. repo_url .. '"'
vim.api.nvim_buf_set_text(
buf, line, crate.vers.decl_col.s, line, end_col + 1, { text }
)
end
end

Expand Down

0 comments on commit 5bb3c9e

Please sign in to comment.