KT-1644 Propose types after fun — for receiver type
#KT-1644 fixed
This commit is contained in:
@@ -90,10 +90,13 @@
|
|||||||
<completion.contributor language="jet" id="JetPackagesContributor" order="after JetKeywordCompletionContributor"
|
<completion.contributor language="jet" id="JetPackagesContributor" order="after JetKeywordCompletionContributor"
|
||||||
implementationClass="org.jetbrains.jet.plugin.completion.JetPackagesContributor" />
|
implementationClass="org.jetbrains.jet.plugin.completion.JetPackagesContributor" />
|
||||||
|
|
||||||
<completion.contributor language="jet" id="JetClassCompletionContributor" order="after JetPackagesContributor"
|
<completion.contributor language="jet" id="JetExtensionFunctionReceiverContributor" order="after JetPackagesContributor"
|
||||||
|
implementationClass="org.jetbrains.jet.plugin.completion.JetExtensionReceiverTypeContributor" />
|
||||||
|
|
||||||
|
<completion.contributor language="jet" id="JetClassCompletionContributor" order="after JetExtensionFunctionReceiverContributor"
|
||||||
implementationClass="org.jetbrains.jet.plugin.completion.JetClassCompletionContributor" />
|
implementationClass="org.jetbrains.jet.plugin.completion.JetClassCompletionContributor" />
|
||||||
|
|
||||||
<completion.contributor language="jet" id="JetCompletionContributor"
|
<completion.contributor language="jet" id="JetCompletionContributor" order="after JetClassCompletionContributor"
|
||||||
implementationClass="org.jetbrains.jet.plugin.completion.JetCompletionContributor"/>
|
implementationClass="org.jetbrains.jet.plugin.completion.JetCompletionContributor"/>
|
||||||
|
|
||||||
<completion.contributor language="jet" implementationClass="org.jetbrains.jet.plugin.liveTemplates.JetLiveTemplateCompletionContributor" id="liveTemplates" order="first"/>
|
<completion.contributor language="jet" implementationClass="org.jetbrains.jet.plugin.liveTemplates.JetLiveTemplateCompletionContributor" id="liveTemplates" order="first"/>
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ public class JetClassCompletionContributor extends CompletionContributor {
|
|||||||
});
|
});
|
||||||
result.stopHere();
|
result.stopHere();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.stopHere();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
completeForReference(parameters, result, position, jetReference, session);
|
completeForReference(parameters, result, position, jetReference, session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent from adding reference variants from standard reference contributor
|
||||||
|
result.stopHere();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -88,9 +91,6 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
@NotNull JetSimpleNameReference jetReference,
|
@NotNull JetSimpleNameReference jetReference,
|
||||||
@NotNull CompletionSession session
|
@NotNull CompletionSession session
|
||||||
) {
|
) {
|
||||||
// Prevent from adding reference variants from standard reference contributor
|
|
||||||
result.stopHere();
|
|
||||||
|
|
||||||
if (isOnlyKeywordCompletion(position)) {
|
if (isOnlyKeywordCompletion(position)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.completion;
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.completion.*;
|
||||||
|
import com.intellij.codeInsight.lookup.LookupElement;
|
||||||
|
import com.intellij.patterns.ElementPattern;
|
||||||
|
import com.intellij.patterns.PlatformPatterns;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.util.Consumer;
|
||||||
|
import com.intellij.util.ProcessingContext;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special contributor for getting completion of type for extensions receiver.
|
||||||
|
*
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetExtensionReceiverTypeContributor extends CompletionContributor {
|
||||||
|
private static class ReceiverTypeCompletionProvider extends CompletionProvider<CompletionParameters> {
|
||||||
|
@Override
|
||||||
|
protected void addCompletions(@NotNull CompletionParameters parameters,
|
||||||
|
ProcessingContext context,
|
||||||
|
final @NotNull CompletionResultSet result
|
||||||
|
) {
|
||||||
|
if (parameters.getInvocationCount() > 0 || parameters.getCompletionType() == CompletionType.CLASS_NAME) {
|
||||||
|
JetClassCompletionContributor.addClasses(parameters, result, new Consumer<LookupElement>() {
|
||||||
|
@Override
|
||||||
|
public void consume(@NotNull LookupElement element) {
|
||||||
|
result.addElement(element);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
result.stopHere();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final ElementPattern<? extends PsiElement> ACTIVATION_PATTERN =
|
||||||
|
PlatformPatterns.psiElement().afterLeaf(JetTokens.FUN_KEYWORD.toString(), JetTokens.VAL_KEYWORD.toString(),
|
||||||
|
JetTokens.VAR_KEYWORD.toString());
|
||||||
|
|
||||||
|
public JetExtensionReceiverTypeContributor() {
|
||||||
|
extend(CompletionType.BASIC, ACTIVATION_PATTERN, new ReceiverTypeCompletionProvider());
|
||||||
|
extend(CompletionType.CLASS_NAME, ACTIVATION_PATTERN, new ReceiverTypeCompletionProvider());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
class Test {
|
||||||
|
val Str<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// TIME: 1
|
||||||
|
// EXIST: String~(jet)
|
||||||
|
// EXIST: StringBuffer
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fun testing() {}
|
||||||
|
|
||||||
|
fun S<caret>
|
||||||
|
|
||||||
|
// Should complete types for receiver after explicit basic completion call
|
||||||
|
// TIME: 1
|
||||||
|
// EXIST: String
|
||||||
|
// EXIST: StringBuffer
|
||||||
|
// EXIST: Set
|
||||||
|
// ABSENT: testing
|
||||||
|
|
||||||
@@ -49,6 +49,14 @@ public class JetBasicCompletionTest extends JetCompletionTestBase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testExtensionFunReceiver() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExtensionForProperty() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testFromImports() {
|
public void testFromImports() {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user