Search in sources :

Example 1 with IncludeAutoInsert

use of ool.intellij.plugin.editor.completion.handler.IncludeAutoInsert in project oxy-template-support-plugin by mutant-industries.

the class JsMacroName method addMacroNameCompletionVariant.

@Override
public boolean addMacroNameCompletionVariant(@NotNull CompletionResultSet result, @NotNull PsiElement position, @NotNull PsiElement lookupElement, @NotNull String fqn, @NotNull String macroName, @NotNull String macroNamespace) {
    result.withPrefixMatcher(new CamelHumpMatcher(namespaceFqn + position.getText().replace(CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED, ""))).consume(LookupElementDecorator.withInsertHandler(LookupElementBuilder.create(lookupElement, fqn + "();").withIcon(OxyTemplateFileType.INSTANCE.getIcon()).withPresentableText(macroName + "([Object] params) (" + macroNamespace + ")").withTailText(" " + lookupElement.getContainingFile().getVirtualFile().getPath().replaceFirst("^.+((src)|(WEB_INF))/", ""), true).withInsertHandler(new TrailingPatternConsumer(INSERT_CONSUME) {

        @Override
        public void handleInsert(InsertionContext context, LookupElement item) {
            CaretModel caretModel = context.getEditor().getCaretModel();
            caretModel.moveToOffset(caretModel.getOffset() - 2);
            super.handleInsert(context, item);
        }
    }).withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE), new IncludeAutoInsert()));
    return fqn.startsWith(namespaceFqn.substring(0, Math.max(namespaceFqn.length(), namespaceFqn.indexOf("."))));
}
Also used : CaretModel(com.intellij.openapi.editor.CaretModel) TrailingPatternConsumer(ool.intellij.plugin.editor.completion.handler.TrailingPatternConsumer) IncludeAutoInsert(ool.intellij.plugin.editor.completion.handler.IncludeAutoInsert) InsertionContext(com.intellij.codeInsight.completion.InsertionContext) LookupElement(com.intellij.codeInsight.lookup.LookupElement) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher)

Aggregations

InsertionContext (com.intellij.codeInsight.completion.InsertionContext)1 CamelHumpMatcher (com.intellij.codeInsight.completion.impl.CamelHumpMatcher)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 CaretModel (com.intellij.openapi.editor.CaretModel)1 IncludeAutoInsert (ool.intellij.plugin.editor.completion.handler.IncludeAutoInsert)1 TrailingPatternConsumer (ool.intellij.plugin.editor.completion.handler.TrailingPatternConsumer)1