fix(lsp): replace text heuristics with CST-aware detection, fix diagnostic locations#95
Merged
fix(lsp): replace text heuristics with CST-aware detection, fix diagnostic locations#95
Conversation
…ostic locations Two safety-relevant fixes to the LSP server: P0: Analysis diagnostics no longer placed at (0,0). resolve_path_to_range() walks the CST to find the named element and maps it to a source Range, so naming/category diagnostics point to the actual declaration. P1: completion_context() and is_in_section() text heuristics replaced with completion_context_from_cst() which uses rowan ancestor walking: - Section detection via CST node kinds (PROPERTY_SECTION, FEATURE_SECTION, etc.) - Keyword detection via token kinds (COLON, WITH_KW, PORT_KW, DATA_KW) - Falls back to simple text matching only when CST is unavailable The old heuristics matched keywords in comments/strings and used rfind() which could jump to the wrong occurrence. The CST-based approach is immune to these false positives. Adds 10 new tests: 7 for completion context (properties, features, colon, with, comment false positive, top-level, subcomponents) and 3 for path resolution (found, missing, single-element). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two safety-relevant LSP fixes driven by STPA analysis (H-1: false negatives, STPA-REQ-020: no diagnostic suppression):
P0: Diagnostics at (0,0) fixed. Analysis diagnostics (naming rules, category rules) now point to the actual declaration in source, not line 0. New
resolve_path_to_range()walks the CST to find named elements.P1: Text heuristics replaced with CST-aware detection.
completion_context()andis_in_section()used backward text scanning (rfind,ends_with) — matching keywords in comments/strings and misidentifying sections. Replaced withcompletion_context_from_cst()using rowan token ancestry:PROPERTY_SECTION,FEATURE_SECTION, etc.)COLON,WITH_KW,PORT_KW)What this fixes
Test plan
🤖 Generated with Claude Code