python-psi-impl extracted

GitOrigin-RevId: e3d808c147ac793701c7b628dbf825a99bb71f2a
This commit is contained in:
Dmitry Trofimov
2019-09-09 04:12:52 +02:00
committed by intellij-monorepo-bot
parent 55fbfb54c2
commit a0bc048dcc
728 changed files with 3029 additions and 2587 deletions

View File

@@ -44,16 +44,6 @@ public final class PythonIcons {
/** 16x16 */ public static final Icon Function = load("/icons/com/jetbrains/python/function.svg");
/** 16x16 */ public static final Icon IpythonNotebook = load("/icons/com/jetbrains/python/IpythonNotebook.svg");
/** 16x16 */ public static final Icon Jython = load("/icons/com/jetbrains/python/jython.svg");
public final static class Nodes {
/** 16x16 */ public static final Icon Cyan_dot = load("/icons/com/jetbrains/python/nodes/cyan-dot.svg");
/** 16x16 */ public static final Icon Lock = load("/icons/com/jetbrains/python/nodes/lock.svg");
/** 16x16 */ public static final Icon Red_inv_triangle = load("/icons/com/jetbrains/python/nodes/red-inv-triangle.svg");
}
/** 16x16 */ public static final Icon PropertyDeleter = load("/icons/com/jetbrains/python/propertyDeleter.svg");
/** 16x16 */ public static final Icon PropertyGetter = load("/icons/com/jetbrains/python/propertyGetter.svg");
/** 16x16 */ public static final Icon PropertySetter = load("/icons/com/jetbrains/python/propertySetter.svg");
/** 16x16 */ public static final Icon Pypy = load("/icons/com/jetbrains/python/pypy.svg");
/** 16x16 */ public static final Icon Python = load("/icons/com/jetbrains/python/python.svg");
/** 16x16 */ public static final Icon PythonClosed = load("/icons/com/jetbrains/python/pythonClosed.svg");

View File

@@ -29,8 +29,7 @@ import com.jetbrains.python.configuration.PyConfigureInterpretersLinkPanel;
import com.jetbrains.python.run.AbstractPyCommonOptionsForm;
import com.jetbrains.python.run.PyCommonOptionsFormData;
import com.jetbrains.python.sdk.PySdkListCellRenderer;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.PythonSdkUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -74,7 +73,7 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm {
myWorkingDirectoryTextField.addBrowseFolderListener("Select Working Directory", "", data.getProject(),
FileChooserDescriptorFactory.createSingleFolderDescriptor());
myPythonSdks = new ArrayList<>(PythonSdkType.getAllSdks());
myPythonSdks = new ArrayList<>(PythonSdkUtil.getAllSdks());
myPythonSdks.add(0, null);
myInterpreterComboBox.setModel(new CollectionComboBoxModel(myPythonSdks, null));
@@ -242,7 +241,7 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm {
@Override
public void setUseModuleSdk(boolean useModuleSdk) {
myInterpreterComboBox.setSelectedItem(useModuleSdk ? null : PythonSdkType.findSdkByPath(myPythonSdks, mySelectedSdkHome));
myInterpreterComboBox.setSelectedItem(useModuleSdk ? null : PythonSdkUtil.findSdkByPath(myPythonSdks, mySelectedSdkHome));
}
@Override
@@ -310,7 +309,7 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm {
}
private void updateRemoteInterpreterMode() {
setRemoteInterpreterMode(PySdkUtil.isRemote(getSdkSelected()));
setRemoteInterpreterMode(PythonSdkUtil.isRemote(getSdkSelected()));
for (Consumer<Boolean> f : myRemoteInterpreterModeListeners) {
f.accept(myInterpreterRemote);
}
@@ -320,13 +319,13 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm {
private Sdk getSdkSelected() {
String sdkHome = getSdkHome();
if (StringUtil.isEmptyOrSpaces(sdkHome)) {
final Sdk projectJdk = PythonSdkType.findPythonSdk(getModule());
final Sdk projectJdk = PythonSdkUtil.findPythonSdk(getModule());
if (projectJdk != null) {
sdkHome = projectJdk.getHomePath();
}
}
return PythonSdkType.findSdkByPath(sdkHome);
return PythonSdkUtil.findSdkByPath(sdkHome);
}
@Override

View File

@@ -35,5 +35,6 @@
<orderEntry type="library" name="javax.annotation-api" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Groovy" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Ant" level="project" />
<orderEntry type="module" module-name="intellij.python.psi.impl" exported="" />
</component>
</module>

View File

@@ -20,7 +20,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.Sdk;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.PythonSdkUtil;
import org.jetbrains.annotations.NotNull;
/**
@@ -30,7 +30,7 @@ public class PyManagePackagesAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Module module = e.getData(LangDataKeys.MODULE);
final Sdk sdk = PythonSdkType.findPythonSdk(module);
final Sdk sdk = PythonSdkUtil.findPythonSdk(module);
if (module != null && sdk != null) {
new PyManagePackagesDialog(module.getProject(), sdk).show();
}
@@ -39,6 +39,6 @@ public class PyManagePackagesAction extends AnAction {
@Override
public void update(@NotNull AnActionEvent e) {
Module module = e.getData(LangDataKeys.MODULE);
e.getPresentation().setEnabled(module != null && PythonSdkType.findPythonSdk(module) != null);
e.getPresentation().setEnabled(module != null && PythonSdkUtil.findPythonSdk(module) != null);
}
}

View File

@@ -11,7 +11,7 @@ import com.intellij.webcore.packaging.PackagesNotificationPanel;
import com.jetbrains.python.packaging.ui.PyInstalledPackagesPanel;
import com.jetbrains.python.sdk.PreferredSdkComparator;
import com.jetbrains.python.sdk.PySdkListCellRenderer;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.PythonSdkUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -31,7 +31,7 @@ public class PyManagePackagesDialog extends DialogWrapper {
super(project, true);
setTitle("Manage Python Packages");
List<Sdk> sdks = PythonSdkType.getAllSdks();
List<Sdk> sdks = PythonSdkUtil.getAllSdks();
Collections.sort(sdks, new PreferredSdkComparator());
final JComboBox sdkComboBox = new JComboBox(new CollectionComboBoxModel(sdks, sdk));
sdkComboBox.setRenderer(new PySdkListCellRenderer(null));

View File

@@ -22,10 +22,7 @@ import com.intellij.ui.RawCommandLineEditor;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.PathMappingSettings;
import com.jetbrains.python.sdk.PreferredSdkComparator;
import com.jetbrains.python.sdk.PySdkListCellRenderer;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.*;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -115,7 +112,7 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
@Override
public void actionPerformed(ActionEvent e) {
for (Consumer<Boolean> f : myRemoteInterpreterModeListeners) {
f.accept(PySdkUtil.isRemote(getSelectedSdk()));
f.accept(PythonSdkUtil.isRemote(getSelectedSdk()));
}
}
});
@@ -124,7 +121,7 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
private void updateControls() {
myModuleComboBox.setEnabled(myUseModuleSdkRadioButton.isSelected());
myInterpreterComboBox.setEnabled(myUseSpecifiedSdkRadioButton.isSelected());
myPathMappingsComponent.setVisible(PySdkUtil.isRemote(getSelectedSdk()));
myPathMappingsComponent.setVisible(PythonSdkUtil.isRemote(getSelectedSdk()));
}
@Override
@@ -182,7 +179,7 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
public void setSdkHome(String sdkHome) {
List<Sdk> sdkList = new ArrayList<>();
sdkList.add(null);
final List<Sdk> allSdks = PythonSdkType.getAllSdks();
final List<Sdk> allSdks = PythonSdkUtil.getAllSdks();
Collections.sort(allSdks, new PreferredSdkComparator());
Sdk selection = null;
for (Sdk sdk : allSdks) {

View File

@@ -16,5 +16,6 @@
<orderEntry type="module" module-name="intellij.java.indexing" />
<orderEntry type="module" module-name="intellij.java.ui" />
<orderEntry type="module" module-name="intellij.python.community.plugin" />
<orderEntry type="module" module-name="intellij.python.psi.impl" />
</component>
</module>

View File

@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.List;
import static com.jetbrains.python.PythonModuleTypeBase.PYTHON_MODULE;
import static com.jetbrains.python.PyNames.PYTHON_MODULE_ID;
/**
* @author traff
@@ -64,7 +64,7 @@ public class PythonFacetType extends FacetType<PythonFacet, PythonFacetType.Pyth
@Override
public boolean isSuitableModuleType(ModuleType moduleType) {
return !(moduleType.getId().equals(PYTHON_MODULE));
return !(moduleType.getId().equals(PYTHON_MODULE_ID));
}
@Override

View File

@@ -12,6 +12,7 @@ import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.NullableFunction;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.sdk.PythonSdkAdditionalData;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.flavors.CondaEnvSdkFlavor;

View File

@@ -43,9 +43,9 @@ import com.jetbrains.python.PyBundle;
import com.jetbrains.python.packaging.PyPackageManagers;
import com.jetbrains.python.packaging.ui.PyInstalledPackagesPanel;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyUtil;
import com.jetbrains.python.sdk.*;
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
import com.jetbrains.python.ui.PyUiUtil;
import one.util.streamex.StreamEx;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -288,7 +288,7 @@ public class PyActiveSdkConfigurable implements UnnamedConfigurable {
final LanguageLevel languageLevel2 = flavor2.getLanguageLevel(prevSdk);
if ((languageLevel1.isPy3K() && languageLevel2.isPython2()) ||
(languageLevel1.isPython2()) && languageLevel2.isPy3K()) {
PyUtil.rehighlightOpenEditors(myProject);
PyUiUtil.rehighlightOpenEditors(myProject);
}
}
}
@@ -320,7 +320,7 @@ public class PyActiveSdkConfigurable implements UnnamedConfigurable {
List<Object> items = new ArrayList<>();
items.add(null);
final Map<PyRenderedSdkType, List<Sdk>> moduleSdksByTypes = groupModuleSdksByTypes(allPythonSdks, myModule, PythonSdkType::isInvalid);
final Map<PyRenderedSdkType, List<Sdk>> moduleSdksByTypes = groupModuleSdksByTypes(allPythonSdks, myModule, PythonSdkUtil::isInvalid);
if (selection != null && !StreamEx.of(moduleSdksByTypes.values()).flatCollection(Function.identity()).toList().contains(selection)) {
items.add(0, selection);
}

View File

@@ -22,9 +22,9 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
import com.intellij.openapi.util.Comparing;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkAdditionalData;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.PythonSdkUtil;
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
import org.jetbrains.annotations.Nullable;
@@ -94,10 +94,10 @@ public class PyConfigurableInterpreterList {
return -Comparing.compare(o1.getName(), o2.getName());
}
final boolean isVEnv1 = PythonSdkType.isVirtualEnv(o1);
final boolean isVEnv2 = PythonSdkType.isVirtualEnv(o2);
final boolean isRemote1 = PySdkUtil.isRemote(o1);
final boolean isRemote2 = PySdkUtil.isRemote(o2);
final boolean isVEnv1 = PythonSdkUtil.isVirtualEnv(o1);
final boolean isVEnv2 = PythonSdkUtil.isVirtualEnv(o2);
final boolean isRemote1 = PythonSdkUtil.isRemote(o1);
final boolean isRemote2 = PythonSdkUtil.isRemote(o2);
if (isVEnv1) {
if (isVEnv2) {

View File

@@ -54,7 +54,7 @@ private class PySdkStatusBar(project: Project) : EditorBasedStatusBarPopup(proje
module = ModuleUtil.findModuleForFile(file, project) ?: return WidgetState.HIDDEN
val sdk = PythonSdkType.findPythonSdk(module)
val sdk = PythonSdkUtil.findPythonSdk(module)
return if (sdk == null) {
WidgetState("", noInterpreterMarker, true)
}
@@ -92,7 +92,7 @@ private class PySdkPopupFactory(val project: Project, val module: Module) {
val group = DefaultActionGroup()
val moduleSdksByTypes = groupModuleSdksByTypes(PyConfigurableInterpreterList.getInstance(project).getAllPythonSdks(project), module) {
PythonSdkType.isInvalid(it) ||
PythonSdkUtil.isInvalid(it) ||
PythonSdkType.hasInvalidRemoteCredentials(it) ||
PythonSdkType.isIncompleteRemote(it) ||
!LanguageLevel.SUPPORTED_LEVELS.contains(PythonSdkType.getLanguageLevelForSdk(it))
@@ -109,7 +109,7 @@ private class PySdkPopupFactory(val project: Project, val module: Module) {
group.add(InterpreterSettingsAction())
group.add(AddInterpreterAction())
val currentSdkName = PythonSdkType.findPythonSdk(module)?.name
val currentSdkName = PythonSdkUtil.findPythonSdk(module)?.name
return JBPopupFactory.getInstance().createActionGroupPopup(
"Project Interpreter",
group,
@@ -172,4 +172,4 @@ private fun shortenNameAndPath(sdk: Sdk) = "${name(sdk)} [${path(sdk)}]".trimMid
private fun name(sdk: Sdk): String {
val (_, primary, secondary) = com.jetbrains.python.sdk.name(sdk)
return if (secondary == null) primary else "$primary [$secondary]"
}
}

View File

@@ -247,7 +247,7 @@ public class PythonSdkDetailsDialog extends DialogWrapper {
private void addCreatedSdk(@Nullable final Sdk sdk, boolean newVirtualEnv) {
if (sdk != null) {
boolean isVirtualEnv = PythonSdkType.isVirtualEnv(sdk);
boolean isVirtualEnv = PythonSdkUtil.isVirtualEnv(sdk);
if (isVirtualEnv && !newVirtualEnv) {
AddVEnvOptionsDialog dialog = new AddVEnvOptionsDialog(myMainPanel);
dialog.show();
@@ -442,7 +442,7 @@ public class PythonSdkDetailsDialog extends DialogWrapper {
}
private PythonPathEditor createPathEditor(final Sdk sdk) {
if (PySdkUtil.isRemote(sdk)) {
if (PythonSdkUtil.isRemote(sdk)) {
return new PyRemotePathEditor(sdk);
}
else {
@@ -502,7 +502,7 @@ public class PythonSdkDetailsDialog extends DialogWrapper {
String[] files = PythonRemoteInterpreterManager
.getInstance().chooseRemoteFiles(project, (PyRemoteSdkAdditionalDataBase)mySdk.getSdkAdditionalData(), false);
final String sourcesLocalPath = PySdkUtil.getRemoteSourcesLocalPath(mySdk.getHomePath());
final String sourcesLocalPath = PythonSdkUtil.getRemoteSourcesLocalPath(mySdk.getHomePath());
VirtualFile[] vFiles = new VirtualFile[files.length];

View File

@@ -25,10 +25,7 @@ import com.jetbrains.python.newProject.PyFrameworkProjectGenerator;
import com.jetbrains.python.newProject.PythonProjectGenerator;
import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyPackageUtil;
import com.jetbrains.python.sdk.PreferredSdkComparator;
import com.jetbrains.python.sdk.PyLazySdk;
import com.jetbrains.python.sdk.PySdkSettings;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.*;
import com.jetbrains.python.sdk.add.PyAddSdkGroupPanel;
import com.jetbrains.python.sdk.add.PyAddSdkPanel;
import one.util.streamex.StreamEx;
@@ -190,7 +187,7 @@ public class ProjectSpecificSettingsStep<T> extends ProjectSettingsStepBase<T> i
// Framework package check may be heavy in case of remote sdk and should not be called on AWT, pretend everything is OK for
// remote and check for packages later
if (!PythonSdkType.isRemote(sdk)) {
if (!PythonSdkUtil.isRemote(sdk)) {
final Pair<Boolean, List<String>> validationInfo = validateFramework(frameworkGenerator, sdk);
myInstallFramework = validationInfo.first;
warnings.addAll(validationInfo.second);
@@ -344,7 +341,7 @@ public class ProjectSpecificSettingsStep<T> extends ProjectSettingsStepBase<T> i
private static List<Sdk> getValidPythonSdks() {
return StreamEx
.of(PyConfigurableInterpreterList.getInstance(null).getAllPythonSdks())
.filter(sdk -> sdk != null && sdk.getSdkType() instanceof PythonSdkType && !PythonSdkType.isInvalid(sdk))
.filter(sdk -> sdk != null && sdk.getSdkType() instanceof PythonSdkType && !PythonSdkUtil.isInvalid(sdk))
.sorted(new PreferredSdkComparator())
.toList();
}

View File

@@ -19,8 +19,8 @@ import com.intellij.util.ui.UIUtil
import com.jetbrains.python.Result
import com.jetbrains.python.remote.PyProjectSynchronizer
import com.jetbrains.python.remote.PythonRemoteInterpreterManager
import com.jetbrains.python.sdk.PySdkUtil
import com.jetbrains.python.sdk.PythonSdkType
import com.jetbrains.python.sdk.PythonSdkUtil
import com.jetbrains.python.sdk.add.PyAddSdkPanel
import com.jetbrains.python.sdk.associatedModulePath
import java.awt.BorderLayout
@@ -60,7 +60,7 @@ class PyAddExistingSdkPanel(project: Project?,
private val remotePathField = PyRemotePathField().apply {
addActionListener {
val currentSdk = sdk ?: return@addActionListener
if (!PySdkUtil.isRemote(currentSdk)) return@addActionListener
if (!PythonSdkUtil.isRemote(currentSdk)) return@addActionListener
textField.text = currentSdk.chooseRemotePath(parent) ?: return@addActionListener
}
}
@@ -100,7 +100,7 @@ class PyAddExistingSdkPanel(project: Project?,
val selectedSdk = sdk
val message = when {
selectedSdk == null -> "No Python interpreter selected"
PythonSdkType.isInvalid(selectedSdk) -> "Choose valid Python interpreter"
PythonSdkUtil.isInvalid(selectedSdk) -> "Choose valid Python interpreter"
else -> return null
}
return ValidationInfo(message, sdkChooserCombo)
@@ -185,4 +185,4 @@ class PyAddExistingSdkPanel(project: Project?,
return if (wrapper.showAndGet()) supplier.get() else null
}
}
}
}

View File

Before

Width:  |  Height:  |  Size: 397 B

After

Width:  |  Height:  |  Size: 397 B

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -69,6 +69,11 @@ public class PyNames {
public static final String TYPE_ENUM = "enum.Enum";
public static final String PYTHON_SDK_ID_NAME = "Python SDK";
public static final String VERBOSE_REG_EXP_LANGUAGE_ID = "PythonVerboseRegExp";
@NonNls public static final String PYTHON_MODULE_ID = "PYTHON_MODULE";
public static final String TESTCASE_SETUP_NAME = "setUp";
private PyNames() {
}

View File

@@ -14,5 +14,15 @@ public final class PythonPsiApiIcons {
return IconManager.getInstance().getIcon(path, PythonPsiApiIcons.class);
}
public final static class Nodes {
/** 16x16 */ public static final Icon Cyan_dot = load("/icons/com/jetbrains/python/nodes/cyan-dot.svg");
/** 16x16 */ public static final Icon Lock = load("/icons/com/jetbrains/python/nodes/lock.svg");
/** 16x16 */ public static final Icon Red_inv_triangle = load("/icons/com/jetbrains/python/nodes/red-inv-triangle.svg");
}
/** 16x16 */ public static final Icon PropertyDeleter = load("/icons/com/jetbrains/python/propertyDeleter.svg");
/** 16x16 */ public static final Icon PropertyGetter = load("/icons/com/jetbrains/python/propertyGetter.svg");
/** 16x16 */ public static final Icon PropertySetter = load("/icons/com/jetbrains/python/propertySetter.svg");
/** 16x16 */ public static final Icon PythonFile = load("/icons/com/jetbrains/python/pythonFile.svg");
}

View File

@@ -485,27 +485,27 @@ public class _PyTypeLexer implements FlexLexer {
else {
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 1:
{ return NL;
{ return PyTypeTokenTypes.NL;
}
case 7: break;
case 2:
{ return SPACE;
{ return PyTypeTokenTypes.SPACE;
}
case 8: break;
case 3:
{ return IDENTIFIER;
{ return PyTypeTokenTypes.IDENTIFIER;
}
case 9: break;
case 4:
{ return MARKUP;
{ return PyTypeTokenTypes.MARKUP;
}
case 10: break;
case 5:
{ return OP;
{ return PyTypeTokenTypes.OP;
}
case 11: break;
case 6:
{ return PARAMETER;
{ return PyTypeTokenTypes.PARAMETER;
}
case 12: break;
default:

View File

@@ -0,0 +1,24 @@
<?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$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="intellij.platform.core" />
<orderEntry type="module" module-name="intellij.python.psi" />
<orderEntry type="library" name="Guava" level="project" />
<orderEntry type="module" module-name="intellij.platform.lang" />
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
<orderEntry type="module" module-name="intellij.platform.lang.impl" />
<orderEntry type="module" module-name="intellij.python.community" />
<orderEntry type="library" name="jsoup" level="project" />
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
</component>
</module>

View File

@@ -0,0 +1,138 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<lang.elementManipulator forClass="com.jetbrains.python.psi.PyReferenceExpression"
implementationClass="com.jetbrains.python.psi.impl.PyReferenceExpressionManipulator"/>
<projectService serviceInterface="com.jetbrains.python.psi.PyElementGenerator"
serviceImplementation="com.jetbrains.python.psi.impl.PyElementGeneratorImpl"/>
<projectService serviceInterface="com.jetbrains.python.psi.PyPsiFacade"
serviceImplementation="com.jetbrains.python.psi.impl.PyPsiFacadeImpl"/>
<stubIndex implementation="com.jetbrains.python.psi.stubs.PyClassNameIndex"/>
<stubIndex implementation="com.jetbrains.python.psi.stubs.PyClassNameIndexInsensitive"/>
<stubIndex implementation="com.jetbrains.python.psi.stubs.PyFunctionNameIndex"/>
<stubIndex implementation="com.jetbrains.python.psi.stubs.PySuperClassIndex"/>
<stubIndex implementation="com.jetbrains.python.psi.stubs.PyVariableNameIndex"/>
<stubIndex implementation="com.jetbrains.python.psi.stubs.PyDecoratorStubIndex"/>
<stubIndex implementation="com.jetbrains.python.psi.stubs.PyClassAttributesIndex"/>
<fileBasedIndex implementation="com.jetbrains.python.psi.stubs.PyModuleNameIndex"/>
<fileBasedIndex implementation="com.jetbrains.python.psi.stubs.PySetuptoolsNamespaceIndex"/>
<definitionsSearch implementation="com.jetbrains.python.psi.search.PyDefinitionsSearch"/>
<stubElementTypeHolder class="com.jetbrains.python.PyStubElementTypes" externalIdPrefix="py."/>
<gotoDeclarationHandler implementation="com.jetbrains.python.psi.impl.PyGotoDeclarationHandler"/>
<filePropertyPusher implementation="com.jetbrains.python.psi.impl.PythonLanguageLevelPusher"/>
<applicationService serviceImplementation="com.jetbrains.python.codeInsight.PyCodeInsightSettings"/>
<weigher key="completion" implementationClass="com.jetbrains.python.codeInsight.completion.PythonCompletionWeigher" order="first"/>
<referencesSearch implementation="com.jetbrains.python.psi.search.PyInitReferenceSearchExecutor"/>
<referencesSearch implementation="com.jetbrains.python.psi.search.PyClassReferenceSearchExecutor"/>
<referencesSearch implementation="com.jetbrains.python.psi.search.PyKeywordArgumentSearchExecutor"/>
<lang.elementManipulator forClass="com.jetbrains.python.psi.PyStringLiteralExpression"
implementationClass="com.jetbrains.python.psi.impl.PyStringLiteralExpressionManipulator"/>
<lang.elementManipulator forClass="com.jetbrains.python.psi.PyKeywordArgument"
implementationClass="com.jetbrains.python.psi.impl.PyKeywordArgumentManipulator"/>
<moduleService serviceInterface="com.jetbrains.python.psi.resolve.PythonPathCache"
serviceImplementation="com.jetbrains.python.psi.resolve.PythonModulePathCache"/>
<applicationService serviceImplementation="com.jetbrains.python.documentation.PythonDocumentationMap"/>
<moduleService serviceImplementation="com.jetbrains.python.documentation.PyDocumentationSettings"/>
<psi.referenceContributor implementation="com.jetbrains.python.documentation.docstrings.DocStringReferenceContributor"
language="Python"/>
<projectService serviceImplementation="com.jetbrains.python.codeInsight.typing.PyStubPackagesInstallingStatus"/>
<!-- PyDocstring -->
<languageInjector implementation="com.jetbrains.python.documentation.doctest.PyDocstringLanguageInjector"/>
<lang.parserDefinition language="PyDocstring" implementationClass="com.jetbrains.python.documentation.doctest.PyDocstringParserDefinition"/>
<highlightErrorFilter implementation="com.jetbrains.python.documentation.doctest.PyDocstringErrorFilter"/>
<lang.parserDefinition language="PythonStub" implementationClass="com.jetbrains.python.pyi.PyiParserDefinition"/>
<fileType name="PythonStub"
language="PythonStub"
extensions="pyi"
implementationClass="com.jetbrains.python.pyi.PyiFileType"
fieldName="INSTANCE"/>
<controlFlowProvider implementation="com.jetbrains.python.codeInsight.controlflow.PyControlFlowProvider"/>
<!-- Code-insight IDE bridge -->
<applicationService
serviceImplementation="com.jetbrains.python.PythonRuntimeService"/>
<applicationService
serviceImplementation="com.jetbrains.python.PythonDialogService"/>
</extensions>
<extensionPoints>
<extensionPoint qualifiedName="Pythonid.customTargetExpressionStubType"
interface="com.jetbrains.python.psi.impl.stubs.CustomTargetExpressionStubType"/>
<extensionPoint qualifiedName="Pythonid.customClassStubType"
interface="com.jetbrains.python.psi.impl.stubs.PyCustomClassStubType"/>
<extensionPoint qualifiedName="Pythonid.visitorFilter" beanClass="com.intellij.lang.LanguageExtensionPoint">
<with attribute="implementationClass" implements="com.jetbrains.python.psi.PythonVisitorFilter"/>
</extensionPoint>
</extensionPoints>
<extensions defaultExtensionNs="Pythonid">
<pySuperMethodsSearch implementation="com.jetbrains.python.psi.search.PySuperMethodsSearchExecutor"/>
<pyClassInheritorsSearch implementation="com.jetbrains.python.psi.search.PyClassInheritorsSearchExecutor"/>
<pyOverridingMethodsSearch implementation="com.jetbrains.python.psi.search.PyOverridingMethodsSearchExecutor"/>
<customTargetExpressionStubType implementation="com.jetbrains.python.psi.impl.stubs.PropertyStubType"/>
<customTargetExpressionStubType implementation="com.jetbrains.python.psi.impl.stubs.PyNamedTupleStubType"/>
<customTargetExpressionStubType implementation="com.jetbrains.python.psi.impl.stubs.PyTypingAliasStubType"/>
<customTargetExpressionStubType implementation="com.jetbrains.python.psi.impl.stubs.PyDataclassFieldStubType"/>
<customTargetExpressionStubType implementation="com.jetbrains.python.psi.impl.stubs.PyTypingNewTypeStubType"/>
<customClassStubType implementation="com.jetbrains.python.psi.impl.stubs.PyDataclassStubType"/>
<dialectsTokenSetContributor implementation="com.jetbrains.python.PythonTokenSetContributor"/>
<typeProvider implementation="com.jetbrains.python.psi.types.PyCollectionTypeByModificationsProvider"/>
<!-- typing -->
<typeProvider implementation="com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider"/>
<typeProvider implementation="com.jetbrains.python.pyi.PyiTypeProvider"/>
<pyModuleMembersProvider implementation="com.jetbrains.python.pyi.PyiModuleMembersProvider"/>
<pyClassMembersProvider implementation="com.jetbrains.python.pyi.PyiClassMembersProvider"/>
<pyReferenceResolveProvider implementation="com.jetbrains.python.psi.resolve.PyForwardReferenceResolveProvider"/>
<visitorFilter language="PythonStub" implementationClass="com.jetbrains.python.pyi.PyiVisitorFilter"/>
<inspectionExtension implementation="com.jetbrains.python.pyi.PyiInspectionExtension"/>
<inspectionExtension implementation="com.jetbrains.python.codeInsight.typing.PyTypingInspectionExtension"/>
<customPackageIdentifier implementation="com.jetbrains.python.pyi.PyiCustomPackageIdentifier"/>
<!-- User skeletons -->
<pyModuleMembersProvider implementation="com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsModuleMembersProvider"/>
<pyClassMembersProvider implementation="com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsClassMembersProvider"/>
<typeProvider implementation="com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsTypeProvider"/>
<pyReferenceResolveProvider implementation="com.jetbrains.python.psi.resolve.PythonBuiltinReferenceResolveProvider"/>
<pyReferenceResolveProvider implementation="com.jetbrains.python.psi.resolve.PythonOverridingBuiltinReferenceResolveProvider"/>
<!-- PyDocstring -->
<typeProvider implementation="com.jetbrains.python.documentation.docstrings.PyDocStringTypeProvider"/>
<dialectsTokenSetContributor implementation="com.jetbrains.python.documentation.doctest.PyDocstringTokenSetContributor"/>
<!-- Type from ancestors -->
<typeProvider implementation="com.jetbrains.python.codeInsight.typing.PyAncestorTypeProvider"/>
</extensions>
</idea-plugin>

View File

@@ -230,7 +230,7 @@ public final class PyCustomType implements PyClassLikeType {
}
return PyBundle.message("custom.type.mimic.name", StringUtil.join(classNames, ","));
return PyPsiBundle.message("custom.type.mimic.name", StringUtil.join(classNames, ","));
}
@Override

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.inspections;
package com.jetbrains.python;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2000-2014 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;
import com.intellij.CommonBundle;
import com.intellij.reference.SoftReference;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.PropertyKey;
import java.lang.ref.Reference;
import java.util.ResourceBundle;
public class PyPsiBundle {
public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) {
return CommonBundle.message(getBundle(), key, params);
}
@Nullable
public static String messageOfNull(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key,
@NotNull Object... params) {
return CommonBundle.messageOfNull(getBundle(), key, params);
}
private static Reference<ResourceBundle> ourBundle;
@NonNls
private static final String BUNDLE = "com.jetbrains.python.PyPsiBundle";
private PyPsiBundle() {
}
// Cached loading
private static ResourceBundle getBundle() {
ResourceBundle bundle = SoftReference.dereference(ourBundle);
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
ourBundle = new SoftReference<>(bundle);
}
return bundle;
}
}

View File

@@ -0,0 +1,104 @@
# Message we display for inspection if user uses custom class type members that do not exist
custom.type.mimic.name=Dynamic class based on {0}
### Refactoring
refactoring.extract.method.error.interrupted.execution.flow=Cannot perform refactoring when execution flow is interrupted
refactoring.extract.method.error.star.import=Cannot perform refactoring with star import statement inside code block
refactoring.extract.method.error.yield=Cannot perform refactoring with 'yield' statement inside code block
### Annotators ###
ANN.deleting.none=Deleting None
ANN.assign.to.none=Assignment to None
ANN.cant.assign.to.call=Can't assign to function call
ANN.cant.delete.call=Can't delete function call
ANN.cant.aug.assign.to.generator=Augmented assign to generator expression not possible
ANN.cant.aug.assign.to.tuple.or.generator=Augmented assign to tuple literal or generator expression not possible
ANN.cant.assign.to.generator=Assign to generator expression not possible
ANN.cant.assign.to.operator=Can't assign to operator
ANN.cant.assign.to.parens=Can't assign to ()
ANN.cant.aug.assign.to.list.or.comprh=Augmented assign to list literal or comprehension not possible
ANN.cant.assign.to.comprh=Can't assign to list comprehension
ANN.cant.assign.to.dict.comprh=Can't assign to dict comprehension
ANN.cant.assign.to.set.comprh=Can't assign to set comprehension
ANN.cant.aug.assign.to.comprh=Augmented assign to list comprehension not possible
ANN.cant.aug.assign.to.dict.comprh=Augmented assign to dict comprehension not possible
ANN.cant.aug.assign.to.set.comprh=Augmented assign to set comprehension not possible
ANN.cant.assign.to.literal=Can't assign to literal
ANN.cant.delete.literal=Can't delete literal
ANN.cant.assign.to.lambda=Can't assign to lambda
ANN.break.outside.loop='break' outside loop
ANN.continue.outside.loop='continue' outside loop
ANN.default.except.must.be.last=default 'except:' must be last
ANN.$0.both.global.and.param=Name ''{0}'' used both as a parameter and as a global
ANN.$0.assigned.before.global.decl=Name ''{0}'' is assigned before global declaration
ANN.duplicate.param.name=duplicate parameter name
ANN.starred.param.after.kwparam=* parameter after ** parameter
ANN.regular.param.after.vararg=regular parameter after * parameter
ANN.regular.param.after.keyword=regular parameter after ** parameter
ANN.non.default.param.after.default=non-default parameter follows default parameter
ANN.named.parameters.after.star=named parameters must follow bare *
ANN.named.parameters.before.slash=named parameters must precede bare /
ANN.tuple.py3=tuple parameter unpacking is not supported in Python 3
ANN.multiple.args=multiple * parameters are not allowed
ANN.multiple.kwargs=multiple ** parameters are not allowed
ANN.multiple.slash=multiple / parameters are not allowed
ANN.slash.param.after.vararg=/ parameter must precede * parameter
ANN.slash.param.after.keyword=/ parameter must precede ** parameter
ANN.star.import.at.top.only='import *' only allowed at module level
ANN.missing.closing.quote=Missing closing quote [{0}]
ANN.missing.closing.triple.quotes=Missing closing triple quotes
ANN.method.$0.removed.use.$1=Method ''{0}'' has been removed, use ''{1}'' instead
ANN.method.$0.removed=Method ''{0}'' removed
### parsing
PARSE.expected.expression=expression expected
PARSE.expected.rbracket=']' expected
PARSE.expected.expr.or.comma.or.bracket=expected expression, ',' or ']'
PARSE.expected.in='in' expected
PARSE.expected.for.or.bracket=']' or 'for' expected
PARSE.expected.comma=',' expected
PARSE.expected.colon=':' expected
PARSE.expected.rpar=')' expected
PARSE.expected.lpar='(' expected
PARSE.expected.rbrace='}' expected
PARSE.expected.tick='`' (backtick) expected
PARSE.expected.name=name expected
PARSE.expected.colon.or.rbracket=':' or ']' expected
PARSE.expected.comma.or.rpar=',' or ')' expected
PARSE.expected.else='else' expected
PARSE.expected.identifier=Identifier expected
PARSE.expected.comma.lpar.rpar=',' or '(' or ')' expected
PARSE.expected.statement.break=Statement break expected
PARSE.expected.@.or.def='@' or 'def' expected
PARSE.expected.formal.param.name=formal parameter name expected
### Surround with templates ###
surround.with.whileelse.template=while / else
surround.with.return.template=return
surround.with.try.except.template=try / except
### qiuck doc generator
QDOC.module.path.unknown=(Module path is unknown)
QDOC.epydoc.python2.sdk.not.found=You need configured Python 2 SDK to render <a href='http://epydoc.sourceforge.net/'>Epydoc</a> docstrings
QDOC.local.sdk.not.found=You need a configured local Python SDK to render docstrings.
QDOC.assigned.to=Assigned to:
QDOC.documentation.is.copied.from=Documentation is copied from:
QDOC.accessor.kind=Accessor kind:
QDOC.raises=Raises:
QDOC.keyword.args=Keyword args:
### Formatter
formatter.panel.dict.alignment.do.not.align=Do not align
formatter.panel.dict.alignment.align.on.colon=Align on colon
formatter.panel.dict.alignment.align.on.value=Align on value
QFIX.added.constructor.$0.for.field.$1=Added a __init__ to class <code>{0}</code><br/>to accommodate new field <code>{1}</code>

View File

@@ -0,0 +1,54 @@
package com.jetbrains.python;
import com.google.common.collect.ImmutableMap;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ResourceUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.packaging.PyPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
public class PyPsiPackageUtil {
private static final Logger LOG = Logger.getInstance(PyPsiPackageUtil.class);
/**
* Contains mapping "importable top-level package" -> "package names on PyPI".
*/
public static final ImmutableMap<String, List<String>> PACKAGES_TOPLEVEL = loadPackageAliases();
@Nullable
public static PyPackage findPackage(@NotNull List<? extends PyPackage> packages, @NotNull String name) {
for (PyPackage pkg : packages) {
if (name.equalsIgnoreCase(pkg.getName())) {
return pkg;
}
}
return null;
}
@NotNull
private static ImmutableMap<String, List<String>> loadPackageAliases() {
final ImmutableMap.Builder<String, List<String>> builder = ImmutableMap.builder();
try {
Arrays.stream(StringUtil.splitByLines(ResourceUtil.loadText(PyPsiPackageUtil.class.getResource("/tools/packages"))))
.forEach(
line -> {
final List<String> split = StringUtil.split(line, " ");
builder.put(split.get(0), new SmartList<>(ContainerUtil.subList(split, 1)));
}
);
}
catch (IOException e) {
LOG.error("Cannot find \"packages\". " + e.getMessage());
}
return builder.build();
}
}

View File

@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.inspections;
package com.jetbrains.python;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.util.ObjectUtils;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.impl.PyStringLiteralDecoder;
import org.jetbrains.annotations.NotNull;

View File

@@ -0,0 +1,35 @@
package com.jetbrains.python;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.util.QualifiedName;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@ApiStatus.Experimental
public class PythonDialogService {
public static PythonDialogService getInstance() {
return ServiceManager.getService(PythonDialogService.class);
}
public int showChooseDialog(String message,
@Nls(capitalization = Nls.Capitalization.Title) String title,
String[] values,
String initialValue,
@Nullable Icon icon) {
throw new FailException();
}
public void showNoExternalDocumentationDialog(Project project, QualifiedName name) {
throw new FailException();
}
private final static class FailException extends UnsupportedOperationException {
private FailException() {
super("no UI in PSI");
}
}
}

View File

@@ -0,0 +1,55 @@
package com.jetbrains.python;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPolyVariantReference;
import com.jetbrains.python.documentation.docstrings.DocStringFormat;
import com.jetbrains.python.parsing.console.PythonConsoleData;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyReferenceExpression;
import com.jetbrains.python.psi.resolve.PyResolveContext;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ApiStatus.Experimental
public class PythonRuntimeService {
public boolean isInPydevConsole(@NotNull PsiElement file) {
return false;
}
@Nullable
public Sdk getConsoleSdk(@NotNull PsiElement foothold) {
return null;
}
public String createPydevDoc(PsiElement element, PsiElement originalElement) {
return null;
}
@NotNull
public LanguageLevel getLanguageLevelForSdk(@Nullable Sdk sdk) {
return LanguageLevel.getDefault();
}
public PsiPolyVariantReference getPydevConsoleReference(@NotNull PyReferenceExpression element,
@NotNull PyResolveContext context) {
return null;
}
public PythonConsoleData getPythonConsoleData(@Nullable ASTNode node) {
return null;
}
public String formatDocstring(Module module, DocStringFormat format, String docstring) {
return null;
}
public static PythonRuntimeService getInstance() {
return ServiceManager.getService(PythonRuntimeService.class);
}
}

View File

@@ -1,13 +1,13 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package com.jetbrains.python.codeInsight.stdlib
package com.jetbrains.python.codeInsight
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.util.QualifiedName
import com.jetbrains.python.PyNames
import com.jetbrains.python.codeInsight.stdlib.PyDataclassParameters.Type
import com.jetbrains.python.codeInsight.PyDataclassParameters.Type
import com.jetbrains.python.psi.*
import com.jetbrains.python.psi.PyKnownDecoratorUtil.KnownDecorator
import com.jetbrains.python.psi.impl.PyCallExpressionHelper
@@ -65,7 +65,8 @@ fun parseDataclassParameters(cls: PyClass, context: TypeEvalContext): PyDataclas
* @see parseStdDataclassParameters
* @see parseDataclassParameters
*/
fun parseDataclassParametersForStub(cls: PyClass): PyDataclassParameters? = parseDataclassParametersFromAST(cls, null)
fun parseDataclassParametersForStub(cls: PyClass): PyDataclassParameters? = parseDataclassParametersFromAST(
cls, null)
fun resolvesToOmittedDefault(expression: PyExpression, type: PyDataclassParameters.Type): Boolean {
if (expression is PyReferenceExpression) {
@@ -118,7 +119,8 @@ private fun parseDataclassParametersFromAST(cls: PyClass, context: TypeEvalConte
)
if (mapping.unmappedArguments.isEmpty() && mapping.unmappedParameters.isEmpty()) {
val builder = PyDataclassParametersBuilder(decoratorAndTypeAndMarkedCallee.second, decoratorAndTypeAndMarkedCallee.first, cls)
val builder = PyDataclassParametersBuilder(decoratorAndTypeAndMarkedCallee.second,
decoratorAndTypeAndMarkedCallee.first, cls)
mapping
.mappedParameters
@@ -231,7 +233,8 @@ private class PyDataclassParametersBuilder(private val type: PyDataclassParamete
return
}
"frozen" -> {
frozen = PyEvaluator.evaluateAsBoolean(value, DEFAULT_FROZEN)
frozen = PyEvaluator.evaluateAsBoolean(value,
DEFAULT_FROZEN)
frozenArgument = argument
return
}
@@ -245,12 +248,14 @@ private class PyDataclassParametersBuilder(private val type: PyDataclassParamete
return
}
"order" -> {
order = PyEvaluator.evaluateAsBoolean(value, DEFAULT_ORDER)
order = PyEvaluator.evaluateAsBoolean(value,
DEFAULT_ORDER)
orderArgument = argument
return
}
"unsafe_hash" -> {
unsafeHash = PyEvaluator.evaluateAsBoolean(value, DEFAULT_UNSAFE_HASH)
unsafeHash = PyEvaluator.evaluateAsBoolean(value,
DEFAULT_UNSAFE_HASH)
unsafeHashArgument = argument
return
}
@@ -267,7 +272,8 @@ private class PyDataclassParametersBuilder(private val type: PyDataclassParamete
return
}
"hash" -> {
unsafeHash = PyEvaluator.evaluateAsBoolean(value, DEFAULT_UNSAFE_HASH)
unsafeHash = PyEvaluator.evaluateAsBoolean(value,
DEFAULT_UNSAFE_HASH)
unsafeHashArgument = argument
return
}
@@ -280,6 +286,7 @@ private class PyDataclassParametersBuilder(private val type: PyDataclassParamete
}
fun build() = PyDataclassParameters(init, repr, eq, order, unsafeHash, frozen,
initArgument, reprArgument, eqArgument, orderArgument, unsafeHashArgument, frozenArgument,
type, others)
}
initArgument, reprArgument, eqArgument, orderArgument,
unsafeHashArgument, frozenArgument,
type, others)
}

View File

@@ -19,14 +19,14 @@ import com.intellij.psi.PsiFileSystemItem
import com.intellij.psi.util.QualifiedName
import com.jetbrains.python.PyNames
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil
import com.jetbrains.python.codeInsight.imports.PythonImportUtils
import com.jetbrains.python.psi.PyClass
import com.jetbrains.python.psi.PyFile
import com.jetbrains.python.psi.PyFunction
import com.jetbrains.python.psi.resolve.QualifiedNameFinder
import com.jetbrains.python.psi.types.TypeEvalContext
import com.jetbrains.python.sdk.PythonSdkType
import icons.PythonIcons
import com.jetbrains.python.sdk.PythonSdkUtil
import icons.PythonPsiApiIcons
import one.util.streamex.StreamEx
/**
* Various utils for custom completions
@@ -67,7 +67,7 @@ fun addMethodToResult(result: CompletionResultSet,
builderPostprocessor: ((LookupElementBuilder) -> LookupElementBuilder)? = null) {
if (pyClass?.findMethodByName(methodName, false, typeEvalContext) != null) return
val item = LookupElementBuilder.create(methodName + methodParentheses).withIcon(PythonIcons.Python.Nodes.Cyan_dot)
val item = LookupElementBuilder.create(methodName + methodParentheses).withIcon(PythonPsiApiIcons.Nodes.Cyan_dot)
result.addElement(TailTypeDecorator.withTail(builderPostprocessor?.invoke(item) ?: item, TailType.CASE_COLON))
}
@@ -84,7 +84,7 @@ fun addFunctionToResult(result: CompletionResultSet,
builderPostprocessor: ((LookupElementBuilder) -> LookupElementBuilder)? = null) {
if (pyFile?.findTopLevelFunction(functionName) != null) return
val item = LookupElementBuilder.create(functionName + functionParentheses).withIcon(PythonIcons.Python.Nodes.Cyan_dot)
val item = LookupElementBuilder.create(functionName + functionParentheses).withIcon(PythonPsiApiIcons.Nodes.Cyan_dot)
result.addElement(TailTypeDecorator.withTail(builderPostprocessor?.invoke(item) ?: item, TailType.CASE_COLON))
}
@@ -138,15 +138,15 @@ fun computeCompletionWeight(element: PsiElement, elementName: String?, path: Qua
val containingFile = element.containingFile
if (element is PsiDirectory) {
vFile = element.virtualFile
sdk = PythonSdkType.findPythonSdk(element)
sdk = PythonSdkUtil.findPythonSdk(element)
}
else if (containingFile != null) {
vFile = containingFile.virtualFile
sdk = PythonSdkType.findPythonSdk(containingFile)
sdk = PythonSdkUtil.findPythonSdk(containingFile)
}
val importPath = path ?: QualifiedNameFinder.findShortestImportableQName(element.containingFile) ?: return FALLBACK_WEIGHT
if (completionLocation != null && !PythonImportUtils.hasImportsFrom(completionLocation, importPath)) {
if (completionLocation != null && !hasImportsFrom(completionLocation, importPath)) {
weight -= LOCATION_NOT_YET_IMPORTED
}
@@ -155,7 +155,7 @@ fun computeCompletionWeight(element: PsiElement, elementName: String?, path: Qua
if (vFile != null) {
weight -= when {
PythonSdkType.isStdLib(vFile, sdk) -> LOCATION
PythonSdkUtil.isStdLib(vFile, sdk) -> LOCATION
ModuleUtilCore.findModuleForFile(vFile, element.project) == null -> LOCATION * 2
else -> 0
}
@@ -168,4 +168,13 @@ fun computeCompletionWeight(element: PsiElement, elementName: String?, path: Qua
}
return weight
}
}
fun hasImportsFrom(file: PsiFile, qName: QualifiedName): Boolean {
return if (file is PyFile) {
StreamEx.of(file.fromImports).map<QualifiedName> { it.getImportSourceQName() }
.nonNull()
.anyMatch { qName == it }
}
else false
}

View File

@@ -9,10 +9,10 @@ import com.intellij.icons.AllIcons
import com.intellij.patterns.PlatformPatterns
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.ProcessingContext
import com.jetbrains.extensions.python.afterDefInMethod
import com.jetbrains.extensions.python.inParameterList
import com.jetbrains.python.extensions.afterDefInMethod
import com.jetbrains.python.extensions.inParameterList
import com.jetbrains.python.PyNames
import com.jetbrains.python.codeInsight.stdlib.*
import com.jetbrains.python.codeInsight.*
import com.jetbrains.python.psi.PyParameter
import com.jetbrains.python.psi.PyParameterList
import com.jetbrains.python.psi.PySubscriptionExpression
@@ -82,9 +82,10 @@ class PyDataclassCompletionContributor : CompletionContributor() {
val typeEvalContext = parameters.getTypeEvalContext()
if (parseDataclassParameters(cls, typeEvalContext)?.type == PyDataclassParameters.Type.ATTRS) {
if (parseDataclassParameters(cls,
typeEvalContext)?.type == PyDataclassParameters.Type.ATTRS) {
result.addElement(LookupElementBuilder.create(if (index == 1) "attribute" else "value").withIcon(AllIcons.Nodes.Parameter))
}
}
}
}
}

View File

@@ -32,7 +32,7 @@ import com.jetbrains.python.documentation.docstrings.DocStringTagCompletionContr
import com.jetbrains.python.documentation.docstrings.DocStringTypeReference;
import com.jetbrains.python.psi.PyDocStringOwner;
import com.jetbrains.python.psi.PyNamedParameter;
import com.jetbrains.python.refactoring.PyRefactoringUtil;
import com.jetbrains.python.psi.PyUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -68,12 +68,12 @@ public class PyDocstringCompletionContributor extends CompletionContributor {
final Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (module != null) {
result = result.withPrefixMatcher(getPrefix(parameters.getOffset(), file));
final Collection<String> identifiers = PyRefactoringUtil.collectUsedNames(docStringOwner);
final Collection<String> identifiers = PyUtil.collectUsedNames(docStringOwner);
for (String identifier : identifiers) {
result.addElement(LookupElementBuilder.create(identifier).withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE));
}
final Collection<String> fileIdentifiers = PyRefactoringUtil.collectUsedNames(parameters.getOriginalFile());
final Collection<String> fileIdentifiers = PyUtil.collectUsedNames(parameters.getOriginalFile());
for (String identifier : fileIdentifiers) {
result.addElement(LookupElementBuilder.create(identifier).withAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE));
}

View File

@@ -5,8 +5,8 @@ import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiFileSystemItem
import com.jetbrains.python.codeInsight.imports.PythonImportUtils
import com.jetbrains.python.psi.PyStringLiteralExpression
import com.jetbrains.python.psi.PyUtil
import com.jetbrains.python.psi.resolve.PyQualifiedNameResolveContext
import com.jetbrains.python.psi.resolve.QualifiedNameFinder
import com.jetbrains.python.psi.resolve.fromFoothold
@@ -34,7 +34,7 @@ class PyModulePackageCompletionContributor : PyExtendedCompletionContributor() {
val resolveContext = fromFoothold(targetFile)
val builders = modulesFromIndex.asSequence()
.flatMap { resolve(it, resolveContext) }
.filter { PythonImportUtils.isImportable(targetFile, it) }
.filter { PyUtil.isImportable(targetFile, it) }
.mapNotNull { createLookupElementBuilder(targetFile, it) }
.map { it.withInsertHandler(
if (inStringLiteral) stringLiteralInsertHandler else importingInsertHandler)

View File

@@ -19,7 +19,7 @@ import com.intellij.codeInsight.completion.*;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.icons.AllIcons;
import com.intellij.util.ProcessingContext;
import com.jetbrains.extensions.python.CaptureExtKt;
import com.jetbrains.python.extensions.CaptureExtKt;
import org.jetbrains.annotations.NotNull;
import static com.intellij.patterns.PlatformPatterns.psiElement;

View File

@@ -5,10 +5,9 @@ import com.intellij.codeInsight.completion.*
import com.intellij.patterns.PlatformPatterns
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.ProcessingContext
import com.jetbrains.extensions.python.afterDefInFunction
import com.jetbrains.python.PyNames
import com.jetbrains.python.PyNames.PREPARE
import com.jetbrains.python.inspections.PyMethodParametersInspection
import com.jetbrains.python.extensions.afterDefInFunction
import com.jetbrains.python.psi.*
import com.jetbrains.python.psi.types.TypeEvalContext
@@ -53,10 +52,7 @@ class PySpecialMethodNamesCompletionContributor : CompletionContributor() {
}
private fun handlePrepare(result: CompletionResultSet, pyClass: PyClass, context: TypeEvalContext, signature: String) {
val mcs = PyMethodParametersInspection.getInstance(pyClass)?.MCS
val signatureAfterApplyingSettings = if (mcs == null) signature else signature.replace("metacls", mcs)
addMethodToResult(result, pyClass, context, PREPARE, signatureAfterApplyingSettings) {
addMethodToResult(result, pyClass, context, PREPARE, signature) {
it.withTypeText("predefined")
it.withInsertHandler { context, _ ->
val function = PsiTreeUtil.getParentOfType(context.file.findElementAt(context.startOffset), PyFunction::class.java)
@@ -68,4 +64,4 @@ class PySpecialMethodNamesCompletionContributor : CompletionContributor() {
}
}
}
}
}

View File

@@ -13,7 +13,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ProcessingContext;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.inspections.PyStringFormatParser;
import com.jetbrains.python.PyStringFormatParser;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.impl.PyPsiUtils;
import org.jetbrains.annotations.NotNull;

View File

@@ -30,7 +30,7 @@ import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.resolve.QualifiedNameFinder;
import com.jetbrains.python.pyi.PyiFile;
import com.jetbrains.python.pyi.PyiUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.PythonSdkUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -348,9 +348,9 @@ public class AddImportHelper {
return new ImportPriorityChoice(ImportPriority.PROJECT, vFile + " belongs to the project and not under interpreter paths");
}
final Module module = ModuleUtilCore.findModuleForPsiElement(importLocation);
final Sdk pythonSdk = module != null ? PythonSdkType.findPythonSdk(module) : projectRootManager.getProjectSdk();
final Sdk pythonSdk = module != null ? PythonSdkUtil.findPythonSdk(module) : projectRootManager.getProjectSdk();
if (PythonSdkType.isStdLib(vFile, pythonSdk)) {
if (PythonSdkUtil.isStdLib(vFile, pythonSdk)) {
return new ImportPriorityChoice(ImportPriority.BUILTIN, vFile + " is either in lib but not under site-packages," +
" or belongs to the root of skeletons," +
" or is a .pyi stub definition for stdlib module");

Some files were not shown because too many files have changed in this diff Show More