use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testReactivityPerformance.
public void testReactivityPerformance() throws Throwable {
@NonNls String filePath = "/psi/resolve/Thinlet.java";
configureByFile(filePath);
type(' ');
CompletionContributor.forLanguage(getFile().getLanguage());
highlightErrors();
final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
int N = Math.max(5, Timings.adjustAccordingToMySpeed(80, false));
System.out.println("N = " + N);
final long[] interruptTimes = new long[N];
for (int i = 0; i < N; i++) {
codeAnalyzer.restart();
final int finalI = i;
final long start = System.currentTimeMillis();
final AtomicLong typingStart = new AtomicLong();
final AtomicReference<RuntimeException> exception = new AtomicReference<>();
Thread watcher = new Thread("reactivity watcher") {
@Override
public void run() {
while (true) {
final long start1 = typingStart.get();
if (start1 == -1)
break;
if (start1 == 0) {
try {
Thread.sleep(5);
} catch (InterruptedException e1) {
throw new RuntimeException(e1);
}
continue;
}
long elapsed = System.currentTimeMillis() - start1;
if (elapsed > 500) {
// too long, see WTF
String message = "Too long interrupt: " + elapsed + "; Progress: " + codeAnalyzer.getUpdateProgress() + "\n----------------------------";
dumpThreadsToConsole();
exception.set(new RuntimeException(message));
throw exception.get();
}
}
}
};
try {
PsiFile file = getFile();
Editor editor = getEditor();
Project project = file.getProject();
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project);
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
watcher.start();
Runnable interrupt = () -> {
long now = System.currentTimeMillis();
if (now - start < 100) {
// wait to engage all highlighting threads
return;
}
typingStart.set(System.currentTimeMillis());
type(' ');
long end = System.currentTimeMillis();
long interruptTime = end - now;
interruptTimes[finalI] = interruptTime;
assertTrue(codeAnalyzer.getUpdateProgress().isCanceled());
System.out.println(interruptTime);
throw new ProcessCanceledException();
};
long hiStart = System.currentTimeMillis();
codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, false, interrupt);
long hiEnd = System.currentTimeMillis();
DaemonProgressIndicator progress = codeAnalyzer.getUpdateProgress();
String message = "Should have been interrupted: " + progress + "; Elapsed: " + (hiEnd - hiStart) + "ms";
dumpThreadsToConsole();
throw new RuntimeException(message);
} catch (ProcessCanceledException ignored) {
} finally {
// cancel watcher
typingStart.set(-1);
watcher.join();
if (exception.get() != null) {
throw exception.get();
}
}
}
long ave = ArrayUtil.averageAmongMedians(interruptTimes, 3);
System.out.println("Average among the N/3 median times: " + ave + "ms");
assertTrue(ave < 300);
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testCancelsItSelfOnTypingInAlienProject.
public void testCancelsItSelfOnTypingInAlienProject() throws Throwable {
String body = StringUtil.repeat("\"String field = null;\"\n", 1000);
configureByText(StdFileTypes.JAVA, "class X{ void f() {" + body + "<caret>\n} }");
File temp = createTempDirectory();
final Project alienProject = createProject(temp + "/alien.ipr", DebugUtil.currentStackTrace());
boolean succ2 = ProjectManagerEx.getInstanceEx().openProject(alienProject);
assertTrue(succ2);
DaemonProgressIndicator.setDebug(true);
try {
Module alienModule = doCreateRealModuleIn("x", alienProject, getModuleType());
final VirtualFile alienRoot = PsiTestUtil.createTestProjectStructure(alienProject, alienModule, myFilesToDelete);
OpenFileDescriptor alienDescriptor = new WriteAction<OpenFileDescriptor>() {
@Override
protected void run(@NotNull Result<OpenFileDescriptor> result) throws Throwable {
VirtualFile alienFile = alienRoot.createChildData(this, "X.java");
setFileText(alienFile, "class Alien { }");
OpenFileDescriptor alienDescriptor = new OpenFileDescriptor(alienProject, alienFile);
result.setResult(alienDescriptor);
}
}.execute().throwException().getResultObject();
FileEditorManager fe = FileEditorManager.getInstance(alienProject);
final Editor alienEditor = fe.openTextEditor(alienDescriptor, false);
((EditorImpl) alienEditor).setCaretActive();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
PsiDocumentManager.getInstance(alienProject).commitAllDocuments();
// start daemon in main project. should check for its cancel when typing in alien
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(getEditor());
DaemonCodeAnalyzerImpl di = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
final boolean[] checked = { false };
di.runPasses(getFile(), getEditor().getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, true, () -> {
if (checked[0])
return;
checked[0] = true;
typeInAlienEditor(alienEditor, 'x');
});
} catch (ProcessCanceledException ignored) {
//System.out.println("indicator = " + indicator[0]);
return;
} finally {
ProjectManagerEx.getInstanceEx().closeAndDispose(alienProject);
}
fail("must throw PCE");
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method _testCaretMovementDoesNotRestartHighlighting.
public void _testCaretMovementDoesNotRestartHighlighting() throws Exception {
configureByText(JavaFileType.INSTANCE, "class X { int f = \"error\"; int f() { int gg<caret> = 11; return 0;} }");
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(getEditor());
final DaemonCodeAnalyzerImpl di = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
final AtomicReference<ProgressIndicator> indicator = new AtomicReference<>();
final List<HighlightInfo> errors = filter(di.runPasses(getFile(), getEditor().getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, false, () -> {
if (indicator.get() == null) {
indicator.set(di.getUpdateProgress());
}
assertSame(indicator.get(), di.getUpdateProgress());
caretRight();
if (getEditor().getCaretModel().getOffset() == getEditor().getDocument().getTextLength() - 1) {
getEditor().getCaretModel().moveToOffset(0);
}
}), HighlightSeverity.ERROR);
assertEquals(1, errors.size());
assertEquals("Incompatible types. Found: 'java.lang.String', required: 'int'", errors.get(0).getDescription());
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testTypingLatencyPerformance.
public void testTypingLatencyPerformance() throws Throwable {
@NonNls String filePath = "/psi/resolve/ThinletBig.java";
configureByFile(filePath);
type(' ');
CompletionContributor.forLanguage(getFile().getLanguage());
long s = System.currentTimeMillis();
highlightErrors();
long e = System.currentTimeMillis();
//System.out.println("Hi elapsed: "+(e-s));
final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
int N = Math.max(5, Timings.adjustAccordingToMySpeed(80, false));
System.out.println("N = " + N);
final long[] interruptTimes = new long[N];
for (int i = 0; i < N; i++) {
codeAnalyzer.restart();
final int finalI = i;
final long start = System.currentTimeMillis();
Runnable interrupt = () -> {
long now = System.currentTimeMillis();
if (now - start < 100) {
// wait to engage all highlighting threads
return;
}
type(' ');
long end = System.currentTimeMillis();
long interruptTime = end - now;
interruptTimes[finalI] = interruptTime;
assertTrue(codeAnalyzer.getUpdateProgress().isCanceled());
System.out.println(interruptTime);
throw new ProcessCanceledException();
};
try {
PsiFile file = getFile();
Editor editor = getEditor();
Project project = file.getProject();
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project);
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, false, interrupt);
throw new RuntimeException("should have been interrupted");
} catch (ProcessCanceledException ignored) {
}
backspace();
//highlightErrors();
}
long mean = ArrayUtil.averageAmongMedians(interruptTimes, 3);
long avg = Arrays.stream(interruptTimes).sum() / interruptTimes.length;
long max = Arrays.stream(interruptTimes).max().getAsLong();
long min = Arrays.stream(interruptTimes).min().getAsLong();
System.out.println("Average among the N/3 median times: " + mean + "ms; max: " + max + "; min:" + min + "; avg: " + avg);
assertTrue(String.valueOf(mean), mean < 10);
}
use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testAllPassesFinishAfterInterruptOnTyping_Performance.
public void testAllPassesFinishAfterInterruptOnTyping_Performance() throws Throwable {
@NonNls String filePath = "/psi/resolve/Thinlet.java";
configureByFile(filePath);
highlightErrors();
final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
type(' ');
for (int i = 0; i < 100; i++) {
backspace();
codeAnalyzer.restart();
try {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
PsiFile file = getFile();
Editor editor = getEditor();
Project project = file.getProject();
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project);
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, true, () -> type(' '));
} catch (ProcessCanceledException ignored) {
codeAnalyzer.waitForTermination();
continue;
}
fail("PCE must have been thrown");
}
}
Aggregations