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.google.common.collect.Lists;
|
||||||
import com.intellij.codeInsight.lookup.LookupElement;
|
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.lang.ASTNode;
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiReference;
|
import com.intellij.psi.PsiReference;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.tree.TokenSet;
|
import com.intellij.psi.tree.TokenSet;
|
||||||
|
import com.intellij.util.Function;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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.parsing.JetExpressionParsing;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
@@ -90,7 +92,7 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
|||||||
BindingContext bindingContext = AnalyzingUtils.analyzeFileWithCache(file);
|
BindingContext bindingContext = AnalyzingUtils.analyzeFileWithCache(file);
|
||||||
final JetType expressionType = bindingContext.getExpressionType(receiverExpression);
|
final JetType expressionType = bindingContext.getExpressionType(receiverExpression);
|
||||||
if (expressionType != null) {
|
if (expressionType != null) {
|
||||||
return collectLookupElements(expressionType.getMemberScope());
|
return collectLookupElements(bindingContext, expressionType.getMemberScope());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -98,7 +100,7 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
|||||||
BindingContext bindingContext = AnalyzingUtils.analyzeFileWithCache(file);
|
BindingContext bindingContext = AnalyzingUtils.analyzeFileWithCache(file);
|
||||||
JetScope resolutionScope = bindingContext.getResolutionScope(JetSimpleNameExpression.this);
|
JetScope resolutionScope = bindingContext.getResolutionScope(JetSimpleNameExpression.this);
|
||||||
if (resolutionScope != null) {
|
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();
|
List<LookupElement> result = Lists.newArrayList();
|
||||||
for (final DeclarationDescriptor descriptor : scope.getAllDescriptors()) {
|
for (final DeclarationDescriptor descriptor : scope.getAllDescriptors()) {
|
||||||
result.add(
|
PsiElement declaration = bindingContext.getDeclarationPsiElement(descriptor.getOriginal());
|
||||||
new LookupElement() {
|
LookupElementBuilder element = LookupElementBuilder.create(descriptor.getName());
|
||||||
@NotNull
|
String typeText = "";
|
||||||
@Override
|
String tailText = "";
|
||||||
public String getLookupString() {
|
boolean tailTextGrayed = false;
|
||||||
return descriptor.getName();
|
if (descriptor instanceof FunctionDescriptor) {
|
||||||
}
|
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||||
|
JetType returnType = functionDescriptor.getUnsubstitutedReturnType();
|
||||||
@Override
|
typeText = DescriptorRenderer.TEXT.renderType(returnType);
|
||||||
public void renderElement(LookupElementPresentation presentation) {
|
tailText = "(" + StringUtil.join(functionDescriptor.getUnsubstitutedValueParameters(), new Function<ValueParameterDescriptor, String>() {
|
||||||
presentation.setItemText(descriptor.getName());
|
@Override
|
||||||
presentation.setTypeText(DescriptorRenderer.TEXT.render(descriptor));
|
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();
|
return result.toArray();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user