about invokeAutoPopup()

I  don't know the purpose of  invokeAutoPopup(). example code as follows:

 

public class DemoAttributeCompletionContributor extends CompletionContributor {

public DemoAttributeCompletionContributor() {
     extend(CompletionType.BASIC,
     PlatformPatterns.psiElement(PsiElement.class),
     new CompletionProvider<CompletionParameters>() {

          @Override
         protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet resultSet) {

         resultSet.addElement(LookupElementBuilder.create( "test" ).withLookupString("test")
         resultSet.stopHere();

        }
    });
}


@Override
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
    return typeChar==' @ ';
    }
}

I think the code can automatically show the auto-complete when I hit @ from my keyboard,  but it doesn't work,so what happen?

Thanks

ML

0
11 comments
Official comment

First, this API is problematic, I'd suggest instead to invoke AutoPopupController#autoPopupMemberLookup from TypedHandlerDelegate (checkAutoPopup or beforeCharTyped).

But, nevertheless, it looks like in your case it should work. Have you tried to debug it, by putting a breakpoint inside "invokeAutoPopup" and checking if it is called?

Also Metaer (and this goes without saying) make sure you have "DemoAttributeCompletionContributor" registered in your plugin.xml.

Also: just out of curiosity, why is typeChar ' @ ' ... shouldn't it be '@'  (i.e.: without spaces)?

Peter: I actually do use invokeAutoPopup(..) in my own plugin. What's problematic about it? I thought it basically just circumvents the need for the psi pattern to match in order to trigger addCompletions(..).

I used it to invoke a completion popup whenever a '\\' backslash is typed into the editor. A pattern could be used for this I guess, but (I think) it would be pain to write a pattern that would allow it to occur anywhere (you'd have to special case, for example, PsiErrorElements etc). 

0

Daniel, the problem with "invokeAutoPopup" is that some PsiElement is passed there, but it's taken from uncommitted document and might be very unrelated to the actual editor text. And committing document on typing every character is not an option, since it'll slow down the UI response time.

0
Avatar
Permanently deleted user

Hi Daniel,

Actually,have registered and without spaces.thanks for your  sincere suggestion.

 

Hi Peter,I am sure invokeAutoPopup() is called when I type '@'  ,and more, the constructor(DemoAttributeCompletionContributor) is called also. But,the auto-popup is not activated.I try autoPopupMemberLookup in my TypedHandlerDelegate,the result is the same:constructor is called,but auto-popup is not activated.

Thanks,

ML

0
Avatar
Permanently deleted user

More information,the auto-popup should be actived via offical method,but the customed char(like `@` in my example code),it do not work.

 

It's ok(I type spacebar,and the auto-popup appear)



nothing happen when i type `@`

 

ML

0

Then I'd suggest to put breakpoints inside AutoPopupController#scheduleAutoPopup and see what's wrong. Maybe CompletionPhase.CommittingDocuments#checkExpired returns true for some reason.

0
Avatar
Permanently deleted user

Peter, i find `editor.getUserData(Key.create("Always Show Completion Auto-Popup") ` is false, any helpful to my problem?

thanks

ML

0

That code would always return false result, but that shouldn't affect your plugin. Or do you mean that you have the option for showing completion autopopup disabled in the settings?

0
Avatar
Permanently deleted user

“ Or do you mean that you have the option for showing completion autopopup disabled in the settings? ”

 

Peter,I do not have this option. I just try all kinds of solutions. and now I I also found that when I set characters to be `*`  instead of @ or other characters, it can pop-up automatically. But the other characters do not.

 public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
   return typeChar=='*';  //it work when i type *
}


public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
   return typeChar==`@`;  //it do not work when i type @
}

Is this information helpful?

Thanks,
ML
0

No, unfortunately this doesn't help. I think only debugging can help, putting breakpoints to various places and then checking what happens there, and why the execution doesn't continue. If you can't do this, we could try to help you with debugging, but we'd need your code for that.

0
Avatar
Permanently deleted user

Peter, I have already solved this problem. `AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, CompletionType.BASIC, Condition.TRUE)` can't put in `charTyped` in my TypedHandlerDelegate, must in `beforeCharTyped`.

Thank you for your patience.

ML

0

Please sign in to leave a comment.