com.intellij.codeInsight.completion.CompletionInitializationContext Java Examples

The following examples show how to use com.intellij.codeInsight.completion.CompletionInitializationContext. 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: KeywordCollector.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@NotNull
private Collection<String> suggestKeywordsBasedOnParserExpectedKeywords(@NotNull PsiElement position) {
    String text = getPrecedingText(position, CompletionInitializationContext.DUMMY_IDENTIFIER);
    Project project = position.getProject();
    PsiFile temporaryFileForCompletionCheck = createFileForText(project, text + "          ");
    int completionOffset = calculateCompletionOffset(position);
    GeneratedParserUtilBase.CompletionState completionStateInTemporaryFile = getCompletionStateForKeywords(completionOffset);
    temporaryFileForCompletionCheck.putUserData(COMPLETION_STATE_KEY, completionStateInTemporaryFile);
    triggerParsingInFile(temporaryFileForCompletionCheck);
    List<String> stripped = stringPrecedingText(StringUtils.normalizeWhitespaces(text), completionStateInTemporaryFile.items);
    return expandMultiWordOptions(stripped);
}
 
Example #2
Source File: TemplateExpressionLookupElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static InsertionContext createInsertionContext(LookupElement item,
                                                       PsiFile psiFile,
                                                       List<? extends LookupElement> elements,
                                                       Editor editor, final char completionChar) {
  final OffsetMap offsetMap = new OffsetMap(editor.getDocument());
  final InsertionContext context = new InsertionContext(offsetMap, completionChar, elements.toArray(new LookupElement[elements.size()]), psiFile, editor, false);
  context.setTailOffset(editor.getCaretModel().getOffset());
  offsetMap.addOffset(CompletionInitializationContext.START_OFFSET, context.getTailOffset() - item.getLookupString().length());
  offsetMap.addOffset(CompletionInitializationContext.SELECTION_END_OFFSET, context.getTailOffset());
  offsetMap.addOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET, context.getTailOffset());
  return context;
}
 
Example #3
Source File: LSIncompleteCompletionProposal.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void handleInsert(@NotNull InsertionContext context) {
    apply(context.getDocument(), context.getCompletionChar(), 0, context.getOffset(CompletionInitializationContext.SELECTION_END_OFFSET));
}
 
Example #4
Source File: BashCompletionContributor.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeCompletion(@NotNull CompletionInitializationContext context) {
    context.setDummyIdentifier("ZZZ");
}
 
Example #5
Source File: BashCompletionContributor.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
public void duringCompletion(@NotNull CompletionInitializationContext context) {
    fixComposedWordEndOffset(context);
}
 
Example #6
Source File: BashCompletionContributor.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
/**
 * Fix the replace offset, for composed bash words use the full composed range
 *
 * @param context The current invocation context
 */
protected void fixComposedWordEndOffset(CompletionInitializationContext context) {
    PsiElement element = context.getFile().findElementAt(context.getStartOffset());
    if (element == null) {
        return;
    }

    OffsetMap offsetMap = context.getOffsetMap();

    //if the completion is like "$<caret>" then element is the string end marker
    // in that case set the end before the end marker
    if (endTokens.contains(element.getNode().getElementType())) {
        offsetMap.addOffset(START_OFFSET, element.getTextOffset());
        offsetMap.addOffset(IDENTIFIER_END_OFFSET, element.getTextOffset());
        return;
    }

    if (wordTokens.contains(element.getNode().getElementType())) {
        if (fixReplacementOffsetInString(element, offsetMap)) {
            return;
        }
    }

    //try the parent if it's not already a BashWord
    if (!(element instanceof BashWord)) {
        element = element.getParent();
    }

    if (element instanceof BashWord) {
        offsetMap.addOffset(START_OFFSET, element.getTextOffset());

        // https://code.google.com/p/bashsupport/issues/detail?id=51
        // a completion at the end of a line with an open string is parsed as string until the first quote in the next line(s)
        // in the case of a newline character in the string the end offset is set to the end of the string to avoid aggressive string replacements

        if (!fixReplacementOffsetInString(element, offsetMap)) {
            offsetMap.addOffset(IDENTIFIER_END_OFFSET, element.getTextRange().getEndOffset());
        }

    }
}
 
Example #7
Source File: CSharpCompletionContributor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeCompletion(@Nonnull CompletionInitializationContext context)
{
	context.setDummyIdentifier(CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED);
}
 
Example #8
Source File: HaxeCodeGenerateUtil.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
private static String trimDummy(String text) {
  if (text.endsWith(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED)) {
    text = text.substring(0, text.length() - CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED.length());
  }
  return text;
}
 
Example #9
Source File: LombokPostfixTemplateProvider.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static boolean isSemicolonNeeded(@NotNull PsiFile file, @NotNull Editor editor) {
  int startOffset = CompletionInitializationContext.calcStartOffset(editor.getCaretModel().getCurrentCaret());
  return JavaCompletionContributor.semicolonNeeded(editor, file, startOffset);
}
 
Example #10
Source File: XQueryCompletionContributor.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeCompletion(@NotNull CompletionInitializationContext context) {
    overwriteDummyIdentifierToTryToCreateFunctionReference(context);
}
 
Example #11
Source File: XQueryCompletionContributor.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private void overwriteDummyIdentifierToTryToCreateFunctionReference(CompletionInitializationContext context) {
    context.setDummyIdentifier(CompletionInitializationContext.DUMMY_IDENTIFIER + PARENTHESES);
}