Skip to content

Conversation

riccardoferretti
Copy link
Collaborator

This PR adds support for reference-style link definitions in Foam, unifying how both wikilinks and standard markdown links handle link references. (Fixes #1116)

It also removes the need for [[//begin]] and [[//end]] placeholders as now definitions are more dynamically managed. (Fixes #1504)

Changes

  • Reference-style link support: Wikilinks and markdown links can now use reference-style definitions (e.g., [[my-note]][ref] and [text][ref])
  • Unified reference handling: Consolidated resolution logic across link types - both wikilinks and markdown links now support the definition field
  • Parser improvements: Enhanced markdown parser to extract and associate link definitions with their corresponding links
  • Janitor updates: Updated link reference generator to handle both link types consistently
  • Code cleanup: Renamed reference field to definition throughout codebase for clarity and removed deprecated [[//begin]]/[[//end]] documentation markers
  • Documentation: removed obsolete [[//begin]]/[[//end]] markers

@Copilot Copilot AI review requested due to automatic review settings October 4, 2025 09:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances Foam's link handling by adding support for reference-style link definitions, unifying how both wikilinks and standard markdown links handle references. The changes eliminate the need for [[//begin]] and [[//end]] placeholder markers by implementing more dynamic definition management.

  • Reference-style link support: Both wikilinks and markdown links can now use reference-style definitions
  • Unified reference handling: Consolidated resolution logic across different link types through a common definition field
  • Code cleanup: Removed deprecated [[//begin]]/[[//end]] markers and renamed reference field to definition throughout

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
readme.md Removed deprecated [[//begin]]/[[//end]] markers from documentation
packages/foam-vscode/test-data/scaffold/*.md Cleaned up test files by removing old reference markers
packages/foam-vscode/src/test/test-utils.ts Updated test helper to support new definition structure
packages/foam-vscode/src/features/*.ts Updated workspace symbol provider and commands to work with new definition handling
packages/foam-vscode/src/core/services/*.ts Enhanced markdown parser and provider to support reference-style links
packages/foam-vscode/src/core/model/note.ts Added ResourceLink helper methods and definition field to links
packages/foam-vscode/src/core/janitor/*.ts Updated link reference generator to handle multiple edits
docs/**/*.md Removed old reference markers from documentation files
Comments suppressed due to low confidence (1)

packages/foam-vscode/src/features/commands/janitor.ts:133

  • Missing closing brace for the forEach loop. The forEach callback function is not properly closed.
  });

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

});

it('should apply multiple TextEdits in reverse order (VS Code behavior)', () => {
// This test shows why reverse order is important for range stability
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name and comment mention 'VS Code behavior' but the implementation comment states it matches VS Code behavior without providing a reference. Consider adding a link to VS Code documentation or specification that describes this behavior.

Suggested change
// This test shows why reverse order is important for range stability
// This test shows why reverse order is important for range stability
// See: https://github.com/microsoft/vscode/blob/1.87.0/src/vs/editor/common/model/textModel.ts#L1242-L1260
// (VS Code applies multiple text edits in reverse order to maintain range stability)

Copilot uses AI. Check for mistakes.

[//begin]: # "Autogenerated link references for markdown compatibility"
[Backlinking]: docs/user/features/backlinking.md "Backlinking"
[//end]: # "Autogenerated link references"
[Backlinking]: docs/user/features/backlinking.md 'Backlinks'
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent link title - changed from 'Backlinking' to 'Backlinks', but the original 'Backlinking' matches the filename and is likely correct.

Suggested change
[Backlinking]: docs/user/features/backlinking.md 'Backlinks'
[Backlinking]: docs/user/features/backlinking.md 'Backlinking'

Copilot uses AI. Check for mistakes.

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.

Foam link preview does not work for link definition pattern Reference-style links are not clickable in preview view

1 participant