CodeCompletion not execute after set language of LanguageTextField
Answered
Please see the following code, if I set PlainTextLanguage.INSTANCE as the language, codeCompletion will work, but if I set Json5Language.INSTANCE
, codeCompletion not work. It always show no suggestions.
So how to make codeCompletion work even I set Json5Language.INSTANCE
as the language
TextFieldWithAutoCompletion.StringsCompletionProvider completionProvider = new com.intellij.ui.TextFieldWithAutoCompletion.StringsCompletionProvider(Lists.newArrayList("a", "b"), AllIcons.Nodes.Method);
new com.intellij.ui.LanguageTextField(Json5Language.INSTANCE,project,"",completionProvider,false);
IDEA: 2023.3
Please sign in to leave a comment.
What happens is that the
StringsCompletionProvider
that you create works only in files that are plain text. More specifically, when you hit completion in your text field, the framework collects all completion contributors that would be appropriate in the current context. This happens here and the “parameters” can take the language into account.So, when you define your
StringsCompletionProvider
and use it in a JSON field, your completion is just not taken into account at the above point and your completions will not be suggested. I'm not sure if there is a way to fix this within this framework right now. All examples I checked use plain text when they have completion and don't have (additional) completion defined when they use a different language than plain text.It also means that when you use
LanguageTextField
with any other language thanPlainText
, you will run into the same problem. However, all other completions for these languages work. This leads me to a possible solution if you really need additional completion in this text field. You can define just a regular completion provider and try to restrict it so it is only invoked in your text field.Your text field:
The completion provider and contributor
Register the contributor in your plugin.xml
The code doesn't compile. Please post the actual working snippet of your issue.
About missing completion, it might be that builtin JSON completion providers interfere here.
Full demo code
Sorry for delay, investigating.
A few days ago, I finally used your solution, which meets my current needs.
Still thank you very much. @Patrick Scheibe