Search in sources :

Example 1 with CamelHumpMatcher

use of com.intellij.codeInsight.completion.impl.CamelHumpMatcher in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTestFunctionCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    Project project = parameters.getPosition().getProject();
    PsiFile file = parameters.getOriginalFile();
    PsiDirectory containingDirectory = file.getContainingDirectory();
    if (file instanceof GoFile && containingDirectory != null) {
        CompletionResultSet resultSet = result.withPrefixMatcher(new CamelHumpMatcher(result.getPrefixMatcher().getPrefix(), false));
        Collection<String> allPackageFunctionNames = collectAllFunctionNames(containingDirectory);
        Set<String> allTestFunctionNames = collectAllTestNames(allPackageFunctionNames, project, (GoFile) file);
        String fileNameWithoutTestPrefix = StringUtil.trimEnd(file.getName(), GoConstants.TEST_SUFFIX_WITH_EXTENSION) + ".go";
        GlobalSearchScope packageScope = GoPackageUtil.packageScope(containingDirectory, ((GoFile) file).getCanonicalPackageName());
        GlobalSearchScope scope = new GoUtil.ExceptTestsScope(packageScope);
        IdFilter idFilter = GoIdFilter.getFilesFilter(scope);
        for (String functionName : allPackageFunctionNames) {
            GoFunctionIndex.process(functionName, project, scope, idFilter, declaration -> {
                addVariants(declaration, functionName, fileNameWithoutTestPrefix, allTestFunctionNames, resultSet);
                return false;
            });
        }
        Collection<String> methodKeys = ContainerUtil.newTroveSet();
        StubIndex.getInstance().processAllKeys(GoMethodIndex.KEY, new CancellableCollectProcessor<>(methodKeys), scope, idFilter);
        for (String key : methodKeys) {
            Processor<GoMethodDeclaration> processor = declaration -> {
                GoMethodDeclarationStubElementType.calcTypeText(declaration);
                String typeText = key.substring(Math.min(key.indexOf('.') + 1, key.length()));
                String methodName = declaration.getName();
                if (methodName != null) {
                    if (!declaration.isPublic() || declaration.isBlank()) {
                        return true;
                    }
                    String lookupString = !typeText.isEmpty() ? StringUtil.capitalize(typeText) + "_" + methodName : methodName;
                    addVariants(declaration, lookupString, fileNameWithoutTestPrefix, allTestFunctionNames, resultSet);
                }
                return true;
            };
            GoMethodIndex.process(key, project, scope, idFilter, processor);
        }
    }
}
Also used : com.goide.psi(com.goide.psi) Document(com.intellij.openapi.editor.Document) GoMethodIndex(com.goide.stubs.index.GoMethodIndex) GotestGenerateAction(com.goide.runconfig.testing.frameworks.gotest.GotestGenerateAction) IdFilter(com.intellij.util.indexing.IdFilter) StubIndex(com.intellij.psi.stubs.StubIndex) ContainerUtil(com.intellij.util.containers.ContainerUtil) GoTestFunctionType(com.goide.runconfig.testing.GoTestFunctionType) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) GoMethodDeclarationStubElementType(com.goide.stubs.types.GoMethodDeclarationStubElementType) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) GoElementFactory(com.goide.psi.impl.GoElementFactory) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) ProcessingContext(com.intellij.util.ProcessingContext) GoFunctionIndex(com.goide.stubs.index.GoFunctionIndex) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) GoUtil(com.goide.util.GoUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) UniqueNameGenerator(com.intellij.util.text.UniqueNameGenerator) com.intellij.codeInsight.completion(com.intellij.codeInsight.completion) GoIdFilter(com.goide.stubs.index.GoIdFilter) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) Processor(com.intellij.util.Processor) GoConstants(com.goide.GoConstants) PsiDirectory(com.intellij.psi.PsiDirectory) GoPackageUtil(com.goide.sdk.GoPackageUtil) NotNull(org.jetbrains.annotations.NotNull) IdFilter(com.intellij.util.indexing.IdFilter) GoIdFilter(com.goide.stubs.index.GoIdFilter) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile)

Example 2 with CamelHumpMatcher

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

the class JavaCompletionUtil method completeVariableNameForRefactoring.

public static void completeVariableNameForRefactoring(Project project, Set<LookupElement> set, String prefix, PsiType varType, VariableKind varKind) {
    final CamelHumpMatcher camelHumpMatcher = new CamelHumpMatcher(prefix);
    JavaMemberNameCompletionContributor.completeVariableNameForRefactoring(project, set, camelHumpMatcher, varType, varKind, true, false);
}
Also used : CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher)

Example 3 with CamelHumpMatcher

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

the class JavaNoVariantsDelegator method suggestQualifierItems.

private static Set<LookupElement> suggestQualifierItems(CompletionParameters parameters, PsiJavaCodeReferenceElement qualifier, ElementFilter filter) {
    String referenceName = qualifier.getReferenceName();
    if (referenceName == null) {
        return Collections.emptySet();
    }
    PrefixMatcher qMatcher = new CamelHumpMatcher(referenceName);
    Set<LookupElement> plainVariants = JavaSmartCompletionContributor.completeReference(qualifier, qualifier, filter, true, true, parameters, qMatcher);
    for (PsiClass aClass : PsiShortNamesCache.getInstance(qualifier.getProject()).getClassesByName(referenceName, qualifier.getResolveScope())) {
        plainVariants.add(JavaClassNameCompletionContributor.createClassLookupItem(aClass, true));
    }
    if (!plainVariants.isEmpty()) {
        return plainVariants;
    }
    final Set<LookupElement> allClasses = new LinkedHashSet<>();
    PsiElement qualifierName = qualifier.getReferenceNameElement();
    if (qualifierName != null) {
        JavaClassNameCompletionContributor.addAllClasses(parameters.withPosition(qualifierName, qualifierName.getTextRange().getEndOffset()), true, qMatcher, new CollectConsumer<>(allClasses));
    }
    return allClasses;
}
Also used : BetterPrefixMatcher(com.intellij.codeInsight.completion.impl.BetterPrefixMatcher) LinkedHashSet(java.util.LinkedHashSet) LookupElement(com.intellij.codeInsight.lookup.LookupElement) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher)

Example 4 with CamelHumpMatcher

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

the class LookupManagerImpl method createLookup.

@NotNull
@Override
public LookupImpl createLookup(@NotNull final Editor editor, @NotNull LookupElement[] items, @NotNull final String prefix, @NotNull final LookupArranger arranger) {
    hideActiveLookup();
    final CodeInsightSettings settings = CodeInsightSettings.getInstance();
    final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
    final LookupImpl lookup = createLookup(editor, arranger, myProject);
    final Alarm alarm = new Alarm();
    final Runnable request = () -> {
        if (myActiveLookup != lookup)
            return;
        LookupElement currentItem = lookup.getCurrentItem();
        if (currentItem != null && currentItem.isValid() && isAutoPopupJavadocSupportedBy(currentItem)) {
            final CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
            if (completion != null && !completion.isAutopopupCompletion()) {
                try {
                    DocumentationManager.getInstance(myProject).showJavaDocInfo(editor, psiFile, false);
                } catch (IndexNotReadyException ignored) {
                }
            }
        }
    };
    if (settings.AUTO_POPUP_JAVADOC_INFO) {
        alarm.addRequest(request, settings.JAVADOC_INFO_DELAY);
    }
    ApplicationManager.getApplication().assertIsDispatchThread();
    myActiveLookup = lookup;
    myActiveLookupEditor = editor;
    myActiveLookup.addLookupListener(new LookupAdapter() {

        @Override
        public void itemSelected(LookupEvent event) {
            lookupClosed();
        }

        @Override
        public void lookupCanceled(LookupEvent event) {
            lookupClosed();
        }

        @Override
        public void currentItemChanged(LookupEvent event) {
            alarm.cancelAllRequests();
            if (settings.AUTO_POPUP_JAVADOC_INFO && DocumentationManager.getInstance(myProject).getDocInfoHint() == null) {
                alarm.addRequest(request, settings.JAVADOC_INFO_DELAY);
            }
        }

        private void lookupClosed() {
            ApplicationManager.getApplication().assertIsDispatchThread();
            alarm.cancelAllRequests();
            lookup.removeLookupListener(this);
        }
    });
    Disposer.register(lookup, new Disposable() {

        @Override
        public void dispose() {
            myActiveLookup = null;
            myActiveLookupEditor = null;
            myPropertyChangeSupport.firePropertyChange(PROP_ACTIVE_LOOKUP, lookup, null);
        }
    });
    CamelHumpMatcher matcher = new CamelHumpMatcher(prefix);
    if (items.length > 0) {
        for (final LookupElement item : items) {
            myActiveLookup.addItem(item, matcher);
        }
        myActiveLookup.refreshUi(true, true);
    } else {
        // no items -> no doc
        alarm.cancelAllRequests();
    }
    myPropertyChangeSupport.firePropertyChange(PROP_ACTIVE_LOOKUP, null, myActiveLookup);
    return lookup;
}
Also used : Disposable(com.intellij.openapi.Disposable) CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) CompletionProcess(com.intellij.codeInsight.completion.CompletionProcess) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher) Alarm(com.intellij.util.Alarm) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CamelHumpMatcher

use of com.intellij.codeInsight.completion.impl.CamelHumpMatcher 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)

Aggregations

CamelHumpMatcher (com.intellij.codeInsight.completion.impl.CamelHumpMatcher)5 PsiFile (com.intellij.psi.PsiFile)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)2 Document (com.intellij.openapi.editor.Document)2 NotNull (org.jetbrains.annotations.NotNull)2 GoConstants (com.goide.GoConstants)1 com.goide.psi (com.goide.psi)1 GoElementFactory (com.goide.psi.impl.GoElementFactory)1 GoTestFunctionType (com.goide.runconfig.testing.GoTestFunctionType)1 GotestGenerateAction (com.goide.runconfig.testing.frameworks.gotest.GotestGenerateAction)1 GoPackageUtil (com.goide.sdk.GoPackageUtil)1 GoFunctionIndex (com.goide.stubs.index.GoFunctionIndex)1 GoIdFilter (com.goide.stubs.index.GoIdFilter)1 GoMethodIndex (com.goide.stubs.index.GoMethodIndex)1 GoMethodDeclarationStubElementType (com.goide.stubs.types.GoMethodDeclarationStubElementType)1 GoUtil (com.goide.util.GoUtil)1 CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)1 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)1 CompletionProcess (com.intellij.codeInsight.completion.CompletionProcess)1