chore: support opening files with correct fine number

This commit is contained in:
Ali Almohaya 2022-09-27 01:37:15 +03:00
parent d03ef94579
commit 0c4f3bf7c0
No known key found for this signature in database
GPG key ID: 4B80BC43FC6007E0
2 changed files with 10 additions and 8 deletions

View file

@ -19,7 +19,6 @@ function M.setup()
end end
function M.openFile() function M.openFile()
-- TODO - 3: get the selected range in the buffer and add it to the file url
if M.is_no_git_origin then if M.is_no_git_origin then
utils.print_no_remote_message() utils.print_no_remote_message()
return return
@ -33,15 +32,14 @@ function M.openFile()
return return
end end
local line_number = utils.get_line_number_from_buf()
local current_branch_name_or_commit_hash = utils.get_current_branch_or_commit() 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 local file_page_url = M.repo_url .. "/blob/" .. current_branch_name_or_commit_hash .. file_path .. "#L" .. line_number
local result = utils.open_url(file_page_url) local result = utils.open_url(file_page_url)
if result then if result == false then
print("Opening url " .. file_page_url)
else
print("Unknown OS please open report") print("Unknown OS please open report")
end end
end end
@ -58,9 +56,7 @@ function M.openRepo()
local result = utils.open_url(repo_page_url) local result = utils.open_url(repo_page_url)
if result then if result == false then
print("Opening url " .. repo_page_url)
else
print("Unknown OS please open report") print("Unknown OS please open report")
end end
end end

View file

@ -72,6 +72,12 @@ function M.get_current_relative_file_path()
return relative_file_path return relative_file_path
end end
-- get the line number in the buffer
function M.get_line_number_from_buf()
local lineNum = vim.api.nvim__buf_stats(0).current_lnum
return lineNum
end
-- opens a url in the correct OS -- opens a url in the correct OS
function M.open_url(url) function M.open_url(url)
local os = vim.loop.os_uname().sysname local os = vim.loop.os_uname().sysname