How to affect priority of results from IImplementationContextSearch and IDeclarationContextSearch (6.1)

I am in the process of extending "Go To Definition" and "Go To Implementation" with IDeclarationContextSearch and IImplementationContextSearch classes, respectively, and I would like the results they return to appear at the top of the list (in front of CSharp results, to be specific). Is there a way to do this?

4 comments
Comment actions Permalink

Without knowing a little more about what you're doing, I'm afraid I'm not sure. It looks like the ordering of the elements is delegated to the SearchResult returned from IRequestContextSearch.GetElementsAndSearch, but that seems to only allow ordering within that implementation of the interface. I can't see right now how or if you can change the order of the returned groups of elements. Could you provide some more context, and perhaps some code to help look into this further?

Thanks
Matt

0
Comment actions Permalink

I can't see right now how or if you can change the order of the returned groups of elements.

This is really what I want to do. In my use case, certain C# classes are generated from our custom documents, and I am trying to add "Go To Definition" results for the definition in the custom document. I would like these results to appear before the CSharp results.

Here's the relevant snippet of code from my IDeclarationContextSearch:

        public bool IsGotoDeclarationApplicable(IDeclaredElement declaredElement)
        {
            return declaredElement is IdrDeclaredElement;
        }
 
        JetTuple<IEnumerable<IDeclaredElement>, GetSearchRequest<SearchDeclarationsRequest>>
            IRequestContextSearch<SearchDeclarationsRequest>.GetElementsAndSearch(IDataContext dataContext)
        {
            var @class = ClassForContext(dataContext);
            if (@class == null)
                return null;
            return
                new JetTuple<IEnumerable<IDeclaredElement>, GetSearchRequest<SearchDeclarationsRequest>>(
                    IdrDeclaredElement.CreateDeclaredElementsForClass(@class), GetSearchDeclRequest);
        }


Thanks!
0
Comment actions Permalink

Sounds cool! Couple of further questions - does this work now, as it stands, but in the wrong order? Is the effect you're after similar to navigating to declaration (ctrl-click) on an MVC action's call to View() - i.e. you get a little popup menu with a cshtml view file, and the definition of the View method.

And, just because I'm curious - have you built a PSI parser for the original custom documents? I'm guessing you have due to the use of the IdrDeclaredElement type.

0
Comment actions Permalink

Yes, this does work right now but in the wrong order.

I actually have not built a PSI parser for the original document. We currently do not need any global knowledge of the constructs declared in our format. Everything can be constructed from the generated code, and we have no plans (yet) for fancy editing in VS. The IdrDeclaredElement is merely a container for navigation-related information, and is created on-demand in the CreateDeclaredElementsForClass method.

0

Please sign in to leave a comment.