@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();
      }
    }
  }
  private void addAllSubsInFile(
      CompletionParameters parameters, CompletionResultSet resultSet, boolean limitResults) {
    ArrayList<Package> packageList =
        ModulesContainer.getPackageListFromFile(
            parameters.getOriginalFile().getVirtualFile().getCanonicalPath());

    for (int i = 0; i < packageList.size(); i++) {
      ArrayList<Sub> subs = packageList.get(i).getAllSubs();
      int amount =
          (false)
              ? Math.min(AUTO_POPUP_SUBS_ITEMS_LIMIT, subs.size())
              : subs.size(); // get all results only if users press ctrl+space
      for (int j = 0; j < amount; j++) {
        addCachedSub(resultSet, subs.get(j));
      }
      ArrayList<ImportedSub> importedSubs = packageList.get(i).getImportedSubs();
      amount =
          (false)
              ? Math.min(AUTO_POPUP_SUBS_ITEMS_LIMIT, importedSubs.size())
              : importedSubs.size(); // get all results only if users press ctrl+space

      for (int j = 0; j < amount; j++) {
        ArrayList<Package> packages =
            ModulesContainer.getPackageList(
                importedSubs.get(j).getContainingPackage()); // TODO: handle more than 1 package
        if (packages.size() > 0) {
          Sub sub = packages.get(0).getSubByName(importedSubs.get(j).getImportSub());
          if (sub != null) {
            addCachedSub(resultSet, sub);
          }
        }
      }
    }
  }
    @Override
    protected void addCompletions(
        @NotNull CompletionParameters completionParameters,
        final ProcessingContext processingContext,
        @NotNull final CompletionResultSet completionResultSet) {

      PsiFile originalFile = completionParameters.getOriginalFile();
      final PsiDirectory containingDirectory = originalFile.getContainingDirectory();
      if (containingDirectory == null) {
        return;
      }

      final VirtualFile containingDirectoryFiles = containingDirectory.getVirtualFile();
      VfsUtil.visitChildrenRecursively(
          containingDirectoryFiles,
          new VirtualFileVisitor() {
            @Override
            public boolean visitFile(@NotNull VirtualFile file) {

              String relativePath = VfsUtil.getRelativePath(file, containingDirectoryFiles, '/');
              if (relativePath == null) {
                return super.visitFile(file);
              }

              completionResultSet.addElement(
                  LookupElementBuilder.create(relativePath).withIcon(file.getFileType().getIcon()));

              return super.visitFile(file);
            }
          });
    }
 private void addAllVariablesInFile(
     CompletionParameters parameters, CompletionResultSet resultSet, boolean limitResults) {
   HashSet<String> rs =
       findAllVariables(
           parameters.getOriginalFile().getNode().getChildren(null), PerlTypes.VARIABLE, false);
   for (String str : rs) {
     addCachedVariables(resultSet, str);
   }
 }
    public void addCompletions(
        @NotNull CompletionParameters parameters,
        ProcessingContext context,
        @NotNull CompletionResultSet resultSet) {

      if (!YamlHelper.isRoutingFile(parameters.getOriginalFile())) {
        return;
      }

      super.addCompletions(parameters, context, resultSet);
    }
 private static boolean isTopLevelKeyCompletion(@NotNull CompletionParameters parameters) {
   PsiElement psiElement = parameters.getPosition();
   Document document = JsPsiUtils.getDocument(parameters.getOriginalFile());
   if (document != null) {
     TextRange textRange = psiElement.getTextRange();
     int startLine = document.getLineNumber(textRange.getStartOffset());
     int startOffset = document.getLineStartOffset(startLine);
     return startOffset == textRange.getStartOffset();
   }
   return false;
 }
 @Nullable
 private static BasePathInfo newBasePathInfo(@NotNull CompletionParameters parameters) {
   YAMLFile yamlFile = ObjectUtils.tryCast(parameters.getOriginalFile(), YAMLFile.class);
   if (yamlFile != null) {
     List<YAMLDocument> yamlDocuments = yamlFile.getDocuments();
     if (!yamlDocuments.isEmpty()) {
       return new BasePathInfo(yamlDocuments.get(0));
     }
   }
   return null;
 }
  @Override
  public void fillCompletionVariants(
      @NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    Project project = parameters.getEditor().getProject();
    assert project != null;

    JsonSchemaService service = JsonSchemaService.Impl.get(project);
    assert service != null;

    CompletionContributor delegate =
        service.getCompletionContributor(parameters.getOriginalFile().getVirtualFile());
    if (delegate != null) {
      delegate.fillCompletionVariants(parameters, result);
    }
  }
    @Override
    protected void addCompletions(
        @NotNull CompletionParameters parameters,
        ProcessingContext processingContext,
        @NotNull CompletionResultSet completionResultSet) {

      if (!Symfony2ProjectComponent.isEnabled(parameters.getPosition())) {
        return;
      }

      PhpIndex phpIndex = PhpIndex.getInstance(parameters.getOriginalFile().getProject());
      for (PhpClass phpClass : phpIndex.getAllSubclasses("\\Doctrine\\ORM\\EntityRepository")) {
        String presentableFQN = phpClass.getPresentableFQN();
        if (presentableFQN != null) {
          completionResultSet.addElement(
              LookupElementBuilder.create(phpClass.getName())
                  .withTypeText(phpClass.getPresentableFQN(), true)
                  .withIcon(phpClass.getIcon()));
        }
      }
    }
  @NotNull
  @Override
  public ThreeState shouldFocusLookup(@NotNull CompletionParameters parameters) {
    final PsiElement position = parameters.getPosition();

    if (position.getParent() instanceof GrReferenceElement
        && psiElement()
            .afterLeaf(psiElement().withText("(").withParent(GrForStatement.class))
            .accepts(position)) {
      return ThreeState.NO;
    }

    if (position.getParent() instanceof GrReferenceExpression) {
      final GrReferenceExpression ref = (GrReferenceExpression) position.getParent();
      final GrExpression qualifier = ref.getQualifierExpression();
      if (qualifier == null) {
        if (isPossibleClosureParameter(ref)) return ThreeState.NO;
        if (parameters.getOriginalFile().getUserData(GroovyShellAction.GROOVY_SHELL_FILE)
            == Boolean.TRUE) {
          return ThreeState.NO;
        }

        GrExpression runtimeQualifier = PsiImplUtil.getRuntimeQualifier(ref);
        if (runtimeQualifier != null && runtimeQualifier.getType() == null) {
          return ThreeState.NO;
        }

        return ThreeState.YES;
      }

      if (qualifier.getType() == null) {
        return ThreeState.NO;
      }
      return ThreeState.YES;
    }
    return ThreeState.UNSURE;
  }