feat: extensions for navigating to harpooned files

This commit is contained in:
mpaulson 2023-12-26 11:36:07 -07:00
parent 2b7cade25a
commit 6f6b1d1d1f
3 changed files with 32 additions and 1 deletions

View File

@ -203,6 +203,17 @@ This can help debug issues on other's computer. To get your debug log please do
1. execute vim command `:lua require("harpoon").logger:show()` and copy the buffer 1. execute vim command `:lua require("harpoon").logger:show()` and copy the buffer
1. paste the buffer as part of the bug creation 1. paste the buffer as part of the bug creation
## Extends
THIS PART OF THE DOCS NEEDS FILLING OUT
```lua
local harpoon = require("harpoon");
local extensions = require("harpoon.extensions");
harpoon:setup()
harpoon:extend(extensions.builtins.command_on_nav("foo bar"));
```
## ⇁ Contribution ## ⇁ Contribution
This project is officially open source, not just public source. If you wish to This project is officially open source, not just public source. If you wish to
contribute start with an issue and I am totally willing for PRs, but I will be contribute start with an issue and I am totally willing for PRs, but I will be

View File

@ -1,3 +1,4 @@
local Extensions = require("harpoon.extensions")
local Logger = require("harpoon.logger") local Logger = require("harpoon.logger")
local Path = require("plenary.path") local Path = require("plenary.path")
local function normalize_path(buf_name, root) local function normalize_path(buf_name, root)
@ -129,6 +130,10 @@ function M.get_default_config()
list_item.context.col or 0, list_item.context.col or 0,
}) })
end end
Extensions.extensions:emit(Extensions.event_names.NAVIGATE, {
buffer = bufnr,
})
end, end,
---@param list_item_a HarpoonListItem ---@param list_item_a HarpoonListItem

View File

@ -12,6 +12,7 @@ local HarpoonExtensions = {}
---@field UI_CREATE? fun(...): nil ---@field UI_CREATE? fun(...): nil
---@field SETUP_CALLED? fun(...): nil ---@field SETUP_CALLED? fun(...): nil
---@field LIST_CREATED? fun(...): nil ---@field LIST_CREATED? fun(...): nil
---@field NAVIGATE? fun(...): nil
HarpoonExtensions.__index = HarpoonExtensions HarpoonExtensions.__index = HarpoonExtensions
@ -40,8 +41,21 @@ function HarpoonExtensions:emit(type, ...)
end end
end end
local extensions = HarpoonExtensions:new()
local Builtins = {
};
function Builtins.command_on_nav(cmd)
return {
NAVIGATE = function()
vim.cmd(cmd)
end,
}
end
return { return {
extensions = HarpoonExtensions:new(), builtins = Builtins,
extensions = extensions,
event_names = { event_names = {
ADD = "ADD", ADD = "ADD",
SELECT = "SELECT", SELECT = "SELECT",
@ -50,5 +64,6 @@ return {
UI_CREATE = "UI_CREATE", UI_CREATE = "UI_CREATE",
SETUP_CALLED = "SETUP_CALLED", SETUP_CALLED = "SETUP_CALLED",
LIST_CREATED = "LIST_CREATED", LIST_CREATED = "LIST_CREATED",
NAVIGATE = "NAVIGATE",
}, },
} }