nicer looking completion items
This commit is contained in:
@@ -2,16 +2,18 @@ package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.parsing.JetExpressionParsing;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -90,7 +92,7 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
||||
BindingContext bindingContext = AnalyzingUtils.analyzeFileWithCache(file);
|
||||
final JetType expressionType = bindingContext.getExpressionType(receiverExpression);
|
||||
if (expressionType != null) {
|
||||
return collectLookupElements(expressionType.getMemberScope());
|
||||
return collectLookupElements(bindingContext, expressionType.getMemberScope());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -98,7 +100,7 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
||||
BindingContext bindingContext = AnalyzingUtils.analyzeFileWithCache(file);
|
||||
JetScope resolutionScope = bindingContext.getResolutionScope(JetSimpleNameExpression.this);
|
||||
if (resolutionScope != null) {
|
||||
return collectLookupElements(resolutionScope);
|
||||
return collectLookupElements(bindingContext, resolutionScope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,24 +109,42 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
||||
};
|
||||
}
|
||||
|
||||
private Object[] collectLookupElements(JetScope scope) {
|
||||
private Object[] collectLookupElements(BindingContext bindingContext, JetScope scope) {
|
||||
List<LookupElement> result = Lists.newArrayList();
|
||||
for (final DeclarationDescriptor descriptor : scope.getAllDescriptors()) {
|
||||
result.add(
|
||||
new LookupElement() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getLookupString() {
|
||||
return descriptor.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderElement(LookupElementPresentation presentation) {
|
||||
presentation.setItemText(descriptor.getName());
|
||||
presentation.setTypeText(DescriptorRenderer.TEXT.render(descriptor));
|
||||
}
|
||||
PsiElement declaration = bindingContext.getDeclarationPsiElement(descriptor.getOriginal());
|
||||
LookupElementBuilder element = LookupElementBuilder.create(descriptor.getName());
|
||||
String typeText = "";
|
||||
String tailText = "";
|
||||
boolean tailTextGrayed = false;
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
JetType returnType = functionDescriptor.getUnsubstitutedReturnType();
|
||||
typeText = DescriptorRenderer.TEXT.renderType(returnType);
|
||||
tailText = "(" + StringUtil.join(functionDescriptor.getUnsubstitutedValueParameters(), new Function<ValueParameterDescriptor, String>() {
|
||||
@Override
|
||||
public String fun(ValueParameterDescriptor valueParameterDescriptor) {
|
||||
return valueParameterDescriptor.getName() + ":" +
|
||||
DescriptorRenderer.TEXT.renderType(valueParameterDescriptor.getOutType());
|
||||
}
|
||||
);
|
||||
}, ",") + ")";
|
||||
}
|
||||
else if (descriptor instanceof VariableDescriptor) {
|
||||
JetType outType = ((VariableDescriptor) descriptor).getOutType();
|
||||
typeText = DescriptorRenderer.TEXT.renderType(outType);
|
||||
}
|
||||
else if (descriptor instanceof ClassDescriptor) {
|
||||
tailText = " (" + DescriptorRenderer.getFQName(descriptor.getContainingDeclaration()) + ")";
|
||||
tailTextGrayed = true;
|
||||
}
|
||||
else {
|
||||
typeText = DescriptorRenderer.TEXT.render(descriptor);
|
||||
}
|
||||
element = element.setTailText(tailText, tailTextGrayed).setTypeText(typeText);
|
||||
if (declaration != null) {
|
||||
element = element.setIcon(declaration.getIcon(ICON_FLAG_OPEN | ICON_FLAG_VISIBILITY));
|
||||
}
|
||||
result.add(element);
|
||||
}
|
||||
return result.toArray();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user