Code completion with CompletionContributor
Hello!
I am developing a plugin for PhpStorm, and I want to provide code completion when the user, for example, calls a method on a class like User::find("").
I want to suggest words which a define to the user when the cursor is between the double quotes.
This is my code. It works for all double quotes, but I want it to work only when the user is inside the "" of a methodpublic class ModelFieldCompletion extends CompletionContributor {
public ModelFieldCompletion() {
extend(CompletionType.BASIC, PlatformPatterns.psiElement(PhpTokenTypes.STRING_LITERAL),
new CompletionProvider<>() {
public void addCompletions(@NotNull CompletionParameters parameters,
@NotNull ProcessingContext context,
@NotNull CompletionResultSet resultSet) {
String[] suggestions = {"hello", "world", "example", "suggestion"};
// Iterate over the array and add each string as a suggestion
for (String suggestion : suggestions) {
resultSet.addElement(LookupElementBuilder.create(suggestion).bold().withCaseSensitivity(false));
}
}
}
);
}
}
Does anyone know what I need to add or what I still have to do to achieve this?
Thanks.
请先登录再写评论。