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)); } } } }
public void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { PsiElement element = parameters.getPosition().getParent(); Project project = element.getProject(); if (!SilexProjectComponent.isEnabled(project)) { return; } if (!(element instanceof StringLiteralExpression)) { return; } Container container = Utils.findContainerForFirstParameterOfPimpleMethod((StringLiteralExpression) element); if (container == null) { return; } for (Service service : container.getServices().values()) { resultSet.addElement(new ServiceLookupElement(service, project)); } for (Parameter parameter : container.getParameters().values()) { resultSet.addElement(new ParameterLookupElement(parameter)); } resultSet.stopHere(); }
@Override protected void addCompletions( @NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { if (!Symfony2ProjectComponent.isEnabled(completionParameters.getPosition())) { return; } XmlEventParser xmlEventParser = ServiceXmlParserFactory.getInstance( completionParameters.getPosition().getProject(), XmlEventParser.class); for (Map.Entry<String, String> event : xmlEventParser.get().entrySet()) { completionResultSet.addElement( LookupElementBuilder.create(event.getKey()) .withTypeText(event.getValue(), true) .withIcon(Symfony2Icons.EVENT)); } for (EventDispatcherSubscribedEvent event : EventDispatcherSubscriberUtil.getSubscribedEvents( completionParameters.getPosition().getProject())) { completionResultSet.addElement( LookupElementBuilder.create(event.getStringValue()) .withTypeText("EventSubscriber", true) .withIcon(Symfony2Icons.EVENT)); } }
@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); } }
@Override protected void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement position = parameters.getPosition(); if (!Symfony2ProjectComponent.isEnabled(position)) { return; } PsiElement prevSiblingOfType = PsiElementUtils.getPrevSiblingOfType( position, YamlElementPatternHelper.getPreviousCommaSibling()); if (prevSiblingOfType == null) { return; } String service = PsiElementUtils.trimQuote(prevSiblingOfType.getText()); if (StringUtils.isBlank(service)) { return; } PhpClass phpClass = ServiceUtil.getServiceClass(prevSiblingOfType.getProject(), service); if (phpClass == null) { return; } for (Method method : phpClass.getMethods()) { if (method.getAccess().isPublic() && !(method.getName().startsWith("__"))) { completionResultSet.addElement(new PhpLookupElement(method)); } } }
@Override protected void addCompletions( @NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement position = completionParameters.getPosition(); if (!Symfony2ProjectComponent.isEnabled(position)) { return; } YAMLCompoundValue yamlCompoundValue = PsiTreeUtil.getParentOfType(position, YAMLCompoundValue.class); if (yamlCompoundValue == null) { return; } String className = YamlHelper.getYamlKeyValueAsString(yamlCompoundValue, "targetEntity", false); if (className == null) { return; } PhpClass phpClass = PhpElementsUtil.getClass(position.getProject(), className); if (phpClass == null) { return; } for (DoctrineModelField field : EntityHelper.getModelFields(phpClass)) { if (field.getRelation() != null) { completionResultSet.addElement(new DoctrineModelFieldLookupElement(field)); } } }
@Override protected void addCompletions( @NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { YAMLKeyValue yamlKeyValue = PsiTreeUtil.getParentOfType( completionParameters.getOriginalPosition(), YAMLKeyValue.class); if (yamlKeyValue != null) { PsiElement compoundValue = yamlKeyValue.getParent(); if (compoundValue instanceof YAMLCompoundValue) { // path and pattern are valid String pattern = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) compoundValue, "path", false); if (pattern == null) { pattern = YamlHelper.getYamlKeyValueAsString( (YAMLCompoundValue) compoundValue, "pattern", false); } if (pattern != null) { Matcher matcher = Pattern.compile("\\{(\\w+)}").matcher(pattern); while (matcher.find()) { completionResultSet.addElement(LookupElementBuilder.create(matcher.group(1))); } } } } }
@Override protected void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { for (String[] completion : RegExpLanguageHosts.getInstance().getPosixCharacterClasses(parameters.getPosition())) { result.addElement( LookupElementBuilder.create(completion[0]) .withTypeText((completion.length > 1) ? completion[1] : null) .withIcon(emptyIcon) .withInsertHandler( new InsertHandler<LookupElement>() { @Override public void handleInsert(InsertionContext context, LookupElement item) { context.setAddCompletionChar(false); final Editor editor = context.getEditor(); final Document document = editor.getDocument(); final int tailOffset = context.getTailOffset(); if (document.getTextLength() < tailOffset + 2 || !document .getText(new TextRange(tailOffset, tailOffset + 2)) .equals(":]")) { document.insertString(tailOffset, ":]"); } editor.getCaretModel().moveCaretRelatively(2, 0, false, false, true); } })); } }
protected CompletionSorter getCompletionSorter( final CompletionParameters parameters, final CompletionResultSet result) { PrefixMatcher _prefixMatcher = result.getPrefixMatcher(); CompletionSorter _defaultSorter = CompletionSorter.defaultSorter(parameters, _prefixMatcher); AbstractCompletionContributor.DispreferKeywordsWeigher _dispreferKeywordsWeigher = new AbstractCompletionContributor.DispreferKeywordsWeigher(); return _defaultSorter.weighBefore("liftShorter", _dispreferKeywordsWeigher); }
public TypeCompletionHandler( @NotNull CompletionParameters parameters, @NotNull CompletionResultSet result, int weight) { super(parameters, result); _filter = getDefaultFilter(parameters.getPosition()); _weight = weight; _prefixMatcher = result.getPrefixMatcher(); _javaCtx = parameters.getPosition() instanceof PsiIdentifier; }
private static void ensureTemplatesShown( Ref<Boolean> templatesShown, List<TemplateImpl> templates, CompletionResultSet result) { if (!templatesShown.get()) { templatesShown.set(true); for (final TemplateImpl possible : templates) { result.addElement(new LiveTemplateLookupElement(possible, false)); } } }
private void addLanguageKeyword(CompletionResultSet resultSet, String text) { // TODO:: order most common used first String keywords = "|abs|accept|alarm|atan2|AUTOLOAD|BEGIN|bind|binmode|bless|break|caller|chdir|CHECK|chmod|chomp|chop|chown|chr|chroot|close|closedir|connect|cos|crypt|dbmclose|dbmopen|defined|delete|DESTROY|die|dump|each|END|endgrent|endhostent|endnetent|endprotoent|endpwent|endservent|eof|eval|exec|exists|exit|fcntl|fileno|flock|fork|format|formline|getc|getgrent|getgrgid|getgrnam|gethostbyaddr|gethostbyname|gethostent|getlogin|getnetbyaddr|getnetbyname|getnetent|getpeername|getpgrp|getppid|getpriority|getprotobyname|getprotobynumber|getprotoent|getpwent|getpwnam|getpwuid|getservbyname|getservbyport|getservent|getsockname|getsockopt|glob|gmtime|goto|grep|hex|index|INIT|int|ioctl|join|keys|kill|last|lc|each|lcfirst|setnetent|length|link|listen|local|localtime|log|lstat|map|mkdir|msgctl|msgget|msgrcv|msgsnd|next|not|oct|open|opendir|ord|our|pack|pipe|pop|pos|print|printf|prototype|push|quotemeta|rand|read|readdir|readline|readlink|readpipe|recv|redo|ref|rename|require|reset|return|reverse|rewinddir|rindex|rmdir|say|scalar|seek|seekdir|select|semctl|semget|semop|send|setgrent|sethostent|each|lcfirst|setnetent|setpgrp|setpriority|setprotoent|setpwent|setservent|setsockopt|shift|shmctl|shmget|shmread|shmwrite|shutdown|sin|sleep|socket|socketpair|sort|splice|split|sprintf|sqrt|srand|stat|state|study|substr|symlink|syscall|sysopen|sysread|sysseek|system|syswrite|tell|telldir|tie|tied|time|times|truncate|ucfirst|umask|undef|UNITCHECK|unlink|unpack|unshift|untie|use|utime|values|vec|wait|waitpid|wantarray|warn|write|each|lcfirst|setnetent|cmp|continue|CORE|else|elsif|exp|for|foreach|lock|package|unless|until|while|ARGV|ARGVOUT|STDERR|STDIN|STDOUT"; Matcher matcher = Utils.applyRegex("\\|(" + text + "[^\\|]+)", keywords); while (matcher.find()) { resultSet.addElement(LookupElementBuilder.create(matcher.group(1))); } }
public void addCompletions( @NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) { PsiElement element = parameters.getPosition(); while (element != null && !(element instanceof CfmlAttributeImpl)) { element = element.getParent(); } if (element == null) { return; } CfmlAttributeImpl attribute = (CfmlAttributeImpl) element; String attributeName = attribute.getFirstChild().getText(); while (element != null && !(element instanceof CfmlTag)) { element = element.getParent(); } if (element == null) { return; } CfmlTag tag = (CfmlTag) element; String tagName = tag.getTagName(); String[] attributeValue = CfmlUtil.getAttributeValues(tagName, attributeName, parameters.getPosition().getProject()); if ("type".equalsIgnoreCase(attributeName) && "cfargument".equalsIgnoreCase(tagName) || "returntype".equalsIgnoreCase(attributeName) && "cffunction".equalsIgnoreCase(tagName)) { Object[] objects = CfmlComponentReference.buildVariants( attribute.getPureAttributeValue(), element.getContainingFile(), element.getProject(), null, true); for (Object o : objects) { result.addElement((LookupElement) o); } } for (String s : attributeValue) { result.addElement(LookupElementBuilder.create(s).withCaseSensitivity(false)); } }
private static void addCachedVariables(CompletionResultSet resultSet, String str) { if (str != null && !variablesCache.containsKey(str)) { if (Utils.verbose) { Utils.print("cache variable: " + str); } variablesCache.put(str, getVariableLookupElementBuilder(str)); } if (resultSet != null) { resultSet.addElement(variablesCache.get(str)); } }
private static void addCachedPackage(CompletionResultSet resultSet, Package packageObj) { if (packageObj != null && !packagesCache.containsKey(packageObj)) { if (Utils.verbose) { Utils.print("cache package: " + packageObj.getQualifiedName()); } packagesCache.put(packageObj, getPackageLookupElementBuilder(packageObj)); } if (resultSet != null) { resultSet.addElement(packagesCache.get(packageObj)); } }
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 + ":")); } } } }
protected void createFollowElementBasedProposals( final CompletionParameters parameters, final CompletionResultSet result) { boolean _or = false; boolean _isEmpty = this.myFollowElementBasedContributors.isEmpty(); if (_isEmpty) { _or = true; } else { CompletionType _completionType = parameters.getCompletionType(); boolean _containsKey = this.myFollowElementBasedContributors.containsKey(_completionType); boolean _not = (!_containsKey); _or = _not; } if (_or) { return; } Editor _editor = parameters.getEditor(); int _offset = parameters.getOffset(); final TokenSet tokenSet = this._tokenSetProvider.getTokenSet(((EditorEx) _editor), _offset); CompletionType _completionType_1 = parameters.getCompletionType(); Map<TokenSet, Multimap<AbstractElement, CompletionProvider<CompletionParameters>>> _get = this.myFollowElementBasedContributors.get(_completionType_1); final Multimap<AbstractElement, CompletionProvider<CompletionParameters>> element2provider = _get.get(tokenSet); boolean _equals = Objects.equal(element2provider, null); if (_equals) { return; } final Set<AbstractElement> followElements = this.computeFollowElements(parameters); final HashSet<CompletionProvider<CompletionParameters>> calledProviders = CollectionLiterals.<CompletionProvider<CompletionParameters>>newHashSet(); Set<AbstractElement> _keySet = element2provider.keySet(); for (final AbstractElement followElement : _keySet) { { final ProcessingContext context = new ProcessingContext(); boolean _contains = followElements.contains(followElement); if (_contains) { final Collection<CompletionProvider<CompletionParameters>> providers = element2provider.get(followElement); for (final CompletionProvider<CompletionParameters> provider : providers) { boolean _add = calledProviders.add(provider); if (_add) { provider.addCompletionVariants(parameters, context, result); boolean _isStopped = result.isStopped(); if (_isStopped) { return; } } } } } } }
@Override public void addCompletions( @NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) { for (String[] stringArray : RegExpLanguageHosts.getInstance().getAllKnownProperties(parameters.getPosition())) { result.addElement( TailTypeDecorator.withTail( createLookupElement(stringArray[0], null, emptyIcon), TailType.createSimpleTailType('}'))); } }
@Override protected void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { UnicodeCharacterNames.iterate( name -> { if (result.getPrefixMatcher().prefixMatches(name)) { final String type = new String(new int[] {UnicodeCharacterNames.getCodePoint(name)}, 0, 1); if (myEmbrace) { result.addElement(createLookupElement("{" + name + "}", type, emptyIcon)); } else { result.addElement( TailTypeDecorator.withTail( createLookupElement(name, type, emptyIcon), TailType.createSimpleTailType('}'))); } } ProgressManager.checkCanceled(); }); }
@Override public boolean process( @NotNull String name, @NotNull GoNamedElement element, @NotNull ExistingImportData importData, @NotNull CompletionResultSet result) { GoTypeSpec spec = ((GoTypeSpec) element); boolean forTypes = myParent instanceof GoTypeReferenceExpression; double priority; if (importData.exists) { priority = forTypes ? GoCompletionUtil.TYPE_PRIORITY : GoCompletionUtil.TYPE_CONVERSION; } else { priority = forTypes ? GoCompletionUtil.NOT_IMPORTED_TYPE_PRIORITY : GoCompletionUtil.NOT_IMPORTED_TYPE_CONVERSION; } String lookupString = replacePackageWithAlias(name, importData.alias); if (forTypes) { result.addElement( GoCompletionUtil.createTypeLookupElement( spec, lookupString, GoAutoImportInsertHandler.SIMPLE_INSERT_HANDLER, importData.importPath, priority)); } else { result.addElement( GoCompletionUtil.createTypeConversionLookupElement( spec, lookupString, GoAutoImportInsertHandler.TYPE_CONVERSION_INSERT_HANDLER, importData.importPath, priority)); } return true; }
@Override public void fillCompletionVariants( final CompletionParameters parameters, final CompletionResultSet result) { CompletionSorter _completionSorter = this.getCompletionSorter(parameters, result); final CompletionResultSet sortedResult = result.withRelevanceSorter(_completionSorter); final Procedure1<CompletionResult> _function = new Procedure1<CompletionResult>() { @Override public void apply(final CompletionResult it) { LookupElement _lookupElement = it.getLookupElement(); boolean _isValidProposal = AbstractCompletionContributor.this.isValidProposal(_lookupElement, parameters); if (_isValidProposal) { LookupElement _lookupElement_1 = it.getLookupElement(); sortedResult.addElement(_lookupElement_1); } } }; final Procedure1<CompletionResult> filteredConsumer = _function; CompletionService _completionService = CompletionService.getCompletionService(); final CompletionResultSet filteredResult = _completionService.createResultSet( parameters, new Consumer<CompletionResult>() { public void consume(CompletionResult t) { filteredConsumer.apply(t); } }, this); this.createMatcherBasedProposals(parameters, filteredResult); this.createReferenceBasedProposals(parameters, filteredResult); this.createTokenSetBasedProposals(parameters, filteredResult); this.createFollowElementBasedProposals(parameters, filteredResult); this.createParserBasedProposals(parameters, filteredResult); result.stopHere(); }
private static void addCachedSubNoArgs(CompletionResultSet resultSet, Sub sub) { if (!subsCacheNoArgs.containsKey(sub)) { if (Utils.verbose) { Utils.print( "cache sub(no args): " + sub.getName() + " , containingPackage:" + sub.getPackageObj().getQualifiedName()); } subsCacheNoArgs.put(sub, getSubLookupElementBuilder(sub, false)); } if (resultSet != null) { resultSet.addElement(subsCacheNoArgs.get(sub)); } }
@Override public boolean process( @NotNull String name, @NotNull GoNamedElement element, @NotNull ExistingImportData importData, @NotNull CompletionResultSet result) { double priority = importData.exists ? GoCompletionUtil.VAR_PRIORITY : GoCompletionUtil.NOT_IMPORTED_VAR_PRIORITY; result.addElement( GoCompletionUtil.createVariableLikeLookupElement( element, replacePackageWithAlias(name, importData.alias), GoAutoImportInsertHandler.SIMPLE_INSERT_HANDLER, priority)); return true; }
@Override public boolean process( @NotNull String name, @NotNull GoNamedElement element, @NotNull ExistingImportData importData, @NotNull CompletionResultSet result) { GoFunctionDeclaration function = ((GoFunctionDeclaration) element); double priority = importData.exists ? GoCompletionUtil.FUNCTION_PRIORITY : GoCompletionUtil.NOT_IMPORTED_FUNCTION_PRIORITY; result.addElement( GoCompletionUtil.createFunctionOrMethodLookupElement( function, replacePackageWithAlias(name, importData.alias), GoAutoImportInsertHandler.FUNCTION_INSERT_HANDLER, priority)); return true; }
@Override protected void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { if (!Symfony2ProjectComponent.isEnabled(parameters.getPosition())) { return; } PhpIndex phpIndex = PhpIndex.getInstance(parameters.getOriginalFile().getProject()); for (PhpClass phpClass : phpIndex.getAllSubclasses("\\Doctrine\\ORM\\EntityRepository")) { String presentableFQN = phpClass.getPresentableFQN(); if (presentableFQN != null) { completionResultSet.addElement( LookupElementBuilder.create(phpClass.getName()) .withTypeText(phpClass.getPresentableFQN(), true) .withIcon(phpClass.getIcon())); } } }
private static void addCompletionElements( CompletionResultSet result, final Consumer<Task> consumer, List<Task> items, int index) { final AutoCompletionPolicy completionPolicy = ApplicationManager.getApplication().isUnitTestMode() ? AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE : AutoCompletionPolicy.NEVER_AUTOCOMPLETE; for (final Task task : items) { LookupElementBuilder builder = LookupElementBuilder.create(task, task.getId()) .setIcon(task.getIcon()) .addLookupString(task.getSummary()) .setTailText(" " + task.getSummary(), true) .setInsertHandler( new InsertHandler<LookupElement>() { @Override public void handleInsert(InsertionContext context, LookupElement item) { Document document = context.getEditor().getDocument(); String s = task.getId() + ": " + task.getSummary(); document.replaceString(context.getStartOffset(), context.getTailOffset(), s); context .getEditor() .getCaretModel() .moveToOffset(context.getStartOffset() + s.length()); consumer.consume(task); } }); if (task.isClosed()) { builder = builder.setStrikeout(); } result.addElement( PrioritizedLookupElement.withGrouping( builder.withAutoCompletionPolicy(completionPolicy), index--)); } }
@Override protected void addCompletions( @NotNull CompletionParameters params, ProcessingContext ctx, @NotNull CompletionResultSet results) { PsiElement curr = params.getPosition().getOriginalElement(); // n: attributes if (curr.getParent() instanceof XmlAttribute) { for (LookupElementBuilder x : ATTR_LOOKUPS) results.addElement(x); return; } // Keywords if (curr.getNode().getElementType() == LatteTokenTypes.MACRO_NAME) { for (LookupElementBuilder x : KEYWORD_LOOKUPS) results.addElement(x); HashSet<String> openedMacros = new HashSet<String>(); // macros which are opened before (should complete closing) HashSet<String> closedMacros = new HashSet<String>(); // which are closed (should not complete closing) // Go up and find open keywords (and offer them for closing) PsiElement cursor = curr; while (cursor != null && (cursor.getPrevSibling() != null || cursor.getParent() != null)) { // macro found {xx} found if (cursor instanceof MacroNodeImpl) { MacroNodeImpl node = (MacroNodeImpl) cursor; String name = node.getMacroName(); if (name.charAt(0) == '/') { // closing macro closedMacros.add(name.substring(1)); } else if (PAIR_MACROS.contains(name)) { if (closedMacros.contains(name)) closedMacros.remove(name); // is closed later else openedMacros.add(name); // not closed, let us close it } } PsiElement tmp; if ((tmp = cursor.getPrevSibling()) != null) cursor = tmp; // Go prev if possible... else cursor = cursor.getParent(); // ... or up } for (String name : openedMacros) { if (name.equals("if")) { results.addElement(reuseClosingTag("else")); results.addElement(reuseClosingTag("elseif")); } results.addElement(reuseClosingTag("/" + name)); } results.stopHere(); } // Modifiers (if after pipe) PsiElement prev = curr.getPrevSibling(); if (prev != null && prev instanceof PsiWhiteSpace) prev = prev.getPrevSibling(); if (prev != null && prev.getNode().getElementType() == LatteTokenTypes.MODIFIER) { for (LookupElementBuilder x : FILTER_LOOKUPS) results.addElement(x); results.stopHere(); } }
public void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { PsiElement stringLiteralExpression = parameters.getPosition().getParent(); Project project = stringLiteralExpression.getProject(); if (!SilexProjectComponent.isEnabled(project)) { return; } if (!(stringLiteralExpression instanceof StringLiteralExpression)) { return; } PsiElement arrayKeyElement = stringLiteralExpression.getParent(); PsiElement element = arrayKeyElement.getParent(); if (element instanceof ArrayHashElement) { if (!arrayKeyElement.isEquivalentTo(element.getFirstChild())) { return; } element = element.getParent(); } if (!(element instanceof ArrayCreationExpression)) { return; } PsiElement parameterList = element.getParent(); if (!(parameterList instanceof ParameterList)) { return; } PsiElement[] params = ((ParameterList) parameterList).getParameters(); if (!(params.length > 1 && params[1].isEquivalentTo(element))) { return; } PsiElement methodReference = parameterList.getParent(); if (!(methodReference instanceof MethodReference)) { return; } String methodReferenceName = ((MethodReference) methodReference).getName(); if ((methodReferenceName == null) || !(methodReferenceName.equals("register"))) { return; } Container container = Utils.findContainerForMethodReference((MethodReference) methodReference); if (container == null) { return; } for (Parameter parameter : container.getParameters().values()) { resultSet.addElement(new ParameterLookupElement(parameter)); } resultSet.stopHere(); }
@Override protected void addCompletions( @NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement position = completionParameters.getPosition(); if (!Symfony2ProjectComponent.isEnabled(position)) { return; } PsiElement psiElement = PsiTreeUtil.findFirstParent( position, new Condition<PsiElement>() { @Override public boolean value(PsiElement psiElement) { if (psiElement instanceof YAMLKeyValue) { String s = ((YAMLKeyValue) psiElement).getKeyText().toLowerCase(); if ("joinTable".equalsIgnoreCase(s)) { return true; } } return false; } }); if (psiElement == null) { return; } PsiElement yamlCompoundValue = psiElement.getParent(); if (!(yamlCompoundValue instanceof YAMLCompoundValue)) { return; } String className = YamlHelper.getYamlKeyValueAsString( (YAMLCompoundValue) yamlCompoundValue, "targetEntity", false); if (className == null) { return; } PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), className); if (phpClass == null) { return; } for (DoctrineModelField field : EntityHelper.getModelFields(phpClass)) { if (field.getRelation() == null) { String columnName = field.getColumn(); if (columnName == null) { completionResultSet.addElement( LookupElementBuilder.create(field.getName()).withIcon(Symfony2Icons.DOCTRINE)); } else { completionResultSet.addElement( LookupElementBuilder.create(columnName) .withTypeText(field.getName(), false) .withIcon(Symfony2Icons.DOCTRINE)); } } } }