Merge branch 'traff/prebuilt-stubs'
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Fri, 8 Sep 2017 08:54:14 +0000 (11:54 +0300)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Fri, 8 Sep 2017 08:54:14 +0000 (11:54 +0300)
# Conflicts:
# platform/util/resources/misc/registry.properties
# python/tools/src/com/jetbrains/python/tools/Utils.kt

1  2 
platform/platform-resources/src/META-INF/LangExtensionPoints.xml
platform/util/resources/misc/registry.properties
python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java
python/tools/src/com/jetbrains/python/tools/Utils.kt

index 51f92ad69949493b01946a3c62fc86279a6f5626,765bbacbe46e328b1c8d964f401c21254e960bf3..e2c9bb5e9079e45bf43aaaf1e83897bff55e4cc7
@@@ -1252,10 -1230,5 +1252,13 @@@ batch.inspections.process.by.default.jv
  junit4.search.4.tests.in.classpath=true
  junit4.search.4.tests.in.classpath.description=Search for tests in the module output
  
 +duplicates.inspection.only.extractable=false
 +duplicates.inspection.only.extractable.description=Highlight duplicate code only if it can be extracted into a method
 +
 +ide.interlanguage.fixes=false
 +ide.interlanguage.fixes.description=Enable 'Create Xxx from usage' fixes in JVM languages
 +ide.create.field.enable.shortening=true
 +ide.create.field.enable.shortening.description=Always enable shortening of FQNs in templates in Create Field fixes
++
+ use.prebuilt.stubs=true
+ use.prebuilt.stubs.description=Use bundled prebuilt stubs if they are available for better indexing performance
index ff818d425cfa192d14f6e57549139c32e906b153,270338a169e5fcae0855cd9f54dc054498878baa..69fd21b143922efe318cc837568de4cc9c63da22
@@@ -24,10 -25,9 +25,11 @@@ import com.intellij.openapi.project.Pro
  import com.intellij.openapi.projectRoots.Sdk
  import com.intellij.openapi.roots.ModuleRootManager
  import com.intellij.openapi.roots.ModuleRootModificationUtil
 +import com.intellij.openapi.util.Computable
+ import com.intellij.openapi.util.Disposer
  import com.intellij.openapi.vfs.VfsUtil
  import com.intellij.util.ui.UIUtil
 +import com.jetbrains.python.PythonModuleTypeBase
  import com.jetbrains.python.sdk.PythonSdkType
  import com.jetbrains.python.sdk.PythonSdkUpdater
  import com.jetbrains.python.tools.sdkTools.PySdkTools
@@@ -47,54 -47,39 +49,67 @@@ fun createSdkForPerformance(module: Mod
  }
  
  
 -fun openProjectWithSdk(projectPath: String, sdkHome: String): Pair<Project?, Sdk?> {
 +fun openProjectWithSdk(projectPath: String, sdkHome: String?): Pair<Project?, Sdk?> {
+   println("Opening project at $projectPath")
    val project: Project? = ProjectManager.getInstance().loadAndOpenProject(projectPath)
  
+   try {
 -    val module = ModuleManager.getInstance(project!!).modules[0]
 +  val module = getOrCreateModule(project!!, projectPath)
  
 -    val sdk = createSdkForPerformance(module, SdkCreationType.SDK_PACKAGES_AND_SKELETONS, sdkHome)
 +  val sdk =
 +    if (sdkHome != null) {
-       val sdk = createSdkForPerformance(module, SdkCreationType.SDK_PACKAGES_AND_SKELETONS, sdkHome)
++  val sdk = createSdkForPerformance(module, SdkCreationType.SDK_PACKAGES_AND_SKELETONS, sdkHome)
 +
-       UIUtil.invokeAndWaitIfNeeded(Runnable {
-         ApplicationManager.getApplication().runWriteAction({
-                                                              PythonSdkUpdater.update(sdk, null, project, null)
-                                                            })
-       })
++  UIUtil.invokeAndWaitIfNeeded(Runnable {
++    ApplicationManager.getApplication().runWriteAction({
++                                                         PythonSdkUpdater.update(sdk, null, project, null)
++                                                       })
++  })
 +
-       ModuleRootModificationUtil.setModuleSdk(module, sdk)
 +
-       assert(ModuleRootManager.getInstance(module).orderEntries().classesRoots.size > 5)
++    ModuleRootModificationUtil.setModuleSdk(module, sdk)
  
 -    UIUtil.invokeAndWaitIfNeeded(Runnable {
 -      ApplicationManager.getApplication().runWriteAction({
 -                                                           PythonSdkUpdater.update(sdk, null, project, null)
 -                                                         })
 -    })
 -    if (module != null) {
 -      ModuleRootModificationUtil.setModuleSdk(module, sdk)
++  assert(ModuleRootManager.getInstance(module).orderEntries().classesRoots.size > 5)
 +      sdk
 +    }
 +    else {
 +      null
      }
  
 -    assert(ModuleRootManager.getInstance(module).orderEntries().classesRoots.size > 5)
 -    assert(ModuleManager.getInstance(project).modules.size == 1)
 +  assert(ModuleManager.getInstance(project).modules.size == 1)
  
-   return Pair(project, sdk)
+     return Pair(project, sdk)
+   }
+   catch (e: Throwable) {
+     if (project != null) {
+       UIUtil.invokeAndWaitIfNeeded(Runnable {
+         ProjectManager.getInstance().closeProject(project)
+         WriteAction.run<Throwable> {
+           Disposer.dispose(project)
+         }
+       })
+     }
+     throw e
+   }
 +}
 +
 +fun getOrCreateModule(project: Project, projectPath: String): Module {
 +  if (ModuleManager.getInstance(project).modules.isNotEmpty()) {
 +    return ModuleManager.getInstance(project).modules[0]
 +  }
 +  else {
 +    val module: Module = ApplicationManager.getApplication().runWriteAction(
 +      Computable<Module> { ModuleManager.getInstance(project).newModule(projectPath, PythonModuleTypeBase.PYTHON_MODULE) }
 +    )
 +
 +    val root = VfsUtil.findFileByIoFile(File(projectPath), true)!!
 +
 +    ModuleRootModificationUtil.updateModel(module, { t ->
 +      val e = t.addContentEntry(root)
 +      e.addSourceFolder(root, false)
 +    })
 +
 +    return module
 +  }
  }