Single-shot intention/quickfixes

I'm looking for some way to have a sort of "single-shot" intention or quickfix, which is only usable after some other action is taken by the user. Here's the use case: I want the user to select a menu action requesting that some complex analysis be done. The action would do an enormous amount of calculation, the end result of which is some blocks of code are highlighted. Then, if the user selects one of those highlighted blocks, they get an intention offering them to perform some interesting action on the code in that block. The initial action, calculation, and highlighting are all pretty easy, but things fall down when I try to offer that intention. I could use a standard intention and allow it to try to figure out when the user has selected in a code segment that had been highlighted, but that seems clunky and error-prone, since calculation results would have to be stored indefinitely.

Any ideas?

--Dave Griffith

5 comments

Well, I don't see why you need to store calculation results indefinitely. You drop them when you like, and the intention does not see anything. A better way though would be to unregister the intention itself when you drop the highlighting, but currently unregistering is not possible (I recall Bas requesting this feature, but his reasons were quite different).

Eugene.

0

Now I have never used it, but would it not be possible to use the language API for this purpose?
com.intellij.lang.Language.findInstance(JavaLanguage)
You might be able to create an external annotator to do the highlighting as soon as the calculation is complete. This annotator could be unregistered as soon as the calculation results are not valid anymore.

Bas

0

The trick is that I would need to store the results at least as long as the highlight is visible. As near as I can tell HighlightManager doesn't tell me when a highlight goes away, so I would have to be "conservative", and possible leak.

I guess another way of stating this is I want to be able to bind intentions to active highlights.

--Dave Griffith

0

From what I remember from when I did SyncEdit, the highlights only go
away when the file is closed or the highlighted text is deleted, both of
which you could detect - other than that you have to remove highlights
manually.

Of course this is only true if you are adding highlights at the low
level via calls to MarkupModel.addRangeHighlighter(); if you are using
some other higher level highlighting functionality then it's possible
Idea may subsequently remove highlighting in other ways that might not
be detectable.

HTH,
N.

Dave Griffith wrote:

The trick is that I would need to store the results at least as long
as the highlight is visible. As near as I can tell HighlightManager
doesn't tell me when a highlight goes away, so I would have to be
"conservative", and possible leak.

I guess another way of stating this is I want to be able to bind
intentions to active highlights.

--Dave Griffith

0

Aha, I see. As for now the posible solution would be lo listen to key pressed event, and predict the highlights will be removed (you know what keys should remove them, don't you? Also you might need to add DocumentListener to check that not all of your highlights have been invalidated by the user yet:(). This is rather dumb, at the very least. Another solution that comes to my mind, is to allow registering one-shot annotations like highlights, not only from Annotator. I don't think highlights and annotations should be mixed, since they are conceptually different.

Eugene.

0

Please sign in to leave a comment.