Java Code Examples for com.intellij.codeInsight.completion.CompletionResultSet#stopHere()
The following examples show how to use
com.intellij.codeInsight.completion.CompletionResultSet#stopHere() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MuleElementCompletionProvider.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { final Project project = completionParameters.getOriginalFile().getProject(); final MuleElementDefinitionService instance = MuleElementDefinitionService.getInstance(project); final List<MuleModuleDefinition> definitions = instance.getDefinitions(); for (MuleModuleDefinition definition : definitions) { final List<MuleElementDefinition> elementDefinitions = definition.getElementDefinitions(); for (MuleElementDefinition elementDefinition : elementDefinitions) { final LookupElementBuilder lookupElement = LookupElementBuilder.create(elementDefinition.getName()) .withCaseSensitivity(false) .withLookupString(definition.getName() + ":" + elementDefinition.getName()) .withTypeText("\t" + StringUtil.capitalizeWords(elementDefinition.getType().name().toLowerCase(), "_", true, false), true) .withPresentableText(definition.getName() + ":" + elementDefinition.getName()) .withInsertHandler(new MuleElementInsertHandler(elementDefinition.getName(), definition.getName(), definition.getNamespace(), definition.getLocationLookup())); completionResultSet.addElement(lookupElement); } } completionResultSet.stopHere(); }
Example 2
Source File: SimpleCompletionExtension.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
@Override public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet, @NotNull String[] query) { PsiElement element = parameters.getPosition(); Module module = ModuleUtilCore.findModuleForPsiElement(element); if (module == null) { return; } List<LookupElement> results = findResults(element, getQueryAtPosition(query)); if (!results.isEmpty()) { resultSet .withRelevanceSorter(CompletionSorter.emptySorter()) .addAllElements(results); resultSet.stopHere(); } }
Example 3
Source File: CamelJavaBeanReferenceSmartCompletion.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { final PsiElement element = completionParameters.getPosition(); final PsiClass psiClass = getCamelIdeaUtils().getBean(element); if (psiClass != null) { Collection<PsiMethod> methods = getJavaMethodUtils().getMethods(psiClass); List<LookupElement> answer = getJavaMethodUtils().getBeanAccessibleMethods(methods) .stream() .map(method -> buildLookupElement(method, getJavaMethodUtils().getPresentableMethodWithParameters(method))) .collect(toList()); // are there any results then add them if (!answer.isEmpty()) { String hackVal = element.getText(); hackVal = hackVal.substring(1, hackVal.indexOf(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED)); completionResultSet.withPrefixMatcher(hackVal).addAllElements(answer); completionResultSet.stopHere(); } } }
Example 4
Source File: StepCompletionProvider.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
@Override public void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { resultSet.stopHere(); final String prefix = getPrefix(parameters); resultSet = resultSet.withPrefixMatcher(new GaugePrefixMatcher(prefix)); Module moduleForPsiElement = GaugeUtil.moduleForPsiElement(parameters.getPosition()); if (moduleForPsiElement == null) { return; } for (Type item : getStepsInModule(moduleForPsiElement)) { LookupElementBuilder element = LookupElementBuilder.create(item.getText()).withTypeText(item.getType(), true); element = element.withInsertHandler((InsertionContext context1, LookupElement item1) -> { if (context1.getCompletionChar() == '\t') { context1.getDocument().insertString(context1.getEditor().getCaretModel().getOffset(), "\n"); PsiDocumentManager.getInstance(context1.getProject()).commitDocument(context1.getDocument()); } PsiElement stepElement = context1.getFile().findElementAt(context1.getStartOffset()).getParent(); final TemplateBuilder templateBuilder = TemplateBuilderFactory.getInstance().createTemplateBuilder(stepElement); replaceStepParamElements(prefix, context1, stepElement, templateBuilder); templateBuilder.run(context1.getEditor(), false); }); resultSet.addElement(element); } }
Example 5
Source File: CommitCompletionContributor.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction @Override public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { PsiFile file = parameters.getOriginalFile(); Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document != null) { DataContext dataContext = document.getUserData(CommitMessage.DATA_CONTEXT_KEY); if (dataContext != null) { result.stopHere(); if (parameters.getInvocationCount() > 0) { ChangeList[] lists = dataContext.getData(VcsDataKeys.CHANGE_LISTS); if (lists != null) { String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters); CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix)); for (ChangeList list : lists) { for (Change change : list.getChanges()) { VirtualFile virtualFile = change.getVirtualFile(); if (virtualFile != null) { LookupElementBuilder element = LookupElementBuilder.create(virtualFile.getName()). withIcon(VirtualFilePresentation.getAWTIcon(virtualFile)); insensitive.addElement(element); } } } } } } } }
Example 6
Source File: CompletionContributorForInplaceRename.java From consulo with Apache License 2.0 | 5 votes |
@RequiredReadAction @Override public void fillCompletionVariants(@Nonnull CompletionParameters parameters, @Nonnull CompletionResultSet result) { final Editor editor = parameters.getEditor(); final TemplateState state = TemplateManagerImpl.getTemplateState(editor); if (state != null) { if (editor.getUserData(InplaceRefactoring.INPLACE_RENAMER) != null && parameters.getInvocationCount() == 0) { result.stopHere(); } } }
Example 7
Source File: CamelEndpointSmartCompletionExtension.java From camel-idea-plugin with Apache License 2.0 | 4 votes |
@Override public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet, @NotNull String[] query) { boolean endsWithAmpQuestionMark = false; // it is a known Camel component String componentName = StringUtils.asComponentName(query[0]); // it is a known Camel component Project project = parameters.getOriginalFile().getManager().getProject(); CamelCatalog camelCatalog = ServiceManager.getService(project, CamelCatalogService.class).get(); String json = camelCatalog.componentJSonSchema(componentName); ComponentModel componentModel = ModelHelper.generateComponentModel(json, true); final PsiElement element = parameters.getPosition(); // grab all existing parameters String concatQuery = query[0]; String suffix = query[1]; String queryAtPosition = query[2]; String prefixValue = query[2]; // camel catalog expects & as & when it parses so replace all & as & concatQuery = concatQuery.replaceAll("&", "&"); boolean editQueryParameters = concatQuery.contains("?"); // strip up ending incomplete parameter if (queryAtPosition.endsWith("&") || queryAtPosition.endsWith("?")) { endsWithAmpQuestionMark = true; queryAtPosition = queryAtPosition.substring(0, queryAtPosition.length() - 1); } // strip up ending incomplete parameter if (concatQuery.endsWith("&") || concatQuery.endsWith("?")) { concatQuery = concatQuery.substring(0, concatQuery.length() - 1); } Map<String, String> existing = null; try { existing = camelCatalog.endpointProperties(concatQuery); } catch (Exception e) { LOG.warn("Error parsing Camel endpoint properties with url: " + queryAtPosition, e); } // are we editing an existing parameter value // or are we having a list of suggested parameters to choose among boolean caretAtEndOfLine = getIdeaUtils().isCaretAtEndOfLine(element); LOG.trace("Caret at end of line: " + caretAtEndOfLine); String[] queryParameter = getIdeaUtils().getQueryParameterAtCursorPosition(element); String optionValue = queryParameter[1]; // a bit complex to figure out whether to edit the endpoint value or not boolean editOptionValue = false; if (endsWithAmpQuestionMark) { // should not edit value but suggest a new option instead editOptionValue = false; } else { if ("".equals(optionValue)) { // empty value so must edit editOptionValue = true; } else if (StringUtils.isNotEmpty(optionValue) && !caretAtEndOfLine) { // has value and cursor not at end of line so must edit editOptionValue = true; } } LOG.trace("Add new option: " + !editOptionValue); LOG.trace("Edit option value: " + editOptionValue); List<LookupElement> answer = null; if (editOptionValue) { EndpointOptionModel endpointOption = componentModel.getEndpointOption(queryParameter[0].substring(1)); if (endpointOption != null) { answer = addSmartCompletionForEndpointValue(parameters.getEditor(), queryAtPosition, suffix, endpointOption, element, xmlMode); } } if (answer == null) { if (editQueryParameters) { // suggest a list of options for query parameters answer = addSmartCompletionSuggestionsQueryParameters(query, componentModel, existing, xmlMode, element, parameters.getEditor()); } else { if (!resultSet.isStopped()) { // suggest a list of options for context-path answer = addSmartCompletionSuggestionsContextPath(queryAtPosition, componentModel, existing, xmlMode, element); } } } // are there any results then add them if (answer != null && !answer.isEmpty()) { resultSet.withPrefixMatcher(prefixValue).addAllElements(answer); resultSet.stopHere(); } }