I am developing a plugin for intellij and I want to add special offers to the xsd based xml editor. So far, I can get the required sentences from the xsd file.
I have implemented a completion contributor for xml as follows
import com.intellij.codeInsight.completion.*; import com.intellij.codeInsight.lookup.LookupElementBuilder; import com.intellij.patterns.PlatformPatterns; import com.intellij.psi.xml.XmlElementType; import com.intellij.util.ProcessingContext; import com.intellij.lang.xml.*; import org.jetbrains.annotations.NotNull; public class SimpleCompletionContributor extends CompletionContributor { public SimpleCompletionContributor() { extend(CompletionType.BASIC,PlatformPatterns.psiElement(XmlElementType.XML_ATTRIBUTE_VALUE).withLanguage(XMLLanguage.INSTANCE), new CompletionProvider<CompletionParameters>() { public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { resultSet.addElement(LookupElementBuilder.create("Hello")); } } ); } }
but it did not give any suggestions. but when I implement a custom language, it works. My goal is to look at the context of the cursor position and suggest based on this sentence. as an example, when a user launches a tag in an XML file, the plugin should provide attributes as code completion. I am new to this custom language.
So can anyone help me with this add-on?
java xml intellij-idea intellij-plugin code-completion
Hasintha samith randika
source share