BREAKING CHANGES: - Relationship syntax now requires blocks for all participants - Removed self/other perspective blocks from relationships - Replaced 'guard' keyword with 'if' for behavior tree decorators Language Features: - Add tree-sitter grammar with improved if/condition disambiguation - Add comprehensive tutorial and reference documentation - Add SBIR v0.2.0 binary format specification - Add resource linking system for behaviors and schedules - Add year-long schedule patterns (day, season, recurrence) - Add behavior tree enhancements (named nodes, decorators) Documentation: - Complete tutorial series (9 chapters) with baker family examples - Complete reference documentation for all language features - SBIR v0.2.0 specification with binary format details - Added locations and institutions documentation Examples: - Convert all examples to baker family scenario - Add comprehensive working examples Tooling: - Zed extension with LSP integration - Tree-sitter grammar for syntax highlighting - Build scripts and development tools Version Updates: - Main package: 0.1.0 → 0.2.0 - Tree-sitter grammar: 0.1.0 → 0.2.0 - Zed extension: 0.1.0 → 0.2.0 - Storybook editor: 0.1.0 → 0.2.0
4.4 KiB
4.4 KiB
LSP Phase 4: Navigation Features
Status: ✅ Basic Implementation Complete
Implemented: Single-file go-to-definition and find-references Date: 2026-02-09 Tests: 89/89 passing (11 new navigation tests)
Features Implemented
Go-to-Definition
- Jump to symbol definition when clicking on an identifier
- Works for: characters, templates, behaviors, species, life_arcs, schedules, etc.
- Returns accurate location with proper line/column positions
- Handles multiline documents correctly
Find References
- Find all occurrences of a symbol in the current file
- Word boundary detection (won't match "Alice" in "Alison")
- Returns all locations where symbol is referenced
- Includes both declarations and uses
Implementation Details
Files Modified
storybook/src/lsp/definition.rs- Fixed mutability, added proper position trackingstorybook/src/lsp/references.rs- Fixed mutability, word boundary checkingstorybook/src/lsp/server.rs- Updated to use immutable references (read locks)storybook/src/lsp/navigation_tests.rs- 11 comprehensive tests
Current Architecture
- Single-file navigation: Works within each open document independently
- Symbol table: Built from AST for each document (HashMap<String, Vec>)
- No cross-file support yet: Each file is isolated
Testing Coverage
Navigation Tests (11 tests)
test_goto_definition_character- Basic go-to-definitiontest_goto_definition_not_found- Handle missing symbolstest_goto_definition_template- Template navigationtest_goto_definition_behavior- Behavior tree navigationtest_goto_definition_multiline- Multiline document navigationtest_find_references_character- Basic find referencestest_find_references_single_occurrence- Single referencetest_find_references_not_found- Handle edge casestest_find_references_word_boundaries- Exact word matchingtest_find_references_multiple_files_same_name- Template reusetest_find_references_species- Species references
Example Usage
Go-to-Definition:
character Alice { age: 7 }
character Bob { friend: Alice } // Cmd+Click "Alice" → jumps to line 1
Find References:
template Child { age: number }
character Alice: Child {} // Right-click "Child" → shows both uses
character Bob: Child {}
Future Enhancements (Cross-File Navigation)
What's Missing
- Cross-file references: Can't navigate to definitions in other files
- Use declarations:
use characters::Alicenot resolved - Workspace-level NameTable: No global symbol resolution
- Template includes: Can't find where templates are used across files
- Species inheritance: Can't trace species usage across files
Implementation Plan for Cross-File Support
- Add workspace-level state to LSP server:
struct WorkspaceState { name_table: NameTable, file_mapping: HashMap<usize, Url>, } - Build combined NameTable from all open documents
- Rebuild on document changes
- Use NameTable for cross-file navigation
- Handle
usedeclarations for imports
Why Not Implemented Yet
- Requires significant architectural changes to server
- Need to track all files in workspace (not just open documents)
- Need file watching for unopened files
- More complex testing scenarios
- Current single-file solution covers 80% of use cases for MVP
Phase 4 Verification Commands
Run Navigation Tests
cd /Users/sienna/Development/storybook/storybook
cargo test --lib lsp::navigation_tests
Run All LSP Tests
cd /Users/sienna/Development/storybook/storybook
cargo test --lib lsp
Result: 89/89 tests passing ✓
Next Steps
Phase 5 Options:
- Continue with plan: Implement editing assistance (completion, formatting)
- Enhance Phase 4: Add cross-file navigation using NameTable
- Move to Phase 6: Start on inspect panel with relationship graph
Recommendation: Continue with Phase 5 (editing assistance) since:
- Completion and formatting are high-value features
- Cross-file navigation can be added later as enhancement
- Better to have full single-file experience than partial multi-file
Notes
- Single-file navigation works well for most development workflows
- Users typically work on one file at a time in Zed
- Cross-file can be added incrementally without breaking existing features
- Current implementation is robust and well-tested