CompletionContributor for Xpath elements
Hello guys,
I'm writing a plug-in for supporting our custom simple language.
This is simple piece of our code:
$SomeVar <= /some/xpath
After parsing this line of code I receive 3 psi elements: VarDeclare($SomeVar), Apply(<=) and XPath(/some/xpath)
I want to implement completion for xpath parts. For example, when I write "/" first time and then one letter "p" popup appears with suggestions(pic.1), after choosing one and pressing enter I write "/" again and nothing appears here(pic.2), but I want to see the same list of suggestions
(pic.1)
(pic.2)
I know that I can do this by rewriting lexer and splitting XPath to something like a list of XpathPart. But it is a little bit tricky in my case.
This is my piece of code which does what I have for now:
extend(CompletionType.BASIC,
PlatformPatterns.psiElement(XrlElementTokenTypes.Xpath).withLanguage(XroolsLanguage()),
new CompletionProvider[CompletionParameters]() {
def addCompletions(parameters: CompletionParameters, context: ProcessingContext, resultSet: CompletionResultSet) {
List("part1","part2","part3","part4") foreach(part => resultSet.addElement(LookupElementBuilder.create(part)))
}
}
)
Is any way to do what I want inside CompletionContributor without changing lexer?
Please sign in to leave a comment.
Most probably the autodetected matching prefix is "/part1/" and it doesn't match your variants. Please try passing your results not to the original resultSet, but to resultSet.withPrefix(<calculate-shorter-prefix-here>).