mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PyType.getCompletionVariants() takes location as PsiElement, not PyExpression
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.ResolveState;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.AccessDirection;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
@@ -61,7 +58,7 @@ public class PyJavaClassType implements PyClassLikeType {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
final CompletionVariantsProcessor processor = new CompletionVariantsProcessor(location);
|
||||
myClass.processDeclarations(processor, ResolveState.initial(), null, location);
|
||||
return processor.getResult();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
@@ -56,7 +57,7 @@ public class PyJavaMethodType implements PyCallableType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
@@ -60,7 +61,7 @@ public class PyJavaPackageType implements PyType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
List<Object> variants = new ArrayList<Object>();
|
||||
final GlobalSearchScope scope = getScope(location.getProject());
|
||||
final PsiClass[] classes = myPackage.getClasses(scope);
|
||||
|
||||
@@ -165,5 +165,5 @@ public interface PyClass extends PsiNameIdentifierOwner, PyStatement, NameDefine
|
||||
String getDocStringValue();
|
||||
|
||||
boolean processClassLevelDeclarations(@NotNull PsiScopeProcessor processor);
|
||||
boolean processInstanceLevelDeclarations(@NotNull PsiScopeProcessor processor, @Nullable PyExpression location);
|
||||
boolean processInstanceLevelDeclarations(@NotNull PsiScopeProcessor processor, @Nullable PsiElement location);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.AccessDirection;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
@@ -37,11 +38,12 @@ public interface PyType {
|
||||
/**
|
||||
* Proposes completion variants from type's attributes.
|
||||
*
|
||||
*
|
||||
* @param location the reference on which the completion was invoked
|
||||
* @param context to share state between nested invocations
|
||||
* @return completion variants good for {@link com.intellij.psi.PsiReference#getVariants} return value.
|
||||
*/
|
||||
Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context);
|
||||
Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context);
|
||||
|
||||
/**
|
||||
* Context key for access to a set of names already found by variant search.
|
||||
|
||||
@@ -59,7 +59,7 @@ public class PyNamedTupleType extends PyClassTypeImpl implements PyCallableType
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
List<Object> result = new ArrayList<Object>();
|
||||
Collections.addAll(result, super.getCompletionVariants(completionPrefix, location, context));
|
||||
for (String field : myFields) {
|
||||
|
||||
@@ -975,7 +975,7 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processInstanceLevelDeclarations(@NotNull PsiScopeProcessor processor, @Nullable PyExpression location) {
|
||||
public boolean processInstanceLevelDeclarations(@NotNull PsiScopeProcessor processor, @Nullable PsiElement location) {
|
||||
Map<String, PyTargetExpression> declarationsInMethod = new HashMap<String, PyTargetExpression>();
|
||||
PyFunction instanceMethod = PsiTreeUtil.getParentOfType(location, PyFunction.class);
|
||||
final PyClass containingClass = instanceMethod != null ? instanceMethod.getContainingClass() : null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.PyNames;
|
||||
@@ -53,7 +54,7 @@ public class PyCallableTypeImpl implements PyCallableType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -335,7 +335,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
private static Key<Set<PyClassType>> CTX_VISITED = Key.create("PyClassType.Visited");
|
||||
public static Key<Boolean> CTX_SUPPRESS_PARENTHESES = Key.create("PyFunction.SuppressParentheses");
|
||||
|
||||
public Object[] getCompletionVariants(String prefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String prefix, PsiElement location, ProcessingContext context) {
|
||||
Set<PyClassType> visited = context.get(CTX_VISITED);
|
||||
if (visited == null) {
|
||||
visited = new HashSet<PyClassType>();
|
||||
@@ -392,7 +392,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
return ret.toArray();
|
||||
}
|
||||
|
||||
private void addOwnClassMembers(PyExpression expressionHook, Set<String> namesAlready, boolean suppressParentheses, List<Object> ret) {
|
||||
private void addOwnClassMembers(PsiElement expressionHook, Set<String> namesAlready, boolean suppressParentheses, List<Object> ret) {
|
||||
PyClass containingClass = PsiTreeUtil.getParentOfType(expressionHook, PyClass.class);
|
||||
if (containingClass != null) {
|
||||
containingClass = CompletionUtil.getOriginalElement(containingClass);
|
||||
@@ -429,7 +429,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInSuperCall(PyExpression hook) {
|
||||
private static boolean isInSuperCall(PsiElement hook) {
|
||||
if (hook instanceof PyReferenceExpression) {
|
||||
final PyExpression qualifier = ((PyReferenceExpression)hook).getQualifier();
|
||||
return qualifier instanceof PyCallExpression && ((PyCallExpression)qualifier).isCalleeText(PyNames.SUPER);
|
||||
@@ -438,7 +438,7 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
|
||||
}
|
||||
|
||||
private void addInheritedMembers(String name,
|
||||
PyExpression expressionHook,
|
||||
PsiElement expressionHook,
|
||||
Set<String> namesAlready,
|
||||
ProcessingContext context,
|
||||
List<Object> ret,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
@@ -53,7 +54,7 @@ public class PyFunctionType implements PyCallableType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.AccessDirection;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
@@ -32,7 +33,7 @@ public class PyGenericType implements PyType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PyImportedModuleType implements PyType {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
List<LookupElement> result = new ArrayList<LookupElement>();
|
||||
ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(location);
|
||||
assert scopeOwner != null;
|
||||
|
||||
@@ -258,10 +258,17 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
Set<String> namesAlready = context.get(CTX_NAMES);
|
||||
List<Object> result = new ArrayList<Object>();
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
List<LookupElement> result = getCompletionVariantsAsLookupElements(location, context, false, false);
|
||||
return result.toArray();
|
||||
}
|
||||
|
||||
public List<LookupElement> getCompletionVariantsAsLookupElements(PsiElement location,
|
||||
ProcessingContext context,
|
||||
boolean wantAllSubmodules, boolean suppressParentheses) {
|
||||
List<LookupElement> result = new ArrayList<LookupElement>();
|
||||
|
||||
Set<String> namesAlready = context.get(CTX_NAMES);
|
||||
PointInImport point = ResolveImportUtil.getPointInImport(location);
|
||||
for (PyModuleMembersProvider provider : Extensions.getExtensions(PyModuleMembersProvider.EP_NAME)) {
|
||||
for (PyDynamicMember member : provider.getMembers(myModule, point)) {
|
||||
@@ -281,6 +288,9 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
|
||||
PsiTreeUtil.getParentOfType(psiElement, PyImportStatementBase.class) instanceof PyFromImportStatement;
|
||||
}
|
||||
}, new PyUtil.UnderscoreFilter(0));
|
||||
if (suppressParentheses) {
|
||||
processor.suppressParentheses();
|
||||
}
|
||||
processor.setPlainNamesOnly(point == PointInImport.AS_NAME); // no parens after imported function names
|
||||
myModule.processDeclarations(processor, ResolveState.initial(), null, location);
|
||||
if (namesAlready != null) {
|
||||
@@ -297,17 +307,17 @@ public class PyModuleType implements PyType { // Modules don't descend from obje
|
||||
}
|
||||
}
|
||||
if (PyUtil.isPackage(myModule)) { // our module is a dir, not a single file
|
||||
if (point == PointInImport.AS_MODULE || point == PointInImport.AS_NAME) { // when imported from somehow, add submodules
|
||||
if (point == PointInImport.AS_MODULE || point == PointInImport.AS_NAME || wantAllSubmodules) { // when imported from somehow, add submodules
|
||||
result.addAll(getSubModuleVariants(myModule.getContainingDirectory(), location, namesAlready));
|
||||
}
|
||||
else {
|
||||
addImportedSubmodules(location, namesAlready, result);
|
||||
}
|
||||
}
|
||||
return result.toArray();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addImportedSubmodules(PyExpression location, Set<String> existingNames, List<Object> result) {
|
||||
private void addImportedSubmodules(PsiElement location, Set<String> existingNames, List<LookupElement> result) {
|
||||
PsiFile file = location.getContainingFile();
|
||||
if (file instanceof PyFile) {
|
||||
PyFile pyFile = (PyFile)file;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.jetbrains.python.psi.AccessDirection;
|
||||
@@ -28,7 +29,7 @@ public class PyNoneType implements PyType { // TODO must extend ClassType. It's
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jetbrains.python.psi.types;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.SmartList;
|
||||
@@ -42,7 +43,7 @@ public class PyUnionType implements PyType {
|
||||
return allNulls ? null : ret;
|
||||
}
|
||||
|
||||
public Object[] getCompletionVariants(String completionPrefix, PyExpression location, ProcessingContext context) {
|
||||
public Object[] getCompletionVariants(String completionPrefix, PsiElement location, ProcessingContext context) {
|
||||
Set<Object> variants = new HashSet<Object>();
|
||||
for (PyType member : myMembers) {
|
||||
if (member != null) {
|
||||
|
||||
Reference in New Issue
Block a user