+++ /dev/null
-/*
- * Copyright 2000-2015 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.openapi.project;
-
-import org.jetbrains.annotations.NotNull;
-
-/**
- * A helper class for {@link DumbService}
- */
-interface DumbPermissionService {
-
- void allowStartingDumbModeInside(@NotNull final DumbModePermission permission, @NotNull Runnable runnable);
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2015 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.openapi.project;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * @author peter
- */
-public class DumbPermissionServiceImpl implements DumbPermissionService {
- private final ThreadLocal<DumbModePermission> myPermission = new ThreadLocal<>();
-
- @Override
- public void allowStartingDumbModeInside(@NotNull DumbModePermission permission, @NotNull Runnable runnable) {
- DumbModePermission prev = myPermission.get();
- if (prev == DumbModePermission.MAY_START_MODAL && permission == DumbModePermission.MAY_START_BACKGROUND) {
- runnable.run();
- return;
- }
-
- myPermission.set(permission);
- try {
- runnable.run();
- }
- finally {
- if (prev == null) {
- myPermission.remove();
- } else {
- myPermission.set(prev);
- }
- }
- }
-
- @Nullable
- public DumbModePermission getPermission() {
- return myPermission.get();
- }
-}
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.*;
import com.intellij.openapi.application.impl.ApplicationImpl;
-import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
public class DumbServiceImpl extends DumbService implements Disposable, ModificationTracker {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.project.DumbServiceImpl");
- private static final NotNullLazyValue<DumbPermissionServiceImpl> ourPermissionService = NotNullLazyValue.createValue(
- () -> (DumbPermissionServiceImpl)ServiceManager.getService(DumbPermissionService.class));
private static Throwable ourForcedTrace;
private final AtomicReference<State> myState = new AtomicReference<>(State.SMART);
private volatile Throwable myDumbStart;
}
else {
myState.set(State.WAITING_FOR_FINISH);
- updateFinished(true);
+ updateFinished();
}
}
}
}
- @Nullable
- public static DumbModePermission getExplicitPermission() {
- return ourPermissionService.getValue().getPermission();
- }
-
@NotNull
public static AccessToken forceDumbModeStartTrace(@NotNull Throwable trace) {
ApplicationManager.getApplication().assertIsDispatchThread();
};
}
- private void queueUpdateFinished(boolean modal) {
+ private void queueUpdateFinished() {
if (myState.compareAndSet(State.RUNNING_DUMB_TASKS, State.WAITING_FOR_FINISH)) {
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(
() -> TransactionGuard.getInstance().submitTransaction(myProject, myDumbStartTransaction, () ->
WriteAction.run(
- () -> updateFinished(modal))));
+ () -> updateFinished())));
}
}
- private void updateFinished(boolean modal) {
+ private void updateFinished() {
synchronized (myRunWhenSmartQueue) {
if (!myState.compareAndSet(State.WAITING_FOR_FINISH, State.SMART)) {
return;
if (ApplicationManager.getApplication().isInternal()) LOG.info("updateFinished");
- // some listeners might start yet another dumb mode
- // allow that whatever the current modality is, because it won't harm anyone
- allowStartingDumbModeInside(modal ? DumbModePermission.MAY_START_MODAL : DumbModePermission.MAY_START_BACKGROUND,
- this::notifyUpdateFinished);
+ notifyUpdateFinished();
}
private void notifyUpdateFinished() {
private void showModalProgress() {
try {
((ApplicationImpl)ApplicationManager.getApplication()).executeSuspendingWriteAction(myProject, IdeBundle.message("progress.indexing"), () ->
- runBackgroundProcess(ProgressManager.getInstance().getProgressIndicator(), true));
+ runBackgroundProcess(ProgressManager.getInstance().getProgressIndicator()));
}
finally {
if (myState.get() != State.SMART) {
if (myState.get() != State.WAITING_FOR_FINISH) throw new AssertionError(myState.get());
- WriteAction.run(() -> updateFinished(true));
+ WriteAction.run(() -> updateFinished());
}
}
}
ProgressManager.getInstance().run(new Task.Backgroundable(myProject, IdeBundle.message("progress.indexing"), false) {
@Override
public void run(@NotNull final ProgressIndicator visibleIndicator) {
- runBackgroundProcess(visibleIndicator, false);
+ runBackgroundProcess(visibleIndicator);
}
});
}
catch (Throwable e) {
- queueUpdateFinished(false);
+ queueUpdateFinished();
LOG.error("Failed to start background index update task", e);
}
}
- private void runBackgroundProcess(@NotNull final ProgressIndicator visibleIndicator, boolean modal) {
+ private void runBackgroundProcess(@NotNull final ProgressIndicator visibleIndicator) {
if (!myState.compareAndSet(State.SCHEDULED_TASKS, State.RUNNING_DUMB_TASKS)) return;
final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance();
DumbModeTask task = null;
while (true) {
- Pair<DumbModeTask, ProgressIndicatorEx> pair = getNextTask(task, modal);
+ Pair<DumbModeTask, ProgressIndicatorEx> pair = getNextTask(task);
if (pair == null) break;
task = pair.first;
}, taskIndicator);
}
- @Nullable private Pair<DumbModeTask, ProgressIndicatorEx> getNextTask(@Nullable final DumbModeTask prevTask, final boolean modal) {
+ @Nullable private Pair<DumbModeTask, ProgressIndicatorEx> getNextTask(@Nullable final DumbModeTask prevTask) {
final Ref<Pair<DumbModeTask, ProgressIndicatorEx>> result = Ref.create();
invokeAndWaitIfNeeded(() -> {
if (myProject.isDisposed()) return;
while (true) {
if (myUpdatesQueue.isEmpty()) {
- queueUpdateFinished(modal);
+ queueUpdateFinished();
return;
}