Exemplo n.º 1
0
        void CreateParseRequest(string file, string text, ModuleID id)
        {
            LibraryTask task = new LibraryTask(file, text);

            task.ModuleID = id;

            lock (_requests)
                _requests.Enqueue(task);

            _requestPresent.Set();
        }
Exemplo n.º 2
0
        public void UnregisterHierarchy(IVsHierarchy hierarchy)
        {
            if ((null == hierarchy) || !_hierarchies.ContainsKey(hierarchy))
            {
                return;
            }

            HierarchyListener listener = _hierarchies[hierarchy];

            if (null != listener)
            {
                listener.Dispose();
            }

            _hierarchies.Remove(hierarchy);

            if (0 == _hierarchies.Count)
            {
                UnregisterRDTEvents();
            }

            lock (_files)
            {
                ModuleID[] keys = new ModuleID[_files.Keys.Count];

                _files.Keys.CopyTo(keys, 0);

                foreach (ModuleID id in keys)
                {
                    if (hierarchy.Equals(id.Hierarchy))
                    {
                        _library.RemoveNode(_files[id]);
                        _files.Remove(id);
                    }
                }
            }

            // Remove the document listeners.
            //
            uint[] docKeys = new uint[_documents.Keys.Count];

            _documents.Keys.CopyTo(docKeys, 0);

            foreach (uint id in docKeys)
            {
                TextLineEventListener docListener = _documents[id];

                if (hierarchy.Equals(docListener.FileID.Hierarchy))
                {
                    _documents.Remove(id);
                    docListener.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            if (_connectionPoint != null && _connectionCookie != 0)
            {
                _connectionPoint.Unadvise(_connectionCookie);
                Debug.WriteLine("\n\tUnadvised from TextLinesEvents\n");
            }

            _connectionCookie = 0;
            _connectionPoint  = null;

            _buffer = null;
            _fileId = null;
        }
Exemplo n.º 4
0
        public TextLineEventListener(IVsTextLines buffer, string fileName, ModuleID id)
        {
            _buffer   = buffer;
            _fileId   = id;
            _fileName = fileName;

            IConnectionPointContainer container = buffer as IConnectionPointContainer;

            if (null != container)
            {
                Guid eventsGuid = typeof(IVsTextLinesEvents).GUID;

                container.FindConnectionPoint(ref eventsGuid, out _connectionPoint);
                _connectionPoint.Advise(this, out _connectionCookie);
            }
        }
Exemplo n.º 5
0
        public TextLineEventListener(IVsTextLines buffer, string fileName, ModuleID id)
        {
            _buffer   = buffer;
            _fileId   = id;
            _fileName = fileName;

            IConnectionPointContainer container = buffer as IConnectionPointContainer;

            if (null != container)
            {
                Guid eventsGuid = typeof(IVsTextLinesEvents).GUID;

                container.FindConnectionPoint(ref eventsGuid, out _connectionPoint);
                _connectionPoint.Advise(this, out _connectionCookie);
            }
        }
Exemplo n.º 6
0
        public override bool Equals(object obj)
        {
            ModuleID other = obj as ModuleID;

            if (null == obj)
            {
                return(false);
            }

            if (!_hierarchy.Equals(other._hierarchy))
            {
                return(false);
            }

            return(_itemID == other._itemID);
        }
Exemplo n.º 7
0
        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)
            {
                NemerleLibraryNode newNode = new NemerleLibraryNode(
                    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 & 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);
            }
        }
Exemplo n.º 8
0
        void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

            if (null == hierarchy)
            {
                return;
            }

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

            lock (_files)
                if (_files.TryGetValue(id, out node))
                {
                    _files.Remove(id);
                }

            if (null != node)
            {
                _library.RemoveNode(node);
            }
        }
Exemplo n.º 9
0
        void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

            if (null == hierarchy)
                return;

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

            lock (_files)
                if (_files.TryGetValue(id, out node))
                    _files.Remove(id);

            if (null != node)
                _library.RemoveNode(node);
        }
Exemplo n.º 10
0
        void CreateParseRequest(string file, string text, ModuleID id)
        {
            LibraryTask task = new LibraryTask(file, text);

            task.ModuleID = id;

            lock (_requests)
                _requests.Enqueue(task);

            _requestPresent.Set();
        }
Exemplo n.º 11
0
        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)
            {
                NemerleLibraryNode newNode = new NemerleLibraryNode(
                    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 & 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);
            }
        }
Exemplo n.º 12
0
        public void UnregisterHierarchy(IVsHierarchy hierarchy)
        {
            if ((null == hierarchy) || !_hierarchies.ContainsKey(hierarchy))
                return;

            HierarchyListener listener = _hierarchies[hierarchy];

            if (null != listener)
                listener.Dispose();

            _hierarchies.Remove(hierarchy);

            if (0 == _hierarchies.Count)
                UnregisterRDTEvents();

            lock (_files)
            {
                ModuleID[] keys = new ModuleID[_files.Keys.Count];

                _files.Keys.CopyTo(keys, 0);

                foreach (ModuleID id in keys)
                {
                    if (hierarchy.Equals(id.Hierarchy))
                    {
                        _library.RemoveNode(_files[id]);
                        _files.Remove(id);
                    }
                }
            }

            // Remove the document listeners.
            //
            uint[] docKeys = new uint[_documents.Keys.Count];

            _documents.Keys.CopyTo(docKeys, 0);

            foreach (uint id in docKeys)
            {
                TextLineEventListener docListener = _documents[id];

                if (hierarchy.Equals(docListener.FileID.Hierarchy))
                {
                    _documents.Remove(id);
                    docListener.Dispose();
                }
            }
        }
