Convert interior positions at the byte column under the negotiated encoding - #370
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #370 +/- ##
=========================================
Coverage 97.60% 97.61%
- Complexity 1692 1696 +4
=========================================
Files 105 105
Lines 4256 4271 +15
=========================================
+ Hits 4154 4169 +15
Misses 102 102 ☔ View full report in Codecov by Harness. |
4 tasks
The corpus round-trip test only asserts a symmetric identity, so a wrong-but-consistent per-codepoint unit count survives it. The 2- and 4-byte widths were pinned by concrete goldens; the 3-byte width was not, so treating a 3-byte BMP codepoint as a surrogate pair passed the whole suite. Pin it the same way. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The existing multibyte variable-access test resolves through the AST node path, so it never exercises resolveVariableAccessWithAst's own text slice; reverting that slice to the raw wire column left the test green. Add a typed-parameter access inside an incomplete while() — a shape that denies a clean AST node and routes through the fallback — on a line carrying a multibyte character, so the byte-column slice is now covered. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Slice
0001-foundational-architecture.md§4.9 (Position Encoding); §8.1 invariant 9Related
positionEncodingand convertedpositions at the document boundary, but deferred the interior sites; this slice
is that deferred interior half.
being driven out. The boundary half landed in Negotiate positionEncoding and convert positions at the document boundary #366; this completes the interior
reads/writes. (Left for the reviewer to decide whether Multibyte/Unicode character handling #192 is fully closed.)
through the immutable
SessionCapabilitiesresolved there.not yet threaded into
TextDocument(documents use the default). Correct whileUTF-16 is the only encoding; tracked for when a second one is added.
What and why
S1.2 (#366) fixed the conversion at the document boundary (
TextDocument::offsetAt/positionAt) but deferred the interior sites that still treated the wirecharacteras a byte length — a §4.9 violation ("interior components MUST operateonly on [the negotiated] representation"). This slice drives those out and adds the
regression net Step P deliberately excludes for the positional surface.
Inbound reads (text before the cursor) now slice at the byte column via a shared
TextDocument::textBeforeCursor()helper instead ofsubstr($lineText, 0, $character):CompletionHandler(classification / call-context text)TextFallbackHelper::getMemberAccessContextSymbolResolver::resolveVariableAccessWithAstOutbound completion
Rangecolumns now size the typed prefix in the negotiatedencoding via a new
Range::forPrefix(line, character, prefix, encoding)factory —the one place the conversion lives — instead of
$character - strlen($prefix):ClassCandidatesandNamespaceCandidates, which now receive the negotiatedencoding through
SessionCapabilitiesProvider(S1.2 kept it confined to thedocument boundary).
Why not native
mb_functionsFlagging this so it is not "simplified" later (and it is documented in
PositionEncoding): an LSPcharacteris a UTF-16 code unit count, but thenative
mb_functions count codepoints. An astral codepoint (e.g.😀,U+1F389, four UTF-8 bytes) is one
mb_character but two UTF-16 code units (asurrogate pair). So
mb_strlenover-shortens a length andmb_substrmis-sliceswhenever an astral codepoint is present — the exact defect this slice fixes. The
surrogate accounting in
PositionEncoding::utf16Units()is whatmb_does notprovide;
mb_str_split(codepoint split) is the onemb_primitive that fits andis already used.
mb_convert_encoding(..., 'UTF-16LE', ...)could shorten thelength-only case but not the
character → bytedirection, so it would fork thesingle shared mechanism for no net gain.
Acceptance criteria
repeated pattern is a shared
TextDocumenthelper (byte column from thedocument's own encoding, no encoding threading).
Rangestart columns are measured in the negotiatedencoding's code units, with
PositionEncodingreachable at the completionsources.
of mixed-width codepoints, and re-runs existing cursor-marker fixtures under
the negotiated encoding.
composer testgreen (PHPStan + suite + PHPCS).§4.9 enforcement
Per §8.1, invariant 9's mechanism is a test (multibyte round-trip at the boundary)
plus review of interior offset use — no new static rule. This slice supplies the
tests:
PositionRoundTripCorpusTest, plus per-site multibyte cases acrossTextDocumentTest,PositionEncodingTest,RangeTest,CompletionHandlerTest,TextFallbackHelperTest,SymbolResolverTest,ClassCandidatesTest, andNamespaceCandidatesTest.Candidate closes
None attributed to S1.5 in the build manifest. See Related above for #192, which
this slice advances (its
Closessits with S1.2 in the manifest); the reviewerdecides whether it is now fully resolved.
Notes for review
SymbolResolver::resolveVariableAccessWithAstis a deep fallback: for the multibytescenarios tried, the AST path (which already uses the correct
offsetAt) serves thequery, so its
substris corrected for consistency and kept covered by the existingtests (16×) rather than by a contrived red case. The shared text-fallback prefix
behavior is proven red→green in
TextFallbackHelperTest.