fix: avoid invalid TextRange in @Value reference provider (#236)#238
Open
imuromtsev wants to merge 1 commit into
Open
fix: avoid invalid TextRange in @Value reference provider (#236)#238imuromtsev wants to merge 1 commit into
imuromtsev wants to merge 1 commit into
Conversation
When the @value placeholder key is resolved from a constant or template, the evaluated string does not appear literally in the host text, so indexOf returns -1 and TextRange.from(-1, n) threw IllegalArgumentException. Skip references whose key cannot be located in the host text. Adds regression tests.
|
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.
Fixes #236.
Problem
ValueConfigurationPropertyReferenceProvider.getReferencesForInjectionHostbuilt aTextRangefromhost.text.indexOf(key). When the@Valueplaceholder key comes from an evaluated string that does not appear literally in the raw host text (e.g. a Kotlin template referencing aconst),indexOfreturns-1andTextRange.from(-1, n)throwsIllegalArgumentException: Invalid range specified: (-1, n).Fix
Switch
map→mapNotNulland skip any reference whose key cannot be located in the host text (startOffset < 0) instead of constructing an invalid range.Tests
Added
ValueConfigurationPropertyReferenceProviderTest:testValueReferencingConstantKeyDoesNotThrow— reproduces the crash (key from aconst); now highlights without throwing.testValueWithLiteralPlaceholderResolvesReference— happy path still resolves a reference.Module test run:
tests=2, failures=0, errors=0.