Skip to content

Conversation

@dev-parkins
Copy link
Owner

🎯 Overview

Implements source span tracking for LSP foundation work as part of v0.0.5 Phase 0, Week 1.

Completes tasks 1-4 from the v0.0.5 planning document. Task 5 (Inspector property fix) will be addressed in a separate PR.

✅ Changes

Core Implementation

  • Created span.rs module (540 lines)
    • Position struct: tracks line (1-indexed), column (1-indexed), offset (0-indexed bytes)
    • Span struct: tracks start/end positions with merge(), contains(), len() methods
    • 31 comprehensive unit tests with 100% coverage

AST Updates

  • Added Stmt::span() accessor method for all statement types
  • Re-exported Span from �st module for backward compatibility
  • All AST nodes now expose their source locations

Parser Infrastructure

  • Added span_from() helper for multi-token constructs (ready for Week 2)
  • Parser creates Position/Span objects from token positions
  • Updated to use new span API

Type Checker Migration

  • Migrated 200+ occurrences from field access to method calls
  • span.line → span.line(), span.column → span.column()
  • All type checking logic unchanged, only API surface updated

Testing

  • 31 new unit tests in span.rs covering all Position/Span functionality
  • 5 new integration tests verifying span tracking on functions, expressions, merge operations
  • All 883 workspace tests passing (568 compiler, 110 runtime, 38 test_harness, etc.)

⚠️ Implementation Notes

Deferred Enhancements

  1. Byte offset tracking: Currently using placeholder

…ase 0, Week 1)

- Created span.rs module with Position and Span structs
  - Position tracks line, column, and byte offset
  - Span tracks start/end positions with merge() support
  - 31 comprehensive unit tests with 100% coverage

- Enhanced AST with span support
  - Added span() accessor methods to Stmt and Expr
  - Re-exported Span from ast module for backward compatibility
  - All AST nodes now expose their source locations

- Updated parser infrastructure
  - Added span_from() helper for multi-token constructs
  - Parser tracks line/column positions from lexer
  - Note: Byte offset tracking deferred as enhancement

- Added integration tests
  - 5 new tests verify span tracking on functions, expressions
  - Test span merge functionality and accessors
  - Total: 883 tests passing across workspace (568 compiler, 110 runtime, 38 test_harness, etc.)

- Updated type_checker to use new span API
  - Changed span.line/span.column to span.line()/span.column()
  - All 568 compiler tests pass with new span implementation

This implements tasks 1-4 from v0.0.5 Phase 0 Week 1:
- ✅ Define Span and Position structs
- ✅ Add span field to all AST nodes
- ✅ Update parser to track spans from tokens
- ✅ Update tests with span assertions

Related to #v0.0.5, LSP foundation work
- Mark tasks 1-4 as completed (span tracking implementation)
- Add implementation notes about byte offset deferral and point spans
- Document backward compatibility approach with ast::Span re-export
- Note Inspector fix (task 5) remains pending in separate PR
@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 90.41916% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/compiler/src/type_checker.rs 93.33% 8 Missing ⚠️
crates/compiler/src/ast.rs 50.00% 4 Missing ⚠️
crates/compiler/src/parser.rs 33.33% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

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