Skip to content

feat: 支持模版标签的右键查看定义的跳转#110

Merged
wangshunnn merged 2 commits into
mpx-ecology:mainfrom
Triumph-light:feature-template-comp-definition
Jun 22, 2026
Merged

feat: 支持模版标签的右键查看定义的跳转#110
wangshunnn merged 2 commits into
mpx-ecology:mainfrom
Triumph-light:feature-template-comp-definition

Conversation

@Triumph-light

@Triumph-light Triumph-light commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Go to Definition functionality for component tags in templates—developers can now navigate directly to component definitions using standard IDE navigation shortcuts.
  • Improvements

    • Enhanced template context parsing and document link generation with improved reliability across template-embedded blocks.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The mpx-sfc-template-links plugin gains a provideDefinition handler that returns LocationLink targets for component tag names in <template>. Shared template-parsing logic is extracted into resolveTemplateContext, getTagHitOffset, and dedupeComponentPaths helpers, and the existing provideDocumentLinks is refactored to use them, removing non-null assertions and inline de-duplication.

Changes

Component Tag Definition Provider

Layer / File(s) Summary
Shared types and helper functions
packages/language-service/src/plugins/mpx-sfc-template-links.ts
Introduces TemplateNodeTag interface and resolveTemplateContext, getTagHitOffset, dedupeComponentPaths helpers used by both link and definition providers.
Capability wiring and provideDocumentLinks refactor
packages/language-service/src/plugins/mpx-sfc-template-links.ts
Adds definitionProvider: true, rewires provideDocumentLinks to use resolveTemplateContext and dedupeComponentPaths, updates style-map typing, and removes non-null assertions in URI decoding.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • mpx-ecology/language-tools#11: Introduced resolveUsingComponents/resolveUsingComponentsPath path-resolution plumbing and realFilename on component entries, which this PR's dedupeComponentPaths filters and consumes directly.
  • mpx-ecology/language-tools#15: Updated the same mpx-sfc-template-links.ts to handle multiple paths per component tag, which this PR replaces with the new dedupeComponentPaths-driven link and definition logic.

Suggested reviewers

  • wangshunnn

🐇 A rabbit hops through template tags,
"Go to definition!" the cursor brags.
resolveTemplateContext shared with care,
no null assertions left to snare.
From link to definition — the path is clear,
hop hop hooray, the components are here! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title in Chinese translates to 'feat: Support right-click view definition jump for template tags', which accurately describes the main change: adding a provideDefinition handler for component tags in templates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
packages/language-service/src/plugins/mpx-sfc-template-links.ts (1)

257-265: 💤 Low value

Consider avoiding the type assertion if upstream types permit.

The as SfcJsonBlockUsingComponents | undefined cast works but could mask type drift if the upstream resolvedUsingComponents.result shape changes. If the @mpxjs/language-core package already exports properly typed result, narrowing without the cast would be safer.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/language-service/src/plugins/mpx-sfc-template-links.ts` around lines
257 - 265, The type assertion on the usingComponents assignment in the return
object is masking potential type issues. Remove the as
SfcJsonBlockUsingComponents | undefined cast and rely on the type that is
already provided by the upstream resolvedUsingComponents.result from
root.sfc.json. TypeScript should be able to infer the correct type automatically
when you assign the result property value directly to usingComponents without
the explicit type assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/language-service/src/plugins/mpx-sfc-template-links.ts`:
- Around line 257-265: The type assertion on the usingComponents assignment in
the return object is masking potential type issues. Remove the as
SfcJsonBlockUsingComponents | undefined cast and rely on the type that is
already provided by the upstream resolvedUsingComponents.result from
root.sfc.json. TypeScript should be able to infer the correct type automatically
when you assign the result property value directly to usingComponents without
the explicit type assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5366725c-4aec-46dc-ba2a-b8ea28a90a07

📥 Commits

Reviewing files that changed from the base of the PR and between 28d61e8 and afbadbe.

📒 Files selected for processing (1)
  • packages/language-service/src/plugins/mpx-sfc-template-links.ts

@wangshunnn wangshunnn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@wangshunnn wangshunnn merged commit 3812163 into mpx-ecology:main Jun 22, 2026
2 checks passed
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