Search in sources :

Example 16 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class MacheteAnnotator method processMacheteGeneratedEntry.

@UIThreadUnsafe
private void processMacheteGeneratedEntry(MacheteGeneratedEntry macheteEntry, AnnotationHolder holder) {
    MacheteGeneratedBranch branch = macheteEntry.getBranch();
    PsiFile file = macheteEntry.getContainingFile();
    val branchNames = MacheteFileUtils.getBranchNamesForPsiFile(file);
    if (branchNames.isEmpty()) {
        if (!cantGetBranchesMessageWasShown) {
            UiThreadExecutionCompat.invokeLaterIfNeeded(NON_MODAL, () -> showCantGetBranchesMessage(file));
        }
        return;
    }
    cantGetBranchesMessageWasShown = false;
    val processedBranchName = branch.getText();
    if (!branchNames.contains(processedBranchName)) {
        holder.newAnnotation(HighlightSeverity.ERROR, format(getString("string.GitMachete.MacheteAnnotator.cannot-find-local-branch-in-repo"), processedBranchName)).range(branch).create();
    }
}
Also used : MacheteGeneratedBranch(com.virtuslab.gitmachete.frontend.file.grammar.MacheteGeneratedBranch) lombok.val(lombok.val) PsiFile(com.intellij.psi.PsiFile) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 17 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class MacheteCompletionContributor method fillCompletionVariants.

@Override
@UIThreadUnsafe
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
    PsiFile file = parameters.getOriginalFile();
    val branchNames = MacheteFileUtils.getBranchNamesForPsiFile(file);
    if (branchNames.isEmpty()) {
        return;
    }
    /**
     * {@link CompletionResultSet#stopHere} marks the result set as stopped.
     * Completion service calls contributors as long as everyone gets called or result set get marked as stopped.
     * The following call allows to avoid other contributor invocations (performance).
     *
     * See {@link com.intellij.codeInsight.completion.CompletionService#getVariantsFromContributors}
     */
    result.stopHere();
    String prefix = getCompletionPrefix(parameters);
    val matcher = new PlainPrefixMatcher(prefix, /* prefixMatchesOnly */
    true);
    val completionResultSet = result.caseInsensitive().withPrefixMatcher(matcher);
    for (String branchName : branchNames) {
        ProgressManager.checkCanceled();
        completionResultSet.addElement(LookupElementBuilder.create(branchName));
    }
}
Also used : lombok.val(lombok.val) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) PsiFile(com.intellij.psi.PsiFile) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 18 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class MacheteFileUtils method getBranchNamesForPsiFile.

@UIThreadUnsafe
public static List<String> getBranchNamesForPsiFile(PsiFile psiFile) {
    val project = psiFile.getProject();
    val gitRepository = List.ofAll(GitRepositoryManager.getInstance(project).getRepositories()).find(repository -> GitVfsUtils.getMacheteFile(repository).map(macheteFile -> macheteFile.equals(psiFile.getVirtualFile())).getOrElse(false));
    if (gitRepository.isEmpty()) {
        return List.empty();
    }
    return List.ofAll(gitRepository.get().getInfo().getLocalBranchesWithHashes().keySet()).map(localBranch -> localBranch.getName());
}
Also used : lombok.val(lombok.val) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 19 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class GitMacheteRepository method discoverLayoutAndCreateSnapshot.

@Override
@UIThreadUnsafe
public IGitMacheteRepositorySnapshot discoverLayoutAndCreateSnapshot() throws GitMacheteException {
    LOG.startTimer().debug("Entering");
    try {
        val aux = new DiscoverGitMacheteRepositoryAux(gitCoreRepository, statusHookExecutor, preRebaseHookExecutor);
        val result = aux.discoverLayoutAndCreateSnapshot(NUMBER_OF_MOST_RECENTLY_CHECKED_OUT_BRANCHES_FOR_DISCOVER);
        LOG.withTimeElapsed().info("Finished");
        return result;
    } catch (GitCoreException e) {
        throw new GitMacheteException(e);
    }
}
Also used : lombok.val(lombok.val) GitMacheteException(com.virtuslab.gitmachete.backend.api.GitMacheteException) GitCoreException(com.virtuslab.gitcore.api.GitCoreException) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Example 20 with UIThreadUnsafe

use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.

the class GitCommandUpdatingCurrentBranchBackgroundable method handleResult.

