Quick Fix with user input

Hello,

I would like to make a quick fix that needs some kind of user input. That seems kind of do-able, but I run into problems concerning permissions.

What I'm trying is making a class than extends BaseIntentionAction, and the invoke method then needs to gather some info, based upon which it will show the user a list pop up (through JBPopupFactory.getInstance().createListPopupBuilder).
Based upon the choice that the user makes, changes in the psi tree need to be performed. These are not several different quick fixes, but one quick fix for which I need user input, to clarify.

I first tried to attach a listener to the pop up and as soon as a choice is made I apply the changes in the psi tree. There, I first ran into write permission problems, which I solved by wrapping the part of the callback function that made the change in an ApplicationManager.getInstance().runWriteAction. The next assertion that failed was that I apparently could not make any changes from the thread I was on. I didn't manage to solve that, I then ended up in thinking about other solutions but at a certain moment it started involving semaphores for synchronization and so on (to make sure the user makes it's selection before I continue running the invoke function from BaseIntentionAction (which is allowed to make changes to the psi tree), but making sure I had all the info and so on and so forth) and then I started realizing that this was likely not the way to go, getting a bit too complicated.

So, here goes, is there an advised way of aquiring user input for a quick fix that involves making changes to the psi tree, or is that impossible and should something else be used?

Kasper

2 comments
Comment actions Permalink

There is actually nothing compilcated here. The popup selection happens in the EDT, and it's the same thread that you have to use for PSI modifications. Simply wrap your code that changes the PSI in a WriteCommandAction, and you'll be fine.

0
Comment actions Permalink

Indeed, thanks. I just wrapped that code in the WriteCommandAction and executed that in the callback registered in setItemChoosenCallback of the list popup. I was making it too complicated.

One question, through, how can I write a test for this? Can I, one way or another, mock the on-screen selection process for the user in my tests?

0

Please sign in to leave a comment.