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;
        }
Example #2
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);
        }
Example #3
0
        internal static bool TryParseSourceData(
            string text, ObjectSearchLanguage searchLanguage, out string fileName, out int lineNumber, out int columnNumber)
        {
            switch (searchLanguage)
            {
            case ObjectSearchLanguage.CSharp:
                return(TryParseSourceDataCSharp(text, out fileName, out lineNumber, out columnNumber));

            case ObjectSearchLanguage.VB:
                return(TryParseSourceDataVB(text, out fileName, out lineNumber, out columnNumber));

            default:
                throw new InvalidOperationException("Unsupported language search type: " + searchLanguage.ToString());
            }
        }
 internal static bool TryParseSourceData(
     string text, ObjectSearchLanguage searchLanguage, out string fileName, out int lineNumber, out int columnNumber)
 {
     switch (searchLanguage)
     {
         case ObjectSearchLanguage.CSharp:
             return TryParseSourceDataCSharp(text, out fileName, out lineNumber, out columnNumber);
         case ObjectSearchLanguage.VB:
             return TryParseSourceDataVB(text, out fileName, out lineNumber, out columnNumber);
         default:
             throw new InvalidOperationException("Unsupported language search type: " + searchLanguage.ToString());
     }
 }