public void RegisterFileNode(SQProjectFileNode node)
        {
            if (_library == null)
            {
                IVsObjectManager2 objManager = node.ProjectMgr.Site.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
                _library = new SQObjectLibrary(new SQObjectLibraryNode(LibraryNodeType.Package, "Project"), objManager);
                if (null == objManager)
                {
                    return;
                }
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    objManager.RegisterSimpleLibrary(_library, out _library.Cookie));
            }
            string ext = Path.GetExtension(node.Url);

            if (ext == ".nut")
            {
                //SQLanguangeService service = (SQLanguangeService)SQVSUtils.GetService<ISQLanguageService>();
                SQDeclaration declaration = Parse(node.Url);
                if (declaration != null)
                {
                    node.OnNodeRemoved += Node_OnFileRemoved;
                    _nodes.Add(node);
                    if (IntellisenseEnabled)
                    {
                        MapObjects(node, declaration);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            // Dispose all the listeners.
            foreach (var info in _hierarchies.Values)
            {
                info.Listener.Dispose();
            }
            _hierarchies.Clear();

            foreach (TextLineEventListener textListener in _documents.Values)
            {
                textListener.Dispose();
            }
            _documents.Clear();

            // Remove this library from the object manager.
            if (0 != _objectManagerCookie)
            {
                IVsObjectManager2 mgr = GetPackageService(typeof(SVsObjectManager)) as IVsObjectManager2;
                if (null != mgr)
                {
                    mgr.UnregisterLibrary(_objectManagerCookie);
                }
                _objectManagerCookie = 0;
            }

            // Unregister this object from the RDT events.
            UnregisterRDTEvents();
        }
Exemplo n.º 3
0
        public void RegisterHierarchy(IVsHierarchy hierarchy)
        {
            if (hierarchy == null || _hierarchies.ContainsKey(hierarchy))
            {
                return;
            }

            if (_objectManagerCookie == 0)
            {
                IVsObjectManager2 objManager =
                    _provider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;

                if (null == objManager)
                {
                    return;
                }

                ErrorHandler.ThrowOnFailure(
                    objManager.RegisterSimpleLibrary(_library, out _objectManagerCookie));
            }

            HierarchyListener listener = new HierarchyListener(hierarchy);

            listener.ItemAdded   += OnFileChanged;
            listener.ItemDeleted += OnDeleteFile;

            listener.StartListening(true);

            _hierarchies.Add(hierarchy, listener);
            RegisterForRDTEvents();
        }
        void RemoveNodesWithFilepath(string filepath)
        {
            var ichildren = _library._root.Children;
            List <SQObjectLibraryNode> nodestoremove = new List <SQObjectLibraryNode>(ichildren.Count);

            foreach (var n in ichildren)
            {
                if (n.FilePath == filepath)
                {
                    nodestoremove.Add(n);
                }
            }
            foreach (var r in nodestoremove)
            {
                ichildren.Remove(r);
                r.Release();
            }
            IVsObjectManager2 objManager = _library._objectManager;

            if (null == objManager)
            {
                return;
            }
            objManager.UnregisterLibrary(_library.Cookie);
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                objManager.RegisterSimpleLibrary(_library, out _library.Cookie));

            _nodeErrors.Remove(filepath);
            _errorHandler.RemoveMessageWithPartialKey(filepath);
            _keywordcache.Remove(filepath);
        }
Exemplo n.º 5
0
        public void RegisterHierarchy(IVsHierarchy hierarchy)
        {
            if ((null == hierarchy) || hierarchies.ContainsKey(hierarchy))
            {
                return;
            }
            if (0 == objectManagerCookie)
            {
                IVsObjectManager2 objManager = provider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
                if (null == objManager)
                {
                    return;
                }
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    objManager.RegisterSimpleLibrary(library, out objectManagerCookie));
            }

            SQLanguageService ls       = (SQLanguageService)provider.GetService(typeof(SQLanguageService));
            HierarchyListener listener = new HierarchyListener(hierarchy, ls.GetSquirrelVersion());

            listener.OnAddItem    += new EventHandler <HierarchyEventArgs>(OnNewFile);
            listener.OnDeleteItem += new EventHandler <HierarchyEventArgs>(OnDeleteFile);
            listener.StartListening(true);
            hierarchies.Add(hierarchy, listener);
            RegisterForRDTEvents();

            parseThread = new Thread(new ThreadStart(ParseThread));
            parseThread.Start();
        }
        public void Dispose()
        {
            // Make sure that the parse thread can exit.
            if (null != shutDownStarted)
            {
                shutDownStarted.Set();
            }
            if ((null != parseThread) && parseThread.IsAlive)
            {
                parseThread.Join(500);
                if (parseThread.IsAlive)
                {
                    parseThread.Abort();
                }
                parseThread = null;
            }

            requests.Clear();

            // Dispose all the listeners.
            foreach (HierarchyListener listener in hierarchies.Values)
            {
                listener.Dispose();
            }
            hierarchies.Clear();

            foreach (TextLineEventListener textListener in documents.Values)
            {
                textListener.Dispose();
            }
            documents.Clear();

            // Remove this library from the object manager.
            if (0 != objectManagerCookie)
            {
                IVsObjectManager2 mgr = provider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
                if (null != mgr)
                {
                    mgr.UnregisterLibrary(objectManagerCookie);
                }
                objectManagerCookie = 0;
            }

            // Unregister this object from the RDT events.
            UnregisterRDTEvents();

            // Dispose the events used to syncronize the threads.
            if (null != requestPresent)
            {
                requestPresent.Close();
                requestPresent = null;
            }
            if (null != shutDownStarted)
            {
                shutDownStarted.Close();
                shutDownStarted = null;
            }
        }
