Skip to content

303 concatenated single quoted strings interacts with riders built in regex validation bugfix#314

Open
MatejFillo wants to merge 4 commits intomasterfrom
303-concatenated-single-quoted-strings-interacts-with-riders-built-in-regex-validation
Open

303 concatenated single quoted strings interacts with riders built in regex validation bugfix#314
MatejFillo wants to merge 4 commits intomasterfrom
303-concatenated-single-quoted-strings-interacts-with-riders-built-in-regex-validation

Conversation

@MatejFillo
Copy link
Collaborator

Signed-off-by: Matej Fillo <matej.fillo@pantheon.tech>
Signed-off-by: Matej Fillo <matej.fillo@pantheon.tech>
Signed-off-by: Matej Fillo <matej.fillo@pantheon.tech>
Signed-off-by: Matej Fillo <matej.fillo@pantheon.tech>
@mmiklus
Copy link
Contributor

mmiklus commented Jun 19, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces changes to correctly handle language injection for regular expressions within concatenated single and double-quoted YANG strings. It achieves this by refining the grammar to create specific PSI elements for individual string segments and then targeting these elements for injection. There's an issue identified in RegExpToYangInjector.java concerning the calculation of the TextRange for injection, which needs to be addressed to ensure the fix works correctly. The suggested change is to use new TextRange(0, context.getTextLength()) to correctly define the injection range within the host PSI element.

if (context instanceof YangDoubleQuotedRegex || context instanceof YangSingleQuotedRegex) {
registrar.startInjecting(XsdRegExpParserDefinition.LANGUAGE)
.addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(context.getStartOffsetInParent() + 1, context.getStartOffsetInParent() + context.getTextLength() - 1))
.addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(context.getStartOffsetInParent(), context.getStartOffsetInParent() + context.getTextLength()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The TextRange provided to addPlace for language injection appears to be incorrect. The TextRange constructor for addPlace expects offsets relative to the host element itself, i.e., (startOffsetInHost, endOffsetInHost). The current code uses context.getStartOffsetInParent(), which provides the offset of the host element within its parent. This is not the correct value for defining a range within the host. The correct TextRange should be new TextRange(0, context.getTextLength()).

Suggested change
.addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(context.getStartOffsetInParent(), context.getStartOffsetInParent() + context.getTextLength()))
.addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(0, context.getTextLength()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concatenated single quoted strings interacts with Rider's built-in regex validation

2 participants