예제 #1
0
        internal PythonLibraryNode(ScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId, IServiceProvider serviceProvider)
            : base(scope.Name)
        {
            if (scope is FunctionNode) {
                this.NodeType = LibraryNodeType.Members;
            } else if (scope is ClassNode) {
                this.NodeType = LibraryNodeType.Classes;
                this.Name = string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix, scope.Name);
            }

            this.serviceProvider = serviceProvider;
            this.ownerHierarchy = hierarchy;
            this.fileId = itemId;

            // Now check if we have all the information to navigate to the source location.
            if ((null != ownerHierarchy) && (VSConstants.VSITEMID_NIL != fileId)) {
                if ((0 != Location.Compare(Location.None, scope.Start)) && (0 != Location.Compare(Location.None, scope.End))) {
                    sourceSpan = new TextSpan();
                    sourceSpan.iStartIndex = scope.Start.Column;
                    if (scope.Start.Line > 0) {
                        sourceSpan.iStartLine = scope.Start.Line - 1;
                    }
                    sourceSpan.iEndIndex = scope.End.Column;
                    if (scope.End.Line > 0) {
                        sourceSpan.iEndLine = scope.End.Line - 1;
                    }
                    this.CanGoToSource = true;
                }
            }
        }
 public void Add(ScopeNode node)
 {
     if (nested == null)
     {
         nested = new List <ScopeNode>();
     }
     nested.Add(node);
 }
        private void AddNode(ScopeNode node)
        {
            if (scopes.Count > 0)
            {
                ScopeNode current = scopes.Peek();
                current.Add(node);
            }
            else
            {
                root.Add(node);
            }

            scopes.Push(node);
        }
예제 #4
0
        private void CreateModuleTree(LibraryNode root, LibraryNode current, ScopeNode scope, string namePrefix, ModuleId moduleId)
        {
            if ((null == root) || (null == scope) || (null == scope.NestedScopes)) {
                return;
            }
            foreach (ScopeNode subItem in scope.NestedScopes) {
                PythonLibraryNode newNode = new PythonLibraryNode(subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID, provider);
                string newNamePrefix = namePrefix;

                // The classes are always added to the root node, the functions to the
                // current node.
                if ((newNode.NodeType & LibraryNode.LibraryNodeType.Members) != LibraryNode.LibraryNodeType.None) {
                    current.AddNode(newNode);
                } else if ((newNode.NodeType & LibraryNode.LibraryNodeType.Classes) != LibraryNode.LibraryNodeType.None) {
                    // Classes are always added to the root.
                    root.AddNode(newNode);
                    newNamePrefix = newNode.Name + ".";
                }

                // Now use recursion to get the other types.
                CreateModuleTree(root, newNode, subItem, newNamePrefix, moduleId);
            }
        }
        private void AddNode(ScopeNode node)
        {
            if (scopes.Count > 0)
            {
                ScopeNode current = scopes.Peek();
                current.Add(node);
            }
            else
            {
                root.Add(node);
            }

            scopes.Push(node);
        }
 public void Add(ScopeNode node)
 {
     if (nested == null) nested = new List<ScopeNode>();
     nested.Add(node);
 }