int IVsSimpleLibrary2.CreateNavInfo(SYMBOL_DESCRIPTION_NODE[] rgSymbolNodes, uint ulcNodes, out IVsNavInfo ppNavInfo)
 {
     return CreateNavInfo(rgSymbolNodes, ulcNodes, out ppNavInfo);
 }
Ejemplo n.º 2
0
 public int CreateNavInfo(
     SYMBOL_DESCRIPTION_NODE[] rgSymbolNodes, uint ulcNodes, out IVsNavInfo ppNavInfo)
 {
     ppNavInfo = null;
     return VSConstants.E_NOTIMPL;
 }
        protected override int CreateNavInfo(SYMBOL_DESCRIPTION_NODE[] rgSymbolNodes, uint ulcNodes, out IVsNavInfo ppNavInfo)
        {
            Debug.Assert(rgSymbolNodes != null || ulcNodes > 0, "Invalid input parameters into CreateNavInfo");

            ppNavInfo = null;

            var count = 0;
            string libraryName = null;
            string referenceOwnerName = null;

            if (rgSymbolNodes[0].dwType != (uint)_LIB_LISTTYPE.LLT_PACKAGE)
            {
                Debug.Fail("Symbol description should always contain LLT_PACKAGE node as first node");
                return VSConstants.E_INVALIDARG;
            }
            else
            {
                count++;

                // If second node is also a package node, the below is the inference Node for
                // which NavInfo is generated is a 'referenced' node in CV
                // First package node ---> project item under which referenced node is displayed
                // Second package node ---> actual lib item node i.e., referenced assembly
                if (ulcNodes > 1 && rgSymbolNodes[1].dwType == (uint)_LIB_LISTTYPE.LLT_PACKAGE)
                {
                    count++;

                    referenceOwnerName = rgSymbolNodes[0].pszName;
                    libraryName = rgSymbolNodes[1].pszName;
                }
                else
                {
                    libraryName = rgSymbolNodes[0].pszName;
                }
            }

            var namespaceName = SharedPools.Default<StringBuilder>().AllocateAndClear();
            var className = SharedPools.Default<StringBuilder>().AllocateAndClear();
            var memberName = string.Empty;

            // Populate namespace, class and member names
            // Generate flattened names for nested namespaces and classes
            for (; count < ulcNodes; count++)
            {
                switch (rgSymbolNodes[count].dwType)
                {
                    case (uint)_LIB_LISTTYPE.LLT_NAMESPACES:
                        if (namespaceName.Length > 0)
                        {
                            namespaceName.Append(".");
                        }

                        namespaceName.Append(rgSymbolNodes[count].pszName);
                        break;

                    case (uint)_LIB_LISTTYPE.LLT_CLASSES:
                        if (className.Length > 0)
                        {
                            className.Append(".");
                        }

                        className.Append(rgSymbolNodes[count].pszName);
                        break;

                    case (uint)_LIB_LISTTYPE.LLT_MEMBERS:
                        if (memberName.Length > 0)
                        {
                            Debug.Fail("Symbol description cannot contain more than one LLT_MEMBERS node.");
                        }

                        memberName = rgSymbolNodes[count].pszName;
                        break;
                }
            }

            SharedPools.Default<StringBuilder>().ClearAndFree(namespaceName);
            SharedPools.Default<StringBuilder>().ClearAndFree(className);

            // TODO: Make sure we pass the right value for Visual Basic.
            ppNavInfo = this.LibraryService.NavInfoFactory.Create(libraryName, referenceOwnerName, namespaceName.ToString(), className.ToString(), memberName);

            return VSConstants.S_OK;
        }