Simplify directionSensitive computation in grammar and cache completion#2092
Merged
curtisman merged 5 commits intomicrosoft:mainfrom Mar 28, 2026
Merged
Conversation
Replace the mutable, incrementally-accumulated directionSensitive flag with a declarative computation evaluated once after the main loop. grammarCompletion.ts: - Remove per-state directionSensitive accumulation and post-loop recomputation logic. - Compute directionSensitive as a single const decision tree based on openWildcard, midPosition, partialKeywordAgrees, and trailingSepAdvanced. - Rename tryPartialStringMatch return field from 'directionSensitive' to 'couldBackUp' to reflect its local semantics. - Remove the now-unnecessary partialKeywordAgreesWithForward per-state variable (logic moved to Phase B). testUtils.ts: - Pass minPrefixLength through to truncated-prefix requeries in cross-direction invariant checks instead of hardcoding undefined, enabling invariant validation when minPrefixLength is specified. constructionCache.ts: - Replace mutable directionSensitive accumulator with a hasMatchedPart tracker, computed post-loop as hasMatchedPart && noTrailingSeparator.
…Agrees Simplify the directionSensitive decision tree: openWildcard positions are always direction-sensitive because the wildcard boundary is ambiguous — backward can always reconsider. Decision tree: openWildcard → true P = minPrefixLength → false midPosition → true This removes partialKeywordAgrees from the codebase (types, candidate tracking, Phase B accumulation, forward partial keyword block). Tighten cross-query invariants in testUtils.ts: - Remove openWildcard guards from #2–microsoft#5 (openWildcard → true means #2/#3 never fire, microsoft#4/microsoft#5 validate correctly) - Remove minPrefixLength blanket skip; pass minPrefixLength through to cross-queries instead - 28 test expectations updated: directionSensitive false→true for openWildcard cases
…, not an approximation
- Group trailingSepAdvanced with the directionSensitive decision tree under a shared section header for better locality (microsoft#7) - Add invariant comment: openWildcard requires a preceding keyword match so P > 0 whenever openWildcard is true (#1) - Add JSDoc to couldBackUp return field in tryPartialStringMatch (microsoft#5) - Compact equivalence analysis tables in actionGrammar.md from 5-column wide format to 3-column for readability in narrow contexts (microsoft#6)
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
Replaces the scattered, mutation-based
directionSensitiveaccumulation inmatchGrammarCompletionwith a single post-loop decision tree. Also simplifies the cache-layer equivalent inconstructionCache.ts.Key changes
constructionCache.ts: MovenoTrailingSeparatorout of the hot loop into a single post-loop derivation (hasMatchedPart && noTrailingSeparator).tryPartialStringMatch: Rename return fielddirectionSensitive→couldBackUpfor clarity (local function shouldn't claim to compute the global property). Add JSDoc.openWildcard: truecases now correctly reportdirectionSensitive: true. RemoveopenWildcardguards from cross-direction invariant checks — invariants are now validated uniformly.actionGrammar.md. Add scope blurbs cross-referencingactionGrammar.md↔completion.md. Compact wide tables for narrow-context readability.Design rationale
openWildcard → directionSensitive=trueis the correct semantic: wildcard boundaries are genuinely ambiguous. Truncating toinput[0..P]removes the wildcard content that established the anchor, socompletion(input[0..P], "backward")always diverges. This eliminatespartialKeywordAgreestracking entirely and enables unguarded cross-query invariant checking in tests.All 419 grammar completion tests pass.