Skip to content

Commit

Permalink
feat: limit marking to open files
Browse files Browse the repository at this point in the history
  • Loading branch information
noortw01 committed Dec 16, 2024
1 parent 471da25 commit ca1332c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 6 additions & 4 deletions lua/adopure/activate.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local Path = require("plenary.path")
local M = {}

---@param pull_request adopure.PullRequest
Expand All @@ -15,9 +16,9 @@ local function buffer_marker_autocmd(state)
local augroup = vim.api.nvim_create_augroup("adopure.nvim", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter" }, {
group = augroup,
callback = function()
if state.pull_request_threads then
require("adopure.marker").create_buffer_extmarks(state.pull_request_threads)
callback = function(args)
if state.pull_request_threads and args.file ~= "" then
require("adopure.marker").create_buffer_extmarks(state.pull_request_threads, args.buf, args.file)
end
end,
})
Expand All @@ -37,7 +38,8 @@ end

---@param state adopure.AdoState
function M.activate_pull_request_context(state)
require("adopure.marker").create_buffer_extmarks(state.pull_request_threads)
local focused_file_path = Path:new(vim.fn.expand("%:.")).filename
require("adopure.marker").create_buffer_extmarks(state.pull_request_threads, 0, focused_file_path)
require("adopure.git").confirm_checkout_and_open(state.active_pull_request, function()
confirm_open_in_diffview(state.active_pull_request)
end)
Expand Down
18 changes: 8 additions & 10 deletions lua/adopure/marker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,25 @@ end

---Create extmarks for pull request threads
---@param pull_request_threads adopure.Thread[]
function M.create_buffer_extmarks(pull_request_threads)
for _, extmark in pairs(vim.api.nvim_buf_get_extmarks(0, namespace, 0, -1, {})) do
local extmark_id = extmark[1]
vim.api.nvim_buf_del_extmark(0, namespace, extmark_id)
end
---@param bufnr number
---@param file_path string
function M.create_buffer_extmarks(pull_request_threads, bufnr, file_path)
vim.api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1)

local focused_file_path = Path:new(vim.fn.expand("%:."))
local focused_file_path = tostring(Path:new(file_path):make_relative())
for _, pull_request_thread in ipairs(pull_request_threads) do
local open_file_paths = get_open_file_paths()
local file_path, context
if type(pull_request_thread.threadContext) == "table" then
local path_reference = pull_request_thread.threadContext.filePath
file_path = Path:new(string.sub(path_reference, 2))
file_path = tostring(Path:new(string.sub(path_reference, 2)))
context = pull_request_thread.threadContext
end

if
file_path
and context
and tostring(focused_file_path.filePath) == tostring(file_path.filePath)
and focused_file_path == file_path
and not pull_request_thread.isDeleted
and open_file_paths[file_path:absolute()]
and pull_request_thread.threadContext.rightFileStart
then
create_extmark(bufnr, pull_request_thread, context)
Expand Down

0 comments on commit ca1332c

Please sign in to comment.