From 16b1761fe79e20e394d40cf641cc5a1b486283b9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 31 May 2011 16:22:13 +0400 Subject: [PATCH 1/9] auto import is HighPriorityAction --- .../python/codeInsight/imports/AutoImportHintAction.java | 3 ++- .../python/codeInsight/imports/AutoImportQuickFix.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/imports/AutoImportHintAction.java b/python/src/com/jetbrains/python/codeInsight/imports/AutoImportHintAction.java index 242cd41efe5e..bc375f95cd93 100644 --- a/python/src/com/jetbrains/python/codeInsight/imports/AutoImportHintAction.java +++ b/python/src/com/jetbrains/python/codeInsight/imports/AutoImportHintAction.java @@ -1,5 +1,6 @@ package com.jetbrains.python.codeInsight.imports; +import com.intellij.codeInsight.intention.HighPriorityAction; import com.intellij.codeInspection.HintAction; import com.intellij.codeInspection.LocalQuickFix; import com.intellij.codeInspection.ProblemDescriptor; @@ -12,7 +13,7 @@ import org.jetbrains.annotations.NotNull; /** * @author yole */ -public class AutoImportHintAction implements LocalQuickFix, HintAction { +public class AutoImportHintAction implements LocalQuickFix, HintAction, HighPriorityAction { private final AutoImportQuickFix myDelegate; public AutoImportHintAction(AutoImportQuickFix delegate) { diff --git a/python/src/com/jetbrains/python/codeInsight/imports/AutoImportQuickFix.java b/python/src/com/jetbrains/python/codeInsight/imports/AutoImportQuickFix.java index e9531b87b45f..aa68beb54dc4 100644 --- a/python/src/com/jetbrains/python/codeInsight/imports/AutoImportQuickFix.java +++ b/python/src/com/jetbrains/python/codeInsight/imports/AutoImportQuickFix.java @@ -3,6 +3,7 @@ package com.jetbrains.python.codeInsight.imports; import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.daemon.impl.ShowAutoImportPass; import com.intellij.codeInsight.hint.HintManager; +import com.intellij.codeInsight.intention.HighPriorityAction; import com.intellij.codeInspection.LocalQuickFix; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.editor.Editor; @@ -32,7 +33,7 @@ import java.util.List; * * @author dcheryasov */ -public class AutoImportQuickFix implements LocalQuickFix { +public class AutoImportQuickFix implements LocalQuickFix, HighPriorityAction { private final PyElement myNode; private final PsiReference myReference; From df08ac4dedccee5a734c9296ebe49fbe03003366 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 31 May 2011 17:12:00 +0400 Subject: [PATCH 2/9] allow custom target expression stubs to provide callee name (PY-2981); looser detection of Django facet --- .../jetbrains/python/psi/impl/PyTargetExpressionImpl.java | 7 ++++++- .../python/psi/impl/stubs/CustomTargetExpressionStub.java | 5 +++++ .../jetbrains/python/psi/stubs/PropertyStubStorage.java | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyTargetExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyTargetExpressionImpl.java index 7fcd02b45068..812873f356d6 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyTargetExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyTargetExpressionImpl.java @@ -25,6 +25,7 @@ import com.jetbrains.python.codeInsight.dataflow.scope.Scope; import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; import com.jetbrains.python.documentation.StructuredDocString; import com.jetbrains.python.psi.*; +import com.jetbrains.python.psi.impl.stubs.CustomTargetExpressionStub; import com.jetbrains.python.psi.resolve.PyResolveContext; import com.jetbrains.python.psi.stubs.PyTargetExpressionStub; import com.jetbrains.python.psi.types.*; @@ -317,9 +318,13 @@ public class PyTargetExpressionImpl extends PyPresentableElementImpl getTypeClass(); void serialize(StubOutputStream stream) throws IOException; + + @Nullable + PyQualifiedName getCalleeName(); } diff --git a/python/src/com/jetbrains/python/psi/stubs/PropertyStubStorage.java b/python/src/com/jetbrains/python/psi/stubs/PropertyStubStorage.java index 9ae95993fb17..11ec9412da0c 100644 --- a/python/src/com/jetbrains/python/psi/stubs/PropertyStubStorage.java +++ b/python/src/com/jetbrains/python/psi/stubs/PropertyStubStorage.java @@ -6,6 +6,7 @@ import com.intellij.util.io.StringRef; import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.PyReferenceExpression; import com.jetbrains.python.psi.impl.PropertyBunch; +import com.jetbrains.python.psi.impl.PyQualifiedName; import com.jetbrains.python.psi.impl.stubs.CustomTargetExpressionStub; import com.jetbrains.python.psi.impl.stubs.CustomTargetExpressionStubType; import com.jetbrains.python.psi.impl.stubs.PropertyStubType; @@ -71,6 +72,11 @@ public class PropertyStubStorage extends PropertyBunch implements Custom stream.writeName(myDoc); } + @Override + public PyQualifiedName getCalleeName() { + return null; // ?? + } + public static PropertyStubStorage deserialize(StubInputStream stream) throws IOException { PropertyStubStorage me = new PropertyStubStorage(); me.myGetter = readOne(stream); From 258a0f44ecdf3188205414a4f5f104bb78310abe Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 31 May 2011 18:02:44 +0400 Subject: [PATCH 3/9] avoid unnecessary stub->AST switch --- .../com/jetbrains/python/psi/impl/PyCallExpressionHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java index 0a3b6f422afc..b9c56a8fa4e3 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java @@ -241,7 +241,7 @@ public class PyCallExpressionHelper { } private static boolean isQualifiedByInstance(Callable resolved, List qualifiers, TypeEvalContext context) { - PyDocStringOwner owner = PsiTreeUtil.getParentOfType(resolved, PyDocStringOwner.class); + PyDocStringOwner owner = PsiTreeUtil.getStubOrPsiParentOfType(resolved, PyDocStringOwner.class); if (!(owner instanceof PyClass)) { return false; } From 0f04e7c835dea5abef7358e11c801bb0508f7af7 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 31 May 2011 19:03:20 +0400 Subject: [PATCH 4/9] avoid mutating cached value --- .../com/jetbrains/python/psi/impl/PyFileImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java index 980dc8fd8558..fd0945e1394d 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyFileImpl.java @@ -358,19 +358,20 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression { VariantsProcessor processor = new VariantsProcessor(this); final List dunderAll = getDunderAll(); processor.setAllowedNames(dunderAll); + final List remainingDunderAll = dunderAll == null ? null : new ArrayList(dunderAll); processDeclarations(processor, ResolveState.initial(), null, this); List result = new ArrayList(); for (LookupElement lookupElement : processor.getResultList()) { final Object value = lookupElement.getObject(); if (value instanceof PyElement) { result.add((PyElement) value); - if (dunderAll != null) { - dunderAll.remove(lookupElement.getLookupString()); + if (remainingDunderAll != null) { + remainingDunderAll.remove(lookupElement.getLookupString()); } } } - if (dunderAll != null) { - for (String s: dunderAll) { + if (remainingDunderAll != null) { + for (String s: remainingDunderAll) { result.add(new LightNamedElement(myManager, PythonLanguage.getInstance(), s)); } } @@ -428,7 +429,8 @@ public class PyFileImpl extends PsiFileBase implements PyFile, PyExpression { return ((PyFileStub) stubElement).getDunderAll(); } if (!myDunderAllCalculated) { - myDunderAll = calculateDunderAll(); + final List dunderAll = calculateDunderAll(); + myDunderAll = dunderAll == null ? null : Collections.unmodifiableList(dunderAll); myDunderAllCalculated = true; } return myDunderAll; From 7726f3cea09f840893829c114e9507edae61125d Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 31 May 2011 15:17:27 +0400 Subject: [PATCH 5/9] Perf opt and PY-3699. --- python/helpers/pydev/pydevd_frame.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/python/helpers/pydev/pydevd_frame.py b/python/helpers/pydev/pydevd_frame.py index de635968f9d3..40181da91a16 100644 --- a/python/helpers/pydev/pydevd_frame.py +++ b/python/helpers/pydev/pydevd_frame.py @@ -40,13 +40,16 @@ class PyDBFrame: can_skip = False - #if not len(mainDebugger.always_exception_set): - # if info.pydev_state == STATE_RUN: - # #we can skip if: - # #- we have no stop marked - # #- we should make a step return/step over and we're not in the current frame - # can_skip = (info.pydev_step_cmd is None and info.pydev_step_stop is None)\ - # or (info.pydev_step_cmd in (CMD_STEP_RETURN, CMD_STEP_OVER) and info.pydev_step_stop is not frame) + + if info.pydev_state == STATE_RUN: + #we can skip if: + #- we have no stop marked + #- we should make a step return/step over and we're not in the current frame + can_skip = (info.pydev_step_cmd is None and info.pydev_step_stop is None)\ + or (info.pydev_step_cmd in (CMD_STEP_RETURN, CMD_STEP_OVER) and info.pydev_step_stop is not frame) + + if mainDebugger.always_exception_set: + can_skip = False if mainDebugger.django_breakpoints: can_skip = False From caad7977e517ebd09609c35538dd620a1f703dd4 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 31 May 2011 17:23:53 +0400 Subject: [PATCH 6/9] Fixed regexp injection in url call (PY-3749). --- .../com/jetbrains/python/psi/impl/PyPsiUtils.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/src/com/jetbrains/python/psi/impl/PyPsiUtils.java b/python/src/com/jetbrains/python/psi/impl/PyPsiUtils.java index da69fc1e278a..906d88c16628 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyPsiUtils.java +++ b/python/src/com/jetbrains/python/psi/impl/PyPsiUtils.java @@ -283,4 +283,19 @@ public class PyPsiUtils { } return element; } + + public static int findArgumentIndex(PyCallExpression call, PsiElement argument) { + final PyExpression[] args = call.getArguments(); + for (int i = 0; i < args.length; i++) { + PyExpression expression = args[i]; + if (expression instanceof PyKeywordArgumentImpl) { + expression = ((PyKeywordArgumentImpl)expression).getValueExpression(); + } + expression = PyUtil.flattenParens(expression); + if (expression == argument) { + return i; + } + } + return -1; + } } \ No newline at end of file From 116053e552500528dc837e23f64a796d35d7451b Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 31 May 2011 17:34:57 +0400 Subject: [PATCH 7/9] Removed unnecessary import leading to PY-3718. --- python/helpers/pydev/pydevd_vars.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/helpers/pydev/pydevd_vars.py b/python/helpers/pydev/pydevd_vars.py index 63275dc998b3..a106a154a9d0 100644 --- a/python/helpers/pydev/pydevd_vars.py +++ b/python/helpers/pydev/pydevd_vars.py @@ -5,7 +5,6 @@ import pickle from django_frame import DjangoTemplateFrame from pydevd_constants import * #@UnusedWildImport from types import * #@UnusedWildImport -from console import pydevconsole from code import compile_command from code import InteractiveInterpreter From bbd12e44c0437327dc4ac05fee551022ab7c5e91 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 31 May 2011 17:49:46 +0400 Subject: [PATCH 8/9] Fixed exception breakpoints. --- python/helpers/pydev/pydevd_breakpoints.py | 4 ++-- python/helpers/pydev/pydevd_comm.py | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/python/helpers/pydev/pydevd_breakpoints.py b/python/helpers/pydev/pydevd_breakpoints.py index 27d7ec91e42a..1c7ee4c87ffe 100644 --- a/python/helpers/pydev/pydevd_breakpoints.py +++ b/python/helpers/pydev/pydevd_breakpoints.py @@ -146,8 +146,8 @@ def restore_pm_excepthook(): def update_exception_hook(dbg): - if len(dbg.exception_set) >0: - set_pm_excepthook(tuple(dbg.exception_set)) + if dbg.exception_set: + set_pm_excepthook(dict(dbg.exception_set)) else: restore_pm_excepthook() diff --git a/python/helpers/pydev/pydevd_comm.py b/python/helpers/pydev/pydevd_comm.py index 281f27cbf04c..0aef5856aa73 100644 --- a/python/helpers/pydev/pydevd_comm.py +++ b/python/helpers/pydev/pydevd_comm.py @@ -775,10 +775,13 @@ class InternalGetCompletions(InternalThreadCommand): try: import console._completer except: - path = os.environ['PYDEV_COMPLETER_PYTHONPATH'] - sys.path.append(path) - remove_path = path - import console._completer + try: + path = os.environ['PYDEV_COMPLETER_PYTHONPATH'] + sys.path.append(path) + remove_path = path + import console._completer + except : + traceback.print_exc() try: From b592885a54ea784cdb9f6e93b9f2ccf907d4cbf0 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 31 May 2011 19:45:51 +0400 Subject: [PATCH 9/9] No exception on completer import when using GAE (PY-3486). --- python/helpers/pydev/pydevd_comm.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/python/helpers/pydev/pydevd_comm.py b/python/helpers/pydev/pydevd_comm.py index 0aef5856aa73..96b4c60409fa 100644 --- a/python/helpers/pydev/pydevd_comm.py +++ b/python/helpers/pydev/pydevd_comm.py @@ -777,11 +777,15 @@ class InternalGetCompletions(InternalThreadCommand): except: try: path = os.environ['PYDEV_COMPLETER_PYTHONPATH'] - sys.path.append(path) - remove_path = path + except : + path = os.path.dirname(__file__) + print (path) + sys.path.append(path) + remove_path = path + try: import console._completer except : - traceback.print_exc() + pass try: @@ -793,10 +797,13 @@ class InternalGetCompletions(InternalThreadCommand): updated_globals = {} updated_globals.update(frame.f_globals) updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals - - completer = console._completer.Completer(updated_globals, None) - #list(tuple(name, descr, parameters, type)) - completions = completer.complete(self.act_tok) + + try: + completer = console._completer.Completer(updated_globals, None) + #list(tuple(name, descr, parameters, type)) + completions = completer.complete(self.act_tok) + except : + completions = [] def makeValid(s):