Skip to content

Improve link pattern parsing to trim punctuation wrappers#45457

Merged
MartinYe1234 merged 6 commits into
zed-industries:mainfrom
subtleGradient:markdown-jump-to-def-improved-candidates
May 20, 2026
Merged

Improve link pattern parsing to trim punctuation wrappers#45457
MartinYe1234 merged 6 commits into
zed-industries:mainfrom
subtleGradient:markdown-jump-to-def-improved-candidates

Conversation

@subtleGradient

Copy link
Copy Markdown
Contributor

Closes # (none)

Summary

Improved the jump-to-definition reliability for file paths in prose strings (comments, markdown, etc.) by smarter stripping of surrounding punctuation.

This allows cmd/ctrl-click to work on file paths in contexts like:

  • Markdown backticks: `path/to/file`
  • Markdown links: [link](path/to/file)
  • Parentheses: (see path/to/file)
  • Sentence endings: Check path/to/file.
  • Code spans: `cat path/to/file`

Technical Details

  • Updated link_pattern_file_candidates in hover_links.rs to iteratively trim common leading and trailing punctuation characters.
  • Candidate generation now produces multiple variations (trimmed, regex match, raw) ordered by specificity (most trimmed first).
  • Refactored test_hover_filenames to be DRY: it now uses a single base document string and targeted replacements, making it easier to add new prose test cases without duplication.

Release Notes:

  • Improved jump-to-definition reliability for file paths wrapped in punctuation (backticks, parens, sentence endings).

Copilot AI review requested due to automatic review settings December 20, 2025 17:43
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Dec 20, 2025

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/editor/src/hover_links.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request improves jump-to-definition reliability for file paths embedded in prose text (comments, markdown, documentation) by implementing smarter punctuation stripping. The changes enable cmd/ctrl-click navigation on file paths wrapped in common punctuation patterns like markdown backticks, parentheses, brackets, and sentence-ending punctuation.

Key Changes:

  • Enhanced link_pattern_file_candidates to iteratively strip leading and trailing punctuation characters from file path candidates
  • Introduced ordered candidate generation (trimmed → regex-extracted → raw) with deduplication
  • Refactored test_hover_filenames to use a DRY approach with a base document and targeted line replacements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/editor/src/hover_links.rs
@subtleGradient subtleGradient marked this pull request as draft December 20, 2025 17:54
@subtleGradient subtleGradient force-pushed the markdown-jump-to-def-improved-candidates branch 2 times, most recently from 207b9bb to d026e11 Compare December 20, 2025 18:06
Handles markdown and prose patterns like [title](path), `path`, (path),
and partial wrappers. Returns candidate file paths ordered from most-
specific (trimmed) to least-specific (raw). Expands and updates tests
for various edge cases.
@subtleGradient subtleGradient force-pushed the markdown-jump-to-def-improved-candidates branch from d026e11 to 921a08d Compare December 20, 2025 18:12
@subtleGradient subtleGradient marked this pull request as ready for review December 20, 2025 18:12
@owlx56

owlx56 commented Jan 16, 2026

Copy link
Copy Markdown

Hi, can this pull request fix the problem?

image

As you can see, the clickable URL includes the trailing punctuation (.").

@probably-neb

Copy link
Copy Markdown
Collaborator

sorry for the delay. Once the merge conflicts are resolved I'd be happy to merge this

@MartinYe1234 MartinYe1234 self-requested a review May 20, 2026 20:14
@MartinYe1234 MartinYe1234 added this pull request to the merge queue May 20, 2026
Merged via the queue into zed-industries:main with commit ee5c7b6 May 20, 2026
32 checks passed
@MartinYe1234 MartinYe1234 self-assigned this May 28, 2026
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 2, 2026
…ries#45457)

Closes # (none)

## Summary

Improved the jump-to-definition reliability for file paths in prose
strings (comments, markdown, etc.) by smarter stripping of surrounding
punctuation.

This allows `cmd/ctrl-click` to work on file paths in contexts like:
- **Markdown backticks**: `` `path/to/file` ``
- **Markdown links**: `[link](path/to/file)`
- **Parentheses**: `(see path/to/file)`
- **Sentence endings**: `Check path/to/file.`
- **Code spans**: `` `cat path/to/file` ``

## Technical Details

- Updated `link_pattern_file_candidates` in `hover_links.rs` to
iteratively trim common leading and trailing punctuation characters.
- Candidate generation now produces multiple variations (trimmed, regex
match, raw) ordered by specificity (most trimmed first).
- Refactored `test_hover_filenames` to be DRY: it now uses a single base
document string and targeted replacements, making it easier to add new
prose test cases without duplication.

Release Notes:

- Improved jump-to-definition reliability for file paths wrapped in
punctuation (backticks, parens, sentence endings).

---------

Co-authored-by: Martin Ye <martin@zed.dev>
Co-authored-by: MartinYe1234 <52641447+MartinYe1234@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants