Search in sources :

Example 6 with CompletionResultSet

use of com.intellij.codeInsight.completion.CompletionResultSet in project intellij-community by JetBrains.

the class CommitCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiFile file = parameters.getOriginalFile();
    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if (document == null)
        return;
    CommitMessage commitMessage = document.getUserData(CommitMessage.DATA_KEY);
    if (commitMessage == null)
        return;
    result.stopHere();
    if (parameters.getInvocationCount() <= 0)
        return;
    List<ChangeList> lists = commitMessage.getChangeLists();
    if (lists.isEmpty())
        return;
    String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters);
    CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix));
    for (ChangeList list : lists) {
        for (Change change : list.getChanges()) {
            ContentRevision revision = change.getAfterRevision() == null ? change.getBeforeRevision() : change.getAfterRevision();
            if (revision != null) {
                FilePath filePath = revision.getFile();
                LookupElementBuilder element = LookupElementBuilder.create(filePath.getName()).withIcon(filePath.getFileType().getIcon());
                insensitive.addElement(element);
            }
        }
    }
}
Also used : CommitMessage(com.intellij.openapi.vcs.ui.CommitMessage) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiFile(com.intellij.psi.PsiFile) Change(com.intellij.openapi.vcs.changes.Change) Document(com.intellij.openapi.editor.Document) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher)

Example 7 with CompletionResultSet

use of com.intellij.codeInsight.completion.CompletionResultSet in project intellij-plugins by JetBrains.

the class CfmlTagNamesCompletionProvider method addCompletionsFromDirectory.

private void addCompletionsFromDirectory(CompletionResultSet result, CompletionParameters parameters, String libtag, String prefix) {
    final PsiFile originalFile = parameters.getOriginalFile();
    final VirtualFile folder = CfmlUtil.findFileByLibTag(originalFile, libtag);
    if (folder != null && folder.isDirectory()) {
        final Set<String> names = new THashSet<>(CfmlIndex.getInstance(originalFile.getProject()).getAllComponentsNames());
        names.retainAll(ContainerUtil.map(folder.getChildren(), virtualFile -> FileUtil.getNameWithoutExtension(virtualFile.getName()).toLowerCase()));
        for (String componentName : names) {
            result.addElement(LookupElementBuilder.create(prefix + ':' + componentName).withCaseSensitivity(false));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessingContext(com.intellij.util.ProcessingContext) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) CfmlUtil(com.intellij.coldFusion.model.CfmlUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) Set(java.util.Set) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) CfmlIndex(com.intellij.coldFusion.model.psi.stubs.CfmlIndex) CompletionProvider(com.intellij.codeInsight.completion.CompletionProvider) Function(com.intellij.util.Function) PsiFile(com.intellij.psi.PsiFile) CfmlImport(com.intellij.coldFusion.model.psi.CfmlImport) FileUtil(com.intellij.openapi.util.io.FileUtil) NotNull(org.jetbrains.annotations.NotNull) CfmlFileViewProvider(com.intellij.coldFusion.model.files.CfmlFileViewProvider) PsiFile(com.intellij.psi.PsiFile) THashSet(gnu.trove.THashSet)

Aggregations

CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)7 PsiFile (com.intellij.psi.PsiFile)4 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)3 Document (com.intellij.openapi.editor.Document)3 NotNull (org.jetbrains.annotations.NotNull)3 ComboBox (com.intellij.openapi.ui.ComboBox)2 EditorTextField (com.intellij.ui.EditorTextField)2 TextFieldCompletionProvider (com.intellij.util.TextFieldCompletionProvider)2 TextFieldCompletionProviderDumbAware (com.intellij.util.TextFieldCompletionProviderDumbAware)2 ModulesComboBox (com.intellij.application.options.ModulesComboBox)1 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 CompletionProvider (com.intellij.codeInsight.completion.CompletionProvider)1 PlainPrefixMatcher (com.intellij.codeInsight.completion.PlainPrefixMatcher)1 CamelHumpMatcher (com.intellij.codeInsight.completion.impl.CamelHumpMatcher)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 CfmlUtil (com.intellij.coldFusion.model.CfmlUtil)1 CfmlFileViewProvider (com.intellij.coldFusion.model.files.CfmlFileViewProvider)1 CfmlImport (com.intellij.coldFusion.model.psi.CfmlImport)1 CfmlIndex (com.intellij.coldFusion.model.psi.stubs.CfmlIndex)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1