PY-26357 Refresh interpreters list if there is no project available

We used to cache interpreters for the default project in that case.
This commit is contained in:
Andrey Vlasovskikh
2017-10-10 05:49:49 +03:00
parent cc5994c866
commit b616d2d01b
3 changed files with 11 additions and 9 deletions
@@ -135,8 +135,7 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyN
}
public ValidationResult validate() {
final Project project = ProjectManager.getInstance().getDefaultProject();
final List<Sdk> sdks = PyConfigurableInterpreterList.getInstance(project).getAllPythonSdks();
final List<Sdk> sdks = PyConfigurableInterpreterList.getInstance(null).getAllPythonSdks();
ValidationResult validationResult;
if (sdks.isEmpty()) {
@@ -178,8 +177,7 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyN
@Nullable
@Override
public LabeledComponent<JComponent> getLanguageSettingsComponent(@NotNull Course selectedCourse) {
final Project project = ProjectManager.getInstance().getDefaultProject();
final List<Sdk> sdks = PyConfigurableInterpreterList.getInstance(project).getAllPythonSdks();
final List<Sdk> sdks = PyConfigurableInterpreterList.getInstance(null).getAllPythonSdks();
VirtualEnvProjectFilter.removeAllAssociated(sdks);
// by default we create new virtual env in project, we need to add this non-existing sdk to sdk list
ProjectJdkImpl fakeSdk = createFakeSdk(selectedCourse);
@@ -17,6 +17,7 @@ package com.jetbrains.python.configuration;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.util.Comparing;
@@ -40,8 +41,13 @@ import java.util.List;
public class PyConfigurableInterpreterList {
private ProjectSdksModel myModel;
public static PyConfigurableInterpreterList getInstance(Project project) {
return ServiceManager.getService(project, PyConfigurableInterpreterList.class);
public static PyConfigurableInterpreterList getInstance(@Nullable Project project) {
final Project effectiveProject = project != null ? project : ProjectManager.getInstance().getDefaultProject();
final PyConfigurableInterpreterList instance = ServiceManager.getService(effectiveProject, PyConfigurableInterpreterList.class);
if (effectiveProject != project) {
instance.disposeModel();
}
return instance;
}
public ProjectSdksModel getModel() {
@@ -17,7 +17,6 @@ package com.jetbrains.python.newProject.steps;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.DefaultProjectFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
@@ -79,8 +78,7 @@ public class PythonSdkChooserCombo extends ComboboxWithBrowseButton {
}
private void showOptions(@Nullable final Project project) {
final Project existingProject = project != null ? project : DefaultProjectFactory.getInstance().getDefaultProject();
final PyConfigurableInterpreterList interpreterList = PyConfigurableInterpreterList.getInstance(existingProject);
final PyConfigurableInterpreterList interpreterList = PyConfigurableInterpreterList.getInstance(project);
final Sdk[] sdks = interpreterList.getModel().getSdks();
//noinspection unchecked
final JComboBox<Sdk> comboBox = getComboBox();