fix completion not launching insert handler after explicit common prefix insertion

This commit is contained in:
peter
2011-03-11 16:11:21 +01:00
parent 1c50268183
commit da18adc88d
6 changed files with 55 additions and 43 deletions

View File

@@ -0,0 +1,5 @@
public class SomeClass {
void foo(String param) {
if (param.<caret>)
}
}

View File

@@ -0,0 +1,5 @@
public class SomeClass {
void foo(String param) {
if (param.equals(<caret>))
}
}

View File

@@ -858,6 +858,16 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
assertStringItems("myField1", "myField2");
}
public void testAfterCommonPrefix() throws Throwable {
configure()
type 'eq'
assertStringItems("equals", "equalsIgnoreCase");
complete()
assertStringItems("equals", "equalsIgnoreCase");
type '('
checkResult()
}
public void testClassNameInsideIdentifierInIf() throws Throwable {
configure()
type '\n'

View File

@@ -119,21 +119,19 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
psiFile.putUserData(PsiFileEx.BATCH_REFERENCE_PROCESSING, Boolean.TRUE);
CompletionPhase phase = CompletionServiceImpl.getCompletionPhase();
CompletionProgressIndicator indicator = phase.newCompletionStarted();
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
if (indicator != null) {
boolean repeated = indicator.isRepeatedInvocation(myCompletionType, editor);
if (repeated && !indicator.isRunning() && (!isAutocompleteCommonPrefixOnInvocation() || indicator.fillInCommonPrefix(true))) {
CompletionProgressIndicator oldIndicator = phase.indicator;
if (oldIndicator != null) {
boolean repeated = oldIndicator.isRepeatedInvocation(myCompletionType, editor);
if (repeated && isAutocompleteCommonPrefixOnInvocation() && phase instanceof CompletionPhase.ItemsCalculated && oldIndicator.fillInCommonPrefix(true)) {
return;
}
oldIndicator.closeAndFinish(false);
if (repeated) {
time = Math.max(indicator.getParameters().getInvocationCount() + 1, 2);
indicator.restorePrefix(phase);
time = phase.handleRepeatedInvocation(time);
}
}
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
if (time > 1) {
if (myCompletionType == CompletionType.CLASS_NAME) {

View File

@@ -43,8 +43,8 @@ import java.util.EventObject;
public abstract class CompletionPhase implements Disposable {
public static final CompletionPhase NoCompletion = new CompletionPhase(null) {
@Override
public CompletionProgressIndicator newCompletionStarted() {
return null;
public int handleRepeatedInvocation(int time) {
return time;
}
};
@@ -58,8 +58,7 @@ public abstract class CompletionPhase implements Disposable {
public void dispose() {
}
@Nullable
public abstract CompletionProgressIndicator newCompletionStarted();
public abstract int handleRepeatedInvocation(int time);
public static class AutoPopupAlarm extends CompletionPhase {
public AutoPopupAlarm() {
@@ -67,8 +66,8 @@ public abstract class CompletionPhase implements Disposable {
}
@Override
public CompletionProgressIndicator newCompletionStarted() {
return null;
public int handleRepeatedInvocation(int time) {
return time;
}
}
public static class Synchronous extends CompletionPhase {
@@ -77,7 +76,7 @@ public abstract class CompletionPhase implements Disposable {
}
@Override
public CompletionProgressIndicator newCompletionStarted() {
public int handleRepeatedInvocation(int time) {
throw new UnsupportedOperationException("Not implemented");
}
}
@@ -96,9 +95,8 @@ public abstract class CompletionPhase implements Disposable {
}
@Override
public CompletionProgressIndicator newCompletionStarted() {
indicator.closeAndFinish(false);
return indicator;
public int handleRepeatedInvocation(int time) {
return indicator.restorePrefix(null);
}
}
public static class ItemsCalculated extends CompletionPhase {
@@ -110,9 +108,8 @@ public abstract class CompletionPhase implements Disposable {
}
@Override
public CompletionProgressIndicator newCompletionStarted() {
indicator.closeAndFinish(false);
return indicator;
public int handleRepeatedInvocation(int time) {
return indicator.restorePrefix(null);
}
}
public static class Restarted extends CompletionPhase {
@@ -121,13 +118,12 @@ public abstract class CompletionPhase implements Disposable {
}
@Override
public CompletionProgressIndicator newCompletionStarted() {
indicator.closeAndFinish(false);
return indicator;
public int handleRepeatedInvocation(int time) {
return indicator.restorePrefix(null);
}
}
public static class ZombiePhase extends CompletionPhase {
public static abstract class ZombiePhase extends CompletionPhase {
protected ZombiePhase(@Nullable final LightweightHint hint, final CompletionProgressIndicator indicator) {
super(indicator);
@@ -179,10 +175,6 @@ public abstract class CompletionPhase implements Disposable {
});
}
@Override
public CompletionProgressIndicator newCompletionStarted() {
return indicator;
}
}
public static class InsertedSingleItem extends ZombiePhase {
@@ -192,21 +184,23 @@ public abstract class CompletionPhase implements Disposable {
super(null, indicator);
this.restorePrefix = restorePrefix;
}
@Override
public int handleRepeatedInvocation(int time) {
return indicator.restorePrefix(restorePrefix);
}
}
public static class NoSuggestionsHint extends ZombiePhase {
public NoSuggestionsHint(@Nullable LightweightHint hint, CompletionProgressIndicator indicator) {
super(hint, indicator);
}
}
public static class PossiblyDisturbingAutoPopup extends CompletionPhase {
public PossiblyDisturbingAutoPopup(CompletionProgressIndicator indicator) {
super(indicator);
}
@Override
public CompletionProgressIndicator newCompletionStarted() {
return null;
public int handleRepeatedInvocation(int time) {
return indicator.restorePrefix(null);
}
}
public static class EmptyAutoPopup extends CompletionPhase {
public final Editor editor;
@@ -302,8 +296,8 @@ public abstract class CompletionPhase implements Disposable {
}
@Override
public CompletionProgressIndicator newCompletionStarted() {
return null;
public int handleRepeatedInvocation(int time) {
return time;
}
}

View File

@@ -526,19 +526,19 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
return aBoolean.booleanValue();
}
public void restorePrefix(final CompletionPhase zombie) {
public int restorePrefix(final Runnable customRestore) {
new WriteCommandAction(getProject(), getCompletionCommandName()) {
@Override
protected void run(Result result) throws Throwable {
setMergeCommand();
if (zombie instanceof CompletionPhase.InsertedSingleItem) {
((CompletionPhase.InsertedSingleItem)zombie).restorePrefix.run();
if (customRestore != null) {
customRestore.run();
}
getLookup().restorePrefix();
}
}.execute();
return Math.max(getParameters().getInvocationCount() + 1, 2);
}
public Editor getEditor() {