⏺ Phase 10 is complete. Here's the summary: #13
No reviewers
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
rust
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-rexx!13
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "phase10"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Phase 10: Language Server (LSP) — Complete
What was done
Project restructuring:
14 new files created:
┌───────────────────────────┬──────────────────────────────────────────────────────┐
│ File │ Purpose │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lib.rs │ Library root with feature-gated pub mod lsp │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/bin/patch-rexx-lsp.rs │ LSP binary entry point │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/mod.rs │ LSP module root │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/server.rs │ LanguageServer trait impl with tower-lsp wiring │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/analysis.rs │ Static document analysis (lex + parse + AST walk) │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/diagnostics.rs │ RexxDiagnostic → LSP Diagnostic mapping │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/completion.rs │ Keywords, BIFs, labels, variables, stems │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/hover.rs │ BIF docs, subroutine info, keyword docs │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/definition.rs │ Go-to label/subroutine definition │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/symbols.rs │ Document outline (labels, subroutines) │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/actions.rs │ Typo suggestions with edit distance │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/hints.rs │ PARSE template and NUMERIC inlay hints │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ src/lsp/bif_docs.rs │ Static BIF signature + description data (48 entries) │
├───────────────────────────┼──────────────────────────────────────────────────────┤
│ tests/phase10.rs │ Feature-gated integration tests (24 tests) │
└───────────────────────────┴──────────────────────────────────────────────────────┘
Verification
PR #13 Review: Language Server (LSP) Implementation
Summary
This PR implements a complete LSP for patch-rexx with 14 new files, feature-gated compilation, and comprehensive test coverage (24 new tests). All 435 tests pass.
Critical Issues
1. Missing SourceLoc in AST Walker (src/lsp/analysis.rs)
Severity: Medium — Affects accuracy of LSP features
Lines: 230, 256, 262, 269
The
AstCollector::walk_*methods createVariableInfoandCallInfowith placeholderSourceLoc::new(0, 0)instead of actual source locations:Impact:
Fix: The AST nodes (
Expr,DoKind::Controlled, etc.) need to carry their ownSourceLoc. This is a deeper architectural issue — expressions currently don't have location info.Recommendation: Either:
loc: SourceLocto allExprvariants (breaking change, correct solution)2. Case-Sensitivity in is_rexx_word_char (src/lsp/hover.rs:174, definition.rs:61)
Severity: Low — Minor deviation from REXX semantics
Lines: hover.rs:174-176, definition.rs:61-63
Issue: REXX variable names can contain
\!,?,@per ANSI X3.274-1996 §2.2.3, so this is correct. However, including.means word-at-position will matchARR.1as a single word instead of stopping atARR.Impact:
ARR.1won't match stem variableARR.correctlyFix: Exclude
.from word characters for LSP purposes, or special-case stem lookups.3. Potential Off-by-One in End Position (src/lsp/diagnostics.rs:19)
Severity: Low — Minor display issue
Line: diagnostics.rs:19
Issue: If
source_lineis present, this underlines the entire line regardless of where the error actually is. For a parse error at column 5, the squiggle should cover just the erroneous token, not columns 5–80.Fix: Store token length in
SourceLocor inRexxDiagnostic, then usecol + token_leninstead ofline.len().4. Subroutine End Line Heuristic (src/lsp/analysis.rs:312-317)
Severity: Low — Affects document outline accuracy
Lines: 312-317
Issue: This assumes subroutines end at the next label. But REXX allows:
The heuristic will include
say 'more code'infoo's range, which is incorrect.Correct behavior: Subroutine ends at the first
RETURNorEXITafter the label, OR at the next label if noRETURNis found.Impact: Document symbol outline (
foofunction) includes extra code.Fix: Walk the AST to find the first
Return/Exitclause after the label.Minor Issues
5. Unnecessary Clone in detect_subroutines (src/lsp/analysis.rs:308)
Severity: Pedantic
Line: 308
Should be:
Both work, but
clone_fromis for reusing allocations, which doesn't apply here sinceexposedis empty.6. Duplicate word_at_position (hover.rs:146, definition.rs:33)
Severity: Pedantic
The
word_at_positionandis_rexx_word_charfunctions are duplicated inhover.rsanddefinition.rs. Extract to a sharedutilsmodule.7. Hard-Coded Keyword List (completion.rs:6-53)
Severity: Pedantic
The
REXX_KEYWORDSlist is manually maintained. If the parser gains support for new keywords (e.g.,OPTIONS,NUMERIC FORM ENGINEERING), this list must be updated manually.Suggestion: Generate from the parser's keyword matching logic or keep a canonical list in
src/keywords.rs.Non-Issues (Correct Behavior)
✅ Error Number Mapping (diagnostics.rs:41)
Correctly converts
RexxErrorto LSP diagnostic code. Error 41 = Bad arithmetic, Error 42 = overflow, etc. ✅✅ REXX Case-Insensitivity (hover.rs:89, completion.rs:94)
All symbol comparisons use
.to_uppercase(). Correct per REXX semantics. ✅✅ Edit Distance (actions.rs:73-98)
Classic Levenshtein algorithm for typo suggestions. Correct implementation. ✅
✅ Feature-Gating (lib.rs:13-14, Cargo.toml)
LSP is correctly feature-gated. Binary builds without
--features lspdon't include tokio/tower-lsp dependencies. ✅✅ Async Handling (server.rs:184-193)
Tokio runtime is correctly created and used to serve the LSP. ✅
Test Coverage
All 24 new LSP tests pass:
Suggested additional tests:
arr.1vsARR.)RETURNstatementsPerformance Notes
Potential Allocations
source.lines().map(String::from).collect()allocates every line. For large files, consider using&strslices or lazy iteration.O(m*n)matrix on every typo check. Pre-filter by length difference to avoid unnecessary work.No Panics
✅ All indexing uses
.get()or.saturating_sub()to avoid panics on malformed input.Architecture Quality
Strengths:
analysis.rswalks AST, LSP modules consumeDocumentAnalysisWeaknesses:
Verdict
Approve with recommendations.
The LSP implementation is structurally sound and demonstrates good understanding of both REXX semantics and LSP architecture. The feature-gating is correct, tests are comprehensive, and clippy is clean.
Critical work:
SourceLocin expressions (defer to Phase 11 or accept as known limitation)RETURN/EXIT.in word char matching for stem variablesNice-to-have:
word_at_positionto utilsAll tests pass (435/435). No panics, no REXX semantic violations.
PR Review: Phase 10 LSP Implementation
I've reviewed the Phase 10 LSP implementation for the REXX interpreter. Overall, this is solid work with good attention to REXX semantics and error handling. The code is well-structured and follows the project's design principles.
✅ Strengths
REXX Semantics - Correct
Arithmetic & Error Handling - Excellent
ArithmeticOverflow(Error 42) in all division paths (eval.rs:1606, 1624, 1639)Safety - No Panics Found
expectin server.rs:185 for runtime initialization)saturating_subusage throughout to prevent underflowArchitecture
util.rsmodule (util.rs:9-39)SourceLoc(0,0)placeholders by threadingctx_locthroughwalk_expr/walk_do_block— this is good practice🔍 Observations (not issues, just notes)
1. Analysis.rs: SourceLoc Usage
The LSP analysis correctly threads
ctx_locthrough expression walkers (analysis.rs:252). This is a smart design decision since expressions don't carry their own SourceLoc in the AST, and using the parent clause's location is the right fallback for diagnostics.2. Word Character Definition
The fix mentioned in commit 2 (removing
.fromis_rexx_word_char) is correct. REXX compound variables likeARR.1should resolve to stemARR, not the full compound (util.rs:37-39).3. Test Coverage
24 new integration tests in phase10.rs covering:
This is solid coverage for the LSP features.
4. Diagnostic Mapping
The single-character underline (diagnostics.rs:16) is correct for pinpoint error location. The error code mapping properly converts RexxError enum values to LSP diagnostic codes.
📊 Summary
No issues found. This PR demonstrates:
The implementation correctly handles:
Recommendation: ✅ Approve and merge
The Phase 10 LSP implementation is production-ready and maintains the high quality standards established in earlier phases.
Review performed using Claude Code CLI