feat(ai): add standalone agent mode and component goToDefinition#109
Conversation
- Add agent mode (initializationOptions.agent=true) using createTypeScriptProject + semantic plugin for standalone TS language service without tsserver - Preserve original IDE mode (simpleProject + sendTsRequest) unchanged - New mpx-component-definition plugin: definitionProvider for JSON usingComponents paths and template component tags - Add volar-service-typescript dependency for agent mode Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds an MPX component definition LanguageServicePlugin, wires it behind a new language-service option, and updates the language-server to support both IDE (tsserver-backed) and agent (standalone TypeScript project with semantic plugin) initialization; also adds the TypeScript service dependency and tweaks an extension theme setting. ChangesComponent Definition and Server Initialization
Sequence Diagram(s)sequenceDiagram
participant Editor
participant MpxComponentDefinitionPlugin
participant JsonHandler
participant TemplateHandler
participant ComponentResolver
Editor->>MpxComponentDefinitionPlugin: provideDefinition(document, position)
MpxComponentDefinitionPlugin->>MpxComponentDefinitionPlugin: decode embedded URI & verify MpxVirtualCode
alt JSON embedded code
MpxComponentDefinitionPlugin->>JsonHandler: provideJsonDefinition(root, offset)
JsonHandler->>ComponentResolver: read sfc.json.resolvedUsingComponents
ComponentResolver-->>JsonHandler: component entries with spans
JsonHandler->>JsonHandler: find component span containing cursor
JsonHandler-->>MpxComponentDefinitionPlugin: location in real file (with originSelectionRange)
else Template embedded code
MpxComponentDefinitionPlugin->>TemplateHandler: provideTemplateDefinition(root, offset)
TemplateHandler->>ComponentResolver: derive generated template node tags
ComponentResolver-->>TemplateHandler: component tag ranges
TemplateHandler->>TemplateHandler: detect cursor within start/end tag span
TemplateHandler-->>MpxComponentDefinitionPlugin: location in real file (with originSelectionRange)
end
MpxComponentDefinitionPlugin-->>Editor: return LocationLink(s)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
packages/language-service/src/plugins/mpx-component-definition.ts (2)
41-44: 💤 Low valueAvoid using
anytype for well-known LSP parameters.The
documentandpositionparameters have known types from the Volar/LSP ecosystem. Usinganyloses type safety and IDE assistance.♻️ Suggested type annotations
async function provideJsonDefinition( root: MpxVirtualCode, - document: any, - position: any, + document: { offsetAt: (position: { line: number; character: number }) => number; positionAt: (offset: number) => { line: number; character: number } }, + position: { line: number; character: number }, ) {Alternatively, import
TextDocumentfromvscode-languageserver-textdocumentandPositionfromvscode-languageserver-protocol.🤖 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-component-definition.ts` around lines 41 - 44, The provideJsonDefinition function is using broad any types for known LSP parameters; update its signature to type document and position with proper LSP types (e.g., TextDocument from vscode-languageserver-textdocument and Position from vscode-languageserver-protocol or the Volar equivalents) so you retain type safety for MpxVirtualCode handling; change the function declaration for provideJsonDefinition(root: MpxVirtualCode, document: TextDocument, position: Position, ...) and add the necessary imports at the top of the file, then fix any downstream usages in the function body to match the narrower types.
105-108: 💤 Low valueEdge case:
startTagOffsetof 0 would be incorrectly skipped.The condition
!startTagOffsetis falsy for the value0, which would skip valid tags at offset 0. While unlikely in practice for MPX files, consider using an explicit null/undefined check.♻️ Suggested fix
for (const { name, startTagOffset, endTagOffset } of templateNodeTags) { - if (!usingComponents.has(name) || !startTagOffset) { + if (!usingComponents.has(name) || startTagOffset == null) { continue }🤖 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-component-definition.ts` around lines 105 - 108, The loop over templateNodeTags incorrectly treats startTagOffset === 0 as absent because it uses a falsy check; update the condition inside the for...of (the block iterating over templateNodeTags) to explicitly check for null/undefined (e.g., startTagOffset == null or startTagOffset === undefined) instead of `!startTagOffset`, so valid tags at offset 0 are not skipped while preserving the existing check for components via usingComponents.has(name).packages/language-server/package.json (1)
28-28: ⚡ Quick winConsider adding
volar-service-*versions to pnpmcatalog:for consistency (repo-wide).
volar-service-typescriptis pinned to0.0.70, and that version exists on npm. This repo also pins all othervolar-service-*packages (volar-service-css/emmet/html/json/prettier/typescript) to0.0.70directly inpackages/language-service/package.jsonrather than usingcatalog:. If centralized version management is desired, addvolar-service-*entries to the pnpm catalog and reference them from bothpackages/language-server/package.jsonandpackages/language-service/package.json.🤖 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-server/package.json` at line 28, The package.json entry "volar-service-typescript": "0.0.70" introduces a direct pin that is consistent with other volar-service-* pins in the repo but not centralized; to make versions consistent across packages, add a catalog entry for the unscoped package (e.g., add a "volar-service-typescript": "0.0.70" line to the pnpm workspace catalog) and then change the dependency in packages/language-server/package.json (the "volar-service-typescript" dependency) to reference the catalog entry; apply the same catalog entry (or new entries for other volar-service-* packages) to packages/language-service/package.json to complete the consistency refactor.
🤖 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-server/package.json`:
- Line 28: The package.json entry "volar-service-typescript": "0.0.70"
introduces a direct pin that is consistent with other volar-service-* pins in
the repo but not centralized; to make versions consistent across packages, add a
catalog entry for the unscoped package (e.g., add a "volar-service-typescript":
"0.0.70" line to the pnpm workspace catalog) and then change the dependency in
packages/language-server/package.json (the "volar-service-typescript"
dependency) to reference the catalog entry; apply the same catalog entry (or new
entries for other volar-service-* packages) to
packages/language-service/package.json to complete the consistency refactor.
In `@packages/language-service/src/plugins/mpx-component-definition.ts`:
- Around line 41-44: The provideJsonDefinition function is using broad any types
for known LSP parameters; update its signature to type document and position
with proper LSP types (e.g., TextDocument from
vscode-languageserver-textdocument and Position from
vscode-languageserver-protocol or the Volar equivalents) so you retain type
safety for MpxVirtualCode handling; change the function declaration for
provideJsonDefinition(root: MpxVirtualCode, document: TextDocument, position:
Position, ...) and add the necessary imports at the top of the file, then fix
any downstream usages in the function body to match the narrower types.
- Around line 105-108: The loop over templateNodeTags incorrectly treats
startTagOffset === 0 as absent because it uses a falsy check; update the
condition inside the for...of (the block iterating over templateNodeTags) to
explicitly check for null/undefined (e.g., startTagOffset == null or
startTagOffset === undefined) instead of `!startTagOffset`, so valid tags at
offset 0 are not skipped while preserving the existing check for components via
usingComponents.has(name).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 577a7dd2-f0ce-41c1-979c-f6f11f44e0cb
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
packages/language-server/package.jsonpackages/language-server/src/node.tspackages/language-service/src/index.tspackages/language-service/src/plugins/mpx-component-definition.ts
mpx-lsp: https://github.com/lidongsevenlee/sevenlee-claude-code-plugins
Summary by CodeRabbit
New Features
Chores