Exemplo n.º 7
0
 private void UnregisterLibrary()
 {
     if (objectManagerCookie != 0)
     {
         IVsObjectManager2 objManager = GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
         if (objManager != null)
         {
             objManager.UnregisterLibrary(objectManagerCookie);
         }
     }
 }
Exemplo n.º 8
0
 private void RegisterLibrary()
 {
     if (objectManagerCookie == 0)
     {
         IVsObjectManager2 objManager = GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
         if (objManager == null)
         {
             return;
         }
         ErrorHandler.ThrowOnFailure(objManager.RegisterSimpleLibrary(library, out objectManagerCookie));
     }
 }
Exemplo n.º 9
0
        private void InitComponent()
        {
            if (library != null && libraryScope != null)
            {
                return;
            }

            // Get the object manager
            IVsObjectManager2 mgr = LanguageService.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;

            if (mgr == null)
            {
                throw new ArgumentException("object mangager not found.");
            }

            if (library == null)
            {
                // Find the com+ library
                IVsLibrary2 libraryCInterface;
                Guid        guid = guidCOMplusplus;
                ErrorHandler.ThrowOnFailure(mgr.FindLibrary(ref guid, out libraryCInterface));
                library = libraryCInterface as IVsSimpleLibrary2;
                if (library == null)
                {
                    throw new ArgumentException("COM+ library not found.");
                }
            }

            if (libraryScope == null)
            {
                // create the command set for the source file
                ErrorHandler.ThrowOnFailure(mgr.CreateSimpleBrowseComponentSet((uint)_BROWSE_COMPONENT_SET_TYPE.BCST_EXCLUDE_LIBRARIES, null, 0, out libraryScope));

                // Add compnents
                string     sBasePath = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\";
                Guid       guid;
                uint       dwStructSize = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORDATA));
                IVsNavInfo nav;
                ErrorHandler.ThrowOnFailure(library.GetGuid(out guid));
                VSCOMPONENTSELECTORDATA[] a = new VSCOMPONENTSELECTORDATA[1];
                ErrorHandler.ThrowOnFailure(libraryScope.AddComponent(ref guid,
                                                                      new[]
                {
                    new VSCOMPONENTSELECTORDATA()
                    {
                        dwSize    = dwStructSize,
                        bstrFile  = sBasePath + "mscorlib.dll",
                        bstrTitle = "mscorlib",
                        type      = VSCOMPONENTTYPE.VSCOMPONENTTYPE_ComPlus
                    }
                }, out nav, a));
            }
        }         // proc InitComponent
Exemplo n.º 10
0
 private void RegisterLibrary()
 {
     if (0 == _objectManagerCookie)
     {
         IVsObjectManager2 objManager = GetPackageService(typeof(SVsObjectManager)) as IVsObjectManager2;
         if (null == objManager)
         {
             return;
         }
         Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
             objManager.RegisterSimpleLibrary(_library, out _objectManagerCookie));
     }
 }
