Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.gabrielbbaldez.stacktale.idea;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
Expand All @@ -8,6 +9,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Alarm;
Expand All @@ -34,6 +36,7 @@ interface Listener {
void reportsChanged(@Nullable Path log, @NotNull List<StReport> reports);
}

private static final Logger LOG = Logger.getInstance(StacktaleReportService.class);
private final Project project;
private final Alarm alarm;
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
Expand Down Expand Up @@ -70,13 +73,19 @@ void refreshNow() {
private void poll() {
if (disposed || project.isDisposed()) return;

refresh(false);

if (!disposed && !project.isDisposed()) {
// Read the interval here rather than capturing it once: every tick arms the next
// one, so a changed setting applies on the following tick instead of only after
// the project is reopened.
alarm.addRequest(this::poll, settings().pollMillis());
try {
refresh(false);
} catch (ProcessCanceledException pce) {
throw pce;
} catch (Throwable t) {
LOG.warn("Stacktale refresh failed; will retry on the next poll", t);
} finally {
if (!disposed && !project.isDisposed()) {
// Read the interval here rather than capturing it once: every tick arms the next
// one, so a changed setting applies on the following tick instead of only after
// the project is reopened.
alarm.addRequest(this::poll, settings().pollMillis());
}
}
}

Expand Down