Skip to content

feat(gea-tools): add go-to-definition and auto-import for JSX components#15

Open
beydemirfurkan wants to merge 1 commit intodashersw:mainfrom
beydemirfurkan:feat/gea-tools-definition-auto-import
Open

feat(gea-tools): add go-to-definition and auto-import for JSX components#15
beydemirfurkan wants to merge 1 commit intodashersw:mainfrom
beydemirfurkan:feat/gea-tools-definition-auto-import

Conversation

@beydemirfurkan
Copy link
Copy Markdown

@beydemirfurkan beydemirfurkan commented Mar 26, 2026

What this does

This improves the JSX editing experience in gea-tools.
It adds Go to Definition for JSX component tags and a Quick Fix for missing imports when a default-exported component is used before being imported.
To support that, the component discovery logic now scans the workspace and keeps enough metadata to resolve declarations and generate relative import paths.

Why

gea-tools already provides completions and hover information, but two common editing actions were still missing:

  • jumping from a JSX tag to the component definition
  • fixing a missing component import without doing it manually
    This makes the extension more useful during regular development and reduces friction when working across multiple components.

Notes

  • auto-import currently supports default exports
  • when multiple matching components exist, the closest relative path is preferred
  • HTML tags and Gea built-in tags are excluded from import fixes

Validation

  • ran npm run compile in packages/gea-tools
  • updated packages/gea-tools/README.md
  • updated packages/gea-tools/TESTING.md

Summary by CodeRabbit

  • New Features

    • "Go to Definition" for JSX components - quickly navigate to component declarations for both imported and workspace-discovered components
    • "Quick Fix Auto Import" - automatically inserts missing relative imports for referenced JSX components, with intelligent resolution when multiple components share the same name
  • Documentation

    • Updated README documenting new language server capabilities
    • Enhanced testing documentation with manual test procedures

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

The pull request introduces two new language-server capabilities: "Go to Definition" for JSX components and "Quick Fix Auto Import" for inserting missing imports of default-exported components. Supporting infrastructure refactors component discovery to scan the workspace, deduplicate components, and select the best match by path proximity.

Changes

Cohort / File(s) Summary
Documentation Updates
packages/gea-tools/README.md, packages/gea-tools/TESTING.md
Added feature documentation and test scenarios for "Go to Definition" and "Quick Fix Auto Import" functionality.
Component Discovery Infrastructure
packages/gea-tools/src/component-discovery.ts
Expanded ComponentInfo with declarationOffset and exportKind fields; added workspace-wide scanning via scanWorkspace() and path normalization; introduced component deduplication and getBestComponentMatch() for ranking by path-distance proximity.
Language Server Implementation
packages/gea-tools/src/server.ts
Implemented definition and code-action handlers; definition support jumps to component declarations; quick-fix code action inserts relative default imports for unknown components with automatic insertion point determination.

Sequence Diagram(s)

sequenceDiagram
    participant Editor as Editor / Client
    participant Server as Language Server
    participant Discovery as Component Discovery
    participant FileSystem as File System

    rect rgba(0, 150, 0, 0.5)
    Note over Editor,FileSystem: Go to Definition Flow
    Editor->>Server: onDefinition(cursor position)
    Server->>Server: Parse JSX tag context
    Server->>Discovery: getBestComponentMatch(tagName)
    Discovery->>Discovery: Filter default exports & rank by path distance
    Discovery-->>Server: Component with filePath & declarationOffset
    alt Same File
        Server->>Editor: Location(current file, declaration line)
    else Different File
        Server->>FileSystem: Read target file
        FileSystem-->>Server: File contents
        Server->>Server: Map declarationOffset to Position
        Server->>Editor: Location(target file, declaration line)
    end
    end

    rect rgba(0, 0, 150, 0.5)
    Note over Editor,FileSystem: Quick Fix Auto Import Flow
    Editor->>Server: onCodeAction(unknown component diagnostic)
    Server->>Server: Parse component name from diagnostic
    Server->>Discovery: getBestComponentMatch(component name)
    Discovery-->>Server: Best matching component
    Server->>Server: Check if import already exists
    alt No Import Found
        Server->>Server: Compute relative import path
        Server->>Server: Find import block insertion point
        Server->>Editor: CodeAction with WorkspaceEdit (insert import)
    else Import Exists
        Server->>Editor: (No action offered)
    end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 A rabbit hops through code so bright,
Finding components left and right,
With definitions clear as day,
And imports sorted out the way!
Quick fixes hopping into place,
Making every file a happy place! 🌿✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the two main features added: go-to-definition and auto-import for JSX components, matching the primary objectives of the changeset.

✏️ 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.

@dashersw
Copy link
Copy Markdown
Owner

Doesn't jump to definition work right now in VS Code / Cursor?

@beydemirfurkan
Copy link
Copy Markdown
Author

The main benefit is consistency.
Today, definition lookup can work through the editor, while import fixes come from gea-tools. This PR makes both rely on the same component discovery path inside gea-tools, instead of depending on two separate resolution paths.

Doesn't jump to definition work right now in VS Code / Cursor?

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