private static BipartiteString findParentDirStrWithLastComponentPrefix(String pathBeforeCaret) {
   BipartiteString unixBipartiteString =
       splitByLastIndexOfSeparatorOccurrence(
           pathBeforeCaret, JstdConfigFileUtils.UNIX_PATH_SEPARATOR);
   BipartiteString winBipartiteString =
       splitByLastIndexOfSeparatorOccurrence(
           pathBeforeCaret, JstdConfigFileUtils.WINDOWS_PATH_SEPARATOR);
   if (unixBipartiteString.getSuffix().length() < winBipartiteString.getSuffix().length()) {
     return unixBipartiteString;
   } else {
     return winBipartiteString;
   }
 }
 @Nullable
 private static Character extractDirectoryTrailingFileSeparator(
     BipartiteString caretBipartiteElementText) {
   Character prefixPrevalentSeparator =
       extractPrevalentSeparator(caretBipartiteElementText.getWholeString());
   if (prefixPrevalentSeparator != null) {
     return prefixPrevalentSeparator;
   }
   Character suffixPrevalentSeparator =
       extractPrevalentSeparator(caretBipartiteElementText.getSuffix());
   if (suffixPrevalentSeparator != null) {
     return suffixPrevalentSeparator;
   }
   return null;
 }
 private static void addPathCompletions(
     @NotNull CompletionResultSet result,
     @NotNull BipartiteString caretBipartiteElementText,
     @NotNull VirtualFile basePath,
     boolean directoryExpected) {
   ParentDirWithLastComponentPrefix parentWithLastComponentPrefix =
       findParentDirWithLastComponentPrefix(basePath, caretBipartiteElementText.getPrefix());
   if (parentWithLastComponentPrefix != null) {
     PrefixMatcher matcher =
         new StrictPrefixMatcher(parentWithLastComponentPrefix.getLastComponentPrefix(), false);
     result = result.withPrefixMatcher(matcher);
     VirtualFile parentFile = parentWithLastComponentPrefix.getParent();
     VirtualFile[] children = parentFile.getChildren();
     Character dirSeparatorSuffix =
         extractDirectoryTrailingFileSeparator(caretBipartiteElementText);
     if (parentFile.isDirectory()) {
       result.addElement(LookupItem.fromString(".."));
     }
     for (VirtualFile child : children) {
       if (child.isDirectory() || !directoryExpected) {
         String name = child.getName();
         if (child.isDirectory() && dirSeparatorSuffix != null) {
           name += dirSeparatorSuffix;
         }
         result.addElement(LookupItem.fromString(name));
       }
     }
   }
 }
 @Nullable
 private static ParentDirWithLastComponentPrefix findParentDirWithLastComponentPrefix(
     @NotNull VirtualFile basePath, @NotNull String pathBeforeCaret) {
   BipartiteString parentDirStrWithLastComponent =
       findParentDirStrWithLastComponentPrefix(pathBeforeCaret);
   String parentDirPath =
       FileUtil.toSystemIndependentName(parentDirStrWithLastComponent.getPrefix());
   {
     VirtualFile parentFile = basePath.findFileByRelativePath(parentDirPath);
     if (parentFile != null) {
       return new ParentDirWithLastComponentPrefix(
           parentFile, parentDirStrWithLastComponent.getSuffix());
     }
   }
   File absolutePath = new File(parentDirPath);
   if (absolutePath.isAbsolute()) {
     VirtualFile absolute = LocalFileSystem.getInstance().findFileByIoFile(absolutePath);
     if (absolute != null) {
       return new ParentDirWithLastComponentPrefix(
           absolute, parentDirStrWithLastComponent.getSuffix());
     }
   }
   return null;
 }
 private static void addTopLevelKeysCompletionIfNeeded(
     @NotNull CompletionParameters parameters,
     @NotNull CompletionResultSet result,
     @NotNull BipartiteString caretBipartiteElementText) {
   PsiElement element = parameters.getPosition();
   YAMLDocument yamlDocument = ObjectUtils.tryCast(element.getParent(), YAMLDocument.class);
   if (yamlDocument == null) {
     yamlDocument =
         JstdConfigFileUtils.getVerifiedHierarchyHead(
             element.getParent(), new Class[] {YAMLKeyValue.class}, YAMLDocument.class);
   }
   if (yamlDocument != null) {
     String prefix = caretBipartiteElementText.getPrefix();
     result = result.withPrefixMatcher(prefix);
     for (String key : JstdConfigFileUtils.VALID_TOP_LEVEL_KEYS) {
       if (key.startsWith(prefix)) {
         result.addElement(LookupItem.fromString(key + ":"));
       }
     }
   }
 }