mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
Fix disappearing of Python repository from settings after Clion restart (CPP-7743)
Python plugin stored the interpreter setting as a module sdk, which was wiped out with it's order entries by Clion. The fix is to store the interpreter setting in a facet and reinitialize it after Clion model clearing.
This commit is contained in:
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -216,6 +216,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/python/python-community-ide-resources/python-community-ide-resources.iml" filepath="$PROJECT_DIR$/python/python-community-ide-resources/python-community-ide-resources.iml" group="python" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/pluginCore/python-community-plugin-core.iml" filepath="$PROJECT_DIR$/python/pluginCore/python-community-plugin-core.iml" group="python" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/pluginJava/python-community-plugin-java.iml" filepath="$PROJECT_DIR$/python/pluginJava/python-community-plugin-java.iml" group="python" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/pluginMinor/python-community-plugin-minor.iml" filepath="$PROJECT_DIR$/python/pluginMinor/python-community-plugin-minor.iml" group="python" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/python-community-plugin-resources.iml" filepath="$PROJECT_DIR$/python/python-community-plugin-resources.iml" group="python" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/testSrc/python-community-tests.iml" filepath="$PROJECT_DIR$/python/testSrc/python-community-tests.iml" group="python" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/educational-python/build/python-edu-build.iml" filepath="$PROJECT_DIR$/python/educational-python/build/python-edu-build.iml" group="python/educational" />
|
||||
|
||||
@@ -12,12 +12,16 @@
|
||||
<add-to-group group-id="ToolsMenu" anchor="last"/>
|
||||
</action>
|
||||
</actions>
|
||||
|
||||
|
||||
<application-components>
|
||||
<component>
|
||||
<interface-class>com.jetbrains.python.console.PythonConsoleRunnerFactory</interface-class>
|
||||
<implementation-class>com.jetbrains.python.console.PydevConsoleRunnerFactory</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<implementation-class>com.jetbrains.python.facet.PythonSdkTableListener</implementation-class>
|
||||
</component>
|
||||
</application-components>
|
||||
|
||||
</idea-plugin>
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.facet;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
|
||||
import static com.jetbrains.python.facet.LibraryContributingFacet.PYTHON_FACET_LIBRARY_NAME_SUFFIX;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class PythonFacetUtil {
|
||||
public static String getFacetLibraryName(final String sdkName) {
|
||||
return sdkName + PYTHON_FACET_LIBRARY_NAME_SUFFIX;
|
||||
}
|
||||
|
||||
public static void updateLibrary(Module module, PythonFacetSettings facetSettings) {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
boolean modelChanged = false;
|
||||
try {
|
||||
// Just remove all old facet libraries except one, that is necessary
|
||||
final Sdk sdk = facetSettings.getSdk();
|
||||
final String name = (sdk != null) ? getFacetLibraryName(sdk.getName()) : null;
|
||||
boolean librarySeen = false;
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry) {
|
||||
final String libraryName = ((LibraryOrderEntry)entry).getLibraryName();
|
||||
if (name != null && name.equals(libraryName)) {
|
||||
librarySeen = true;
|
||||
continue;
|
||||
}
|
||||
if (libraryName != null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
|
||||
model.removeOrderEntry(entry);
|
||||
modelChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (name != null) {
|
||||
final ModifiableModelsProvider provider = ModifiableModelsProvider.SERVICE.getInstance();
|
||||
final LibraryTable.ModifiableModel libraryTableModifiableModel = provider.getLibraryTableModifiableModel();
|
||||
Library library = libraryTableModifiableModel.getLibraryByName(name);
|
||||
provider.disposeLibraryTableModifiableModel(libraryTableModifiableModel);
|
||||
if (library == null) {
|
||||
// we just create new project library
|
||||
library = PythonSdkTableListener.addLibrary(sdk);
|
||||
}
|
||||
if (!librarySeen) {
|
||||
model.addLibraryEntry(library);
|
||||
modelChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (modelChanged){
|
||||
model.commit();
|
||||
}
|
||||
else {
|
||||
model.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeLibrary(Module module) {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
// Just remove all old facet libraries
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry) {
|
||||
final Library library = ((LibraryOrderEntry)entry).getLibrary();
|
||||
if (library != null) {
|
||||
final String libraryName = library.getName();
|
||||
if (libraryName!=null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
|
||||
model.removeOrderEntry(entry);
|
||||
//PyBuiltinCache.clearInstanceCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
model.commit();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.facet;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class PythonSdkTableListener implements Disposable {
|
||||
public PythonSdkTableListener(MessageBus messageBus) {
|
||||
ProjectJdkTable.Listener jdkTableListener = new ProjectJdkTable.Listener() {
|
||||
@Override
|
||||
public void jdkAdded(final Sdk sdk) {
|
||||
if (sdk.getSdkType() instanceof PythonSdkType) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
addLibrary(sdk);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jdkRemoved(final Sdk sdk) {
|
||||
if (sdk.getSdkType() instanceof PythonSdkType) {
|
||||
removeLibrary(sdk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jdkNameChanged(final Sdk sdk, final String previousName) {
|
||||
if (sdk.getSdkType() instanceof PythonSdkType) {
|
||||
renameLibrary(sdk, previousName);
|
||||
}
|
||||
}
|
||||
};
|
||||
messageBus.connect(this).subscribe(ProjectJdkTable.JDK_TABLE_TOPIC, jdkTableListener);
|
||||
}
|
||||
|
||||
static Library addLibrary(Sdk sdk) {
|
||||
final LibraryTable.ModifiableModel libraryTableModel = ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
|
||||
final Library library = libraryTableModel.createLibrary(PythonFacetUtil.getFacetLibraryName(sdk.getName()));
|
||||
final Library.ModifiableModel model = library.getModifiableModel();
|
||||
for (String url : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) {
|
||||
model.addRoot(url, OrderRootType.CLASSES);
|
||||
model.addRoot(url, OrderRootType.SOURCES);
|
||||
}
|
||||
model.commit();
|
||||
libraryTableModel.commit();
|
||||
return library;
|
||||
}
|
||||
|
||||
private static void removeLibrary(final Sdk sdk) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final LibraryTable.ModifiableModel libraryTableModel =
|
||||
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
|
||||
final Library library = libraryTableModel.getLibraryByName(PythonFacetUtil.getFacetLibraryName(sdk.getName()));
|
||||
if (library != null) {
|
||||
libraryTableModel.removeLibrary(library);
|
||||
}
|
||||
libraryTableModel.commit();
|
||||
}), ModalityState.NON_MODAL);
|
||||
}
|
||||
|
||||
private static void renameLibrary(final Sdk sdk, final String previousName) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final LibraryTable.ModifiableModel libraryTableModel =
|
||||
ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
|
||||
final Library library = libraryTableModel.getLibraryByName(PythonFacetUtil.getFacetLibraryName(previousName));
|
||||
if (library != null) {
|
||||
final Library.ModifiableModel model = library.getModifiableModel();
|
||||
model.setName(PythonFacetUtil.getFacetLibraryName(sdk.getName()));
|
||||
model.commit();
|
||||
}
|
||||
libraryTableModel.commit();
|
||||
}), ModalityState.NON_MODAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
both Community and Professional versions. -->
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<moduleType id="PYTHON_MODULE" implementationClass="com.jetbrains.python.module.PythonModuleType"/>
|
||||
<facetType implementation="com.jetbrains.python.facet.PythonFacetType"/>
|
||||
|
||||
<framework.detector implementation="com.jetbrains.python.facet.PythonFacetType$PythonFrameworkDetector"/>
|
||||
<frameworkSupport implementation="com.jetbrains.python.facet.PythonFrameworkSupportProvider"/>
|
||||
<projectStructureDetector implementation="com.jetbrains.python.module.PyProjectStructureDetector"/>
|
||||
@@ -20,10 +20,4 @@
|
||||
<pySuperMethodsSearch implementation="com.jetbrains.python.psi.impl.PyJavaSuperMethodsSearchExecutor"/>
|
||||
<importCandidateProvider implementation="com.jetbrains.python.psi.impl.PyJavaImportCandidateProvider"/>
|
||||
</extensions>
|
||||
|
||||
<application-components>
|
||||
<component>
|
||||
<implementation-class>com.jetbrains.python.facet.PythonSdkTableListener</implementation-class>
|
||||
</component>
|
||||
</application-components>
|
||||
</idea-plugin>
|
||||
@@ -18,12 +18,7 @@ package com.jetbrains.python.facet;
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.FacetType;
|
||||
import com.intellij.facet.FacetTypeId;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -32,81 +27,20 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class PythonFacet extends LibraryContributingFacet<PythonFacetConfiguration> {
|
||||
public static final FacetTypeId<PythonFacet> ID = new FacetTypeId<>("python");
|
||||
|
||||
public PythonFacet(@NotNull final FacetType facetType, @NotNull final Module module, final @NotNull String name, @NotNull final PythonFacetConfiguration configuration,
|
||||
public PythonFacet(@NotNull final FacetType facetType,
|
||||
@NotNull final Module module,
|
||||
final @NotNull String name,
|
||||
@NotNull final PythonFacetConfiguration configuration,
|
||||
Facet underlyingFacet) {
|
||||
super(facetType, module, name, configuration, underlyingFacet);
|
||||
}
|
||||
|
||||
public void updateLibrary() {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final Module module = getModule();
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
boolean modelChanged = false;
|
||||
try {
|
||||
// Just remove all old facet libraries except one, that is necessary
|
||||
final Sdk sdk = getConfiguration().getSdk();
|
||||
final String name = (sdk != null) ? getFacetLibraryName(sdk.getName()) : null;
|
||||
boolean librarySeen = false;
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry) {
|
||||
final String libraryName = ((LibraryOrderEntry)entry).getLibraryName();
|
||||
if (name != null && name.equals(libraryName)) {
|
||||
librarySeen = true;
|
||||
continue;
|
||||
}
|
||||
if (libraryName != null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
|
||||
model.removeOrderEntry(entry);
|
||||
modelChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (name != null) {
|
||||
final ModifiableModelsProvider provider = ModifiableModelsProvider.SERVICE.getInstance();
|
||||
final LibraryTable.ModifiableModel libraryTableModifiableModel = provider.getLibraryTableModifiableModel();
|
||||
Library library = libraryTableModifiableModel.getLibraryByName(name);
|
||||
provider.disposeLibraryTableModifiableModel(libraryTableModifiableModel);
|
||||
if (library == null) {
|
||||
// we just create new project library
|
||||
library = PythonSdkTableListener.addLibrary(sdk);
|
||||
}
|
||||
if (!librarySeen) {
|
||||
model.addLibraryEntry(library);
|
||||
modelChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (modelChanged){
|
||||
model.commit();
|
||||
}
|
||||
else {
|
||||
model.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
PythonFacetUtil.updateLibrary(getModule(), getConfiguration());
|
||||
}
|
||||
|
||||
public void removeLibrary() {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final Module module = getModule();
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
// Just remove all old facet libraries
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry) {
|
||||
final Library library = ((LibraryOrderEntry)entry).getLibrary();
|
||||
if (library != null) {
|
||||
final String libraryName = library.getName();
|
||||
if (libraryName!=null && libraryName.endsWith(PYTHON_FACET_LIBRARY_NAME_SUFFIX)) {
|
||||
model.removeOrderEntry(entry);
|
||||
//PyBuiltinCache.clearInstanceCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
model.commit();
|
||||
});
|
||||
PythonFacetUtil.removeLibrary(getModule());
|
||||
}
|
||||
|
||||
public static String getFacetLibraryName(final String sdkName) {
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="module" module-name="java-psi-api" />
|
||||
<orderEntry type="module" module-name="java-indexing-api" />
|
||||
<orderEntry type="module" module-name="idea-ui" />
|
||||
<orderEntry type="module" module-name="python-community-plugin-core" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,15 @@
|
||||
<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude" url="https://confluence.jetbrains.com/display/PYH/">
|
||||
<!-- Components and extensions declared in this file work ONLY in the Python plugin for minor IDEs -->
|
||||
|
||||
<xi:include href="/META-INF/python-community-plugin-core.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<projectConfigurable groupId="build" groupWeight="118"
|
||||
id="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
|
||||
displayName="Python Interpreter"
|
||||
instance="com.jetbrains.python.sdk.PyPluginSdkModuleConfigurable"/>
|
||||
|
||||
<facetType implementation="com.jetbrains.python.facet.PythonFacetType"/>
|
||||
</extensions>
|
||||
|
||||
</idea-plugin>
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.facet;
|
||||
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.FacetType;
|
||||
import com.intellij.facet.FacetTypeId;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This facet is intended to be used in the python plugin for IDEs other then IntelliJ IDEA
|
||||
*
|
||||
* @author traff
|
||||
*/
|
||||
public class PythonFacet extends LibraryContributingFacet<PythonFacetType.PythonFacetConfiguration> {
|
||||
public static final FacetTypeId<PythonFacet> ID = new FacetTypeId<>("python");
|
||||
|
||||
public PythonFacet(@NotNull final FacetType facetType, @NotNull final Module module, final @NotNull String name, @NotNull final PythonFacetType.PythonFacetConfiguration configuration,
|
||||
Facet underlyingFacet) {
|
||||
super(facetType, module, name, configuration, underlyingFacet);
|
||||
}
|
||||
|
||||
public void updateLibrary() {
|
||||
PythonFacetUtil.updateLibrary(getModule(), getConfiguration());
|
||||
}
|
||||
|
||||
public void removeLibrary() {
|
||||
PythonFacetUtil.removeLibrary(getModule());
|
||||
}
|
||||
|
||||
public void initFacet() {
|
||||
updateLibrary();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.facet;
|
||||
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.FacetConfiguration;
|
||||
import com.intellij.facet.FacetType;
|
||||
import com.intellij.facet.ui.FacetEditorContext;
|
||||
import com.intellij.facet.ui.FacetEditorTab;
|
||||
import com.intellij.facet.ui.FacetValidatorsManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import icons.PythonIcons;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
import static com.jetbrains.python.PythonModuleTypeBase.PYTHON_MODULE;
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
public class PythonFacetType extends FacetType<PythonFacet, PythonFacetType.PythonFacetConfiguration> {
|
||||
|
||||
@NonNls
|
||||
private static final String ID = "Python";
|
||||
|
||||
public static PythonFacetType getInstance() {
|
||||
return findInstance(PythonFacetType.class);
|
||||
}
|
||||
|
||||
public PythonFacetType() {
|
||||
super(PythonFacet.ID, ID, "Python");
|
||||
}
|
||||
|
||||
public PythonFacetConfiguration createDefaultConfiguration() {
|
||||
PythonFacetConfiguration result = new PythonFacetConfiguration();
|
||||
List<Sdk> sdks = ProjectJdkTable.getInstance().getSdksOfType(PythonSdkType.getInstance());
|
||||
if (sdks.size() > 0) {
|
||||
result.setSdk(sdks.get(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public PythonFacet createFacet(@NotNull Module module,
|
||||
String name,
|
||||
@NotNull PythonFacetConfiguration configuration,
|
||||
@Nullable Facet underlyingFacet) {
|
||||
return new PythonFacet(this, module, name, configuration, underlyingFacet);
|
||||
}
|
||||
|
||||
public boolean isSuitableModuleType(ModuleType moduleType) {
|
||||
return !(moduleType.getId().equals(PYTHON_MODULE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return PythonIcons.Python.Python;
|
||||
}
|
||||
|
||||
public static class PythonFacetConfiguration extends PythonFacetSettings implements FacetConfiguration {
|
||||
private static final String SDK_NAME = "sdkName";
|
||||
|
||||
public FacetEditorTab[] createEditorTabs(FacetEditorContext editorContext, FacetValidatorsManager validatorsManager) {
|
||||
return new FacetEditorTab[]{};
|
||||
}
|
||||
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
String sdkName = element.getAttributeValue(SDK_NAME);
|
||||
mySdk = StringUtil.isEmpty(sdkName) ? null : ProjectJdkTable.getInstance().findJdk(sdkName, PythonSdkType.getInstance().getName());
|
||||
|
||||
ApplicationManager.getApplication().getMessageBus().syncPublisher(ProjectJdkTable.JDK_TABLE_TOPIC).jdkAdded(mySdk);
|
||||
}
|
||||
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
element.setAttribute(SDK_NAME, mySdk == null ? "" : mySdk.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.sdk
|
||||
|
||||
import com.intellij.facet.FacetManager
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.options.UnnamedConfigurable
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.jetbrains.python.configuration.PyActiveSdkConfigurable
|
||||
import com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable
|
||||
import com.jetbrains.python.facet.PythonFacet
|
||||
import com.jetbrains.python.facet.PythonFacetType
|
||||
|
||||
/**
|
||||
* @author traff
|
||||
*/
|
||||
|
||||
|
||||
class PyPluginSdkModuleConfigurable(project: Project?) : PyActiveSdkModuleConfigurable(project) {
|
||||
override fun createModuleConfigurable(module: Module): UnnamedConfigurable {
|
||||
return object : PyActiveSdkConfigurable(module) {
|
||||
override fun setSdk(item: Sdk?) {
|
||||
val facetManager = FacetManager.getInstance(module)
|
||||
var facet = facetManager.getFacetByType(PythonFacet.ID)
|
||||
if (facet == null) {
|
||||
ApplicationManager.getApplication().runWriteAction {
|
||||
facetManager.addFacet(PythonFacetType.getInstance(), "Python facet", null).configuration.sdk = item
|
||||
}
|
||||
}
|
||||
else {
|
||||
facet.configuration.sdk = item
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun getSdk(): Sdk? {
|
||||
val facetManager = FacetManager.getInstance(module)
|
||||
val facet = facetManager.getFacetByType(PythonFacet.ID)
|
||||
return facet?.configuration?.sdk
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
16
python/pluginMinor/python-community-plugin-minor.iml
Normal file
16
python/pluginMinor/python-community-plugin-minor.iml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="lang-api" />
|
||||
<orderEntry type="module" module-name="lang-impl" />
|
||||
<orderEntry type="module" module-name="python-community" />
|
||||
<orderEntry type="module" module-name="python-community-configure" />
|
||||
<orderEntry type="module" module-name="python-community-plugin-core" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -23,8 +23,7 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
|
||||
<xi:include href="/META-INF/python-community-plugin-core.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
|
||||
<depends optional="true" config-file="python-community-plugin-java.xml">com.intellij.modules.java</depends>
|
||||
<depends optional="true" config-file="python-plugin-minor-ide.xml">com.intellij.modules.clion</depends>
|
||||
<depends optional="true" config-file="python-plugin-minor-ide.xml">com.intellij.modules.webstorm</depends>
|
||||
<depends optional="true" config-file="python-community-plugin-minor.xml">com.intellij.modules.clion</depends>
|
||||
<depends optional="true" config-file="python-plugin-rider.xml">com.intellij.modules.rider</depends>
|
||||
|
||||
<!-- Two different versions of this file exist: one is used when building from sources (when auxiliary
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude" url="https://confluence.jetbrains.com/display/PYH/">
|
||||
<xi:include href="/META-INF/python-community-configure-common.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<projectConfigurable groupId="build" groupWeight="118"
|
||||
id="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
|
||||
displayName="Python Interpreter"
|
||||
instance="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -1,5 +1,5 @@
|
||||
<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude" url="https://confluence.jetbrains.com/display/PYH/">
|
||||
<xi:include href="/META-INF/python-plugin-minor-ide.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
<xi:include href="/META-INF/python-community-plugin-minor.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<completion.contributor language="Python" implementationClass="com.intellij.codeInsight.completion.LegacyCompletionContributor" id="legacy"
|
||||
|
||||
@@ -238,7 +238,7 @@ public class PyActiveSdkConfigurable implements UnnamedConfigurable {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Sdk getSdk() {
|
||||
protected Sdk getSdk() {
|
||||
if (myModule == null) {
|
||||
return ProjectRootManager.getInstance(myProject).getProjectSdk();
|
||||
}
|
||||
@@ -302,7 +302,7 @@ public class PyActiveSdkConfigurable implements UnnamedConfigurable {
|
||||
}
|
||||
}
|
||||
|
||||
private void setSdk(final Sdk item) {
|
||||
protected void setSdk(final Sdk item) {
|
||||
ApplicationManager.getApplication().runWriteAction(() -> ProjectRootManager.getInstance(myProject).setProjectSdk(item));
|
||||
if (myModule != null) {
|
||||
ModuleRootModificationUtil.setModuleSdk(myModule, item);
|
||||
|
||||
Reference in New Issue
Block a user