From 84aa9b4bf5d60ba0a3ce58fa414ebbdc28fb70de Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Mon, 8 Oct 2018 18:33:24 +0300 Subject: [PATCH] PY-32109 Use the latest supported language version for the example in colorscheme settings --- .../highlighting/PySyntaxHighlighterFactory.java | 10 +++++++++- .../python/highlighting/PythonColorsPage.java | 11 +++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/highlighting/PySyntaxHighlighterFactory.java b/python/src/com/jetbrains/python/highlighting/PySyntaxHighlighterFactory.java index 545806359205..97bdc9ed6eac 100644 --- a/python/src/com/jetbrains/python/highlighting/PySyntaxHighlighterFactory.java +++ b/python/src/com/jetbrains/python/highlighting/PySyntaxHighlighterFactory.java @@ -34,6 +34,14 @@ public class PySyntaxHighlighterFactory extends SyntaxHighlighterFactory { final LanguageLevel level = project != null && virtualFile != null ? PyUtil.getLanguageLevelForVirtualFile(project, virtualFile) : LanguageLevel.getDefault(); - return myMap.get(level); + return getSyntaxHighlighterForLanguageLevel(level); + } + + /** + * Returns a syntax highlighter targeting the specified version of Python. + */ + @NotNull + public SyntaxHighlighter getSyntaxHighlighterForLanguageLevel(@NotNull LanguageLevel version) { + return myMap.get(version); } } diff --git a/python/src/com/jetbrains/python/highlighting/PythonColorsPage.java b/python/src/com/jetbrains/python/highlighting/PythonColorsPage.java index 0e1f53ee5c09..67a55f7099d3 100644 --- a/python/src/com/jetbrains/python/highlighting/PythonColorsPage.java +++ b/python/src/com/jetbrains/python/highlighting/PythonColorsPage.java @@ -17,6 +17,7 @@ import com.intellij.psi.codeStyle.DisplayPrioritySortable; import com.intellij.util.PlatformUtils; import com.jetbrains.python.PythonFileType; import com.jetbrains.python.PythonLanguage; +import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -114,9 +115,11 @@ public class PythonColorsPage implements RainbowColorSettingsPage, InspectionCol @Override @NotNull public SyntaxHighlighter getHighlighter() { - final SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(PythonFileType.INSTANCE, null, null); - assert highlighter != null; - return highlighter; + final SyntaxHighlighterFactory factory = SyntaxHighlighterFactory.LANGUAGE_FACTORY.forLanguage(PythonLanguage.getInstance()); + if (factory instanceof PySyntaxHighlighterFactory) { + return ((PySyntaxHighlighterFactory)factory).getSyntaxHighlighterForLanguageLevel(LanguageLevel.getLatest()); + } + return factory.getSyntaxHighlighter(null, null); } @Override @@ -136,7 +139,7 @@ public class PythonColorsPage implements RainbowColorSettingsPage, InspectionCol "class Foo:\n" + " tags: List[str]\n" + " def __init__(self: Foo):\n" + - " byte_string: str = 'newline:\\n also newline:\\x0a'\n" + + " byte_string: bytes = b'newline:\\n also newline:\\x0a'\n" + " text_string = u\"Cyrillic Я is \\u042f. Oops: \\u042g\"\n" + " self.makeSense(whatever=1)\n" + " \n" +