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);
          }
        }
      }
    }
  }
  private void addAllSubsInPackage(
      CompletionResultSet resultSet,
      PerlElement packageName,
      boolean withArguments,
      boolean limitResults) {
    ArrayList<Package> packageList = ModulesContainer.getPackageList(packageName.getText());

    if (Utils.verbose) {
      Utils.print("Detected Package:" + packageName);
    }
    for (int i = 0; i < packageList.size(); i++) {
      Package packageObj = packageList.get(i);

      ArrayList<Sub> subs = packageObj.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++) {
        if (withArguments) {
          addCachedSub(resultSet, subs.get(j));
        } else {
          addCachedSubNoArgs(resultSet, subs.get(j));
        }
      }
    }
  }
  // ==================
  // add cached methods
  // ==================
  private void addAllPackages(
      CompletionResultSet resultSet, PerlElement element, boolean limitResults) {
    ArrayList<Package> packageList = ModulesContainer.searchPackageList(element.getText(), false);

    for (int i = 0; i < packageList.size(); i++) {
      addCachedPackage(resultSet, packageList.get(i));
    }
  }
 public static void cacheSingleFile(Project project, VirtualFile openFile) {
   if (openFile.exists()) {
     // cache attributes
     PsiManager psiManager = PsiManager.getInstance(project);
     if (psiManager == null) return;
     PsiFile psiFile = psiManager.findFile(openFile);
     if (psiFile == null) return;
     FileASTNode astNode = psiFile.getNode();
     if (astNode == null) return;
     HashSet<String> rs = findAllVariables(astNode.getChildren(null), PerlTypes.VARIABLE, false);
     if (rs == null) return;
     for (String str : rs) {
       addCachedVariables(null, str);
     }
     // cache subs
     ArrayList<Package> packages = ModulesContainer.getPackageListFromFile(openFile.getPath());
     for (int i = 0; i < packages.size(); i++) {
       ArrayList<Sub> subs = packages.get(i).getAllSubs();
       for (int j = 0; j < subs.size(); j++) {
         addCachedSub(null, subs.get(j));
       }
     }
   }
 }
 private static void cacheAllPackages() {
   ArrayList<Package> packages = ModulesContainer.getAllPackages();
   for (int i = 0; i < packages.size(); i++) {
     addCachedPackage(null, packages.get(i));
   }
 }