Skip to content

feat(ai): add standalone agent mode and component goToDefinition#109

Merged
wangshunnn merged 3 commits into
mpx-ecology:mainfrom
lidongsevenlee:feat/standalone-ts-and-component-definition
May 28, 2026
Merged

feat(ai): add standalone agent mode and component goToDefinition#109
wangshunnn merged 3 commits into
mpx-ecology:mainfrom
lidongsevenlee:feat/standalone-ts-and-component-definition

Conversation

@lidongsevenlee

@lidongsevenlee lidongsevenlee commented May 25, 2026

Copy link
Copy Markdown
  • 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

mpx-lsp: https://github.com/lidongsevenlee/sevenlee-claude-code-plugins

Summary by CodeRabbit

  • New Features

    • Added a standalone agent mode for TypeScript initialization so the language server can run without IDE TypeScript integration.
    • Added "Go to Definition" navigation for MPX components from templates and component configuration.
  • Chores

    • Added a pinned TypeScript-related service dependency.

Review Change Stack

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

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds 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.

Changes

Component Definition and Server Initialization

Layer / File(s) Summary
Component definition plugin
packages/language-service/src/plugins/mpx-component-definition.ts
New plugin implements definitionProvider, decodes embedded URIs, and resolves component definitions via JSON or template handlers, returning locations mapped to real component files.
Plugin registration and options
packages/language-service/src/index.ts
Adds MpxLanguageServicePluginOptions with componentDefinitionProvider?: boolean, threads options into createMpxLanguageServicePlugins, and conditionally registers createMpxComponentDefinitionPlugin() when enabled.
Agent mode initialization and dependency
packages/language-server/src/node.ts, packages/language-server/package.json
Language-server initialization branches on initializationOptions.agent to either create a standalone TS project (via createTypeScriptProject) with a Volar TypeScript semantic plugin or retain tsserver-backed behavior; adds volar-service-typescript@0.0.70.
VS Code extension setting
inspect-extension/.vscode/settings.json
Updates workbench.colorTheme from Default Dark Modern to Dark Modern.

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)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • wangshunnn

Poem

🐰 I hopped through generated code and span—
From JSON roots to template land,
A plugin points the curious paw,
Agent mode hums, no tsserver law,
Definitions found, a tidy stand.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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.
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.
Title check ✅ Passed The title accurately summarizes the two main changes: adding standalone agent mode and introducing component goToDefinition functionality.

✏️ 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 (3)
packages/language-service/src/plugins/mpx-component-definition.ts (2)

41-44: 💤 Low value

Avoid using any type for well-known LSP parameters.

The document and position parameters have known types from the Volar/LSP ecosystem. Using any loses 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 TextDocument from vscode-languageserver-textdocument and Position from vscode-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 value

Edge case: startTagOffset of 0 would be incorrectly skipped.

The condition !startTagOffset is falsy for the value 0, 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 win

Consider adding volar-service-* versions to pnpm catalog: for consistency (repo-wide).

volar-service-typescript is pinned to 0.0.70, and that version exists on npm. This repo also pins all other volar-service-* packages (volar-service-css/emmet/html/json/prettier/typescript) to 0.0.70 directly in packages/language-service/package.json rather than using catalog:. If centralized version management is desired, add volar-service-* entries to the pnpm catalog and reference them from both packages/language-server/package.json and packages/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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba7a6a and 296805d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • packages/language-server/package.json
  • packages/language-server/src/node.ts
  • packages/language-service/src/index.ts
  • packages/language-service/src/plugins/mpx-component-definition.ts

@wangshunnn wangshunnn self-assigned this May 28, 2026
@wangshunnn wangshunnn added the enhancement New feature or request label May 28, 2026
@wangshunnn wangshunnn changed the title feat: add standalone agent mode and component goToDefinition feat(ai): add standalone agent mode and component goToDefinition May 28, 2026
@wangshunnn wangshunnn merged commit 0f61bd9 into mpx-ecology:main May 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants