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);
}
}
}
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);
}
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;
}
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;
}
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);
}
}
}
}
Aggregations