Skip to content

Commit

Permalink
fix(#38): Startup error: Slow operations are prohibited on EDT
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaBraska committed Oct 29, 2023
1 parent cf6afd1 commit 92c7a48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

### Acknowledge undefined action inputs & outputs

- Fix: Keep user settings after action refresh
- Feat: [#33 Acknowledge undefined action inputs & outputs](https://github.com/YunaBraska/github-workflow-plugin/issues/33)
- Feat: Click on `Needs` navigates directly to the `Job`
- Fix: [Startup error: Slow operations are prohibited on EDT](https://github.com/YunaBraska/github-workflow-plugin/issues/38)
- Fix: Keep user settings after action refresh
- Chore: refactored & split logic to specific classes
like \[`Action`, `Envs`, `GitHub`, `Inputs`, `Jobs`, `Needs`, `Runner`, `Secrets`, `Steps`]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,25 @@ public static void asyncInitAllActionsAfterInit(final Project project, final Vir
}

private static void asyncInitAllActions(final Project project, final VirtualFile virtualFile) {
if (virtualFile != null && (GitHubWorkflowHelper.isWorkflowPath(toPath(virtualFile.getPath())))) {
final List<GitHubAction> actions = new ArrayList<>();
// READ CONTEXT
ApplicationManager.getApplication().runReadAction(() -> Optional.of(PsiManager.getInstance(project))
.map(psiManager -> psiManager.findFile(virtualFile))
.map(psiFile -> PsiElementHelper.getAllElements(psiFile, FIELD_USES))
.ifPresent(usesList -> usesList.stream().map(GitHubActionCache::getAction).filter(action -> !action.isSuppressed()).filter(action -> !action.isResolved()).forEach(actions::add))
);

// ASYNC HTTP CONTEXT
GitHubActionCache.resolveActionsAsync(actions);
final Runnable task = () -> {
if (virtualFile != null && (GitHubWorkflowHelper.isWorkflowPath(toPath(virtualFile.getPath())))) {
final List<GitHubAction> actions = new ArrayList<>();
// READ CONTEXT
ApplicationManager.getApplication().runReadAction(() -> Optional.of(PsiManager.getInstance(project))
.map(psiManager -> psiManager.findFile(virtualFile))
.map(psiFile -> PsiElementHelper.getAllElements(psiFile, FIELD_USES))
.ifPresent(usesList -> usesList.stream().map(GitHubActionCache::getAction).filter(action -> !action.isSuppressed()).filter(action -> !action.isResolved()).forEach(actions::add))
);

// ASYNC HTTP CONTEXT
GitHubActionCache.resolveActionsAsync(actions);
}
};

if (!DumbService.isDumb(project)) {
ApplicationManager.getApplication().executeOnPooledThread(task);
} else {
DumbService.getInstance(project).runWhenSmart(() -> ApplicationManager.getApplication().executeOnPooledThread(task));
}
}
}

0 comments on commit 92c7a48

Please sign in to comment.