Exemplo n.º 11
0
        //public static IVsLibrary2 GetCSharpLibrary(DTE2 dte)
        //{
        //    if (dte == null)
        //        throw new ArgumentNullException("dte");

        //    return GetIVsLibrary2(dte, VsUtilities.CSharpLibrary);
        //}

        public static IVsLibrary2 GetIVsLibrary2(DTE2 dte, Guid guid)
        {
            if (dte == null)
            {
                throw new ArgumentNullException("dte");
            }

            IVsObjectManager2 objectManager = GetIVsObjectManager2(dte);
            IVsLibrary2       library       = null;

            objectManager.FindLibrary(ref guid, out library);
            return(library);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Called when a project is loaded
        /// </summary>
        /// <param name="hierarchy"></param>
        public void RegisterHierarchy(IVsHierarchy hierarchy, XProject Prj, XSharpProjectNode ProjectNode)
        {
            // No Hierarchy or... Hierarchy already registered ?
            var optionsPage = XSharpProjectPackage.Instance.GetIntellisenseOptionsPage();

            // disable classview for now
            if (optionsPage.DisableClassViewObjectView)// || true)
            {
                return;
            }

            if ((null == hierarchy) || hierarchies.ContainsKey(hierarchy))
            {
                return;
            }
            //
            if (0 == objectManagerCookie)
            {
                IVsObjectManager2 objManager = provider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
                if (null == objManager)
                {
                    return;
                }
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    objManager.RegisterSimpleLibrary(library, out objectManagerCookie));
            }
            // The project is the Root of the Library
            XSharpLibraryProject prjNode = new XSharpLibraryProject(Prj, hierarchy);

            library.AddNode(prjNode);

            //this._defaultNameSpace = prjNode.DefaultNameSpace;
            //Define Callback
            ProjectNode.ProjectModel.FileWalkComplete    = new XProject.OnFileWalkComplete(OnFileWalkComplete);
            ProjectNode.ProjectModel.ProjectWalkComplete = new XProject.OnProjectWalkComplete(OnProjectWalkComplete);

            // Attach a listener to the Project/Hierarchy,so any change is raising an event
            HierarchyListener listener = new HierarchyListener(hierarchy);

            //listener.OnAddItem += new EventHandler<HierarchyEventArgs>(OnNewFile);
            listener.OnDeleteItem += new EventHandler <HierarchyEventArgs>(OnDeleteFile);
            listener.StartListening();
            hierarchies.Add(hierarchy, listener);
            // and ask for any change in the files that are opened in Source editor.
            RegisterForRDTEvents();
        }
Exemplo n.º 13
0
        private static IVsObjectManager2 GetIVsObjectManager2(DTE2 dte)
        {
            if (dte == null)
            {
                throw new ArgumentNullException("dte");
            }

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte;
            Guid   iid     = typeof(IVsObjectManager2).GUID;
            Guid   service = typeof(SVsObjectManager).GUID;
            IntPtr pUnk;

            sp.QueryService(ref service, ref iid, out pUnk);
            IVsObjectManager2 manager = (IVsObjectManager2)Marshal.GetObjectForIUnknown(pUnk);

            return(manager);
        }
