From 4864794b64502d411b6d1da4e7b41eb5b57bcb23 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Fri, 22 May 2015 16:05:42 +0200 Subject: [PATCH] Guess Python language level for scratch files (PY-15898) The language level pusher was unable to find the correct language level because there is no SDK associated with scratch files. Now we use the same guessing mechanism we've been using for PyUtil.getLanguageLevelForFile(). --- .../psi-api/src/com/jetbrains/python/psi/LanguageLevel.java | 1 + python/src/com/jetbrains/python/psi/PyUtil.java | 3 ++- .../python/psi/impl/PythonLanguageLevelPusher.java | 6 +++++- python/src/com/jetbrains/python/sdk/PythonSdkType.java | 1 + .../src/com/jetbrains/python/sdk/flavors/PyPySdkFlavor.java | 3 ++- .../com/jetbrains/python/sdk/flavors/PythonSdkFlavor.java | 3 ++- 6 files changed, 13 insertions(+), 4 deletions(-) diff --git a/python/psi-api/src/com/jetbrains/python/psi/LanguageLevel.java b/python/psi-api/src/com/jetbrains/python/psi/LanguageLevel.java index ae22e57e82ab..52ec5ae5de61 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/LanguageLevel.java +++ b/python/psi-api/src/com/jetbrains/python/psi/LanguageLevel.java @@ -56,6 +56,7 @@ public enum LanguageLevel { public static LanguageLevel FORCE_LANGUAGE_LEVEL = null; + @NotNull public static LanguageLevel getDefault() { return DEFAULT2; } diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index 5ec8c8d0e16b..756683124644 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -828,7 +828,8 @@ public class PyUtil { return guessLanguageLevel(project); } - private static LanguageLevel guessLanguageLevel(@NotNull Project project) { + @NotNull + public static LanguageLevel guessLanguageLevel(@NotNull Project project) { final ModuleManager moduleManager = ModuleManager.getInstance(project); if (moduleManager != null) { for (Module projectModule : moduleManager.getModules()) { diff --git a/python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java b/python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java index c93f776948ba..a78934b33b12 100644 --- a/python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java +++ b/python/src/com/jetbrains/python/psi/impl/PythonLanguageLevelPusher.java @@ -49,6 +49,7 @@ import com.jetbrains.python.PythonFileType; import com.jetbrains.python.PythonModuleTypeBase; import com.jetbrains.python.facet.PythonFacetSettings; import com.jetbrains.python.psi.LanguageLevel; +import com.jetbrains.python.psi.PyUtil; import com.jetbrains.python.psi.resolve.PythonSdkPathCache; import com.jetbrains.python.sdk.PythonSdkType; import org.jetbrains.annotations.NotNull; @@ -108,7 +109,10 @@ public class PythonLanguageLevelPusher implements FilePropertyPusher