mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed (PY-2375) Doctest run configuration is suggested for non-Python files
This commit is contained in:
+5
-6
@@ -42,7 +42,7 @@ public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction {
|
||||
PyLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyLambdaExpression.class);
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
if (lambdaExpression != null) {
|
||||
String name;
|
||||
String name = "function";
|
||||
PsiElement parent = lambdaExpression.getParent();
|
||||
if (parent instanceof PyAssignmentStatement) {
|
||||
name = ((PyAssignmentStatement)parent).getLeftHandSideExpression().getText();
|
||||
@@ -57,8 +57,6 @@ public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction {
|
||||
name = dialog.getAlias();
|
||||
if (name.isEmpty()) return;
|
||||
}
|
||||
else
|
||||
name = "function";
|
||||
}
|
||||
|
||||
PyExpression body = lambdaExpression.getBody();
|
||||
@@ -80,9 +78,10 @@ public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction {
|
||||
PyFunction function = elementGenerator.createFromText(LanguageLevel.forElement(lambdaExpression),
|
||||
PyFunction.class, stringBuilder.toString());
|
||||
|
||||
PyFunction pyFunction = PsiTreeUtil.getParentOfType(lambdaExpression, PyFunction.class);
|
||||
if (pyFunction != null) {
|
||||
pyFunction.getStatementList().addBefore(function, pyFunction.getStatementList().getStatements()[0]);
|
||||
PyFunction parentFunction = PsiTreeUtil.getParentOfType(lambdaExpression, PyFunction.class);
|
||||
if (parentFunction != null) {
|
||||
PyStatementList statements = parentFunction.getStatementList();
|
||||
statements.addBefore(function, statements.getStatements()[0]);
|
||||
}
|
||||
else {
|
||||
PyStatement statement = PsiTreeUtil.getParentOfType(lambdaExpression, PyStatement.class);
|
||||
|
||||
+4
-6
@@ -156,13 +156,11 @@ public class PythonDocTestConfigurationProducer extends RuntimeConfigurationProd
|
||||
@Nullable
|
||||
private RunnerAndConfigurationSettings createConfigurationFromFile(Location location, PsiElement element) {
|
||||
PsiElement file = element.getContainingFile();
|
||||
if (file == null) return null;
|
||||
if (file == null || !(file instanceof PyFile)) return null;
|
||||
|
||||
if (file instanceof PyFile) {
|
||||
final PyFile pyFile = (PyFile)file;
|
||||
final List<PyElement> testCases = PythonDocTestUtil.getDocTestCasesFromFile(pyFile);
|
||||
if (testCases.isEmpty()) return null;
|
||||
}
|
||||
final PyFile pyFile = (PyFile)file;
|
||||
final List<PyElement> testCases = PythonDocTestUtil.getDocTestCasesFromFile(pyFile);
|
||||
if (testCases.isEmpty()) return null;
|
||||
|
||||
final RunnerAndConfigurationSettings settings = makeConfigurationSettings(location, "doc tests from file");
|
||||
final PythonDocTestRunConfiguration configuration = (PythonDocTestRunConfiguration)settings.getConfiguration();
|
||||
|
||||
Reference in New Issue
Block a user