Fix project completion in the beginning
This commit is contained in:
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
|||||||
import org.jetbrains.jet.lang.psi.JetNamespaceHeader;
|
import org.jetbrains.jet.lang.psi.JetNamespaceHeader;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||||
|
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs completion in package directive. Should suggest only packages and avoid showing fake package produced by
|
* Performs completion in package directive. Should suggest only packages and avoid showing fake package produced by
|
||||||
@@ -59,20 +60,16 @@ public class JetPackagesContributor extends CompletionContributor {
|
|||||||
|
|
||||||
final PsiReference ref = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
|
final PsiReference ref = parameters.getPosition().getContainingFile().findReferenceAt(parameters.getOffset());
|
||||||
|
|
||||||
if (ref != null) {
|
if (ref instanceof JetSimpleNameReference) {
|
||||||
|
JetSimpleNameReference simpleNameReference = (JetSimpleNameReference)ref;
|
||||||
|
|
||||||
// For package there will be a wrong prefix matcher with the whole package directive as prefix
|
String name = simpleNameReference.getExpression().getText();
|
||||||
PsiElement nameIdentifier = namespaceHeader.getNameIdentifier();
|
if (name == null) {
|
||||||
if (nameIdentifier == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(nameIdentifier.getTextOffset() <= parameters.getOffset())) {
|
int prefixLength = parameters.getOffset() - simpleNameReference.getExpression().getTextOffset();
|
||||||
return;
|
result = result.withPrefixMatcher(new PlainPrefixMatcher(name.substring(0, prefixLength)));
|
||||||
}
|
|
||||||
|
|
||||||
int prefixLength = parameters.getOffset() - nameIdentifier.getTextOffset();
|
|
||||||
result = result.withPrefixMatcher(new PlainPrefixMatcher(nameIdentifier.getText().substring(0, prefixLength)));
|
|
||||||
|
|
||||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(
|
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(
|
||||||
(JetFile)namespaceHeader.getContainingFile())
|
(JetFile)namespaceHeader.getContainingFile())
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package kttesting<caret>.util
|
||||||
|
|
||||||
|
// Test that there won't be package with completion fake suffix
|
||||||
|
|
||||||
|
// NUMBER: 0
|
||||||
@@ -105,6 +105,10 @@ public class JetBasicCompletionTest extends JetCompletionTestBase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInPackageBegin() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
public void testInTypeAnnotation() {
|
public void testInTypeAnnotation() {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,13 +64,22 @@ public abstract class JetCompletionTestBase extends LightCompletionTestCase {
|
|||||||
ExpectedCompletionUtils.CompletionProposal[] unexpected = completionUtils.itemsShouldAbsent(fileText);
|
ExpectedCompletionUtils.CompletionProposal[] unexpected = completionUtils.itemsShouldAbsent(fileText);
|
||||||
Integer itemsNumber = completionUtils.getExpectedNumber(fileText);
|
Integer itemsNumber = completionUtils.getExpectedNumber(fileText);
|
||||||
|
|
||||||
assertTrue("Should be some assertions about completion", expected.length != 0 || unexpected.length != 0 || itemsNumber != null);
|
assertTrue("Should be some assertions about completion",
|
||||||
|
expected.length != 0 || unexpected.length != 0 || itemsNumber != null);
|
||||||
|
|
||||||
|
if (myItems == null) {
|
||||||
|
myItems = new LookupElement[0];
|
||||||
|
}
|
||||||
|
|
||||||
ExpectedCompletionUtils.assertContainsRenderedItems(expected, myItems);
|
ExpectedCompletionUtils.assertContainsRenderedItems(expected, myItems);
|
||||||
ExpectedCompletionUtils.assertNotContainsRenderedItems(unexpected, myItems);
|
ExpectedCompletionUtils.assertNotContainsRenderedItems(unexpected, myItems);
|
||||||
|
|
||||||
if (itemsNumber != null) {
|
if (itemsNumber != null) {
|
||||||
assertEquals("Invalid number of completion items", itemsNumber.intValue(), myItems.length);
|
assertEquals(
|
||||||
|
String.format(
|
||||||
|
"Invalid number of completion items: %s",
|
||||||
|
ExpectedCompletionUtils.listToString(ExpectedCompletionUtils.getItemsInformation(myItems))),
|
||||||
|
itemsNumber.intValue(), myItems.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -78,9 +87,8 @@ public abstract class JetCompletionTestBase extends LightCompletionTestCase {
|
|||||||
ConfigRuntimeUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
|
ConfigRuntimeUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
} catch (Exception e) {
|
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,7 +110,7 @@ public abstract class JetCompletionTestBase extends LightCompletionTestCase {
|
|||||||
protected void complete(final int time) {
|
protected void complete(final int time) {
|
||||||
new CodeCompletionHandlerBase(type, false, false, true).invokeCompletion(getProject(), getEditor(), time, false);
|
new CodeCompletionHandlerBase(type, false, false, true).invokeCompletion(getProject(), getEditor(), time, false);
|
||||||
|
|
||||||
LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
|
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor);
|
||||||
myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
|
myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
|
||||||
myPrefix = lookup == null ? null : lookup.itemPattern(lookup.getItems().get(0));
|
myPrefix = lookup == null ? null : lookup.itemPattern(lookup.getItems().get(0));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user