[svn] r6777: vs-plugin/trunk/Nemerle.VsIntegration: NemerlePackage.cs Project/HierarchyListener.cs Project...

IT svnadmin at nemerle.org
Sun Oct 22 21:10:12 CEST 2006


Log:
Little refactoring.

Author: IT
Date: Sun Oct 22 21:10:09 2006
New Revision: 6777

Modified:
   vs-plugin/trunk/Nemerle.VsIntegration/NemerlePackage.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Project/HierarchyListener.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleProjectFactory.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleProjectNode.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleTokenProcessor.cs
   vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs

Modified: vs-plugin/trunk/Nemerle.VsIntegration/NemerlePackage.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/NemerlePackage.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/NemerlePackage.cs	Sun Oct 22 21:10:09 2006
@@ -97,10 +97,9 @@
 		public NemerlePackage()
 		{
 			IServiceContainer      container = this;
-			ServiceCreatorCallback callback  = new ServiceCreatorCallback(CreateService);
 
-			container.AddService(typeof(NemerleLanguageService), callback, true);
-			container.AddService(typeof(INemerleLibraryManager), callback, true);
+			container.AddService(typeof(NemerleLanguageService), CreateService, true);
+			container.AddService(typeof(INemerleLibraryManager), CreateService, true);
 		}
 
 		protected override void Initialize()
@@ -121,9 +120,24 @@
 			//NativeMethods.ThrowOnFailure(result);
 		}
 		
-		#endregion
+		private object CreateService(IServiceContainer container, Type serviceType)
+		{
+			if (serviceType == typeof(NemerleLanguageService))
+			{
+				NemerleLanguageService language = new NemerleLanguageService();
 
-		#region RegisterForIdleTime()
+				language.SetSite(this);
+				RegisterForIdleTime();
+
+				return language;
+			}
+			else if (serviceType == typeof(INemerleLibraryManager))
+			{
+				return _libraryManager = new NemerleLibraryManager(this);
+			}
+
+			return null;
+		}
 
 		private void RegisterForIdleTime()
 		{
@@ -132,13 +146,13 @@
 			if (_componentID == 0)
 			{
 				OLECRINFO[] crinfo = new OLECRINFO[1];
+
 				crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
-				crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime
-					| (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
-				crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal
-					| (uint)_OLECADVF.olecadvfRedrawOff
-					| (uint)_OLECADVF.olecadvfWarningsOff;
+				crinfo[0].grfcrf   = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
+				crinfo[0].grfcadvf = (uint)
+					(_OLECADVF.olecadvfModal | _OLECADVF.olecadvfRedrawOff | _OLECADVF.olecadvfWarningsOff);
 				crinfo[0].uIdleTimeInterval = 1000;
+
 				ErrorHandler.ThrowOnFailure(mgr.FRegisterComponent(this, crinfo, out _componentID));
 			}
 		}
@@ -177,8 +191,7 @@
 			TItf service = GetService(typeof(TSrv)) as TItf;
 
 			if (service == null && throwIfFail)
-				throw new ArgumentException("GetService() failed for query "
-					+ typeof(TSrv).Name);
+				throw new ArgumentException("GetService() failed for query " + typeof(TSrv).Name);
 
 			return service;
 		}
@@ -188,7 +201,6 @@
 				return GetService<IOleComponentManager, SOleComponentManager>(true);
 			}
 
-
 		#endregion
 
 		#region Dispose()
@@ -200,11 +212,12 @@
 				if (_componentID != 0)
 				{
 					IOleComponentManager mgr = GetIOleComponentManager();
+
 					mgr.FRevokeComponent(_componentID);
 					_componentID = 0;
 				}
 
