From cdb64582dc48080e74e9d51c96bf71cab8ceeffb Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Thu, 3 Feb 2022 15:52:44 -0800 Subject: [PATCH 1/2] harpoon.ui: use vim.loop.cwd() to avoid blocking the event loop Prefer the async API for getting the cwd. --- lua/harpoon/ui.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index e816c01..42ef515 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -164,7 +164,7 @@ function M.nav_file(id) end local mark = Marked.get_marked_file(idx) - local buf_id = vim.fn.bufnr(vim.fn.getcwd() .. "/" .. mark.filename, true) + local buf_id = vim.fn.bufnr(vim.api.cwd() .. "/" .. mark.filename, true) local set_row = not vim.api.nvim_buf_is_loaded(buf_id) vim.api.nvim_set_current_buf(buf_id) From a204fc29dfa0139d7edb8bf4cda07712c1b22a71 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Thu, 3 Feb 2022 02:44:33 -0800 Subject: [PATCH 2/2] harpoon.ui: handle absolute paths If the filename is an absolute path then there is no need to prepend the path with the current directory. Detect absolute paths and open them as-is. This fixes harpoon when editing files through symlinks that point to other places on the filesystem. --- lua/harpoon/ui.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index 42ef515..db880b7 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -164,7 +164,11 @@ function M.nav_file(id) end local mark = Marked.get_marked_file(idx) - local buf_id = vim.fn.bufnr(vim.api.cwd() .. "/" .. mark.filename, true) + local filename = mark.filename + if filename:sub(1, 1) ~= "/" then + filename = vim.loop.cwd() .. "/" .. mark.filename + end + local buf_id = vim.fn.bufnr(filename, true) local set_row = not vim.api.nvim_buf_is_loaded(buf_id) vim.api.nvim_set_current_buf(buf_id)