Skip to content

wmccrthy/LuauASTExplorer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

152 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AST Highlight Helper

A powerful VSCode extension for visualizing and analyzing Abstract Syntax Trees (AST) of Luau/Lua code with interactive type exploration, advanced diffing capabilities, and comprehensive AST node inspection.

๐Ÿš€ Features

๐Ÿ” Live AST Editor

  • Interactive code editor with live AST updates
  • Instant parsing as you type or on-demand
  • Side-by-side view of code and corresponding AST
  • Perfect for learning how code structures translate to AST nodes

Live AST Editor Demo

โšก AST Diff Analyzer

  • Visual comparison between two code snippets
  • Intelligent change detection (additions, modifications, removals)
  • Before/after type annotations show type transformations
  • Symbol and color-coded indicators:
    • Additions (+)
    • Removals (-)
    • Modifications (~)
    • Containers with changes (โ—‹)

Diff Analyzer Demo

๐ŸŽฏ Smart Tree Display

  • Expandable/collapsible tree branches and nodes
  • Auto-collapse noisy nodes (trivia, location, position data, etc)
  • Clean visual hierarchy for easy navigation
  • Type-aware rendering with enhanced annotation display

๐Ÿ’ก Advanced Type System

  • Comprehensive type annotations with tooltip details
  • Before/after type display in diff mode

๐Ÿ”ง Code Translation & Tooltips

  • Hover over nodes to show generated/translated code for AST nodes
  • Node path display for non-translatable nodes

๐Ÿ“ฆ Installation

From Editor Marketplaces

From VSIX File

  1. Download the .vsix file from Releases
  2. Open Editor Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
  3. Run Extensions: Install from VSIX...
  4. Select the downloaded .vsix file

Prerequisites

๐ŸŽฎ Usage

Quick Start

  1. Open a Luau/Lua file in VSCode
  2. Select some code you want to analyze
  3. Press Cmd+Shift+A (macOS) or Ctrl+Shift+A (Windows/Linux)
  4. Choose your mode:
    • Live Editor: Interactive editing with live AST
    • Diff Analyzer: Compare two code snippets

Keyboard Shortcuts

Shortcut Action
Cmd+Shift+A / Ctrl+Shift+A Open AST Highlight Helper

Advanced Usage

Live Editor Mode

  • Type or paste code in the editor pane
  • Click "Parse AST" for on-demand parsing
  • View real-time AST as your code structure changes
  • Hover over type annotations to see detailed property information
  • Hover over node keys to see corresponding Luau code
  • Perfect for experimentation and learning AST structure

Diff Analyzer Mode

  • Input two code snippets in separate editors
  • Click "Analyze Transformation" to see differences
  • Visual diff highlighting shows exactly what changed
  • Type tooltips and code tooltips work in diff mode for enhanced analysis
  • Before/after type annotations show how types transform
  • Understand code transformations for refactoring and codemod work

๐Ÿ› ๏ธ Development

Setup

# Clone the repository
git clone https://github.com/wmccrthy/LuauASTExplorer.git
cd LuauASTExplorer

# Install dependencies
npm install
cd frontend && npm install && cd ..

# Install Lute with foreman...
foreman install
# or with rokit...
rokit install

Building

# Development build with watch mode
npm run watch

# Production build
npm run compile

# Package extension
vsce package

Testing

# Run frontend tests
npm test

# Run Lua tests
lute run lua_tests/runner.luau

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    VSCode Extension                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚   Backend       โ”‚   Frontend      โ”‚   External Tools        โ”‚
โ”‚ (Node + Luau)   โ”‚   (React)       โ”‚                         โ”‚
โ”‚                 โ”‚                 โ”‚                         โ”‚
โ”‚ โ€ข extension.ts  โ”‚ โ€ข App.tsx       โ”‚ โ€ข Lute (Luau parser)    โ”‚
โ”‚ โ€ข astParser.ts  โ”‚ โ€ข TreeNode.tsx  โ”‚ โ€ข json-diff-ts          โ”‚
โ”‚ โ€ข Luau helpers  โ”‚ โ€ข TypeTooltip   โ”‚ โ€ข highlight.js          โ”‚
โ”‚ โ€ข Type system   โ”‚ โ€ข diffUtils.ts  โ”‚ โ€ข Foreman (tool mgmt)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Data Flow:
(initial code-> AST translation) Luau Code โ†’ Lute Parser โ†’ typeAnnotations.lua (adds _astType) โ†’ JSON โ†’ React UI
(node hover AST -> code translation) React UI Node โ†’ astJsonToCode.luau โ†’ lutePrinter.luau โ†’ Generated Src Code โ†’ Tooltips in React UI

Project Structure

