KT-985 Don't show the default package in the completion list
This commit is contained in:
@@ -5,7 +5,11 @@ import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespaceHeader;
|
||||
@@ -23,10 +27,7 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.NamespaceType;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintType.RECEIVER;
|
||||
|
||||
@@ -48,7 +49,7 @@ public final class TipsManager {
|
||||
|
||||
if (expressionType != null && resolutionScope != null) {
|
||||
return includeExternalCallableExtensions(
|
||||
expressionType.getMemberScope().getAllDescriptors(),
|
||||
excludePrivateDescriptors(expressionType.getMemberScope().getAllDescriptors()),
|
||||
resolutionScope, new ExpressionReceiver(receiverExpression, expressionType));
|
||||
}
|
||||
} else {
|
||||
@@ -57,7 +58,7 @@ public final class TipsManager {
|
||||
if (expression.getParent() instanceof JetImportDirective || expression.getParent() instanceof JetNamespaceHeader) {
|
||||
return excludeNonPackageDescriptors(resolutionScope.getAllDescriptors());
|
||||
} else {
|
||||
java.util.HashSet<DeclarationDescriptor> descriptorsSet = Sets.newHashSet();
|
||||
HashSet<DeclarationDescriptor> descriptorsSet = Sets.newHashSet();
|
||||
|
||||
ArrayList<ReceiverDescriptor> result = new ArrayList<ReceiverDescriptor>();
|
||||
resolutionScope.getImplicitReceiversHierarchy(result);
|
||||
@@ -68,10 +69,7 @@ public final class TipsManager {
|
||||
}
|
||||
|
||||
descriptorsSet.addAll(resolutionScope.getAllDescriptors());
|
||||
|
||||
ClassDescriptor anInt = context.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, "Int");
|
||||
|
||||
return excludeNotCallableExtensions(descriptorsSet, resolutionScope);
|
||||
return excludeNotCallableExtensions(excludePrivateDescriptors(descriptorsSet), resolutionScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,6 +77,30 @@ public final class TipsManager {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Collection<DeclarationDescriptor> excludePrivateDescriptors(
|
||||
@NotNull Collection<DeclarationDescriptor> descriptors) {
|
||||
|
||||
return Collections2.filter(descriptors, new Predicate<DeclarationDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable DeclarationDescriptor descriptor) {
|
||||
if (descriptor == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (descriptor instanceof NamespaceDescriptor) {
|
||||
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) descriptor;
|
||||
if (namespaceDescriptor.getName().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Collection<DeclarationDescriptor> excludeNotCallableExtensions(
|
||||
@NotNull Collection<? extends DeclarationDescriptor> descriptors, @NotNull final JetScope scope
|
||||
) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
<caret>
|
||||
}
|
||||
|
||||
// ABSENT: ""
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.jetbrains.jet.completion;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -73,14 +75,14 @@ public class ExpectedCompletionUtils {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
for (String line : findLinesWithPrefixRemoved(prefix, fileText)) {
|
||||
String[] completions = line.split(",");
|
||||
String[] variants = line.split(",");
|
||||
|
||||
for (String completion : completions) {
|
||||
result.add(completion.trim());
|
||||
for (String variant : variants) {
|
||||
result.add(StringUtil.unquoteString(variant.trim()));
|
||||
}
|
||||
}
|
||||
|
||||
return result.toArray(new String[result.size()]);
|
||||
return ArrayUtil.toStringArray(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -61,6 +61,10 @@ public class JetBasicCompletionTest extends JetCompletionTestBase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoEmptyNamespace() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testOverloadFunctions() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user