Add custom codecompletions to cucumber step

Hi all, i wanna get autocomplete for cucumber step parameters, i try make Completion Contributor, and add results, but when i press Ctrl+Space(caret in the step) i see link to step definition and not see my parameters.

How i can add elements to completion list?

I have elements in project with annotation @Name

public class TestCompletion extends CompletionContributor {
public TestCompletion() {
extend(CompletionType.BASIC,
PlatformPatterns.psiElement(),
new CompletionProvider<CompletionParameters>() {
public void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context,
@NotNull CompletionResultSet resultSet) {
PsiElement psiElement = parameters.getOriginalPosition();
assert psiElement != null;
Project project = psiElement.getProject();
Collection<PsiAnnotation> psiAnnotations = StubIndexImpl.getInstance().get(JavaStubIndexKeys.ANNOTATIONS, "Name", project, GlobalSearchScope.allScope(project));
List<LookupElement> completeElements = new ArrayList<>();
for (PsiAnnotation annotation : psiAnnotations) {
String current = annotation.getText()
.replace("@Name(\"", "")
.replace("\")", "");
if (current.length() > 0){
completeElements.add(LookupElementBuilder.create(current));
}
}
resultSet.addAllElements(completeElements);

}
});
}

}
1

Hi,

 

Could you check that collection psiAnnotations is not empty? Also your completion element could be filtered out by prefix, so also you should check what is value of variable current.

 

By the way, from performance point of view it's better to add a condition to check that current file is ".feature" file and return if it's wrong file type

1
Avatar
Permanently deleted user

Denis,

I too am on a similar path to extend functionality of default cucumber plugin.

What approach did you use ?

How did you build the opensource plugins https://github.com/JetBrains/intellij-plugins for your needs ?

Any help is appreciated https://intellij-support.jetbrains.com/hc/en-us/community/posts/360008260740-Questions-on-cleanly-extending-functionality-of-cucumber-java-plugin

0

请先登录再写评论。