mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
PY-18253: Context passed to PyLineMarkerNavigator#search
We used to use loose context that prevents user from accessing other classes. We use user-initiated context now since this navigation is user-initiated action
This commit is contained in:
@@ -22,6 +22,8 @@ import com.intellij.psi.NavigatablePsiElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.Query;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -34,7 +36,7 @@ import java.util.List;
|
||||
public abstract class PyLineMarkerNavigator<T extends PsiElement> implements GutterIconNavigationHandler<T> {
|
||||
public void navigate(final MouseEvent e, final T elt) {
|
||||
final List<NavigatablePsiElement> navElements = new ArrayList<NavigatablePsiElement>();
|
||||
Query<T> elementQuery = search(elt);
|
||||
final Query<T> elementQuery = search(elt, TypeEvalContext.userInitiated(elt.getProject(), elt.getContainingFile()));
|
||||
if (elementQuery == null) return;
|
||||
elementQuery.forEach(new Processor<T>() {
|
||||
public boolean process(final T psiElement) {
|
||||
@@ -51,5 +53,5 @@ public abstract class PyLineMarkerNavigator<T extends PsiElement> implements Gut
|
||||
protected abstract String getTitle(T elt);
|
||||
|
||||
@Nullable
|
||||
protected abstract Query<T> search(T elt);
|
||||
protected abstract Query<T> search(T elt, @NotNull TypeEvalContext context);
|
||||
}
|
||||
|
||||
@@ -108,9 +108,8 @@ public class PyLineMarkerProvider implements LineMarkerProvider, PyLineSeparator
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Query<PsiElement> search(final PsiElement elt) {
|
||||
protected Query<PsiElement> search(final PsiElement elt, @NotNull final TypeEvalContext context) {
|
||||
if (!(elt.getParent() instanceof PyFunction)) return null;
|
||||
final TypeEvalContext context = TypeEvalContext.codeAnalysis(elt.getProject(), null);
|
||||
return PySuperMethodsSearch.search((PyFunction)elt.getParent(), context);
|
||||
}
|
||||
};
|
||||
@@ -121,12 +120,12 @@ public class PyLineMarkerProvider implements LineMarkerProvider, PyLineSeparator
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Query<PsiElement> search(final PsiElement elt) {
|
||||
protected Query<PsiElement> search(final PsiElement elt, @NotNull final TypeEvalContext context) {
|
||||
List<PsiElement> result = new ArrayList<PsiElement>();
|
||||
PyClass containingClass = PsiTreeUtil.getParentOfType(elt, PyClass.class);
|
||||
if (containingClass != null && elt instanceof PyTargetExpression) {
|
||||
for (PyClass ancestor : containingClass.getAncestorClasses(null)) {
|
||||
final PyTargetExpression attribute = ancestor.findClassAttribute(((PyTargetExpression)elt).getReferencedName(), false, null);
|
||||
for (PyClass ancestor : containingClass.getAncestorClasses(context)) {
|
||||
final PyTargetExpression attribute = ancestor.findClassAttribute(((PyTargetExpression)elt).getReferencedName(), false, context);
|
||||
if (attribute != null) {
|
||||
result.add(attribute);
|
||||
}
|
||||
@@ -141,7 +140,7 @@ public class PyLineMarkerProvider implements LineMarkerProvider, PyLineSeparator
|
||||
return "Choose Subclass of " + elt.getName();
|
||||
}
|
||||
|
||||
protected Query<PyClass> search(final PyClass elt) {
|
||||
protected Query<PyClass> search(final PyClass elt, @NotNull TypeEvalContext context) {
|
||||
return PyClassInheritorsSearch.search(elt, true);
|
||||
}
|
||||
};
|
||||
@@ -151,7 +150,7 @@ public class PyLineMarkerProvider implements LineMarkerProvider, PyLineSeparator
|
||||
return "Choose Overriding Method of " + elt.getName();
|
||||
}
|
||||
|
||||
protected Query<PyFunction> search(final PyFunction elt) {
|
||||
protected Query<PyFunction> search(final PyFunction elt, @NotNull TypeEvalContext context) {
|
||||
return PyOverridingMethodsSearch.search(elt, true);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user