use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class OutdatedVersionNotifier method updateAllEditors.
private void updateAllEditors() {
if (myCache.getCachedIncomingChanges() == null) {
requestLoadIncomingChanges();
return;
}
debug("Updating editors");
final VirtualFile[] files = myFileEditorManager.getOpenFiles();
for (VirtualFile file : files) {
final Pair<CommittedChangeList, Change> pair = myCache.getIncomingChangeList(file);
final FileEditor[] fileEditors = myFileEditorManager.getEditors(file);
for (FileEditor editor : fileEditors) {
final OutdatedRevisionPanel oldPanel = editor.getUserData(PANEL_KEY);
if (pair != null) {
if (oldPanel != null) {
oldPanel.setChangeList(pair.first, pair.second);
} else {
initPanel(pair.first, pair.second, editor);
}
} else if (oldPanel != null) {
myFileEditorManager.removeTopComponent(editor, oldPanel);
editor.putUserData(PANEL_KEY, null);
}
}
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class LargeFileNotificationProvider method createNotificationPanel.
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
if (!(fileEditor instanceof LargeFileEditorProvider.LargeTextFileEditor))
return null;
Editor editor = ((TextEditor) fileEditor).getEditor();
Project project = editor.getProject();
if (project == null || editor.getUserData(HIDDEN_KEY) != null || PropertiesComponent.getInstance().isTrueValue(DISABLE_KEY)) {
return null;
}
EditorNotificationPanel panel = new EditorNotificationPanel();
panel.createActionLabel("Hide notification", () -> {
editor.putUserData(HIDDEN_KEY, "true");
update(file, project);
});
panel.createActionLabel("Don't show again", () -> {
PropertiesComponent.getInstance().setValue(DISABLE_KEY, "true");
update(file, project);
});
return panel.text(String.format("This file is too large for editing (%s). Read only preview mode is activated.", StringUtil.formatFileSize(file.getLength())));
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class DaemonCodeAnalyzerImpl method runPasses.
@NotNull
@TestOnly
List<HighlightInfo> runPasses(@NotNull PsiFile file, @NotNull Document document, @NotNull List<TextEditor> textEditors, @NotNull int[] toIgnore, boolean canChangeDocument, @Nullable final Runnable callbackWhileWaiting) throws ProcessCanceledException {
assert myInitialized;
assert !myDisposed;
ApplicationEx application = ApplicationManagerEx.getApplicationEx();
application.assertIsDispatchThread();
if (application.isWriteAccessAllowed()) {
throw new AssertionError("Must not start highlighting from within write action, or deadlock is imminent");
}
DaemonProgressIndicator.setDebug(!ApplicationInfoImpl.isInStressTest());
((FileTypeManagerImpl) FileTypeManager.getInstance()).drainReDetectQueue();
// pump first so that queued event do not interfere
UIUtil.dispatchAllInvocationEvents();
// refresh will fire write actions interfering with highlighting
while (RefreshQueueImpl.isRefreshInProgress() || HeavyProcessLatch.INSTANCE.isRunning()) {
UIUtil.dispatchAllInvocationEvents();
}
long dstart = System.currentTimeMillis();
while (mustWaitForSmartMode && DumbService.getInstance(myProject).isDumb()) {
if (System.currentTimeMillis() > dstart + 100000) {
throw new IllegalStateException("Timeout waiting for smart mode. If you absolutely want to be dumb, please use DaemonCodeAnalyzerImpl.mustWaitForSmartMode(false).");
}
UIUtil.dispatchAllInvocationEvents();
}
UIUtil.dispatchAllInvocationEvents();
Project project = file.getProject();
FileStatusMap fileStatusMap = getFileStatusMap();
fileStatusMap.allowDirt(canChangeDocument);
Map<FileEditor, HighlightingPass[]> map = new HashMap<>();
for (TextEditor textEditor : textEditors) {
if (textEditor instanceof TextEditorImpl) {
try {
((TextEditorImpl) textEditor).waitForLoaded(10, TimeUnit.SECONDS);
} catch (TimeoutException e) {
throw new RuntimeException(textEditor + " has not completed loading in 10 seconds");
}
}
TextEditorBackgroundHighlighter highlighter = (TextEditorBackgroundHighlighter) textEditor.getBackgroundHighlighter();
if (highlighter == null) {
Editor editor = textEditor.getEditor();
throw new RuntimeException("Null highlighter from " + textEditor + "; loaded: " + AsyncEditorLoader.isEditorLoaded(editor));
}
final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore);
HighlightingPass[] array = passes.toArray(new HighlightingPass[passes.size()]);
assert array.length != 0 : "Highlighting is disabled for the file " + file;
map.put(textEditor, array);
}
for (int ignoreId : toIgnore) {
fileStatusMap.markFileUpToDate(document, ignoreId);
}
myUpdateRunnableFuture.cancel(false);
final DaemonProgressIndicator progress = createUpdateProgress();
myPassExecutorService.submitPasses(map, progress);
try {
long start = System.currentTimeMillis();
while (progress.isRunning() && System.currentTimeMillis() < start + 5 * 60 * 1000) {
wrap(() -> {
progress.checkCanceled();
if (callbackWhileWaiting != null) {
callbackWhileWaiting.run();
}
waitInOtherThread(50, canChangeDocument);
UIUtil.dispatchAllInvocationEvents();
Throwable savedException = PassExecutorService.getSavedException(progress);
if (savedException != null)
throw savedException;
});
}
if (progress.isRunning() && !progress.isCanceled()) {
throw new RuntimeException("Highlighting still running after " + (System.currentTimeMillis() - start) / 1000 + " seconds.\n" + ThreadDumper.dumpThreadsToString());
}
final HighlightingSessionImpl session = (HighlightingSessionImpl) HighlightingSessionImpl.getOrCreateHighlightingSession(file, textEditors.get(0).getEditor(), progress, null);
wrap(() -> {
if (!waitInOtherThread(60000, canChangeDocument)) {
throw new TimeoutException("Unable to complete in 60s");
}
session.waitForHighlightInfosApplied();
});
UIUtil.dispatchAllInvocationEvents();
UIUtil.dispatchAllInvocationEvents();
assert progress.isCanceled() && progress.isDisposed();
return getHighlights(document, null, project);
} finally {
DaemonProgressIndicator.setDebug(false);
fileStatusMap.allowDirt(true);
waitForTermination();
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class DaemonCodeAnalyzerImpl method cleanFileLevelHighlights.
@Override
public void cleanFileLevelHighlights(@NotNull Project project, final int group, PsiFile psiFile) {
if (psiFile == null)
return;
FileViewProvider provider = psiFile.getViewProvider();
VirtualFile vFile = provider.getVirtualFile();
final FileEditorManager manager = FileEditorManager.getInstance(project);
for (FileEditor fileEditor : manager.getEditors(vFile)) {
final List<HighlightInfo> infos = fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS);
if (infos == null)
continue;
List<HighlightInfo> infosToRemove = new ArrayList<>();
for (HighlightInfo info : infos) {
if (info.getGroup() == group) {
manager.removeTopComponent(fileEditor, info.fileLevelComponent);
infosToRemove.add(info);
}
}
infos.removeAll(infosToRemove);
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class PassExecutorService method findOrCreatePredecessorPass.
private ScheduledPass findOrCreatePredecessorPass(@NotNull FileEditor fileEditor, @NotNull Map<Pair<FileEditor, Integer>, ScheduledPass> toBeSubmitted, @NotNull List<TextEditorHighlightingPass> textEditorHighlightingPasses, @NotNull List<ScheduledPass> freePasses, @NotNull List<ScheduledPass> dependentPasses, @NotNull DaemonProgressIndicator updateProgress, @NotNull AtomicInteger myThreadsToStartCountdown, final int predecessorId) {
Pair<FileEditor, Integer> predKey = Pair.create(fileEditor, predecessorId);
ScheduledPass predecessor = toBeSubmitted.get(predKey);
if (predecessor == null) {
TextEditorHighlightingPass textEditorPass = findPassById(predecessorId, textEditorHighlightingPasses);
predecessor = textEditorPass == null ? null : createScheduledPass(fileEditor, textEditorPass, toBeSubmitted, textEditorHighlightingPasses, freePasses, dependentPasses, updateProgress, myThreadsToStartCountdown);
}
return predecessor;
}
Aggregations