Exemplo n.º 14
0
        //=====================================================================

        /// <summary>
        /// Search for and go to the definition of the given member ID
        /// </summary>
        /// <param name="memberId">The member ID for which to search</param>
        /// <returns>True if successful, false if not</returns>
        /// <remarks>We cannot guarantee any particular order for the search results so it will go to the first
        /// match it finds which may or may not be the one you are expecting.  Results are more exact when the
        /// member ID is more fully qualified.  For example, if using <c>ToString</c> you may not end up in the
        /// class you were expecting.  Using a more qualified ID such as <c>MyClass.ToString</c> will get a
        /// better result unless you have two classes by the same name in different namespaces or if the member
        /// is overloaded.</remarks>
        public bool GotoDefinitionFor(string memberId)
        {
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                if (String.IsNullOrWhiteSpace(memberId) || !this.DetermineSearchCriteria(memberId))
                {
                    return(false);
                }

                if (objectManager == null)
                {
                    objectManager = serviceProvider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;

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

                // As noted, we only support the C# library
                if (library == null)
                {
                    if (objectManager.FindLibrary(new Guid(BrowseLibraryGuids80.CSharp), out library) != VSConstants.S_OK)
                    {
                        return(false);
                    }
                }

                var criteria = new VSOBSEARCHCRITERIA2
                {
                    eSrchType  = VSOBSEARCHTYPE.SO_SUBSTRING,
                    grfOptions = (uint)_VSOBSEARCHOPTIONS.VSOBSO_NONE
                };

                // Give precedence to classes by searching for them first if wanted
                if ((searchFlags & _LIB_LISTTYPE.LLT_CLASSES) != 0)
                {
                    foreach (string searchText in searchClassCandidates)
                    {
                        criteria.szName = searchText;

                        foreach (var r in this.PerformSearch(_LIB_LISTTYPE.LLT_CLASSES, criteria))
                        {
                            if (this.IsMatch(searchText, r, false))
                            {
                                return(r.GoToSource());
                            }
                        }
                    }
                }

                // Search for members if wanted
                if ((searchFlags & _LIB_LISTTYPE.LLT_MEMBERS) != 0)
                {
                    foreach (string searchText in searchMemberCandidates)
                    {
                        criteria.szName = searchText;

                        var results = new List <SearchResult>(this.PerformSearch(_LIB_LISTTYPE.LLT_MEMBERS, criteria));

                        // Try for a match including parameters first
                        foreach (var r in results)
                        {
                            if (this.IsMatch(searchText, r, true))
                            {
                                return(r.GoToSource());
                            }
                        }

                        // Try for a match without parameters if nothing was found
                        foreach (var r in results)
                        {
                            if (this.IsMatch(searchText, r, false))
                            {
                                return(r.GoToSource());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Ignore exceptions, we'll just fail the search
                System.Diagnostics.Debug.WriteLine(ex);
            }

            return(false);
        }
Exemplo n.º 15
0
        //=====================================================================

        /// <summary>
        /// Search for and go to the definition of the given member ID
        /// </summary>
        /// <param name="memberId">The member ID for which to search</param>
        /// <returns>True if successful, false if not</returns>
        /// <remarks>We cannot guarantee any particular order for the search results so it will go to the first
        /// match it finds which may or may not be the one you are expecting.  Results are more exact when the
        /// member ID is more fully qualified.  For example, if using <c>ToString</c> you may not end up in the
        /// class you were expecting.  Using a more qualified ID such as <c>MyClass.ToString</c> will get a
        /// better result unless you have two classes by the same name in different namespaces or if the member
        /// is overloaded.</remarks>
        public bool GotoDefinitionFor(string memberId)
        {
            try
            {
                if(String.IsNullOrWhiteSpace(memberId) || !this.DetermineSearchCriteria(memberId))
                    return false;

                if(objectManager == null)
                {
                    objectManager = serviceProvider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;

                    if(objectManager == null)
                        return false;
                }

                // As noted, we only support the C# library
                if(library == null)
                    if(objectManager.FindLibrary(new Guid(BrowseLibraryGuids80.CSharp), out library) != VSConstants.S_OK)
                        return false;

                var criteria = new VSOBSEARCHCRITERIA2
                {
                    eSrchType = VSOBSEARCHTYPE.SO_SUBSTRING,
                    grfOptions = (uint)_VSOBSEARCHOPTIONS.VSOBSO_NONE
                };

                // Give precedence to classes by searching for them first if wanted
                if((searchFlags & _LIB_LISTTYPE.LLT_CLASSES) != 0)
                    foreach(string searchText in searchClassCandidates)
                    {
                        criteria.szName = searchText;

                        foreach(var r in this.PerformSearch(_LIB_LISTTYPE.LLT_CLASSES, criteria))
                            if(this.IsMatch(searchText, r, false))
                                return r.GoToSource();
                    }

                // Search for members if wanted
                if((searchFlags & _LIB_LISTTYPE.LLT_MEMBERS) != 0)
                    foreach(string searchText in searchMemberCandidates)
                    {
                        criteria.szName = searchText;

                        var results = new List<SearchResult>(this.PerformSearch(_LIB_LISTTYPE.LLT_MEMBERS, criteria));

                        // Try for a match including parameters first
                        foreach(var r in results)
                            if(this.IsMatch(searchText, r, true))
                                return r.GoToSource();

                        // Try for a match without parameters if nothing was found
                        foreach(var r in results)
                            if(this.IsMatch(searchText, r, false))
                                return r.GoToSource();
                    }
            }
            catch(Exception ex)
            {
                // Ignore exceptions, we'll just fail the search
                System.Diagnostics.Debug.WriteLine(ex);
            }

            return false;
        }
Exemplo n.º 16
0
 public SQObjectLibrary(SQObjectLibraryNode root, IVsObjectManager2 objectManager)
 {
     _objectManager = objectManager;
     _root          = root;
     _global        = new SQObjectLibraryNode(LibraryNodeType.Package, "(GLOBAL)");
 }