Added support for ranges when opening a file
This commit is contained in:
parent
602cae773b
commit
0882b3d798
2 changed files with 19 additions and 6 deletions
|
|
@ -22,7 +22,7 @@ function M.setup()
|
|||
M.repo_url = string.format("http://%s/%s/%s", gh.host, gh.user_or_org, gh.reponame)
|
||||
end
|
||||
|
||||
function M.openFile()
|
||||
function M.openFile(range_start, range_end)
|
||||
-- make sure to update the current directory
|
||||
M.setup()
|
||||
if M.is_no_git_origin then
|
||||
|
|
@ -38,10 +38,17 @@ function M.openFile()
|
|||
return
|
||||
end
|
||||
|
||||
local line_number = utils.get_line_number_from_buf()
|
||||
local lines = nil
|
||||
|
||||
if range_start and range_end then
|
||||
lines = "#L" .. range_start .. "-" .. "L" .. range_end
|
||||
else
|
||||
lines = "#L" .. utils.get_line_number_from_buf()
|
||||
end
|
||||
|
||||
local current_branch_name_or_commit_hash = utils.get_current_branch_or_commit()
|
||||
|
||||
local file_page_url = M.repo_url .. "/blob/" .. current_branch_name_or_commit_hash .. file_path .. "#L" .. line_number
|
||||
local file_page_url = M.repo_url .. "/blob/" .. current_branch_name_or_commit_hash .. file_path .. lines
|
||||
|
||||
local result = utils.open_url(file_page_url)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,15 @@ vim.g.openingh = true
|
|||
|
||||
local openingh = require("openingh")
|
||||
|
||||
vim.api.nvim_create_user_command("OpenInGHFile", function()
|
||||
openingh:openFile()
|
||||
end, {})
|
||||
vim.api.nvim_create_user_command("OpenInGHFile", function(opts)
|
||||
if opts.range == 0 or opts.range == 1 then
|
||||
openingh.openFile()
|
||||
else
|
||||
openingh.openFile(opts.line1, opts.line2)
|
||||
end
|
||||
end, {
|
||||
range = true,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("OpenInGHRepo", function()
|
||||
openingh:openRepo()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue