feat: add ObsidianFindIncomingLinks and ObsidianFindOutgoingLinks commands - #930
Open
metalelf0 wants to merge 3 commits into
Open
feat: add ObsidianFindIncomingLinks and ObsidianFindOutgoingLinks commands#930metalelf0 wants to merge 3 commits into
metalelf0 wants to merge 3 commits into
Conversation
…mands Two new note-context commands for surfacing unlinked plain-text mentions: - `:Obsidian incoming_links` / `:ObsidianFindIncomingLinks` Scans all cached vault notes for plain-text mentions of the current note's title and aliases. Opens a picker; selecting entries (with multi-select via <Tab>) replaces the plain text with a proper link in the target file. - `:Obsidian outgoing_links` / `:ObsidianFindOutgoingLinks` Scans the current buffer for plain-text mentions of other vault notes (by title or alias). Opens a picker; selecting entries converts the mentions to links in-place. Both commands: - Reuse the existing `note/link_suggestion` scan infrastructure (symbols, find, find_in_line) — no new skip logic introduced. - Inherit all existing exclusions: already-linked text, code fences, inline code spans, frontmatter, tags, and bare URLs. - Respect `link.style` / `link.format` config for the produced link. - Require the cache to be enabled and warm; error gracefully otherwise. - Support multi-select (<Tab> to toggle, <CR> to apply all). Incoming-links fast pre-filter: raw string search on file content before full note parse, keeping large-vault performance acceptable. Tests: 7 new cases in tests/test_find_links.lua covering outgoing scan, skip-link, skip-code-fence, skip-inline-code, incoming scan, alias matching, and wikilink exclusion.
Refactor incoming_links.lua to use a scan_note() helper function instead of goto/::continue:: labels. Refactor test_find_links.lua similarly, extracting the shared incoming scan Lua snippet to a module-level constant.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does the PR do?
Adds two new note-context commands for surfacing and converting unlinked plain-text mentions:
:Obsidian incoming_links/:ObsidianFindIncomingLinks— scans all cached vault notes for plain-text mentions of the current note's title or aliases; opens a picker to select matches and convert them to links in the target files.:Obsidian outgoing_links/:ObsidianFindOutgoingLinks— scans the current buffer for plain-text mentions of other vault notes (by title or alias); opens a picker to select and convert matches to links in-place.Both commands support multi-select (
<Tab>to toggle,<CR>to apply all selected).Implementation notes
note/link_suggestionmodule (symbols,find,find_in_line). All skip rules (existing links, code fences, inline code, frontmatter, tags, bare URLs) are inherited for free.cache.notes.all(), applies a fast raw-string pre-filter before full note parse, then scans withfind_in_line. On confirm itbufadd/bufloads the target file, appliesnvim_buf_set_text, writes, and unloads if it was not previously open.link_suggestion.find(note)on the current buffer and delegates conversion to the existingactions.link_suggestion.link.style/link.format.Files changed
lua/obsidian/commands/incoming_links.lualua/obsidian/commands/outgoing_links.lualua/obsidian/commands/init.luanote_action = truelua/obsidian/commands/init-legacy.luaObsidianFindIncomingLinks/ObsidianFindOutgoingLinkslegacy aliasestests/test_find_links.luaCHANGELOG.md/README.mdScreenshots
Picker UI is identical to
:Obsidian backlinks— standard picker with preview, multi-select via<Tab>.PR Checklist
CHANGELOG.mdis updatedREADME.mdfilemake chores(for style, lint, types, and tests)