Skip to content

Add ruff parser backend as experimental alternative to tree-sitter#16

Merged
ram-nadella merged 5 commits intomainfrom
refactor/ruff-parser
Jun 30, 2025
Merged

Add ruff parser backend as experimental alternative to tree-sitter#16
ram-nadella merged 5 commits intomainfrom
refactor/ruff-parser

Conversation

@ram-nadella
Copy link
Owner

Summary

This PR adds support for using ruff's Python parser as an experimental alternative to tree-sitter, while maintaining full backward compatibility. The tree-sitter parser remains the default.

Changes

Parser Abstraction

  • Created a Parser trait to abstract symbol extraction logic
  • Implemented TreeSitterParser wrapper for existing tree-sitter functionality
  • Implemented RuffParser using ruff's AST for symbol extraction
  • Both parsers extract identical symbols (only column positions differ slightly)

CLI and Configuration

  • Added --parser CLI flag to select backend (default: tree-sitter)
  • Parser backend selection flows through the entire system (LSP server, index, updater)
  • Implemented standard FromStr trait for ParserBackend enum

DevTools Improvements

  • Split UI into tabs: "Symbol Search" and "Parser Comparison"
  • Added parser backend dropdown in Symbol Search tab
  • Parser selection is passed to pylight when spawning LSP server
  • Improved tab styling with blue active states and better contrast
  • Removed rounded corners for cleaner, modern look

Testing and Validation

  • All existing tests updated to use SymbolIndex::default()
  • Created test program to verify both parsers extract same symbols
  • Added parser comparison tool in devtools for side-by-side results
  • Verified on multiple Python codebases - both parsers find identical symbols

Performance

Initial testing shows comparable performance between the two parsers. The ruff parser may have advantages for certain use cases, particularly when integrating with other ruff-based tooling.

Future Work

  • Add benchmarks comparing parser performance on large codebases
  • Consider making ruff the default parser after more testing
  • Integrate with ruff's error recovery for better handling of invalid syntax

Test Plan

  • All existing tests pass
  • Manual testing with devtools shows identical symbol extraction
  • Parser selection works correctly in LSP mode
  • DevTools UI improvements tested in browser

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

ram-nadella and others added 5 commits June 29, 2025 19:27
- Add parser trait abstraction to support multiple backends
- Implement ruff-based Python parser as alternative to tree-sitter
- Add --parser CLI flag to select backend (default: tree-sitter)
- Update pylight_devtools with parser comparison tool
- Both parsers extract identical symbols with minor column differences
- All tests updated to use SymbolIndex::default()

This enables experimenting with ruff's parser while maintaining
full compatibility with the existing tree-sitter implementation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Split UI into tabs: "Symbol Search" and "Parser Comparison"
- Add parser backend dropdown in Symbol Search tab (tree-sitter/ruff)
- Pass selected parser to pylight when spawning LSP server
- Improve visual design with proper tab navigation
- Show current parser in search metrics
- Update IndexRequest to include parser parameter

This makes it easy to test different parsers without restarting
devtools and provides a cleaner separation of concerns in the UI.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove rounded corners from all UI elements for cleaner look
- Fix active tab hover state with better contrast (white text on green)
- Add subtle hover effect for inactive tabs
- Improve visual hierarchy with better color transitions
- Active tab now has solid green background for better visibility

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Active tabs now use blue (#2196F3) with darker blue on hover (#1976D2)
- Buttons remain green for visual distinction between navigation and actions
- Better separation of UI element purposes through color coding

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace custom from_str method with standard FromStr trait
- Apply clippy suggestions for cleaner code
- Fix redundant closure warnings
- All tests passing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ram-nadella ram-nadella merged commit 2799083 into main Jun 30, 2025
4 checks passed
@ram-nadella
Copy link
Owner Author

File discovery down from 6 seconds to 1.3 seconds!

Python file read, parse and index down from 8.79s to 5.29s

Logs of initial bootstrap before optimizations (before switch to ruff and also before the faster file discovery changes in #14)

2025-06-29T16:06:39.443215Z  INFO pylight::lsp::server: File watcher started for workspace: /path/to/large/python-repo
2025-06-29T16:06:39.443447Z  WARN pylight_devtools: pylight stderr: 2025-06-29T16:06:39.443276Z  INFO pylight::index: Starting workspace indexing for: /path/to/large/python-repo
2025-06-29T16:06:45.438247Z  WARN pylight_devtools: pylight stderr: 2025-06-29T16:06:45.438224Z  INFO pylight::index: Found 92845 Python files to index
2025-06-29T16:06:45.438262Z  WARN pylight_devtools: pylight stderr: 2025-06-29T16:06:45.438232Z  INFO pylight::index: Starting parallel processing with 11 concurrent tasks
2025-06-29T16:06:54.517424Z  WARN pylight_devtools: pylight stderr: 2025-06-29T16:06:54.517390Z  INFO pylight::index: Parallel parsing completed in 8.79s (10561 files/sec)
2025-06-29T16:06:54.517437Z  WARN pylight_devtools: pylight stderr: 2025-06-29T16:06:54.517400Z  INFO pylight::index: Indexed 92845 files with 713082 symbols
2025-06-29T16:06:54.517438Z  WARN pylight_devtools: pylight stderr: 2025-06-29T16:06:54.517409Z  INFO pylight::lsp::server: Initial workspace indexing completed

After these fixes landed:

2025-06-30T03:26:25.446133Z  WARN pylight_devtools: pylight stderr: 2025-06-30T03:26:25.446118Z  INFO pylight::lsp::server: File watcher started for workspace: /path/to/large/python-repo
2025-06-30T03:26:25.446149Z  WARN pylight_devtools: pylight stderr: 2025-06-30T03:26:25.446142Z  INFO pylight::index::symbol_index: Starting workspace indexing for: /path/to/large/python-repo
2025-06-30T03:26:26.744525Z  WARN pylight_devtools: pylight stderr: 2025-06-30T03:26:26.744507Z  INFO pylight::index::symbol_index: Found 92845 Python files to index in 1.30s (using 11 threads)
2025-06-30T03:26:26.744536Z  WARN pylight_devtools: pylight stderr: 2025-06-30T03:26:26.744516Z  INFO pylight::index::symbol_index: Starting parallel processing with 11 concurrent tasks
2025-06-30T03:26:32.300334Z  WARN pylight_devtools: pylight stderr: 2025-06-30T03:26:32.300303Z  INFO pylight::index::symbol_index: Parallel parsing completed in 5.29s (17551 files/sec)
2025-06-30T03:26:32.300353Z  WARN pylight_devtools: pylight stderr: 2025-06-30T03:26:32.300314Z  INFO pylight::index::symbol_index: Indexed 92845 files with 713084 symbols
2025-06-30T03:26:32.300354Z  WARN pylight_devtools: pylight stderr: 2025-06-30T03:26:32.300316Z  INFO pylight::lsp::server: Initial workspace indexing completed

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.

1 participant