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);
}
}
Aggregations