use of com.intellij.tasks.youtrack.YouTrackIntellisense 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);
}
}
use of com.intellij.tasks.youtrack.YouTrackIntellisense in project intellij-community by JetBrains.
the class YouTrackHighlightingAnnotator method collectInformation.
@Nullable
@Override
public QueryInfo collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) {
final YouTrackIntellisense intellisense = file.getUserData(YouTrackIntellisense.INTELLISENSE_KEY);
if (intellisense == null || !intellisense.getRepository().isConfigured()) {
return null;
}
final String text = file.getText();
final int offset = editor.getCaretModel().getOffset();
//LOG.debug(String.format("Highlighting YouTrack query: '%s' (cursor=%d)", text, offset));
return new QueryInfo(offset, text, intellisense);
}
Aggregations