Search in sources :

Example 1 with YouTrackIntellisense

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

Example 2 with YouTrackIntellisense

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);
}
Also used : YouTrackIntellisense(com.intellij.tasks.youtrack.YouTrackIntellisense) QueryInfo(com.intellij.tasks.youtrack.lang.YouTrackHighlightingAnnotator.QueryInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

YouTrackIntellisense (com.intellij.tasks.youtrack.YouTrackIntellisense)2 Application (com.intellij.openapi.application.Application)1 PsiFile (com.intellij.psi.PsiFile)1 CompletionItem (com.intellij.tasks.youtrack.YouTrackIntellisense.CompletionItem)1 QueryInfo (com.intellij.tasks.youtrack.lang.YouTrackHighlightingAnnotator.QueryInfo)1 Function (com.intellij.util.Function)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 Nullable (org.jetbrains.annotations.Nullable)1