private void AddLibrary(IVsLibrary2 lib, IVsCombinedBrowseComponentSet extras) { if (lib == null) return; var simpleLib = lib as IVsSimpleLibrary2; Guid libGuid; ErrorHandler.Succeeded(simpleLib.GetGuid(out libGuid)); var libRoot = new TreeViewItem { Header = "guid=(" + libGuid + ")" }; var expander = new TreeViewItem(); libRoot.Items.Add(expander); libRoot.Expanded += (sender, args) => AddLibraryContent(libRoot, expander, extras, lib); treeView1.Items.Add(libRoot); }
private void AddLibraryContent(TreeViewItem libRoot, TreeViewItem expander, IVsCombinedBrowseComponentSet extras, IVsLibrary2 lib) { if (lib == null) return; if (libRoot.Items.Count != 1 || libRoot.Items[0] != expander) return; libRoot.Items.Clear(); var simpleLib = lib as IVsSimpleLibrary2; uint libFlags; ErrorHandler.Succeeded(lib.GetLibFlags2(out libFlags)); var flags = ""; if ((libFlags & (uint)_LIB_FLAGS.LF_EXPANDABLE) != 0) flags += "|LF_EXPANDABLE"; if ((libFlags & (uint)_LIB_FLAGS.LF_GLOBAL) != 0) flags += "|LF_GLOBAL"; if ((libFlags & (uint)_LIB_FLAGS.LF_HIDEINLIBPICKER) != 0) flags += "|LF_HIDEINLIBPICKER"; if ((libFlags & (uint)_LIB_FLAGS.LF_PROJECT) != 0) flags += "|LF_PROJECT"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSBASETYPES) != 0) flags += "|LF_SUPPORTSBASETYPES"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSCALLBROWSER) != 0) flags += "|LF_SUPPORTSCALLBROWSER"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSCLASSDESIGNER) != 0) flags += "|LF_SUPPORTSCLASSDESIGNER"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSDERIVEDTYPES) != 0) flags += "|LF_SUPPORTSDERIVEDTYPES"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSFILTERING) != 0) flags += "|LF_SUPPORTSFILTERING"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSFILTERINGWITHEXPANSION) != 0) flags += "|LF_SUPPORTSFILTERINGWITHEXPANSION"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSINHERITEDMEMBERS) != 0) flags += "|LF_SUPPORTSINHERITEDMEMBERS"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSLISTREFERENCES) != 0) flags += "|LF_SUPPORTSLISTREFERENCES"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSPRIVATEMEMBERS) != 0) flags += "|LF_SUPPORTSPRIVATEMEMBERS"; if ((libFlags & (uint)_LIB_FLAGS2.LF_SUPPORTSPROJECTREFERENCES) != 0) flags += "|LF_SUPPORTSPROJECTREFERENCES"; flags = flags.Substring(1); Guid libGuid; ErrorHandler.Succeeded(simpleLib.GetGuid(out libGuid)); IVsNavInfo navInfo = null; var rc = VSConstants.E_NOTIMPL; //for (var i = (uint)0; navInfo==null && i<32 && rc != VSConstants.S_OK; i++) //{ // //rc = extras.CreateNavInfo( // // libGuid, // // new[] // // { // // new SYMBOL_DESCRIPTION_NODE {dwType = (uint)(0), pszName = "ClassLibrary12"}, // // }, // // 1, // // out navInfo // // ); // //if (rc == VSConstants.S_OK) // // break; rc = extras.CreateNavInfo( libGuid, new[] { new SYMBOL_DESCRIPTION_NODE {dwType = (uint)_LIB_LISTTYPE.LLT_NAMESPACES, pszName = "ClassLibrary3"}, }, 1, out navInfo ); //} var navInfoRoot = new TreeViewItem { Header = "NavInfo (rc=" + rc + ")" }; if (rc == VSConstants.S_OK) { Guid symbolGuid; ErrorHandler.Succeeded(navInfo.GetLibGuid(out symbolGuid)); navInfoRoot.Items.Add("Guid=" + symbolGuid); uint symbolType; ErrorHandler.Succeeded(navInfo.GetSymbolType(out symbolType)); var symbolTypeString = Enum.GetName(typeof(_LIB_LISTTYPE), symbolType); if (symbolTypeString != null) { navInfoRoot.Items.Add("Type = _LIB_LISTTYPE." + symbolTypeString); } else { symbolTypeString = Enum.GetName(typeof(_LIB_LISTTYPE2), symbolType); if (symbolTypeString != null) { navInfoRoot.Items.Add("Type = _LIB_LISTTYPE2." + symbolTypeString); } else { navInfoRoot.Items.Add("Type = " + symbolType); } } IVsEnumNavInfoNodes infoNodes; ErrorHandler.Succeeded(navInfo.EnumCanonicalNodes(out infoNodes)); var navInfoNodesArray = new IVsNavInfoNode[20]; uint fetched; ErrorHandler.Succeeded(infoNodes.Next((uint)navInfoNodesArray.Length, navInfoNodesArray, out fetched)); if (fetched > 0) { var navNodes = new TreeViewItem { Header = "Nodes" }; foreach (var node in navInfoNodesArray) { if (node == null) continue; string nodeName; ErrorHandler.Succeeded(node.get_Name(out nodeName)); uint nodeType; ErrorHandler.Succeeded(node.get_Type(out nodeType)); var nodeTypeString = Enum.GetName(typeof(_LIB_LISTTYPE), nodeType); if (nodeTypeString != null) { navNodes.Items.Add(nodeName + "(_LIB_LISTTYPE." + nodeTypeString + ")"); } else { nodeTypeString = Enum.GetName(typeof(_LIB_LISTTYPE2), symbolType); if (symbolTypeString != null) { navNodes.Items.Add(nodeName + "(_LIB_LISTTYPE." + nodeTypeString + ")"); } else { navNodes.Items.Add(nodeName + "(" + symbolType + ")"); } } } } } libRoot.Items.Add(navInfoRoot); libRoot.Items.Add("Flags=" + flags); IVsLiteTreeList globalLibs; ErrorHandler.Succeeded(lib.GetLibList(LIB_PERSISTTYPE.LPT_GLOBAL, out globalLibs)); AddLibList(libRoot, "Global", globalLibs); IVsLiteTreeList projectLibs; ErrorHandler.Succeeded(lib.GetLibList(LIB_PERSISTTYPE.LPT_PROJECT, out projectLibs)); AddLibList(libRoot, "Project", globalLibs); AddNested(lib, libRoot, _LIB_LISTTYPE.LLT_NAMESPACES); AddNested(lib, libRoot, _LIB_LISTTYPE.LLT_CLASSES); AddNested(lib, libRoot, _LIB_LISTTYPE.LLT_MEMBERS); AddNested(lib, libRoot, _LIB_LISTTYPE.LLT_REFERENCES); //expander.Items.Add(libRoot); }