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:
- 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.
- Find usages action ran in my file type should never search in .js files
- 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.
Please sign in to leave a comment.
Hi Peter,
1,2. You can use JSElementResolveScopeProvider(JavaScript.elementScopeProvider) extension point for that. You'll need to override getResolveScope method to return only
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.
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: