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

1
2 comments

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.

0

Full  demo code

import com.google.common.collect.Lists;
import com.intellij.icons.AllIcons;
import com.intellij.json.json5.Json5Language;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.TextFieldWithAutoCompletion;
import com.intellij.util.textCompletion.TextCompletionUtil;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class DemoDialogWrapper extends DialogWrapper {
    private final Project project;

    public DemoDialogWrapper(@Nullable Project project) {
        super(project, false);
        this.project = project;
        init();
        setSize(400, 300);
        setTitle("demo");
    }


    @Override
    protected @Nullable JComponent createCenterPanel() {
        TextFieldWithAutoCompletion.StringsCompletionProvider completionProvider = new TextFieldWithAutoCompletion.StringsCompletionProvider(Lists.newArrayList("a", "b"), AllIcons.Nodes.Method);
        TextCompletionUtil.DocumentWithCompletionCreator documentWithCompletionCreator = new TextCompletionUtil.DocumentWithCompletionCreator(completionProvider, false, false);
        return new com.intellij.ui.LanguageTextField(com.intellij.json.json5.Json5Language.INSTANCE, project, "", documentWithCompletionCreator, false);
        
        //Change Json5Language.INSTANCE to com.intellij.openapi.fileTypes.PlainTextLanguage 
        //CodeCompletion works

    }
}

 

 

 

 

0

Please sign in to leave a comment.