PY-31442 Similarly to Kotlin highlight all formatting syntax of f-strings as escapes

This way colon and type conversion are more noticeable right away.
This commit is contained in:
Mikhail Golubev
2018-10-01 12:46:48 +03:00
parent 6354daae42
commit b2193bbcc7
2 changed files with 11 additions and 7 deletions
@@ -105,7 +105,9 @@ public class PyHighlighter extends SyntaxHighlighterBase {
public static final TextAttributesKey PY_INVALID_STRING_ESCAPE = TextAttributesKey.createTextAttributesKey("PY.INVALID_STRING_ESCAPE", INVALID_STRING_ESCAPE);
public static final TextAttributesKey PY_FSTRING_EXPRESSION_BRACES = TextAttributesKey.createTextAttributesKey("PY.FSTRING_EXPRESSION_BRACES", PY_BRACES);
public static final TextAttributesKey PY_FSTRING_FRAGMENT_BRACES = TextAttributesKey.createTextAttributesKey("PY.FSTRING_FRAGMENT_BRACES", VALID_STRING_ESCAPE);
public static final TextAttributesKey PY_FSTRING_FRAGMENT_COLON = TextAttributesKey.createTextAttributesKey("PY.FSTRING_FRAGMENT_COLON", VALID_STRING_ESCAPE);
public static final TextAttributesKey PY_FSTRING_FRAGMENT_TYPE_CONVERSION = TextAttributesKey.createTextAttributesKey("PY.FSTRING_FRAGMENT_TYPE_CONVERSION", VALID_STRING_ESCAPE);
/**
* The 'heavy' constructor that initializes everything. PySyntaxHighlighterFactory caches such instances per level.
@@ -129,11 +131,11 @@ public class PyHighlighter extends SyntaxHighlighterBase {
keys.put(PyTokenTypes.FSTRING_START, PY_UNICODE_STRING);
keys.put(PyTokenTypes.FSTRING_END, PY_UNICODE_STRING);
keys.put(PyTokenTypes.FSTRING_TEXT, PY_UNICODE_STRING);
keys.put(PyTokenTypes.FSTRING_FRAGMENT_TYPE_CONVERSION, PY_UNICODE_STRING);
keys.put(PyTokenTypes.FSTRING_FRAGMENT_FORMAT_START, PY_UNICODE_STRING);
keys.put(PyTokenTypes.FSTRING_FRAGMENT_START, PY_FSTRING_EXPRESSION_BRACES);
keys.put(PyTokenTypes.FSTRING_FRAGMENT_END, PY_FSTRING_EXPRESSION_BRACES);
keys.put(PyTokenTypes.FSTRING_FRAGMENT_TYPE_CONVERSION, PY_FSTRING_FRAGMENT_TYPE_CONVERSION);
keys.put(PyTokenTypes.FSTRING_FRAGMENT_FORMAT_START, PY_FSTRING_FRAGMENT_COLON);
keys.put(PyTokenTypes.FSTRING_FRAGMENT_START, PY_FSTRING_FRAGMENT_BRACES);
keys.put(PyTokenTypes.FSTRING_FRAGMENT_END, PY_FSTRING_FRAGMENT_BRACES);
keys.put(PyTokenTypes.DOCSTRING, PY_DOC_COMMENT);
@@ -38,7 +38,9 @@ public class PythonColorsPage implements RainbowColorSettingsPage, InspectionCol
new AttributesDescriptor("Parentheses", PyHighlighter.PY_PARENTHS),
new AttributesDescriptor("Brackets", PyHighlighter.PY_BRACKETS),
new AttributesDescriptor("Braces", PyHighlighter.PY_BRACES),
new AttributesDescriptor("f-string expression braces", PyHighlighter.PY_FSTRING_EXPRESSION_BRACES),
new AttributesDescriptor("f-string expression braces", PyHighlighter.PY_FSTRING_FRAGMENT_BRACES),
new AttributesDescriptor("f-string type conversion", PyHighlighter.PY_FSTRING_FRAGMENT_TYPE_CONVERSION),
new AttributesDescriptor("f-string format specifier start", PyHighlighter.PY_FSTRING_FRAGMENT_COLON),
new AttributesDescriptor("Comma", PyHighlighter.PY_COMMA),
new AttributesDescriptor("Dot", PyHighlighter.PY_DOT),
new AttributesDescriptor("Function definition", PyHighlighter.PY_FUNC_DEFINITION),
@@ -120,7 +122,7 @@ public class PythonColorsPage implements RainbowColorSettingsPage, InspectionCol
"" +
RainbowHighlighter.generatePaletteExample("\n ") + "\n" +
" \"\"\"</docComment>\n" +
" <localVar>s</localVar> = (\"Test\", 2+3, {'a': 'b'}, f'{<param>x</param>}') # Comment\n" +
" <localVar>s</localVar> = (\"Test\", 2+3, {'a': 'b'}, f'{<param>x</param>!s:{\"foo\"}}') # Comment\n" +
" <call>f</call>(<localVar>s</localVar>[0].<mcall>lower()</mcall>)\n" +
"\n" +
"class <classDef>Foo</classDef>:\n" +