-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: grapple.nvim integration (#29)
* feat: grapple integration * feat(grapple): update command completion * readme: update for grapple integration * fix(harpoon): use portal log for errors instead of a raw error
- Loading branch information
Showing
4 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
---@type Portal.QueryGenerator | ||
local function generator(opts, settings) | ||
local Iterator = require("portal.iterator") | ||
local Search = require("portal.search") | ||
|
||
local ok, _ = require("grapple") | ||
if not ok then | ||
require("portal.log").error("Unable to load 'grapple'. Please ensure that grapple.nvim is installed.") | ||
end | ||
|
||
local tags = require("grapple").tags() | ||
|
||
opts = vim.tbl_extend("force", { | ||
direction = "forward", | ||
max_results = #settings.labels, | ||
}, opts or {}) | ||
|
||
if settings.max_results then | ||
opts.max_results = math.min(opts.max_results, settings.max_results) | ||
end | ||
|
||
-- stylua: ignore | ||
local iter = Iterator:new(tags) | ||
:take(settings.lookback) | ||
|
||
if opts.start then | ||
iter = iter:start_at(opts.start) | ||
end | ||
if opts.direction == Search.direction.backward then | ||
iter = iter:reverse() | ||
end | ||
|
||
iter = iter:map(function(v, _) | ||
local buffer | ||
if vim.fn.bufexists(v.file_path) ~= 0 then | ||
buffer = vim.fn.bufnr(v.file_path) | ||
else | ||
buffer = vim.fn.bufadd(v.file_path) | ||
end | ||
|
||
if buffer == vim.fn.bufnr() then | ||
return nil | ||
end | ||
|
||
return { | ||
type = "grapple", | ||
buffer = buffer, | ||
cursor = { row = v.cursor[1], col = v.cursor[2] }, | ||
select = function(content) | ||
require("grapple").select({ key = content.key }) | ||
end, | ||
key = v.key, | ||
} | ||
end) | ||
|
||
iter = iter:filter(function(v) | ||
return vim.api.nvim_buf_is_valid(v.buffer) | ||
end) | ||
if settings.filter then | ||
iter = iter:filter(settings.filter) | ||
end | ||
if opts.filter then | ||
iter = iter:filter(opts.filter) | ||
end | ||
if not opts.slots then | ||
iter = iter:take(opts.max_results) | ||
end | ||
|
||
return { | ||
source = iter, | ||
slots = opts.slots, | ||
} | ||
end | ||
|
||
return generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters