Autocompletion hangs in custom MultiHostInjector
Answered
I defined the following instance of MultiHostInjector to treat comments a java methods' bodies:
public class MyCustomMultiHostInjector implements MultiHostInjector {
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
if (context instanceof PsiDocComment) return;
final PsiComment psiComment = (PsiComment) context;
registrar.startInjecting(JavaLanguage.INSTANCE);
registrar.addPlace(
"class A { void method() { ",
"; }}",
(PsiLanguageInjectionHost) context,
new TextRange(3, psiComment.getTextLength())
);
registrar.doneInjecting();
}
@NotNull
@Override
public List<? extends Class<? extends PsiElement>> elementsToInjectIn() {
return Collections.singletonList(PsiComment.class);
}
}
Intellij IDEA recognizes a comment a body of a java method, it adds highlighting, but when I try to use autocompletion (like // System.<CTRL+SPACE>) it hangs: the progress ring is spinning forever:

What is wrong with my class?
Please sign in to leave a comment.
I tried to reproduce it, but everything works as expected:
Could you try to invalidate the cache and restart IDE?
Jakub Chrzanowski, thank you for checking it on your IDEA, I have figure it out, there is a custom com.intellij.codeInsight.completion.CompletionProvider with an infinity loop inside of TypeAliasCompletionProvider#addCompletions, that is why the autocomplete hung.