Javascript - find usages & resolve scope

Hi,

I'm working on language support for template engine based on rhino js. In templates I managed to resolve specific variables / calls via extension of JSReferenceExpressionResolver (JavaScriptSpecificHandlersFactory#createReferenceExpressionResolver(JSReferenceExpressionImpl, PsiFile)) which is working just fine, but I'd like to get through some more things:

  1. Nothing from my file type should ever resolve to .js file. At the moment it's working vice versa - stuff from .js file never resolves to my file type. I'm using  predefined library registered via JSPredefinedLibraryProvider, where the functionality should be perserved.
  2. Find usages action ran in my file type should never search in .js files
  3. Template specific functions are defined as object properties  (JSProperty) - e.g. myNamespace.foo = {bar: function(){...}}. For this  case I'd like to tweak 'find uasges' action so that it will find just  references, which resolve to this property. By this I mean to filter out the default functionality (dynamic usages), e.g. myNamespace.foo = {bar: function(){...}} - usages of 'bar' never finds someobject.bar.


Any help will be greatly appreciated.

2 comments
Comment actions Permalink

Hi Peter,

1,2. You can use JSElementResolveScopeProvider(JavaScript.elementScopeProvider) extension point for that. You'll need to override getResolveScope method to return only

 
GlobalSearchScope.getScopeRestrictedByFileTypes(scopeExcludingJsLibs, YourFileType.INSTANCE)


3. Currently that's not possible to customize, and here's one problem that may affect you: even if reference is resolving exactly to the element you want it may happen that resolve was performed via dynamic case.

0
Comment actions Permalink

Thanks for the reply, I had to override JSElementResolveScopeProvider#getElementResolveScope(PsiElement), because getResolveScope(VirtualFile, Project) is for some reason never called. Now via ctrl+click I never get to .js file, but it's not working for find usages / refactor action. Here's my code:

 
public class InnerJsResolveScopeProvider extends JSElementResolveScopeProvider
{
    @NotNull
    @Override
    public
GlobalSearchScope getElementResolveScope(@NotNull PsiElement element)
    {
        return GlobalSearchScope.getScopeRestrictedByFileTypes(super.getElementResolveScope(element),
                
MyFileType.INSTANCE);
    
}

    @Nullable
    @Override
    public
GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project)
    {
        return null;    // never called
    
}

}
 
<elementScopeProvider implementationClass="package.InnerJsResolveScopeProvider" language="MyInnerJs"/>
0

Please sign in to leave a comment.