mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
a more unified API for autopopup invocation
This commit is contained in:
@@ -90,17 +90,12 @@ public class AutoPopupController implements Disposable {
|
||||
|
||||
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
|
||||
if (settings.AUTO_POPUP_COMPLETION_LOOKUP) {
|
||||
final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, myProject);
|
||||
if (file == null) return;
|
||||
if (PsiUtilBase.getPsiFileInEditor(editor, myProject) == null) return;
|
||||
final Runnable request = new Runnable(){
|
||||
public void run(){
|
||||
if (myProject.isDisposed()) return;
|
||||
if (editor.isDisposed()) return;
|
||||
|
||||
//PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
if (!file.isValid()) return;
|
||||
|
||||
CompletionAutoPopupHandler.invokeAutoPopupCompletion(myProject, editor, condition);
|
||||
if (!myProject.isDisposed() && !editor.isDisposed()) {
|
||||
CompletionAutoPopupHandler.scheduleAutoPopup(editor, condition);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -591,7 +591,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
|
||||
public void scheduleRestart() {
|
||||
if (isAutopopupCompletion() && hideAutopopupIfMeaningless()) {
|
||||
CompletionAutoPopupHandler.scheduleAutoPopup(getProject(), myEditor);
|
||||
CompletionAutoPopupHandler.scheduleAutoPopup(myEditor, null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+12
-38
@@ -35,6 +35,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.PsiDocumentManagerImpl;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -82,59 +83,32 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
|
||||
scheduleAutoPopup(project, editor);
|
||||
scheduleAutoPopup(editor, null);
|
||||
return Result.STOP;
|
||||
}
|
||||
|
||||
public static void scheduleAutoPopup(final Project project, final Editor editor) {
|
||||
public static void scheduleAutoPopup(final Editor editor, @Nullable final Condition<PsiFile> condition) {
|
||||
final Project project = editor.getProject();
|
||||
assert project != null;
|
||||
final CompletionPhase.AutoPopupAlarm phase = new CompletionPhase.AutoPopupAlarm(false, editor);
|
||||
CompletionServiceImpl.setCompletionPhase(phase);
|
||||
|
||||
final Runnable request = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (phase.isExpired()) return;
|
||||
invokeCompletion(CompletionType.BASIC, true, project, editor, 0);
|
||||
}
|
||||
};
|
||||
AutoPopupController.getInstance(project).invokeAutoPopupRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runLaterWithCommitted(project, editor.getDocument(), request);
|
||||
}
|
||||
}, CodeInsightSettings.getInstance().AUTO_LOOKUP_DELAY);
|
||||
}
|
||||
|
||||
public static void invokeAutoPopupCompletion(final Project project, final Editor editor, final Condition<PsiFile> condition) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
|
||||
final Document document = editor.getDocument();
|
||||
final long beforeStamp = document.getModificationStamp();
|
||||
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
documentManager.cancelAndRunWhenAllCommitted("start completion when all docs committed", new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long afterStamp = document.getModificationStamp();
|
||||
if (beforeStamp != afterStamp) {
|
||||
// no luck, will try later
|
||||
return;
|
||||
}
|
||||
// later because we may end up in write action here if there was a synchronous commit
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
runLaterWithCommitted(project, editor.getDocument(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long afterStamp = document.getModificationStamp();
|
||||
if (beforeStamp != afterStamp) {
|
||||
// no luck, will try later
|
||||
return;
|
||||
}
|
||||
PsiFile file = documentManager.getPsiFile(document);
|
||||
if (phase.isExpired()) return;
|
||||
|
||||
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
|
||||
if (file != null && condition != null && !condition.value(file)) return;
|
||||
|
||||
invokeCompletion(CompletionType.BASIC, true, project, editor, 0);
|
||||
}
|
||||
}, project.getDisposed());
|
||||
});
|
||||
}
|
||||
});
|
||||
}, CodeInsightSettings.getInstance().AUTO_LOOKUP_DELAY);
|
||||
}
|
||||
|
||||
public static void invokeCompletion(CompletionType completionType,
|
||||
|
||||
@@ -77,7 +77,7 @@ public class TypedHandler extends TypedActionHandlerBase {
|
||||
});
|
||||
lookup.appendPrefix(charTyped);
|
||||
if (lookup.isStartCompletionWhenNothingMatches() && lookup.getItems().isEmpty()) {
|
||||
CompletionAutoPopupHandler.scheduleAutoPopup(editor.getProject(), editor);
|
||||
CompletionAutoPopupHandler.scheduleAutoPopup(editor, null);
|
||||
}
|
||||
|
||||
AutoHardWrapHandler.getInstance().wrapLineIfNecessary(editor, dataContext, modificationStamp);
|
||||
|
||||
Reference in New Issue
Block a user