From 047cd66d6f6df343ae26e303b2d42f6f87428e82 Mon Sep 17 00:00:00 2001 From: mpaulson Date: Thu, 30 Nov 2023 20:12:04 -0700 Subject: [PATCH] fix: addresses #346 and #345 --- lua/harpoon/config.lua | 8 +++++++- lua/harpoon/list.lua | 4 ++++ lua/harpoon/utils.lua | 4 ---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua index 8254ff9..09f744b 100644 --- a/lua/harpoon/config.lua +++ b/lua/harpoon/config.lua @@ -1,3 +1,9 @@ +local Path = require("plenary.path") +local function normalize_path(buf_name) + return Path:new(buf_name):make_relative(vim.loop.cwd()) +end + + local M = {} ---@alias HarpoonListItem {value: any, context: any} @@ -127,7 +133,7 @@ function M.get_default_config() -- path, if that is the case we can use the context to -- store the bufname and then have value be the normalized -- value - or vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()) + or normalize_path(vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf())) local bufnr = vim.fn.bufnr(name, false) diff --git a/lua/harpoon/list.lua b/lua/harpoon/list.lua index a0e7771..c760a10 100644 --- a/lua/harpoon/list.lua +++ b/lua/harpoon/list.lua @@ -43,6 +43,10 @@ function HarpoonList:length() return #self.items end +function HarpoonList:clear() + self.items = {} +end + ---@return HarpoonList function HarpoonList:append(item) item = item or self.config.add() diff --git a/lua/harpoon/utils.lua b/lua/harpoon/utils.lua index 8dfa86a..61dcb44 100644 --- a/lua/harpoon/utils.lua +++ b/lua/harpoon/utils.lua @@ -1,9 +1,5 @@ -local Path = require("plenary.path") local M = {} -function M.normalize_path(item) - return Path:new(item):make_relative(M.project_key()) -end function M.is_white_space(str) return str:gsub("%s", "") == ""