Encapsulate location encoding in response builders#4089
Draft
vinistock wants to merge 1 commit intorubydex_adoption_feature_branchfrom
Draft
Encapsulate location encoding in response builders#4089vinistock wants to merge 1 commit intorubydex_adoption_feature_branchfrom
vinistock wants to merge 1 commit intorubydex_adoption_feature_branchfrom
Conversation
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.
Motivation
While working on the Rubydex migration, I realized that we weren't actually returning the expected code units for the different encodings in a bunch of requests.
The primary reason for that is the fact that listeners don't have access to the parse result or the encoding to access the code units cache and compute the expected response. This also means add-ons can't provide correct code unit positions.
This PR changes our base response builder to be instantiated with the code units cache for the specific encoding. All listeners (including the ones coming from add-ons) have access to the response builder to make contributions to the final response, so this makes it straightforward for all listeners to use the correct code unit positions.
Note: this also uncovered a bug in Prism, which calculates UTF-8 code units incorrectly. The fix is merged, but we can only ship this PR once there's a Prism release (and we will need to bump our requirement to be strictly the latest).
Implementation
The idea is simple: the base response builder class now enforces that all of them are instantiated with the encoding and parse result for the document being served, so that we can get the right code units cache.
Then we expose a public API that any listener can use to produce new locations.
After all listeners are migrated to this new API and have their responses fixed for all encodings, we need to remove the old helpers from
Support::Commonas those produce incorrect code unit positions.Automated Tests
Added a test to verify that we are creating locations with the expected code unit values for a multibyte source.