Highlight origin of reference on click

Hey,

I would like to highlight the referred node automatically when I select the reference. So something similar to pressing Cntr+Shift+F7 (Highlight Usages).

I see that there is an action called CLICK but not RELEASE. Or just a FOCUS action would be nice.

Is there something like that so that the user of the language does not need to press the shortcut?

1
3 comments
Official comment

Hi! 

Unfortunately, there is no such action in the action map declaration.

However, you could implement it via API.

Here are the steps to do it:

1) Create the plugin solution and the project plugin there (https://confluence.jetbrains.com/display/MPSD20181/Plugin)

2) Subscribe to the editor component creation in the init block of the project plugin:

myMessageBusConnection = project.getProject().getMessageBus().connect();
myMessageBusConnection.subscribe(EditorComponentCreateListener.EDITOR_COMPONENT_CREATION, myEditorComponentCreationHandler);

3) Define the 

myEditorComponentCreationHandler

as follows:

When the editor component is created, add the selection listener to its selection manager;

editorComponent.getSelectionManager().addSelectionListener(listener)

In the selection listener, you can find all the references of the selected node and highlight them:

editor.getHighlightManager().mark(message, this));
myEditorComponent.getHighlightManager().repaintAndRebuildEditorMessages();

In order to remove the messages, use

myEditorComponent.getHighlightManager().clearForOwner(this);

It's worth mentioning it is quite complicated task and we have this feature in our plan

Hey Semen,

thanks for your reply. Yes, looks costly. I think I will wait for an official implementation since it is not an important feature.

1

Hello Semen,

we have another use case for this RELEASE (or similar) action, so this feature would indeed be very useful!

Kind regards, Andreas

0

Please sign in to leave a comment.