Problem implementing ReferencesSearch extension

Hi all,

A couple of days ago I reported javascript:;which turned out to be invalid - I thought Find Usages wasn't working correctly but it seems that I had to implement the ReferencesSearch extension point. I copied the CachesBasedRefSearcher code and modified it to do what I need and it seems to work. The code requires a PsiManagerEx object, which I obtain like this:

    DataContext dataContext = DataManager.getInstance().getDataContext();
    Project project = DataKeys.PROJECT.getData(dataContext);
    this.myManager = (PsiManagerEx) PsiManager.getInstance(project);


Currently I'm doing this in the constructor of my ReferencesSearch object, is this correct? If these objects have application scope, this won't work in the presence of multiple projects. Should I be doing this lookup in the execute() method each time it's called?

Thanks,
Colin

2 comments
Comment actions Permalink

Hello Colin,

No, this is not correct. The correct thing to do is to get the project from
the getElementToSearch() PSI element in the execute() method.

In general, taking the project forom DataManager should be used only as the
last resort - almost always there's a better way available.

A couple of days ago I reported which turned out to be invalid - I
thought Find Usages wasn't working correctly but it seems that I had
to implement the ReferencesSearch extension point. I copied the
CachesBasedRefSearcher code and modified it to do what I need and it
seems to work. The code requires a PsiManagerEx object, which I obtain
like this:

DataContext dataContext =
DataManager.getInstance().getDataContext();
Project project = DataKeys.PROJECT.getData(dataContext);
this.myManager = (PsiManagerEx) PsiManager.getInstance(project);
Currently I'm doing this in the constructor of my ReferencesSearch
object, is this correct? If these objects have application scope, this
won't work in the presence of multiple projects. Should I be doing
this lookup in the execute() method each time it's called?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

Ok, great, thanks - I'll do that.

Cheers,
Colin

0

Please sign in to leave a comment.