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