/// <inheritdoc />
        protected override void GoToDefinition(string id, string definitionType)
        {
            switch(definitionType)
            {
                case "codeEntityReference":
                    if(!IntelliSense.RoslynHacks.RoslynUtilities.IsFinalRoslyn || (id.Length > 2 && id[1] == ':'))
                    {
                        var entitySearcher = new CodeEntitySearcher(this.ServiceProvider);

                        if(!entitySearcher.GotoDefinitionFor(id))
                        {
                            Guid clsid = Guid.Empty;
                            int result;
                            var uiShell = this.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

                            if(uiShell != null)
                                uiShell.ShowMessageBox(0, ref clsid, "Unable to navigate to XML comments member " +
                                    "definition.", String.Format(CultureInfo.CurrentCulture, "Member ID: {0}\r\n\r\n" +
                                    "If valid, the most likely cause is that it is not a member of a C# project " +
                                    "within the current solution.  Navigating to members in non-C# projects and " +
                                    ".NET Framework or reference assemblies is not supported.", id), String.Empty, 0,
                                    OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                    OLEMSGICON.OLEMSGICON_INFO, 0, out result);

                            System.Diagnostics.Debug.WriteLine("Unable to go to declaration for member ID: " + id);
                        }
                    }
                    else
                    {
                        // VS2015 and later do support actual Go To Definition on cref targets in XML comments
                        Guid cmdGroup = VSConstants.GUID_VSStandardCommandSet97;
                        var shellCommandDispatcher = this.ServiceProvider.GetService(
                            typeof(SUIHostCommandDispatcher)) as IOleCommandTarget;

                        shellCommandDispatcher.Exec(ref cmdGroup, (uint)VSConstants.VSStd97CmdID.GotoDefn,
                            (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, System.IntPtr.Zero, System.IntPtr.Zero);
                    }
                    break;

                case "link":
                case "token":
                    var projectFileSearcher = new ProjectFileSearcher(this.ServiceProvider, this.TextView);

                    ProjectFileSearcher.IdType idType;

                    if(!Enum.TryParse(definitionType, true, out idType))
                        idType = ProjectFileSearcher.IdType.Unknown;

                    if(!projectFileSearcher.OpenFileFor(idType, id))
                    {
                        if(idType == ProjectFileSearcher.IdType.Link)
                            definitionType = "conceptualLink";

                        Guid clsid = Guid.Empty;
                        int result;
                        var uiShell = this.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

                        if(uiShell != null)
                            uiShell.ShowMessageBox(0, ref clsid, "Unable to open file for XML comments element " +
                                "target.", String.Format(CultureInfo.CurrentCulture, "Type: {0}\r\nID: {1}\r\n\r\n" +
                                "If valid, it may not be a part of a help file builder project within this " +
                                "solution.", definitionType, id), String.Empty, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO, 0, out result);

                        System.Diagnostics.Debug.WriteLine("Unable to go to open file for ID '{0}' ({1}): ", id,
                            definitionType);
                    }
                    break;

                default:
                    break;
            }
        }
示例#2
0
        private void GoToDefinition(string id, string definitionType)
        {
            switch (definitionType)
            {
            case "codeEntityReference":
                var entitySearcher = new CodeEntitySearcher(_provider.ServiceProvider);

                if (!entitySearcher.GotoDefinitionFor(id))
                {
                    Guid clsid = Guid.Empty;
                    int  result;
                    var  uiShell = _provider.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

                    if (uiShell != null)
                    {
                        uiShell.ShowMessageBox(0, ref clsid, "Unable to navigate to code entity reference " +
                                               "definition.", String.Format(CultureInfo.CurrentCulture, "Member ID: {0}\r\n\r\n" +
                                                                            "If valid, the most likely cause is that it is not a member of a C# project " +
                                                                            "within the current solution.  Navigating to members in non-C# projects and " +
                                                                            ".NET Framework or reference assemblies is not supported.", id), String.Empty, 0,
                                               OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                               OLEMSGICON.OLEMSGICON_INFO, 0, out result);
                    }

                    System.Diagnostics.Debug.WriteLine("Unable to go to declaration for member ID: " + id);
                }
                break;

            case "codeReference":
            case "image":
            case "link":
            case "token":
                var projectFileSearcher = new ProjectFileSearcher(_provider.ServiceProvider, _textView);

                ProjectFileSearcher.IdType idType;

                if (!Enum.TryParse(definitionType, true, out idType))
                {
                    idType = ProjectFileSearcher.IdType.Unknown;
                }

                if (!projectFileSearcher.OpenFileFor(idType, id))
                {
                    if (idType == ProjectFileSearcher.IdType.Link)
                    {
                        definitionType = "conceptualLink";
                    }

                    Guid clsid = Guid.Empty;
                    int  result;
                    var  uiShell = _provider.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

                    if (uiShell != null)
                    {
                        uiShell.ShowMessageBox(0, ref clsid, "Unable to open file for element target.",
                                               String.Format(CultureInfo.CurrentCulture, "Type: {0}\r\nID: {1}\r\n\r\nIf " +
                                                             "valid, it may not be a part of a help file builder project within this " +
                                                             "solution.", definitionType, id), String.Empty, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                               OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO, 0, out result);
                    }

                    System.Diagnostics.Debug.WriteLine("Unable to go to open file for ID '{0}' ({1}): ", id,
                                                       definitionType);
                }
                break;

            default:
                break;
            }
        }
示例#3
0
        /// <summary>
        /// This is used to go to the definition based on the span under the cursor
        /// </summary>
        /// <param name="id">The ID of the definition to go to</param>
        /// <param name="definitionType">A definition type to further classify the ID</param>
        private void GoToDefinition(string id, string definitionType)
        {
            switch (definitionType)
            {
            case "codeEntityReference":
                if (!IntelliSense.RoslynHacks.RoslynUtilities.IsFinalRoslyn || !isCodeFile ||
                    (id.Length > 2 && id[1] == ':'))
                {
                    var entitySearcher = new CodeEntitySearcher(provider.ServiceProvider);

                    if (!entitySearcher.GotoDefinitionFor(id))
                    {
                        Guid clsid = Guid.Empty;
                        int  result;
                        var  uiShell = provider.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

                        if (uiShell != null)
                        {
                            uiShell.ShowMessageBox(0, ref clsid, "Unable to navigate to XML comments member " +
                                                   "definition.", String.Format(CultureInfo.CurrentCulture, "Member ID: {0}\r\n\r\n" +
                                                                                "If valid, the most likely cause is that it is not a member of a C# project " +
                                                                                "within the current solution.  Navigating to members in non-C# projects and " +
                                                                                ".NET Framework or reference assemblies is not supported.", id), String.Empty, 0,
                                                   OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                   OLEMSGICON.OLEMSGICON_INFO, 0, out result);
                        }

                        System.Diagnostics.Debug.WriteLine("Unable to go to declaration for member ID: " + id);
                    }
                }
                else
                {
                    // VS2015 and later do support actual Go To Definition on cref targets in XML comments
                    Guid cmdGroup = VSConstants.GUID_VSStandardCommandSet97;
                    var  shellCommandDispatcher = provider.ServiceProvider.GetService(
                        typeof(SUIHostCommandDispatcher)) as IOleCommandTarget;

                    shellCommandDispatcher.Exec(ref cmdGroup, (uint)VSConstants.VSStd97CmdID.GotoDefn,
                                                (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, System.IntPtr.Zero, System.IntPtr.Zero);
                }
                break;

            case "codeReference":
            case "conceptualLink":
            case "image":
            case "link":
            case "token":
                var projectFileSearcher = new ProjectFileSearcher(provider.ServiceProvider, textView);

                ProjectFileSearcher.IdType idType;

                if (definitionType == "conceptualLink")
                {
                    idType = ProjectFileSearcher.IdType.Link;
                }
                else
                if (!Enum.TryParse(definitionType, true, out idType))
                {
                    idType = ProjectFileSearcher.IdType.Unknown;
                }

                if (!projectFileSearcher.OpenFileFor(idType, id))
                {
                    Guid clsid = Guid.Empty;
                    int  result;
                    var  uiShell = provider.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

                    if (uiShell != null)
                    {
                        uiShell.ShowMessageBox(0, ref clsid, "Unable to open file for element target.",
                                               String.Format(CultureInfo.CurrentCulture, "Type: {0}\r\nID: {1}\r\n\r\nIf " +
                                                             "valid, it may not be a part of a help file builder project within this " +
                                                             "solution.", definitionType, id), String.Empty, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                               OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO, 0, out result);
                    }

                    System.Diagnostics.Debug.WriteLine("Unable to go to open file for ID '{0}' ({1}): ", id,
                                                       definitionType);
                }
                break;

            default:
                break;
            }
        }
        /// <inheritdoc />
        protected override void GoToDefinition(string id, string definitionType)
        {
            switch(definitionType)
            {
                case "codeEntityReference":
                    var entitySearcher = new CodeEntitySearcher(this.ServiceProvider);

                    if(!entitySearcher.GotoDefinitionFor(id))
                    {
                        Guid clsid = Guid.Empty;
                        int result;
                        var uiShell = this.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

                        if(uiShell != null)
                            uiShell.ShowMessageBox(0, ref clsid, "Unable to navigate to code entity reference " +
                                "definition.", String.Format(CultureInfo.CurrentCulture, "Member ID: {0}\r\n\r\n" +
                                "If valid, the most likely cause is that it is not a member of a C# project " +
                                "within the current solution.  Navigating to members in non-C# projects and " +
                                ".NET Framework or reference assemblies is not supported.", id), String.Empty, 0,
                                OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                OLEMSGICON.OLEMSGICON_INFO, 0, out result);

                        System.Diagnostics.Debug.WriteLine("Unable to go to declaration for member ID: " + id);
                    }
                    break;

                case "codeReference":
                case "image":
                case "link":
                case "token":
                    var projectFileSearcher = new ProjectFileSearcher(this.ServiceProvider, this.TextView);

                    ProjectFileSearcher.IdType idType;

                    if(!Enum.TryParse(definitionType, true, out idType))
                        idType = ProjectFileSearcher.IdType.Unknown;

                    if(!projectFileSearcher.OpenFileFor(idType, id))
                    {
                        Guid clsid = Guid.Empty;
                        int result;
                        var uiShell = this.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

                        if(uiShell != null)
                            uiShell.ShowMessageBox(0, ref clsid, "Unable to open file for element target.",
                                String.Format(CultureInfo.CurrentCulture, "Type: {0}\r\nID: {1}\r\n\r\nIf " +
                                "valid, it may not be a part of a help file builder project within this " +
                                "solution.", definitionType, id), String.Empty, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_INFO, 0, out result);

                        System.Diagnostics.Debug.WriteLine("Unable to go to open file for ID '{0}' ({1}): ", id,
                            definitionType);
                    }
                    break;

                default:
                    break;
            }
        }