Exemplo n.º 13
0
        public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            // Check if this document is in the list of the documents.
            //
            if (_documents.ContainsKey(docCookie))
                return VSConstants.S_OK;

            // Get the information about this document from the RDT.
            //
            IVsRunningDocumentTable rdt =
                _provider.GetService(typeof (SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (null != rdt)
            {
                // Note that here we don't want to throw in case of error.
                uint		 flags;
                uint		 readLocks;
                uint		 writeLoks;
                string	   documentMoniker;
                IVsHierarchy hierarchy;
                uint		 itemId;
                IntPtr	   unkDocData;

                int hr = rdt.GetDocumentInfo(
                    docCookie,
                    out flags,
                    out readLocks,
                    out writeLoks,
                    out documentMoniker,
                    out hierarchy,
                    out itemId,
                    out unkDocData);

                try
                {
                    if (ErrorHandler.Failed(hr) || (IntPtr.Zero == unkDocData))
                        return VSConstants.S_OK;

                    // Check if the herarchy is one of the hierarchies this service is monitoring.
                    //
                    if (!_hierarchies.ContainsKey(hierarchy))
                        // This hierarchy is not monitored, we can exit now.
                        return VSConstants.S_OK;

                    // Check the extension of the file to see if a listener is required.
                    //
                    string extension = Path.GetExtension(documentMoniker);

                    if (string.Compare(extension, NemerleConstants.FileExtension, StringComparison.OrdinalIgnoreCase) != 0)
                        return VSConstants.S_OK;

                    // Create the module id for this document.
                    //
                    ModuleID docId = new ModuleID(hierarchy, itemId);

                    // Try to get the text buffer.
                    //
                    IVsTextLines buffer = Marshal.GetObjectForIUnknown(unkDocData) as IVsTextLines;

                    // Create the listener.
                    //
                    TextLineEventListener listener = new TextLineEventListener(buffer, documentMoniker, docId);

                    // Set the event handler for the change event. Note that there is no
                    // difference between the AddFile and FileChanged operation, so we
                    // can use the same handler.
                    //
                    listener.OnFileChanged += OnFileChanged;

                    // Add the listener to the dictionary, so we will not create it anymore.
                    //
                    _documents.Add(docCookie, listener);
                }
                finally
                {
                    if (IntPtr.Zero != unkDocData)
                        Marshal.Release(unkDocData);
                }
            }

            // Always return success.
            //
            return VSConstants.S_OK;
        }
Exemplo n.º 14
0
        public void Dispose()
        {
            if (_connectionPoint != null && _connectionCookie != 0)
            {
                _connectionPoint.Unadvise(_connectionCookie);
                Debug.WriteLine("\n\tUnadvised from TextLinesEvents\n");
            }

            _connectionCookie = 0;
            _connectionPoint  = null;

            _buffer = null;
            _fileId = null;
        }
Exemplo n.º 15
0
        public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            // Check if this document is in the list of the documents.
            //
            if (_documents.ContainsKey(docCookie))
            {
                return(VSConstants.S_OK);
            }

            // Get the information about this document from the RDT.
            //
            IVsRunningDocumentTable rdt =
                _provider.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (null != rdt)
            {
                // Note that here we don't want to throw in case of error.
                uint         flags;
                uint         readLocks;
                uint         writeLoks;
                string       documentMoniker;
                IVsHierarchy hierarchy;
                uint         itemId;
                IntPtr       unkDocData;

                int hr = rdt.GetDocumentInfo(
                    docCookie,
                    out flags,
                    out readLocks,
                    out writeLoks,
                    out documentMoniker,
                    out hierarchy,
                    out itemId,
                    out unkDocData);

                try
                {
                    if (ErrorHandler.Failed(hr) || (IntPtr.Zero == unkDocData))
                    {
                        return(VSConstants.S_OK);
                    }

                    // Check if the herarchy is one of the hierarchies this service is monitoring.
                    //
                    if (!_hierarchies.ContainsKey(hierarchy))
                    {
                        // This hierarchy is not monitored, we can exit now.
                        return(VSConstants.S_OK);
                    }

                    // Check the extension of the file to see if a listener is required.
                    //
                    string extension = Path.GetExtension(documentMoniker);

                    if (string.Compare(extension, NemerleConstants.FileExtension, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        return(VSConstants.S_OK);
                    }

                    // Create the module id for this document.
                    //
                    ModuleID docId = new ModuleID(hierarchy, itemId);

                    // Try to get the text buffer.
                    //
                    IVsTextLines buffer = Marshal.GetObjectForIUnknown(unkDocData) as IVsTextLines;

                    // Create the listener.
                    //
                    TextLineEventListener listener = new TextLineEventListener(buffer, documentMoniker, docId);

                    // Set the event handler for the change event. Note that there is no
                    // difference between the AddFile and FileChanged operation, so we
                    // can use the same handler.
                    //
                    listener.OnFileChanged += OnFileChanged;

                    // Add the listener to the dictionary, so we will not create it anymore.
                    //
                    _documents.Add(docCookie, listener);
                }
                finally
                {
                    if (IntPtr.Zero != unkDocData)
                    {
                        Marshal.Release(unkDocData);
                    }
                }
            }

            // Always return success.
            //
            return(VSConstants.S_OK);
        }