Search in sources :

Example 1 with CompletionItem

use of com.intellij.tasks.youtrack.YouTrackIntellisense.CompletionItem in project intellij-community by JetBrains.

the class YouTrackCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull CompletionResultSet result) {
    if (LOG.isDebugEnabled()) {
        LOG.debug(DebugUtil.psiToString(parameters.getOriginalFile(), true));
    }
    super.fillCompletionVariants(parameters, result);
    PsiFile file = parameters.getOriginalFile();
    final YouTrackIntellisense intellisense = file.getUserData(YouTrackIntellisense.INTELLISENSE_KEY);
    if (intellisense == null) {
        return;
    }
    final Application application = ApplicationManager.getApplication();
    Future<List<CompletionItem>> future = application.executeOnPooledThread(() -> intellisense.fetchCompletion(parameters.getOriginalFile().getText(), parameters.getOffset()));
    try {
        final List<CompletionItem> suggestions = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
        // actually backed by original CompletionResultSet
        result = result.withPrefixMatcher(extractPrefix(parameters)).caseInsensitive();
        result.addAllElements(ContainerUtil.map(suggestions, (Function<CompletionItem, LookupElement>) item -> LookupElementBuilder.create(item, item.getOption()).withTypeText(item.getDescription(), true).withInsertHandler(INSERT_HANDLER).withBoldness(item.getStyleClass().equals("keyword"))));
    } catch (Exception ignored) {
        //noinspection InstanceofCatchParameter
        if (ignored instanceof TimeoutException) {
            LOG.debug(String.format("YouTrack request took more than %d ms to complete", TIMEOUT));
        }
        LOG.debug(ignored);
    }
}
Also used : Function(com.intellij.util.Function) YouTrackIntellisense(com.intellij.tasks.youtrack.YouTrackIntellisense) CompletionItem(com.intellij.tasks.youtrack.YouTrackIntellisense.CompletionItem) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) Application(com.intellij.openapi.application.Application) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Application (com.intellij.openapi.application.Application)1 PsiFile (com.intellij.psi.PsiFile)1 YouTrackIntellisense (com.intellij.tasks.youtrack.YouTrackIntellisense)1 CompletionItem (com.intellij.tasks.youtrack.YouTrackIntellisense.CompletionItem)1 Function (com.intellij.util.Function)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1