From 0c4f3bf7c08f256bbc5753e756789447c7fa76c4 Mon Sep 17 00:00:00 2001 From: Ali Almohaya Date: Tue, 27 Sep 2022 01:37:15 +0300 Subject: [PATCH] chore: support opening files with correct fine number --- lua/openingh/init.lua | 12 ++++-------- lua/openingh/utils.lua | 6 ++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lua/openingh/init.lua b/lua/openingh/init.lua index 6eb16b2..45cb8df 100644 --- a/lua/openingh/init.lua +++ b/lua/openingh/init.lua @@ -19,7 +19,6 @@ function M.setup() end 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 utils.print_no_remote_message() return @@ -33,15 +32,14 @@ function M.openFile() return end + local line_number = utils.get_line_number_from_buf() 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) - if result then - print("Opening url " .. file_page_url) - else + if result == false then print("Unknown OS please open report") end end @@ -58,9 +56,7 @@ function M.openRepo() local result = utils.open_url(repo_page_url) - if result then - print("Opening url " .. repo_page_url) - else + if result == false then print("Unknown OS please open report") end end diff --git a/lua/openingh/utils.lua b/lua/openingh/utils.lua index 65f7600..38191ad 100644 --- a/lua/openingh/utils.lua +++ b/lua/openingh/utils.lua @@ -72,6 +72,12 @@ function M.get_current_relative_file_path() return relative_file_path 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 function M.open_url(url) local os = vim.loop.os_uname().sysname