コード例 #1
0
 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));
       }
     }
   }
 }
コード例 #2
0
 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 + ":"));
       }
     }
   }
 }