@UIThreadUnsafe
private void handleResult(GitCommandResult result, GitLocalChangesWouldBeOverwrittenDetector localChangesDetector, GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector, GitRevisionNumber currentRev, Label beforeLabel, @Nullable GitUpdatedRanges updatedRanges) {
    VirtualFile root = gitRepository.getRoot();
    if (result.success()) {
        VfsUtil.markDirtyAndRefresh(/* async */
        false, /* recursive */
        true, /* reloadChildren */
        false, root);
        gitRepository.update();
        if (updatedRanges != null && AbstractCommonUpdateAction.showsCustomNotification(java.util.Collections.singletonList(GitVcs.getInstance(project)))) {
            val ranges = updatedRanges.calcCurrentPositions();
            GitUpdateInfoAsLog.NotificationData notificationData = new GitUpdateInfoAsLog(project, ranges).calculateDataAndCreateLogTab();
            Notification notification;
            if (notificationData != null) {
                String title = getTitleForUpdateNotification(notificationData.getUpdatedFilesCount(), notificationData.getReceivedCommitsCount());
                String content = getBodyForUpdateNotification(notificationData.getFilteredCommitsCount());
                notification = VcsNotifier.STANDARD_NOTIFICATION.createNotification(title, content, INFORMATION, /* listener */
                null);
                notification.addAction(NotificationAction.createSimple(getString("action.GitMachete.GitCommandUpdatingCurrentBranchBackgroundable.notification.message.view-commits"), notificationData.getViewCommitAction()));
            } else {
                // When the pull results with no commits, there is no git update info (as log).
                // Based on that we know that all files are up-to-date.
                notification = VcsNotifier.STANDARD_NOTIFICATION.createNotification(getString("action.GitMachete.GitCommandUpdatingCurrentBranchBackgroundable.notification.title.all-files-are-up-to-date"), /* content */
                "", INFORMATION, /* listener */
                null);
            }
            VcsNotifier.getInstance(project).notify(notification);
        } else {
            showUpdates(currentRev, beforeLabel);
        }
    } else if (localChangesDetector.wasMessageDetected()) {
        localChangesWouldBeOverwrittenHelper_showErrorNotification(project, gitRepository.getRoot(), getOperationName(), localChangesDetector.getRelativeFilePaths());
    } else if (untrackedFilesDetector.wasMessageDetected()) {
        GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), getOperationName(), /* description */
        null);
    } else {
        IntelliJNotificationCompat.notifyError(project, format(getString("action.GitMachete.GitCommandUpdatingCurrentBranchBackgroundable.notification.title.update-fail"), getOperationName()), result.getErrorOutputAsJoinedString());
        gitRepository.update();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) lombok.val(lombok.val) GitUpdateInfoAsLog(git4idea.update.GitUpdateInfoAsLog) GitMacheteBundle.getString(com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getString) GitUpdateSessionKt.getTitleForUpdateNotification(git4idea.update.GitUpdateSessionKt.getTitleForUpdateNotification) Notification(com.intellij.notification.Notification) GitUpdateSessionKt.getBodyForUpdateNotification(git4idea.update.GitUpdateSessionKt.getBodyForUpdateNotification) IntelliJNotificationCompat.localChangesWouldBeOverwrittenHelper_showErrorNotification(com.virtuslab.gitmachete.frontend.compat.IntelliJNotificationCompat.localChangesWouldBeOverwrittenHelper_showErrorNotification) ViewUpdateInfoNotification(com.intellij.vcs.ViewUpdateInfoNotification) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe)

Aggregations

UIThreadUnsafe (com.virtuslab.qual.guieffect.UIThreadUnsafe)27 lombok.val (lombok.val)25 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)8 Task (com.intellij.openapi.progress.Task)8 GitMacheteBundle.getString (com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getString)8 UIEffect (org.checkerframework.checker.guieffect.qual.UIEffect)6 VcsException (com.intellij.openapi.vcs.VcsException)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 GitCoreException (com.virtuslab.gitcore.api.GitCoreException)3 GitMacheteException (com.virtuslab.gitmachete.backend.api.GitMacheteException)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 AccessToken (com.intellij.openapi.application.AccessToken)2 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2 IManagedBranchSnapshot (com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot)2 DeleteBranchOnSlideOutSuggestionDialog (com.virtuslab.gitmachete.frontend.actions.dialogs.DeleteBranchOnSlideOutSuggestionDialog)2 IExpectsKeyGitMacheteRepository (com.virtuslab.gitmachete.frontend.actions.expectedkeys.IExpectsKeyGitMacheteRepository)2 IEnhancedLambdaLogger (com.virtuslab.logger.IEnhancedLambdaLogger)2 GitRebaseParams (git4idea.branch.GitRebaseParams)2