-				if (null != _libraryManager)
+				if (_libraryManager != null)
 				{
 					_libraryManager.Dispose();
 					_libraryManager = null;
@@ -218,29 +231,6 @@
 		
 		#endregion
 
-		#region CreateService()
-
-		private object CreateService(IServiceContainer container, Type serviceType)
-		{
-			object service = null;
-			if (typeof(NemerleLanguageService) == serviceType)
-			{
-				NemerleLanguageService language = new NemerleLanguageService();
-				language.SetSite(this);
-				RegisterForIdleTime();
-				service = language;
-			}
-			else if (typeof(INemerleLibraryManager) == serviceType)
-			{
-				_libraryManager = new NemerleLibraryManager(this);
-				service = _libraryManager;
-			}
-
-			return service;
-		}
-
-		#endregion
-
 		#region IOleComponent Members
 
 		public int FContinueMessageLoop(uint uReason, IntPtr pvLoopData, MSG[] pMsgPeeked)
@@ -255,17 +245,21 @@
 			if (lang != null)
 				lang.OnIdle((grfidlef & (uint)_OLEIDLEF.oleidlefPeriodic) != 0);
 
-			if (null != _libraryManager)
+			if (_libraryManager != null)
 				_libraryManager.OnIdle();
 
 			return 0;
 		}
 
 		public int FPreTranslateMessage(MSG[] pMsg) { return 0; }
-		public int FQueryTerminate(int fPromptUser) { return 1; }
+		public int  FQueryTerminate     (int fPromptUser)                   { return 1; }
+
+		public void OnAppActivate       (int fActive, uint dwOtherThreadID) {}
+		public void OnEnterState        (uint uStateID, int fEnter)         {}
+		public void OnLoseActivation    () {}
+		public void Terminate           () {}
 
-		public int FReserved1(uint dwReserved, uint message, 
-			IntPtr wParam, IntPtr lParam)
+		public int FReserved1(uint dwReserved, uint message, IntPtr wParam, IntPtr lParam)
 		{
 			return 1;
 		}
@@ -275,69 +269,50 @@
 			return IntPtr.Zero;
 		}
 
-		public void OnActivationChange(IOleComponent pic, int fSameComponent,
-			OLECRINFO[] pcrinfo, int fHostIsActivating, 
-			OLECHOSTINFO[] pchostinfo, uint dwReserved)
+		public void OnActivationChange(
+			IOleComponent  pic,
+			int            fSameComponent,
+			OLECRINFO[]    pcrinfo,
+			int            fHostIsActivating, 
+			OLECHOSTINFO[] pchostinfo,
+			uint           dwReserved)
 		{
 		}
 
-		public void OnAppActivate(int fActive, uint dwOtherThreadID) { }
-		public void OnEnterState(uint uStateID, int fEnter) { }
-		public void OnLoseActivation() { }
-		public void Terminate() { }
-
 		#endregion
 
 		#region IVsInstalledProduct Members
