コード例 #1
0
  @Override
  public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
    PsiFile file = parameters.getOriginalFile();
    final Consumer<Task> consumer = file.getUserData(KEY);

    if (CompletionService.getCompletionService().getAdvertisementText() == null) {
      final String shortcut = getActionShortcut(IdeActions.ACTION_QUICK_JAVADOC);
      if (shortcut != null) {
        CompletionService.getCompletionService()
            .setAdvertisementText(
                "Pressing " + shortcut + " would show task description and comments");
      }
    }

    if (consumer != null) {
      result.stopHere();

      String text = parameters.getOriginalFile().getText();
      int i = text.lastIndexOf(' ', parameters.getOffset() - 1) + 1;
      final String prefix = text.substring(i, parameters.getOffset());
      if (parameters.getInvocationCount() == 0
          && !file.getUserData(AUTO_POPUP_KEY)) { // is autopopup
        return;
      }
      result = result.withPrefixMatcher(new PlainPrefixMatcher(prefix));

      final TaskSearchSupport searchSupport = new TaskSearchSupport(file.getProject());
      List<Task> items = searchSupport.getItems(prefix, true);
      addCompletionElements(result, consumer, items, -10000);

      Future<List<Task>> future =
          ApplicationManager.getApplication()
              .executeOnPooledThread(
                  new Callable<List<Task>>() {
                    @Override
                    public List<Task> call() {
                      return searchSupport.getItems(prefix, false);
                    }
                  });

      while (true) {
        try {
          List<Task> tasks = future.get(100, TimeUnit.MILLISECONDS);
          if (tasks != null) {
            addCompletionElements(result, consumer, tasks, 0);
            return;
          }
        } catch (ProcessCanceledException e) {
          throw e;
        } catch (Exception ignore) {

        }
        ProgressManager.checkCanceled();
      }
    }
  }
コード例 #2
0
 @Nullable
 private List<Task> getIssuesFromRepositories(
     @Nullable String request,
     int max,
     long since,
     boolean forceRequest,
     @NotNull final ProgressIndicator cancelled) {
   List<Task> issues = null;
   for (final TaskRepository repository : getAllRepositories()) {
     if (!repository.isConfigured() || (!forceRequest && myBadRepositories.contains(repository))) {
       continue;
     }
     try {
       Task[] tasks = repository.getIssues(request, max, since, cancelled);
       myBadRepositories.remove(repository);
       if (issues == null) issues = new ArrayList<Task>(tasks.length);
       if (!repository.isSupported(TaskRepository.NATIVE_SEARCH) && request != null) {
         List<Task> filteredTasks =
             TaskSearchSupport.filterTasks(request, ContainerUtil.list(tasks));
         ContainerUtil.addAll(issues, filteredTasks);
       } else {
         ContainerUtil.addAll(issues, tasks);
       }
     } catch (ProcessCanceledException ignored) {
       // OK
     } catch (Exception e) {
       String reason = "";
       // Fix to IDEA-111810
       if (e.getClass() == Exception.class) {
         // probably contains some message meaningful to end-user
         reason = e.getMessage();
       }
       //noinspection InstanceofCatchParameter
       if (e instanceof SocketTimeoutException) {
         LOG.warn("Socket timeout from " + repository);
       } else {
         LOG.warn("Cannot connect to " + repository, e);
       }
       myBadRepositories.add(repository);
       if (forceRequest) {
         notifyAboutConnectionFailure(repository, reason);
       }
     }
   }
   return issues;
 }