Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

VS2015: Custom Go To Definition Location (F12)

$
0
0

I'm looking to extend the functionality of 'Go To Definition' for JavaScript in VS2015 and running into some issues. From the sparse examples online it looks as though I can "intercept" the command using an IOleCommandTarget. I'm hitting a few issues though:

        public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            if ((VSConstants.VSStd97CmdID)prgCmds[0].cmdID != VSConstants.VSStd97CmdID.GotoDefn)
                return Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);

            prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED;
            return VSConstants.S_OK;
        }

This is the QueryStatus implementation I'm using for my CommandTarget. I'm not certain this is necessary in the first place since "Go To Definition" is already enabled and supported by default for JavaScript - I think I could just safely rely on the 'Next' CommandTarget. Here is my Exec method:

        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            var hresult = VSConstants.S_OK;
            switch ((VSConstants.VSStd97CmdID)nCmdID)
            {
                case VSConstants.VSStd97CmdID.GotoDefn:
                    var caretBufferPosition = TextView.Caret.Position.BufferPosition;
                    var originalText = caretBufferPosition.GetContainingLine().GetText();

                    // open the correct file/location here

                    return hresult;
                default:
                    hresult = Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                    break;
            }

            return hresult;
        }

It would seem to me that my first case statement should get executed when I hit F12 and/or select "Go To Definition..." from the editor's context menu, but alas my breakpoint never gets hit.

The few examples I've seen online related to GoToDefn are generally for some new, unsupported  by VS language. Is what I am trying to accomplish possible for JavaScript?

Thanks!


Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>