internal static List<VsObjectSearchResult> Search(string name, ObjectSearchLanguage searchLanguage)
        {
            var results = new List<VsObjectSearchResult>();
            var searchService = PackageManager.Package.GetService(typeof(SVsObjectSearch)) as IVsObjectSearch;

            if (searchService != null)
            {
                IVsObjectList2 objectList;
                IVsObjectList searchResult;
                var criteria = new VSOBSEARCHCRITERIA();
                criteria.eSrchType = VSOBSEARCHTYPE.SO_ENTIREWORD;
                criteria.szName = name;

                // Need to switch between case sensitive and case insentive searches for C# and VB
                switch (searchLanguage)
                {
                    case ObjectSearchLanguage.CSharp:
                        criteria.grfOptions = (uint)_VSOBSEARCHOPTIONS.VSOBSO_LOOKINREFS | (uint)_VSOBSEARCHOPTIONS.VSOBSO_CASESENSITIVE;
                        break;
                    case ObjectSearchLanguage.VB:
                        criteria.grfOptions = (uint)_VSOBSEARCHOPTIONS.VSOBSO_LOOKINREFS;
                        break;
                    default:
                        throw new InvalidOperationException("Unsupported language search type: " + searchLanguage.ToString());
                }

                if (searchService.Find(
                    (uint)__VSOBSEARCHFLAGS.VSOSF_NOSHOWUI | (uint)_VSOBSEARCHOPTIONS.VSOBSO_LOOKINREFS,
                    new VSOBSEARCHCRITERIA[1] { criteria }, out searchResult) == VSConstants.S_OK)
                {
                    objectList = searchResult as IVsObjectList2;
                    if (objectList != null)
                    {
                        uint pCount;
                        if (objectList.GetItemCount(out pCount) == VSConstants.S_OK)
                        {
                            for (uint i = 0; i < pCount; i++)
                            {
                                IVsObjectList2 subList;
                                if (objectList.GetList2(
                                    i, (uint)_LIB_LISTTYPE.LLT_HIERARCHY, (uint)_LIB_LISTFLAGS.LLF_NONE, new VSOBSEARCHCRITERIA2[0],
                                    out subList)
                                    == VSConstants.S_OK)
                                {
                                    // Switch to using our "safe" PInvoke interface for IVsObjectList2 to avoid potential memory management issues
                                    // when receiving strings as out params.
                                    var safeSubList = subList as ISafeVsObjectList2;
                                    if (safeSubList != null)
                                    {
                                        AddResultsToList(safeSubList, searchLanguage, results);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return results;
        }
Esempio n. 2
0
        bool LaunchRefSearch(string name)
        {
            IVsObjectSearch objectSearch = ((System.IServiceProvider)m_package).GetService(typeof(SVsObjectSearch)) as IVsObjectSearch;

            if (objectSearch == null)
            {
                return(false);
            }

            const __VSOBSEARCHFLAGS flags = __VSOBSEARCHFLAGS.VSOSF_EXPANDREFS;

            VSOBSEARCHCRITERIA[] pobSrch = new VSOBSEARCHCRITERIA[1];
            pobSrch[0].grfOptions = (uint)(_VSOBSEARCHOPTIONS.VSOBSO_CASESENSITIVE | _VSOBSEARCHOPTIONS.VSOBSO_LOOKINREFS);
            pobSrch[0].eSrchType  = VSOBSEARCHTYPE.SO_ENTIREWORD;
            pobSrch[0].szName     = name;

            try
            {
                ErrorHandler.ThrowOnFailure(objectSearch.Find((uint)flags, pobSrch, out m_searchResultList));
                var  objectList  = m_searchResultList as IVsObjectList2;
                uint resultCount = 0;
                if (objectList.GetItemCount(out resultCount) != VSConstants.S_OK || resultCount <= 0)
                {
                    return(false);
                }
                if (resultCount > 0)
                {
                    string text;
                    ushort img;
                    bool   isProcessing;
                    GetListItemInfo(objectList, 0, out text, out img, out isProcessing);
                    if (text == "Search found no results")
                    {
                        return(false);
                    }
                }
            }
            catch (InvalidCastException)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        internal static List <VsObjectSearchResult> Search(string name, ObjectSearchLanguage searchLanguage)
        {
            var results       = new List <VsObjectSearchResult>();
            var searchService = PackageManager.Package.GetService(typeof(SVsObjectSearch)) as IVsObjectSearch;

            if (searchService != null)
            {
                IVsObjectList2 objectList;
                IVsObjectList  searchResult;
                var            criteria = new VSOBSEARCHCRITERIA();
                criteria.eSrchType = VSOBSEARCHTYPE.SO_ENTIREWORD;
                criteria.szName    = name;

                // Need to switch between case sensitive and case insentive searches for C# and VB
                switch (searchLanguage)
                {
                case ObjectSearchLanguage.CSharp:
                    criteria.grfOptions = (uint)_VSOBSEARCHOPTIONS.VSOBSO_LOOKINREFS | (uint)_VSOBSEARCHOPTIONS.VSOBSO_CASESENSITIVE;
                    break;

                case ObjectSearchLanguage.VB:
                    criteria.grfOptions = (uint)_VSOBSEARCHOPTIONS.VSOBSO_LOOKINREFS;
                    break;

                default:
                    throw new InvalidOperationException("Unsupported language search type: " + searchLanguage.ToString());
                }

                if (searchService.Find(
                        (uint)__VSOBSEARCHFLAGS.VSOSF_NOSHOWUI | (uint)_VSOBSEARCHOPTIONS.VSOBSO_LOOKINREFS,
                        new VSOBSEARCHCRITERIA[1] {
                    criteria
                }, out searchResult) == VSConstants.S_OK)
                {
                    objectList = searchResult as IVsObjectList2;
                    if (objectList != null)
                    {
                        uint pCount;
                        if (objectList.GetItemCount(out pCount) == VSConstants.S_OK)
                        {
                            for (uint i = 0; i < pCount; i++)
                            {
                                IVsObjectList2 subList;
                                if (objectList.GetList2(
                                        i, (uint)_LIB_LISTTYPE.LLT_HIERARCHY, (uint)_LIB_LISTFLAGS.LLF_NONE, new VSOBSEARCHCRITERIA2[0],
                                        out subList)
                                    == VSConstants.S_OK)
                                {
                                    // Switch to using our "safe" PInvoke interface for IVsObjectList2 to avoid potential memory management issues
                                    // when receiving strings as out params.
                                    var safeSubList = subList as ISafeVsObjectList2;
                                    if (safeSubList != null)
                                    {
                                        AddResultsToList(safeSubList, searchLanguage, results);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(results);
        }
 int IVsLibrary.GetList(uint listType, uint flags, VSOBSEARCHCRITERIA[] pobSrch, out IVsObjectList pplist)
 {
     pplist = null;
     return VSConstants.E_NOTIMPL;
 }