303 concatenated single quoted strings interacts with riders built in regex validation bugfix#314
Conversation
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>
|
/gemini review |
There was a problem hiding this comment.
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())) |
There was a problem hiding this comment.
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()).
| .addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(context.getStartOffsetInParent(), context.getStartOffsetInParent() + context.getTextLength())) | |
| .addPlace(null, null, (PsiLanguageInjectionHost) context, new TextRange(0, context.getTextLength())) |
#303