KT-825 Completion doesn't show overloaded functions
This commit is contained in:
@@ -22,6 +22,10 @@ public class JetFunctionInsertHandler implements InsertHandler<LookupElement> {
|
||||
|
||||
@Override
|
||||
public void handleInsert(InsertionContext context, LookupElement item) {
|
||||
if (context.getCompletionChar() == '(') {
|
||||
context.setAddCompletionChar(false);
|
||||
}
|
||||
|
||||
int startOffset = context.getStartOffset();
|
||||
int lookupStringLength = item.getLookupString().length();
|
||||
int endOffset = startOffset + lookupStringLength;
|
||||
|
||||
@@ -148,7 +148,7 @@ class JetSimpleNameReference extends JetPsiReference {
|
||||
List<LookupElement> result = Lists.newArrayList();
|
||||
|
||||
for (final DeclarationDescriptor descriptor : descriptors) {
|
||||
LookupElementBuilder element = LookupElementBuilder.create(descriptor.getName());
|
||||
LookupElementBuilder element = LookupElementBuilder.create(descriptor, descriptor.getName());
|
||||
String typeText = "";
|
||||
String tailText = "";
|
||||
boolean tailTextGrayed = false;
|
||||
@@ -165,6 +165,7 @@ class JetSimpleNameReference extends JetPsiReference {
|
||||
DescriptorRenderer.TEXT.renderType(valueParameterDescriptor.getOutType());
|
||||
}
|
||||
}, ",") + ")";
|
||||
|
||||
|
||||
// TODO: A special case when it's impossible to resolve type parameters from arguments. Need '<' caret '>'
|
||||
// TODO: Support omitting brackets for one argument functions
|
||||
@@ -185,6 +186,7 @@ class JetSimpleNameReference extends JetPsiReference {
|
||||
else {
|
||||
typeText = DescriptorRenderer.TEXT.render(descriptor);
|
||||
}
|
||||
|
||||
element = element.setTailText(tailText, tailTextGrayed).setTypeText(typeText);
|
||||
|
||||
PsiElement declaration = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor.getOriginal());
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Test.MyTest
|
||||
|
||||
class A {
|
||||
class object {
|
||||
public fun testOther() {
|
||||
|
||||
}
|
||||
|
||||
public fun testOther(a: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
public fun testOther(a: Int) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testMy() {
|
||||
A.test<caret>
|
||||
}
|
||||
|
||||
// EXIST: testOther
|
||||
// NUMBER: 3
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Test.MyTest
|
||||
|
||||
class A {
|
||||
class object {
|
||||
public fun testOther(a: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
public fun testOther(a: Int) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testMy() {
|
||||
A.testOther<caret>
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Test.MyTest
|
||||
|
||||
class A {
|
||||
class object {
|
||||
public fun testOther(a: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
public fun testOther(a: Int) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testMy() {
|
||||
A.testOther()
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -59,6 +60,11 @@ public abstract class JetCompletionTestBase extends LightCompletionTestCase {
|
||||
|
||||
assertContainsItems(itemsShouldExist(getFile().getText()));
|
||||
assertNotContainItems(itemsShouldAbsent(getFile().getText()));
|
||||
|
||||
Integer itemsNumber = getExpectedNumber(getFile().getText());
|
||||
if (itemsNumber != null) {
|
||||
assertEquals(itemsNumber.intValue(), myItems.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,6 +91,16 @@ public abstract class JetCompletionTestBase extends LightCompletionTestCase {
|
||||
return findListWithPrefix("// ABSENT:", fileText);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Integer getExpectedNumber(String fileText) {
|
||||
final String[] numberStrings = findListWithPrefix("// NUMBER:", fileText);
|
||||
if (numberStrings.length > 0) {
|
||||
return Integer.parseInt(numberStrings[0]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String[] findListWithPrefix(String prefix, String fileText) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
@@ -20,6 +20,14 @@ public class FunctionsHandlerTest extends LightCompletionTestCase {
|
||||
checkResultByFile("ParamsFunction.kt.after");
|
||||
}
|
||||
|
||||
public void testSingleBrackets() {
|
||||
configureByFile("SingleBrackets.kt");
|
||||
type('(');
|
||||
checkResultByFile("SingleBrackets.kt.after");
|
||||
}
|
||||
|
||||
// public void
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/completion/handlers/").getPath() +
|
||||
|
||||
Reference in New Issue
Block a user