-		/// <summary>
-		/// This method is called during Devenv /Setup to get the bitmap to display on the splash screen for this package.
-		/// </summary>
-		/// <param name="pIdBmp">The resource id corresponding to the bitmap to display on the splash screen</param>
-		/// <returns>HRESULT, indicating success or failure</returns>
-		public int IdBmpSplash(out uint pIdBmp) {
+
+		public int IdBmpSplash(out uint pIdBmp)
+		{
 			pIdBmp = 300; // nevermind, does not called by VS2005
 			return VSConstants.S_OK;
 		}
 
-		/// <summary>
-		/// This method is called to get the icon that will be displayed in the Help About dialog when this package is selected.
-		/// </summary>
-		/// <param name="pIdIco">The resource id corresponding to the icon to display on the Help About dialog</param>
-		/// <returns>HRESULT, indicating success or failure</returns>
-		public int IdIcoLogoForAboutbox(out uint pIdIco) {
+		public int IdIcoLogoForAboutbox(out uint pIdIco)
+		{
 			pIdIco = 300; // used for splash screen also
 			return VSConstants.S_OK;
 		}
 
-		/// <summary>
-		/// This methods provides the product official name, it will be displayed in the help about dialog.
-		/// </summary>
-		/// <param name="pbstrName">Out parameter to which to assign the product name</param>
-		/// <returns>HRESULT, indicating success or failure</returns>
-		public int OfficialName(out string pbstrName) {
+		public int OfficialName(out string pbstrName)
+		{
 			pbstrName = NemerleConstants.LanguageName;
 			return VSConstants.S_OK;
 		}
 
-		/// <summary>
-		/// This methods provides the product description, it will be displayed in the help about dialog.
-		/// </summary>
-		/// <param name="pbstrProductDetails">Out parameter to which to assign the description of the package</param>
-		/// <returns>HRESULT, indicating success or failure</returns>
-		public int ProductDetails(out string pbstrProductDetails) {
+		public int ProductDetails(out string pbstrProductDetails)
+		{
 			pbstrProductDetails = NemerleConstants.ProductDetails;
 			return VSConstants.S_OK;
 		}
 
-		/// <summary>
-		/// This methods provides the product version, it will be displayed in the help about dialog.
-		/// </summary>
-		/// <param name="pbstrPID">Out parameter to which to assign the version number</param>
-		/// <returns>HRESULT, indicating success or failure</returns>
-		public int ProductID(out string pbstrPID) {
+		public int ProductID(out string pbstrPID)
+		{
 			pbstrPID = NemerleConstants.ProductID;
 			return VSConstants.S_OK;
 		}
+
 		#endregion
 	}
 }

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/HierarchyListener.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/HierarchyListener.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/HierarchyListener.cs	Sun Oct 22 21:10:09 2006
@@ -40,10 +40,10 @@
 		/// <param name="doInitialScan">if set to <c>true</c> [do initial scan].</param>
 		public void StartListening(bool doInitialScan)
 		{
-			if (0 == _cookie)
+			if (_cookie == 0)
 			{
-				ErrorHandler.ThrowOnFailure(
-					_hierarchy.AdviseHierarchyEvents(this, out _cookie));
+				ErrorHandler.ThrowOnFailure(_hierarchy.AdviseHierarchyEvents(this, out _cookie));
+
 				if (doInitialScan)
 					InternalScanHierarchy(VSConstants.VSITEMID_ROOT);
 			}
@@ -185,7 +185,7 @@
 				// It is not a file, we can exit now.
 				return false;
 
-			// This item is a file; find if it is a pyhon file.
+			// This item is a file; find if it is a nemerle file.
 			//
 			hr = _hierarchy.GetCanonicalName(itemId, out canonicalName);
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleProjectFactory.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleProjectFactory.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleProjectFactory.cs	Sun Oct 22 21:10:09 2006
@@ -17,15 +17,17 @@
 
 		protected override ProjectNode CreateProject()
 		{
-			IServiceProvider    provider           = Package;
-			IOleServiceProvider oleServiceProvider =
-				(IOleServiceProvider)provider.GetService(typeof(IOleServiceProvider));
-
-			ProjectNode project = new NemerleProjectNode((NemerlePackage)Package);
+			ProjectNode         project            = new NemerleProjectNode(Package);
+			IOleServiceProvider oleServiceProvider = Package.GetService<IOleServiceProvider>();
 
 			project.SetSite(oleServiceProvider);
 
 			return project;
 		}
+
+		public new NemerlePackage Package
+		{
+			get { return (NemerlePackage)base.Package; }
+		}
 	}
 }

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleProjectNode.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleProjectNode.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleProjectNode.cs	Sun Oct 22 21:10:09 2006
@@ -21,10 +21,7 @@
 	[Guid(NemerleConstants.ProjectNodeGuidString)]
 	public class NemerleProjectNode : ProjectNode, IVsProjectSpecificEditorMap2
 	{
-		NemerlePackage _package;
-		static ImageList _nemerleImageList = LoadProjectImageList();
-		
-		#region ctor
+		#region Init
 
 		public NemerleProjectNode(NemerlePackage pkg)
 		{
@@ -39,21 +36,6 @@
 			InitializeCATIDs();
 		}
 
-		private static ImageList LoadProjectImageList()
-		{
-			// Make the name of resource bitmap.
-			// It's bitmap used in project ImageList.
-			//
-			Type     type         = typeof(NemerleProjectNode);
-			Assembly assembly     = type.Assembly;
-			string   resourceName = Utils.GetModuleName(type) + "." + NemerleConstants.ProjectImageListName;
-			Stream   imageStream  = assembly.GetManifestResourceStream(resourceName);
-
-			Trace.Assert(imageStream != null);
-
-			return PkgUtils.GetImageList(imageStream);
-		}
-
 		/// <summary>
 		/// Provide mapping from our browse objects and automation objects to our CATIDs
 		/// </summary>
@@ -83,15 +65,33 @@
 			// We could also provide CATIDs for references and the references container node, if we wanted to.
 		}
 
+		private static ImageList LoadProjectImageList()
+		{
+			// Make the name of resource bitmap.
+			// It's bitmap used in project ImageList.
+			//
+			Type     type         = typeof(NemerleProjectNode);
+			Assembly assembly     = type.Assembly;
+			string   resourceName = Utils.GetModuleName(type) + "." + NemerleConstants.ProjectImageListName;
+			Stream   imageStream  = assembly.GetManifestResourceStream(resourceName);
+
+			Trace.Assert(imageStream != null);
+
+			return PkgUtils.GetImageList(imageStream);
+		}
+
 		#endregion
 
 		#region Fields
 
 		readonly Guid GUID_MruPage = new Guid("{19B97F03-9594-4c1c-BE28-25FF030113B3}");
 
+		NemerlePackage       _package;
 		VSLangProj.VSProject _vsProject = null;
 		IVSMDCodeDomProvider _codeDomProvider;
 
+		static ImageList _nemerleImageList = LoadProjectImageList();
+
 		#endregion
 
 		#region Properties
@@ -149,12 +149,11 @@
 			get
 			{
 				IntPtr unknownPtr = PkgUtils.QueryInterfaceIUnknown(this);
+
 				if (unknownPtr == IntPtr.Zero)
 					return null;
 
-				IVsHierarchy hier = (IVsHierarchy)Marshal.GetObjectForIUnknown(
-					unknownPtr);
-				return hier;
+				return (IVsHierarchy)Marshal.GetObjectForIUnknown(unknownPtr);
 			}
 		}
 
@@ -162,7 +161,7 @@
 		public  ProjectInfo  ProjectInfo
 		{
 			get { return _projectInfo;  }
-			set { _projectInfo = value; }
+			//set { _projectInfo = value; }
 		}
 
 		/// <summary>
@@ -229,9 +228,9 @@
 			// IT: ProjectInfo needs to be created before loading
 			// as we will catch assembly reference adding.
 			//
-			_projectInfo = new ProjectInfo(Site, BuildProject, InteropSafeHierarchy, filename, location);
+			_projectInfo = new ProjectInfo(this, InteropSafeHierarchy, filename, location);
 
-			ProjectInfo.ProjectsInfos.Add(_projectInfo);
+			ProjectInfo.Projects.Add(_projectInfo);
 
 			base.Load(filename, location, name, flags, ref iidProject, out canceled);
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleTokenProcessor.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleTokenProcessor.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/NemerleTokenProcessor.cs	Sun Oct 22 21:10:09 2006
@@ -10,7 +10,7 @@
 		{
 			// VladD2:
 			// If file is located in subdirectory, we need to create this subdirectory.
-			// TokenProcessor does not take it in account.
+			// TokenProcessor does not take it into account.
 			//
 			string destDir = Path.GetDirectoryName(destination);
 

Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs	Sun Oct 22 21:10:09 2006
@@ -22,14 +22,13 @@
 	public class ProjectInfo
 	{
 		private HierarchyListener              _listener;
-		private Dictionary<string, int>        _filesMap      = new Dictionary<string, int>();
-		private static Collection<ProjectInfo> _projectsInfos = new Collection<ProjectInfo>();
+		private Dictionary<string, int>        _fileMap  = new Dictionary<string, int>();
+
+		private static Collection<ProjectInfo> _projects = new Collection<ProjectInfo>();
 		private string                         _projectLocation;
-		private readonly IServiceProvider      _site;
 
 		public ProjectInfo(
-			IServiceProvider site, 
-			MSBuild.Project  buildProject, 
+			NemerleProjectNode projectNode,
 			IVsHierarchy     hierarchy, 
 			string           fileName, 
 			string           location
@@ -37,18 +36,17 @@
 		{
 			ErrorHelper.ThrowIsNull(hierarchy, "hierarchy");
 
-			_site         = site;
-			_buildProject = buildProject;
+			_projectNode = projectNode;
+			_hierarchy   = hierarchy;
 
 			CompilationOptions options = new CompilationOptions();
 
 			options.DoNotLoadStdlib = NoStdLib;
 			options.DoNotLoadMacros = NoStdMacros;
 
-			_hierarchy = hierarchy;
 			_engine    = new Engine(options, new TraceWriter()); // it enables parser working.
 
-			if (!String.IsNullOrEmpty(location))
+			if (!string.IsNullOrEmpty(location))
 				_projectLocation = location;
 			else
 				_projectLocation = Path.GetDirectoryName(fileName);
@@ -62,11 +60,14 @@
 			_engine.Init();
 		}
 
-		private MSBuild.Project  _buildProject;
-		public  MSBuild.Project MSBuildProject { get { return _buildProject; } }
+		private Engine _engine;
+		public  Engine  Engine { get { return _engine; } }
 
-		public bool NoStdLib    { get { return Utils.IsTrue(MSBuildProject, "NoStdLib");    } }
-		public bool NoStdMacros { get { return Utils.IsTrue(MSBuildProject, "NoStdMacros"); } }
+		private NemerleProjectNode _projectNode;
+		public  NemerleProjectNode  ProjectNode { get { return _projectNode; } }
+
+		public bool NoStdLib    { get { return Utils.IsTrue(ProjectNode.BuildProject, "NoStdLib");    } }
+		public bool NoStdMacros { get { return Utils.IsTrue(ProjectNode.BuildProject, "NoStdMacros"); } }
 
 		IVsHierarchy _hierarchy;
 
@@ -80,17 +81,14 @@
 			_listener.StartListening(true);
 		}
 
-		private Engine _engine;
-		public  Engine  Engine { get { return _engine; } }
-
-		public static Collection<ProjectInfo> ProjectsInfos
+		public static Collection<ProjectInfo> Projects
 		{
-			get { return _projectsInfos; }
+			get { return _projects; }
 		}
 
 		public  IVsSmartOpenScope SmartOpenScope
 		{
-			get { return (IVsSmartOpenScope)_site.GetService(typeof (SVsSmartOpenScope)); }
+			get { return (IVsSmartOpenScope)ProjectNode.Site.GetService(typeof(SVsSmartOpenScope)); }
 		}
 
 		#region Project References
@@ -141,13 +139,13 @@
 		public int GetFileTimestamp(string filePath)
 		{
 			int version;
-			return _filesMap.TryGetValue(filePath, out version) ? version : 0;
+			return _fileMap.TryGetValue(filePath, out version) ? version : 0;
 		}
 
 		public bool IsFileInProject(string filePath)
 		{
 			ErrorHelper.ThrowIfPathNullOrEmpty(filePath, "filePath");
-			return _filesMap.ContainsKey(filePath);
+			return _fileMap.ContainsKey(filePath);
 		}
 
 		public void UpdateFile(ParseRequest request)
@@ -158,13 +156,13 @@
 			string filePath  = request.FileName;
 			int    timestamp = request.Timestamp;
 
-			if (!_filesMap.TryGetValue(filePath, out oldTimestamp))
+			if (!_fileMap.TryGetValue(filePath, out oldTimestamp))
 				throw new ArgumentException("File '" + filePath + "' not found.", "filePath");
 
 			if (timestamp != oldTimestamp)
 			{
 				Engine.Sources.AddOrUpdate(filePath, GetFileContent(request));
-				_filesMap[filePath] = timestamp;
+				_fileMap[filePath] = timestamp;
 			}
 		}
 
@@ -210,7 +208,7 @@
 
 			string path = ergs.FileName;
 
-			_filesMap.Add(path, 1);
+			_fileMap.Add(path, 1);
 
 			try
 			{
@@ -232,7 +230,7 @@
 
 			string path = ergs.FileName;
 
-			_filesMap.Remove(path);
+			_fileMap.Remove(path);
 			Engine.Sources.Remove(path);
 		}
 
@@ -240,7 +238,7 @@
 		{
 			ErrorHelper.ThrowIfPathNullOrEmpty(fileName, "fileName");
 
-			foreach (ProjectInfo proj in _projectsInfos)
+			foreach (ProjectInfo proj in _projects)
 				if (proj.IsFileInProject(fileName))
 					return proj;
 



More information about the svn mailing list