Skip to content

Honor user-level workbench.editorAssociations for attachment links (#1675) - #1693

Merged
riccardoferretti merged 7 commits into
mainfrom
claude/research-issue-1675-5vtovd
Jul 26, 2026
Merged

Honor user-level workbench.editorAssociations for attachment links (#1675)#1693
riccardoferretti merged 7 commits into
mainfrom
claude/research-issue-1675-5vtovd

Conversation

@riccardoferretti

Copy link
Copy Markdown
Collaborator

Problem

#1675: with workbench.editorAssociations set 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

  • A DocumentLink with a plain file URI target is opened via openerServiceeditorService.openCodeEditor, which does not go through the same editor resolution as the vscode.open command; user-level (profile-propagated) workbench.editorAssociations is ignored on that path.
  • The built-in Markdown extension opens its links through the vscode.open command (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.
  • Foam's DocumentLink over the whole [text](file.jpg) range also shadowed the built-in link (overlapping links are deduped), replacing the working native behavior.

Changes

  • Wikilinks and reference-style links to attachments/images now emit a DocumentLink targeting command:vscode.open (via the existing commandAsURI helper) — the same mechanism the built-in Markdown extension uses. Verified that VS Code's CommandOpener revives $mid-marshalled Uri command arguments, so the target round-trips correctly.
  • Direct markdown links ([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 honoring markdown.links.openLocation). Foam still suppresses its Definition for these targets so nothing hijacks ctrl+click.
  • Clickable ranges now match VS Code's markdown link styling: wikilinks cover only the inner content of [[...]] (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.
  • Test infrastructure: added a DocumentLink class to the vscode mock and marked navigation-provider.spec.ts as @unit-ready so it runs under the mock as well as in the extension host.
  • Changeset: foam-vscode patch (no @foam/core changes).

Testing

  • Followed the test-first workflow for each behavior change: updated/added specs (vscode.open command 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.
  • Full unit suite green; the only failures are two pre-existing environmental ones in cache.spec.ts (chmod-based readonly simulation is a no-op when running as root) that reproduce on a clean checkout.
  • The real-VS Code e2e run could not execute in the dev environment (VS Code download blocked by proxy) — CI should be the gate for the extension-host run.
  • Recommended manual check: for the shortcut form [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

claude added 6 commits July 25, 2026 11:45
… 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
Comment thread packages/foam-vscode/src/vscode/features/navigation/navigation-provider.spec.ts Outdated
Comment thread packages/foam-vscode/src/vscode/features/navigation/navigation-provider.spec.ts Outdated
Comment thread packages/foam-vscode/src/vscode/features/navigation/navigation-provider.spec.ts Outdated
Comment thread packages/foam-vscode/src/vscode/features/navigation/navigation-provider.ts Outdated
Co-authored-by: Riccardo <code@riccardoferretti.com>
@riccardoferretti
riccardoferretti merged commit 5c5d89d into main Jul 26, 2026
8 checks passed
@riccardoferretti
riccardoferretti deleted the claude/research-issue-1675-5vtovd branch July 26, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants