Skip to content

Commit 238780e

Browse files
committed
refactor: move normalize_path() into harpoon.utils
1 parent 0378a6c commit 238780e

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lua/harpoon/config.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
local Extensions = require("harpoon.extensions")
22
local Logger = require("harpoon.logger")
3-
local Path = require("plenary.path")
4-
local function normalize_path(buf_name, root)
5-
return Path:new(buf_name):make_relative(root)
6-
end
3+
local Utils = require("harpoon.utils")
4+
75
local function to_exact_name(value)
86
return "^" .. value .. "$"
97
end
@@ -190,7 +188,7 @@ function M.get_default_config()
190188
---@return HarpoonListItem
191189
create_list_item = function(config, name)
192190
name = name
193-
or normalize_path(
191+
or Utils.normalize_path(
194192
vim.api.nvim_buf_get_name(
195193
vim.api.nvim_get_current_buf()
196194
),
@@ -219,7 +217,7 @@ function M.get_default_config()
219217
---@param list HarpoonList
220218
BufLeave = function(arg, list)
221219
local bufnr = arg.buf
222-
local bufname = normalize_path(
220+
local bufname = Utils.normalize_path(
223221
vim.api.nvim_buf_get_name(bufnr),
224222
list.config.get_root_dir()
225223
)

lua/harpoon/list.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local Logger = require("harpoon.logger")
2-
local utils = require("harpoon.utils")
32
local Extensions = require("harpoon.extensions")
43

54
local function guess_length(arr)
@@ -259,7 +258,7 @@ function HarpoonList:resolve_displayed(displayed, length)
259258
for i = 1, length do
260259
local v = displayed[i]
261260
local index = index_of(list_displayed, self._length, v)
262-
if utils.is_white_space(v) then
261+
if Utils.is_white_space(v) then
263262
new_list[i] = nil
264263
elseif index == -1 then
265264
new_list[i] = self.config.create_list_item(self.config, v)

lua/harpoon/utils.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local Path = require("plenary.path")
2+
13
local M = {}
24

35
function M.trim(str)
@@ -22,4 +24,8 @@ function M.is_white_space(str)
2224
return str:gsub("%s", "") == ""
2325
end
2426

27+
function M.normalize_path(buf_name, root)
28+
return Path:new(buf_name):make_relative(root)
29+
end
30+
2531
return M

0 commit comments

Comments
 (0)