LuauASTExplorer/
โ”œโ”€โ”€ src/                     # VSCode extension backend
โ”‚   โ”œโ”€โ”€ extension.ts         # Main entry point
โ”‚   โ””โ”€โ”€ astParser.ts         # Lute integration & communication
โ”œโ”€โ”€ frontend/                # React frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.tsx          # Main React component
โ”‚   โ”‚   โ”œโ”€โ”€ components/      # UI components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ TreeNode.tsx        # AST tree rendering
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ TypeTooltip.tsx     # Interactive type tooltips
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ CodeTooltip.tsx     # Code translation tooltips
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ LiveEditor.tsx      # Live editing mode
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ DiffAnalyzer.tsx    # Diff analysis mode
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ CodeEditor.tsx      # Code input component
โ”‚   โ”‚   โ”œโ”€โ”€ utils/           # Core utilities
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ astTypeDefinitions.ts  # Complete Luau AST type definitions
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ astTypeHelpers.ts      # Type inference & manipulation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ diffUtils.ts           # Diff annotation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ syntaxHighlighting.ts  # Code highlighting & theme detection
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ nodeEmphasisHelpers.ts # Auto-collapse logic
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ parsingMessageHandlers.ts # VSCode communication
โ”‚   โ”‚   โ”œโ”€โ”€ context/         # React context
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ codeTranslationContext.ts # Code tooltip state management
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/           # Custom React hooks
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ useCodeTranslation.ts     # Code translation logic
โ”‚   โ”‚   โ”œโ”€โ”€ types/           # TypeScript definitions
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ typesAndInterfaces.ts     # Shared type definitions
โ”‚   โ”‚   โ””โ”€โ”€ tests/           # Frontend test suites
โ”‚   โ”‚       โ”œโ”€โ”€ TreeNode.test.tsx         # Comprehensive component tests
โ”‚   โ”‚       โ”œโ”€โ”€ astTypeHelpers.test.ts    # Type system tests
โ”‚   โ”‚       โ”œโ”€โ”€ diffUtils.test.ts         # Diff algorithm tests
โ”‚   โ”‚       โ”œโ”€โ”€ nodeEmphasisHelpers.test.ts # Auto-collapse tests
โ”‚   โ”‚       โ””โ”€โ”€ syntaxHighlighting.test.ts  # Syntax highlighting tests
โ”‚   โ””โ”€โ”€ build/              # Built React app
โ”œโ”€โ”€ lua_helpers/            # Luau scripts for parsing
โ”‚   โ”œโ”€โ”€ astToJson.luau      # Main AST serialization script
โ”‚   โ”œโ”€โ”€ astJsonToCode.luau  # AST to code conversion
โ”‚   โ”œโ”€โ”€ typeAnnotations.lua # Enhanced type annotation system
โ”‚   โ”œโ”€โ”€ sortByPositionTable.lua # AST position sorting utilities
โ”‚   โ””โ”€โ”€ temp_vendor/
โ”‚       โ””โ”€โ”€ lutePrinter.luau    # Luau code generation engine
โ”œโ”€โ”€ lua_tests/             # Lua test suites
โ”‚   โ”œโ”€โ”€ runner.luau        # Test runner
โ”‚   โ”œโ”€โ”€ typeAnnotations.spec.lua   # Type annotation tests
โ”‚   โ”œโ”€โ”€ printASTNode.spec.lua      # Code generation tests
โ”‚   โ”œโ”€โ”€ astJsonToCode.spec.lua     # AST conversion tests
โ”‚   โ””โ”€โ”€ helpers/           # Test utilities
โ”‚       โ”œโ”€โ”€ astJsonToCodeHelpers.lua   # Test case definitions
โ”‚       โ””โ”€โ”€ typeAnnotationTestHelpers.lua # Type testing utilities
โ”œโ”€โ”€ ci_scripts/            # Build automation
โ”‚   โ””โ”€โ”€ readChangelog.ts   # Changelog processing
โ”œโ”€โ”€ docs/                  # Documentation assets
โ”‚   โ”œโ”€โ”€ ASTExplorerDiffGIF.gif
โ”‚   โ””โ”€โ”€ ASTExplorerLiveEditorGIF.gif
โ”œโ”€โ”€ .github/workflows/     # GitHub Actions
โ”‚   โ”œโ”€โ”€ release.yml        # Automated VSIX packaging
โ”‚   โ””โ”€โ”€ ci.yml            # Continuous integration
โ”œโ”€โ”€ package.json           # Extension manifest
โ””โ”€โ”€ README.md             # This file

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and test thoroughly
  4. Commit your changes: git commit -m 'Add amazing feature'
  5. Push to the branch: git push origin feature/amazing-feature
  6. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Add tests for new functionality (both frontend and Lua)
  • Update documentation as needed
  • Test with various Luau code samples
  • Use conventional commit messages for changelog automation

PR Title Format

Use these formats for automatic changelog creation:

  • #feat Add new feature description โ†’ Creates feature changelog entry
  • #bug Fix issue description โ†’ Creates bug fix changelog entry
  • #chore Update documentation โ†’ No changelog entry (maintenance)

๐Ÿ“‹ Requirements

  • VSCode 1.74.0 or higher
  • Lute (>= 0.1.0-nightly.20260312)
  • Foreman or Rokit (See installation instructions linked above)
  • Node.js 16+ (for development)

๐Ÿ› Known Issues

  • Large AST trees (1000+ nodes) may have performance impact
  • Some complex and niche types may not display perfectly in tooltips
  • Code translation works for most AST nodes but may fall back to path display for edge cases (eg, Trivia, Position, Location)

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support


Made with โค๏ธ for the Luau/Roblox development community

VSCode Extension TypeScript React Luau Jest

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages