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)); } } } }
@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 static void addResult( CompletionResultSet result, Collection<Lookup> collection, PsiElement position, int offset) { result = result.withPrefixMatcher(findPrefixStatic(position, offset)); for (Lookup lookup : collection) { final LookupItem<Lookup> item = new LookupItem<>(lookup, lookup.toString()); item.setInsertHandler(INSERT_HANDLER); if (lookup.isKeyword()) { item.setBold(); } result.addElement(item); } }
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 + ":")); } } } }