Beispiel #1
0
        private void CreateModuleTree(LibraryNode root, LibraryNode current, IScopeNode scope, string namePrefix, ModuleId moduleId)
        {
            if ((null == root) || (null == scope) || (null == scope.NestedScopes))
            {
                return;
            }
            foreach (IScopeNode subItem in scope.NestedScopes)
            {
                LibraryNode newNode       = CreateLibraryNode(subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);
                string      newNamePrefix = namePrefix;

                // The classes are always added to the root node, the functions to the
                // current node.

                if ((newNode.NodeType & LibraryNodeType.Classes) != LibraryNodeType.None)
                {
                    // Classes are always added to the root.
                    root.AddNode(newNode);
                    newNamePrefix = namePrefix + newNode.Name + ".";
                }
                else
                {
                    current.AddNode(newNode);
                }

                // Now use recursion to get the other types.
                CreateModuleTree(root, newNode, subItem, newNamePrefix, moduleId);
            }
        }
Beispiel #2
0
        public PythonFileLibraryNode(LibraryNode parent, HierarchyNode hierarchy, string name, string filename)
            : base(parent, name, filename, LibraryNodeType.Namespaces, children: new PythonFileChildren((FileNode)hierarchy))
        {
            _hierarchy = hierarchy;

            ((PythonFileChildren)Children)._parent = this;
        }
Beispiel #3
0
 internal void RemoveNode(LibraryNode node)
 {
     lock (this) {
         _root = _root.Clone();
         _root.RemoveNode(node);
         _updateCount++;
     }
 }
Beispiel #4
0
 internal void AddNode(LibraryNode node)
 {
     lock (this) {
         // re-create root node here because we may have handed out the node before and don't want to mutate it's list.
         _root = _root.Clone();
         _root.AddNode(node);
         _updateCount++;
     }
 }
Beispiel #5
0
        private static LibraryNodeType GetLibraryNodeType(CompletionResult value, LibraryNode parent)
        {
            switch (value.MemberType)
            {
            case PythonMemberType.Class:
                return(LibraryNodeType.Classes);

            case PythonMemberType.Function:
                //if (parent is PythonFileLibraryNode) {
                //    return LibraryNodeType.Classes | LibraryNodeType.Members;
                //}
                return(LibraryNodeType.Members);

            default:
                return(LibraryNodeType.Members);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Called by derived class when a file has been parsed.  The caller should
        /// provide the LibraryTask received from the OnNewFile call and an IScopeNode
        /// which represents the contents of the library.
        ///
        /// It is safe to call this method from any thread.
        /// </summary>
        protected void FileParsed(LibraryTask task, IScopeNode scope)
        {
            var project = task.ModuleID.Hierarchy as IProject;

            HierarchyNode fileNode = null;

            if (project != null)
            {
                fileNode = ((ProjectSmuggler)project.Project).Project.NodeFromItemId(task.ModuleID.ItemID);
            }

            LibraryNode module = CreateFileLibraryNode(
                fileNode,
                System.IO.Path.GetFileName(task.FileName),
                task.FileName,
                LibraryNodeType.PhysicalContainer
                );

            // TODO: Creating the module tree should be done lazily as needed
            // Currently we replace the entire tree and rely upon the libraries
            // update count to invalidate the whole thing.  We could do this
            // finer grained and only update the changed nodes.  But then we
            // need to make sure we're not mutating lists which are handed out.

            CreateModuleTree(module, module, scope, task.FileName + ":", task.ModuleID);

            if (null != task.ModuleID)
            {
                LibraryNode previousItem = null;
                lock (_files) {
                    if (_files.TryGetValue(task.ModuleID, out previousItem))
                    {
                        _files.Remove(task.ModuleID);
                    }
                }
                _library.RemoveNode(previousItem);
            }
            _library.AddNode(module);
            if (null != task.ModuleID)
            {
                lock (_files) {
                    _files.Add(task.ModuleID, module);
                }
            }
        }
Beispiel #7
0
        public PythonLibraryNode(LibraryNode parent, CompletionResult value, IVsHierarchy hierarchy, uint itemId, IList <LibraryNode> children)
            : base(parent, value.Name, value.Name, hierarchy, itemId, GetLibraryNodeType(value, parent), children: children)
        {
            _value = value;
            bool hasLocation = false;

            foreach (var completion in value.Values)
            {
                if (completion.locations.MaybeEnumerate().Any())
                {
                    hasLocation = true;
                }
            }
            if (hasLocation)
            {
                CanGoToSource = true;
            }
        }
Beispiel #8
0
        private void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

            if (null == hierarchy)
            {
                return;
            }

            ModuleId    id   = new ModuleId(hierarchy, args.ItemID);
            LibraryNode node = null;

            lock (_files) {
                if (_files.TryGetValue(id, out node))
                {
                    _files.Remove(id);
                }
            }
            if (null != node)
            {
                _library.RemoveNode(node);
            }
        }
 public override LibraryNode CreateFileLibraryNode(LibraryNode parent, HierarchyNode hierarchy, string name, string filename)
 {
     return(new PythonFileLibraryNode(parent, hierarchy, hierarchy.Caption, filename));
 }
 public PythonLibraryNode(LibraryNode parent, IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId)
     : base(parent, scope, namePrefix, hierarchy, itemId)
 {
 }
Beispiel #11
0
 protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid)
 {
     return(new PythonLibraryNode(parent, subItem, namePrefix, hierarchy, itemid));
 }
