Search in sources :

Example 1 with PostfixLiveTemplate

use of com.intellij.codeInsight.template.postfix.templates.PostfixLiveTemplate in project intellij-community by JetBrains.

the class PostfixTemplatesCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    Editor editor = parameters.getEditor();
    if (!isCompletionEnabled(parameters) || LiveTemplateCompletionContributor.shouldShowAllTemplates() || editor.getCaretModel().getCaretCount() != 1) {
        /*
        disabled or covered with {@link com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor}
       */
        return;
    }
    PsiFile originalFile = parameters.getOriginalFile();
    PostfixLiveTemplate postfixLiveTemplate = getPostfixLiveTemplate(originalFile, editor);
    if (postfixLiveTemplate != null) {
        postfixLiveTemplate.addCompletions(parameters, result.withPrefixMatcher(new MyPrefixMatcher(result.getPrefixMatcher().getPrefix())));
        String possibleKey = postfixLiveTemplate.computeTemplateKeyWithoutContextChecking(new CustomTemplateCallback(editor, originalFile));
        if (possibleKey != null) {
            result = result.withPrefixMatcher(possibleKey);
            result.restartCompletionOnPrefixChange(StandardPatterns.string().oneOf(postfixLiveTemplate.getAllTemplateKeys(originalFile, parameters.getOffset())));
        }
    }
}
Also used : PostfixTemplateCompletionContributor.getPostfixLiveTemplate(com.intellij.codeInsight.template.postfix.completion.PostfixTemplateCompletionContributor.getPostfixLiveTemplate) PostfixLiveTemplate(com.intellij.codeInsight.template.postfix.templates.PostfixLiveTemplate) PsiFile(com.intellij.psi.PsiFile) CustomTemplateCallback(com.intellij.codeInsight.template.CustomTemplateCallback) Editor(com.intellij.openapi.editor.Editor)

Aggregations

CustomTemplateCallback (com.intellij.codeInsight.template.CustomTemplateCallback)1 PostfixTemplateCompletionContributor.getPostfixLiveTemplate (com.intellij.codeInsight.template.postfix.completion.PostfixTemplateCompletionContributor.getPostfixLiveTemplate)1 PostfixLiveTemplate (com.intellij.codeInsight.template.postfix.templates.PostfixLiveTemplate)1 Editor (com.intellij.openapi.editor.Editor)1 PsiFile (com.intellij.psi.PsiFile)1