Search in sources :

Example 1 with Backgroundable

use of com.intellij.openapi.progress.Task.Backgroundable in project intellij-community by JetBrains.

the class GenerateBinaryStubsFix method applyFix.

@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
    final PsiFile file = descriptor.getPsiElement().getContainingFile();
    final Backgroundable backgroundable = getFixTask(file);
    ProgressManager.getInstance().runProcessWithProgressAsynchronously(backgroundable, new BackgroundableProcessIndicator(backgroundable));
}
Also used : BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) PsiFile(com.intellij.psi.PsiFile) Backgroundable(com.intellij.openapi.progress.Task.Backgroundable)

Example 2 with Backgroundable

use of com.intellij.openapi.progress.Task.Backgroundable in project intellij-community by JetBrains.

the class GenerateBinaryStubsFix method getFixTask.

/**
   * Returns fix task that is used to generate stubs
   *
   * @param fileToRunTaskIn file where task should run
   * @return task itself
   */
@NotNull
public Backgroundable getFixTask(@NotNull final PsiFile fileToRunTaskIn) {
    final Project project = fileToRunTaskIn.getProject();
    final String folder = fileToRunTaskIn.getContainingDirectory().getVirtualFile().getCanonicalPath();
    return new Task.Backgroundable(project, "Generating skeletons for binary module", false) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            final List<String> assemblyRefs = new ReadAction<List<String>>() {

                @Override
                protected void run(@NotNull Result<List<String>> result) throws Throwable {
                    result.setResult(collectAssemblyReferences(fileToRunTaskIn));
                }
            }.execute().getResultObject();
            try {
                final PySkeletonRefresher refresher = new PySkeletonRefresher(project, null, mySdk, null, null, folder);
                if (needBinaryList(myQualifiedName)) {
                    if (!generateSkeletonsForList(refresher, indicator, folder))
                        return;
                } else {
                    //noinspection unchecked
                    refresher.generateSkeleton(myQualifiedName, "", assemblyRefs, Consumer.EMPTY_CONSUMER);
                }
                final VirtualFile skeletonDir;
                skeletonDir = LocalFileSystem.getInstance().findFileByPath(refresher.getSkeletonsPath());
                if (skeletonDir != null) {
                    skeletonDir.refresh(true, true);
                }
            } catch (InvalidSdkException e) {
                LOG.error(e);
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PySkeletonRefresher(com.jetbrains.python.sdk.skeletons.PySkeletonRefresher) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ReadAction(com.intellij.openapi.application.ReadAction) Backgroundable(com.intellij.openapi.progress.Task.Backgroundable) InvalidSdkException(com.jetbrains.python.sdk.InvalidSdkException) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Backgroundable (com.intellij.openapi.progress.Task.Backgroundable)2 ReadAction (com.intellij.openapi.application.ReadAction)1 Result (com.intellij.openapi.application.Result)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 BackgroundableProcessIndicator (com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 InvalidSdkException (com.jetbrains.python.sdk.InvalidSdkException)1 PySkeletonRefresher (com.jetbrains.python.sdk.skeletons.PySkeletonRefresher)1 NotNull (org.jetbrains.annotations.NotNull)1