Honor user-level workbench.editorAssociations for attachment links (#1675) - #1693
Merged
Conversation
… links Analysis of why the 0.44.2 fix (commit 0c25941) did not resolve the issue: plain-URI DocumentLinks open via openerService/openCodeEditor, which does not honor user-level workbench.editorAssociations, unlike the vscode.open command used by the built-in Markdown extension. Proposes routing attachment/image links through a vscode.open command URI. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VNA7nU1yjJVsDmo2bbj5h8
) DocumentLinks with a plain file URI target are opened through the openerService, which does not honor user-level (or profile-propagated) workbench.editorAssociations. Route attachment and image links through a command URI invoking vscode.open instead - the same mechanism the built-in Markdown extension uses - so the configured editor is resolved at every settings scope. Reference-style links to attachments now go through the same path. Also adds a DocumentLink class to the vscode mock and marks the navigation-provider spec as @unit-ready so it runs under the mock. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VNA7nU1yjJVsDmo2bbj5h8
…sion A Foam DocumentLink over [text](file.pdf) shadows the built-in Markdown extension's link, which already opens through vscode.open and honors markdown.links.openLocation. Skip emitting Foam links for direct markdown links to attachments/images; wikilinks and reference-style links keep the vscode.open command link, since VS Code has no native handling for them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VNA7nU1yjJVsDmo2bbj5h8
The clickable range of a wikilink DocumentLink now covers only the inner content of [[...]], consistent with how VS Code styles markdown links. Applies to both resolved-reference links and attachment/image links. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VNA7nU1yjJVsDmo2bbj5h8
For [text][ref] the DocumentLink now covers only the reference label; for collapsed [text][] and shortcut [text] forms it covers the text. Applies to both note and attachment targets via the shared linkRange helper. Multi-line links fall back to the full range. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VNA7nU1yjJVsDmo2bbj5h8
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VNA7nU1yjJVsDmo2bbj5h8
Co-authored-by: Riccardo <code@riccardoferretti.com>
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.
Problem
#1675: with
workbench.editorAssociationsset in user settings (e.g."*.jpg": "default"), ctrl+clicking a link to that file type in a Foam workspace opens the wrong editor (e.g. the built-in image preview). The same setting at workspace scope works, and with Foam disabled the user-level setting works too. The fix shipped in 0.44.2 (DocumentLinks with plain file URI targets) did not resolve it — the reporter reproduced the bug on 0.44.2 itself.Root cause
openerService→editorService.openCodeEditor, which does not go through the same editor resolution as thevscode.opencommand; user-level (profile-propagated)workbench.editorAssociationsis ignored on that path.vscode.opencommand (extensions/markdown-language-features/src/util/openDocumentLink.ts), which resolves the editor correctly at every settings scope — that's why everything works with Foam disabled.[text](file.jpg)range also shadowed the built-in link (overlapping links are deduped), replacing the working native behavior.Changes
command:vscode.open(via the existingcommandAsURIhelper) — the same mechanism the built-in Markdown extension uses. Verified that VS Code'sCommandOpenerrevives$mid-marshalledUricommand arguments, so the target round-trips correctly.[text](file.pdf)) emit no Foam DocumentLink at all: the built-in Markdown extension's link is no longer shadowed and handles the click natively (also honoringmarkdown.links.openLocation). Foam still suppresses its Definition for these targets so nothing hijacks ctrl+click.[[...]](also for resolved-reference wikilinks, the Go to Definition mouse gesture on wikilink doesn't open linked note #1294 case), full reference links[text][ref]cover only the reference label, and collapsed ([text][]) / shortcut ([text]) forms cover the text. Multi-line links fall back to the full range.DocumentLinkclass to the vscode mock and markednavigation-provider.spec.tsas@unit-readyso it runs under the mock as well as in the extension host.foam-vscodepatch (no@foam/corechanges).Testing
vscode.opencommand targets, no-link-for-direct-markdown-links, bracket-free wikilink ranges, reference-label ranges for all three reference forms), confirmed each failed against the previous implementation, then implemented.cache.spec.ts(chmod-based readonly simulation is a no-op when running as root) that reproduce on a clean checkout.[test](+ collapsed/full reference forms), Foam's link range is now identical to the built-in Markdown extension's, so overlap dedup depends on provider ordering — verify in a real window that ctrl+click still opens the target file rather than jumping to the[ref]:definition line. Also worth re-running the reporter's matrix (user-level vs workspace-level setting, with a profile +applyToAllProfiles) for[test](a.jpg),[[a.jpg]], and a PDF.Since #1675 was closed with the 0.44.2 fix that turned out to be insufficient, it may be worth reopening it until this lands.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VNA7nU1yjJVsDmo2bbj5h8
Generated by Claude Code