[svn] r6873: vs-plugin/trunk: Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj Nemerle.Compiler.Utils/...

kliss svnadmin at nemerle.org
Sun Nov 12 21:44:06 CET 2006


Log:
Formatter stubs

Author: kliss
Date: Sun Nov 12 21:44:02 2006
New Revision: 6873

Added:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n
Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
   vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleViewFilter.cs

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Compiler.Utils.csproj	Sun Nov 12 21:44:02 2006
@@ -149,6 +149,7 @@
     <Compile Include="Nemerle.Completion2\TextManagement\ProjectManager.n" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Nemerle.Completion2\CodeModel\Formatter.n" />
     <Compile Include="Nemerle.Completion2\TextManagement\ISource.n" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

Added: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n
==============================================================================
--- (empty file)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n	Sun Nov 12 21:44:02 2006
@@ -0,0 +1,44 @@
+
+using Nemerle.Utility;
+using Nemerle.Compiler;
+using Nemerle.Completion2;
+
+using MsgBox = System.Windows.Forms.MessageBox;
+
+namespace Nemerle.Completion2
+{
+	public class Formatter
+	{
+		mutable _startLine = 0;
+		mutable _endLine = 0;
+		[Accessor] _engine : Engine;
+
+		private this()
+		{
+		}
+
+		private this(startLn : int, endLn : int)
+		{
+			_startLine = startLn;
+			_endLine = endLn;
+		}
+		public this(engine : Engine)
+		{
+			_engine = engine;
+		}
+
+
+		// Here we have to fund out what piece of AST to analyze
+		public FormatSpan(startLine : int, 
+							startCol : int, 
+							endLine : int, 
+							endCol : int,
+							filePath : string) : void
+		{
+			
+			def rootDecl = this.Engine.Project.GetActiveDecl(filePath, startLine, startCol);
+			//MsgBox.Show(rootDecl.ToString());
+
+		}
+	}
+}

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs	Sun Nov 12 21:44:02 2006
@@ -156,6 +156,7 @@
 			{
 				_preferences = new LanguagePreferences(Site, typeof(NemerleLanguageService).GUID, Name);
 				_preferences.Init();
+				_preferences.EnableFormatSelection = true;
 
 #if DEBUG
 				//VladD2: Switch on synchronous mode for debugging purpose!

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleSource.cs	Sun Nov 12 21:44:02 2006
@@ -9,6 +9,10 @@
 using Microsoft.VisualStudio.TextManager.Interop;
 
 using Nemerle.VisualStudio.Project;
+using Nemerle.Completion2;
+using System.Windows.Forms;
+using System.Text;
+using Nemerle.Collections;
 
 namespace Nemerle.VisualStudio.LanguageService
 {
@@ -252,5 +256,44 @@
 				Marshal.ReleaseComObject(ppenum);
 			}
 		}
+		public override void ReformatSpan(EditArray mgr, TextSpan span)
+		{
+			string filePath = GetFilePath();
+			ProjectInfo projectInfo = ProjectInfo.FindProject(filePath);
+			Engine engine = projectInfo.Engine;
+			
+			//MessageBox.Show(engine.Project.GetActiveDecl(GetFilePath(), span.iStartLine, span.iStartIndex).ToString());
+			//return;
+
+			// This is a piece of code from DoFormatting sample function.
+			IVsTextLines pBuffer = GetTextLines();
+			StringBuilder msg = new StringBuilder();
+			if (pBuffer != null)
+			{ 
+                int    startIndex = span.iStartIndex;
+                int    endIndex   = 0;
+                string line       = "";
+                // Loop over all lines in span
+				for (int i = span.iStartLine; i <= span.iEndLine; i++)
+				{
+					if (i < span.iEndLine)
+					{
+						pBuffer.GetLengthOfLine(i, out endIndex);
+					}
+					else
+					{
+						endIndex = span.iEndIndex;
+					}
+					pBuffer.GetLineText(i, startIndex, i, endIndex, out line);
+					msg.AppendFormat("{0}{1}", line, Environment.NewLine);
+				}
+			}
+			//MessageBox.Show(msg.ToString());
+			Formatter f = new Formatter(engine);
+			
+			f.FormatSpan(span.iStartLine, span.iEndLine, span.iEndLine, span.iEndIndex,
+				filePath);
+			base.ReformatSpan(mgr, span);
+		}
 	}
 }

Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleViewFilter.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleViewFilter.cs	(original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleViewFilter.cs	Sun Nov 12 21:44:02 2006
@@ -4,6 +4,8 @@
 using Microsoft.VisualStudio.OLE.Interop;
 using Microsoft.VisualStudio.Package;
 using Microsoft.VisualStudio.TextManager.Interop;
+using System.Diagnostics;
+using Nemerle.Completion2;
 
 namespace Nemerle.VisualStudio.LanguageService
 {
@@ -31,7 +33,14 @@
 		{
 			if (guidCmdGroup == VSConstants.VSStd2K)
 			{
-				if (nCmdId == (uint)VSConstants.VSStd2KCmdID.INSERTSNIPPET)
+				switch (nCmdId)
+				{
+					case (uint)VSConstants.VSStd2KCmdID.FORMATSELECTION:
+						{
+							this.ReformatSelection();
+							return true;
+						}
+					case (uint)VSConstants.VSStd2KCmdID.INSERTSNIPPET:
 				{
 					ExpansionProvider ep = GetExpansionProvider();
 
@@ -40,7 +49,7 @@
 
 					return true; // Handled the command.
 				}
-				else if (nCmdId == (uint)VSConstants.VSStd2KCmdID.SURROUNDWITH)
+					case (uint)VSConstants.VSStd2KCmdID.SURROUNDWITH:
 				{
 					ExpansionProvider ep = GetExpansionProvider();
 
@@ -50,10 +59,42 @@
 					return true; // Handled the command.
 				}
 			}
+			}
 
 			// Base class handled the command.  Do nothing more here.
 			//
 			return base.HandlePreExec(ref guidCmdGroup, nCmdId, nCmdexecopt, pvaIn, pvaOut);
 		}
+
+		/// <summary>
+		/// Here we will do our formatting...
+		/// </summary>
+		//public override void ReformatSelection()
+		//{
+		//    if (this.CanReformat())
+		//    {
+				
+		//        Debug.Assert(this.Source != null);
+		//        if (this.Source != null)
+		//        {
+		//            TextSpan ts = GetSelection();
+		//            if (TextSpanHelper.IsEmpty(ts))
+		//            {
+		//                // format just this current line.
+		//                ts.iStartIndex = 0;
+		//                ts.iEndLine = ts.iStartLine;
+		//                ts.iEndIndex = this.Source.GetLineLength(ts.iStartLine);
+		//            }
+		//            Formatter.FormatSpan(ts.iStartLine, ts.iEndLine);
+		//            //using (EditArray mgr = new EditArray(this.Source, this.TextView, true, "Formatting"))
+		//            //{
+		//            //    this.Source.ReformatSpan(mgr, ts);
+		//            //    mgr.ApplyEdits();
+		//            //}
+		//        }
+		//    }
+
+		//    //base.ReformatSelection();
+		//}
 	}
 }
\ No newline at end of file



More information about the svn mailing list