mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-31442 Don't warn about closing braces of named unicode escapes
This commit is contained in:
@@ -17,6 +17,7 @@ package com.jetbrains.python.validation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -24,6 +25,7 @@ import com.jetbrains.python.psi.PyFStringFragment;
|
||||
import com.jetbrains.python.psi.PyFStringFragmentFormatPart;
|
||||
import com.jetbrains.python.psi.PyFormattedStringElement;
|
||||
import com.jetbrains.python.psi.PyStringLiteralExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -75,6 +77,11 @@ public class FStringsAnnotator extends PyAnnotator {
|
||||
for (TextRange textRange : node.getLiteralPartRanges()) {
|
||||
int i = textRange.getStartOffset();
|
||||
while (i < textRange.getEndOffset()) {
|
||||
final int nextOffset = skipNamedUnicodeEscape(wholeNodeText, i, textRange.getEndOffset());
|
||||
if (i != nextOffset) {
|
||||
i = nextOffset;
|
||||
continue;
|
||||
}
|
||||
final char c = wholeNodeText.charAt(i);
|
||||
if (c == '}') {
|
||||
if (i + 1 < textRange.getEndOffset() && wholeNodeText.charAt(i + 1) == '}') {
|
||||
@@ -88,6 +95,14 @@ public class FStringsAnnotator extends PyAnnotator {
|
||||
}
|
||||
}
|
||||
|
||||
private static int skipNamedUnicodeEscape(@NotNull String nodeText, int offset, int endOffset) {
|
||||
if (StringUtil.startsWith(nodeText, offset, "\\N{")) {
|
||||
final int rightBraceOffset = nodeText.indexOf('}', offset + 3);
|
||||
return rightBraceOffset < 0 ? endOffset : rightBraceOffset + 1;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitComment(PsiComment comment) {
|
||||
final boolean insideFragment = PsiTreeUtil.getParentOfType(comment, PyFStringFragment.class) != null;
|
||||
|
||||
@@ -3,4 +3,5 @@ f'{x}{y}<error descr="Single '}' is not allowed inside f-strings">}</error>'
|
||||
f'{x}}}<error descr="Single '}' is not allowed inside f-strings">}</error>'
|
||||
f'{x:{y}}<error descr="Single '}' is not allowed inside f-strings">}</error>'
|
||||
f'{x:{y}}}}'
|
||||
f'{"}":{"}"}}'
|
||||
f'{"}":{"}"}}'
|
||||
f'\N{FOO BAR}'
|
||||
Reference in New Issue
Block a user