Beispiel #12
0
        public int GetList2(uint ListType, uint flags, VSOBSEARCHCRITERIA2[] pobSrch, out IVsSimpleObjectList2 ppIVsSimpleObjectList2)
        {
            ICustomSearchListProvider listProvider;

            if (pobSrch != null &&
                pobSrch.Length > 0)
            {
                if ((listProvider = pobSrch[0].pIVsNavInfo as ICustomSearchListProvider) != null)
                {
                    switch ((_LIB_LISTTYPE)ListType)
                    {
                    case _LIB_LISTTYPE.LLT_NAMESPACES:
                        ppIVsSimpleObjectList2 = listProvider.GetSearchList();
                        break;

                    default:
                        ppIVsSimpleObjectList2 = null;
                        return(VSConstants.E_FAIL);
                    }
                }
                else
                {
                    if (pobSrch[0].eSrchType == VSOBSEARCHTYPE.SO_ENTIREWORD && ListType == (uint)_LIB_LISTTYPE.LLT_MEMBERS)
                    {
                        string srchText = pobSrch[0].szName;
                        int    colonIndex;
                        if ((colonIndex = srchText.LastIndexOf(':')) != -1)
                        {
                            string filename = srchText.Substring(0, srchText.LastIndexOf(':'));

                            foreach (var item in _root.Children)
                            {
                                if (item.FullName == filename)
                                {
                                    ppIVsSimpleObjectList2 = item.DoSearch(pobSrch[0]);
                                    if (ppIVsSimpleObjectList2 != null)
                                    {
                                        return(VSConstants.S_OK);
                                    }
                                }
                            }
                        }

                        ppIVsSimpleObjectList2 = null;
                        return(VSConstants.E_FAIL);
                    }
                    else if (pobSrch[0].eSrchType == VSOBSEARCHTYPE.SO_SUBSTRING && ListType == (uint)_LIB_LISTTYPE.LLT_NAMESPACES)
                    {
                        var lib = new LibraryNode("Search results " + pobSrch[0].szName, "Search results " + pobSrch[0].szName, LibraryNodeType.Package);
                        foreach (var item in SearchNodes(pobSrch[0], new SimpleObjectList <LibraryNode>(), _root).Children)
                        {
                            lib.Children.Add(item);
                        }
                        ppIVsSimpleObjectList2 = lib;
                        return(VSConstants.S_OK);
                    }
                    else
                    {
                        ppIVsSimpleObjectList2 = null;
                        return(VSConstants.E_FAIL);
                    }
                }
            }
            else
            {
                ppIVsSimpleObjectList2 = _root as IVsSimpleObjectList2;
            }
            return(VSConstants.S_OK);
        }
Beispiel #13
0
 public Library(Guid libraryGuid)
 {
     _guid = libraryGuid;
     _root = new LibraryNode(String.Empty, String.Empty, LibraryNodeType.Package);
 }
Beispiel #14
0
        private static SimpleObjectList <LibraryNode> SearchNodes(VSOBSEARCHCRITERIA2 srch, SimpleObjectList <LibraryNode> list, LibraryNode curNode)
        {
            foreach (var child in curNode.Children)
            {
                if (child.Name.IndexOf(srch.szName, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    list.Children.Add(child.Clone(child.Name));
                }

                SearchNodes(srch, list, child);
            }
            return(list);
        }
Beispiel #15
0
 public PythonFileLibraryNode(LibraryNode parent, HierarchyNode hierarchy, string name, string filename, LibraryNodeType libraryNodeType)
     : base(parent, name, filename, libraryNodeType)
 {
     _hierarchy = hierarchy;
 }