Completion does not work for custom language
Answered
Completion
extend(CompletionType.BASIC, PlatformPatterns.psiElement(MyTypes.ID), new CompletionProvider<CompletionParameters>() {
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement element = parameters.getPosition();
PsiElement parent = element.getParent();
PsiElement prevSibling = element.getPrevSibling();
PsiElement nextSibling = element.getNextSibling();
LOG.warn("---------------ID------------------");
LOG.warn("position=" + element);
LOG.warn("original position=" + parameters.getOriginalPosition());
LOG.warn("parent=" + parent);
if (prevSibling != null) {
LOG.warn("prevSibling=" + prevSibling);
}
if (nextSibling != null) {
LOG.warn("nextSibling=" + nextSibling);
}
}
});
does not work for a tag like [[~10]]
But for some reason it works for him
extend(CompletionType.BASIC, PlatformPatterns.psiElement(MyTypes.IDENTIFIER), new CompletionProvider<CompletionParameters>() {
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement element = parameters.getPosition();
PsiElement parent = element.getParent();
PsiElement prevSibling = element.getPrevSibling();
PsiElement nextSibling = element.getNextSibling();
LOG.warn("---------------IDENTIFIER------------------");
LOG.warn("position=" + element);
LOG.warn("original position=" + parameters.getOriginalPosition());
LOG.warn("parent=" + parent);
if (prevSibling != null) {
LOG.warn("prevSibling=" + prevSibling);
}
if (nextSibling != null) {
LOG.warn("nextSibling=" + nextSibling);
}
}
});
which for a tag like [[+pls]]
In parameters.getPosition() always PsiElement(MyTokenType.IDENTIFIER)
Please sign in to leave a comment.
Hi,
I'm sorry, but I don't understand what the issue is. What are expected/actual behaviors? Please try to explain it again.
I want my code to be executed when the cursor is inside a tag [[~10]] near a number and Ctrl + Space is pressed.
But this doesn't happen with
Before invoking completion, two important steps are done:
CompletionInitializationContext.DUMMY_IDENTIFIER
) is inserted at the caret position, so that there is always a token present, that in most cases makes the PSI tree valid.As far as I understand, in your case, the dummy identifier with characters is inserted, but you need a number. You can change the dummy identifier in your contributor to numbers by overriding
com.intellij.codeInsight.completion.CompletionContributor.beforeCompletion()
and usingcom.intellij.codeInsight.completion.CompletionInitializationContext.setDummyIdentifier()
.