[svn] r6948: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n

kliss svnadmin at nemerle.org
Sun Nov 19 01:20:02 CET 2006


Log:
Work on formatting.

Author: kliss
Date: Sun Nov 19 01:19:53 2006
New Revision: 6948

Modified:
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Formatter.n	Sun Nov 19 01:19:53 2006
@@ -63,28 +63,41 @@
       
       def source = ProjectManager.SimpleSourceTextManager(this.Engine.Sources[filePath]);
            
-      def formatNS(ns : Decl.Using)
-      {
-        def loc = ns.Location;
-        def fullStr = source.GetLine(loc.Line);
-        def start = loc.Column - 1;
-        def width = loc.EndColumn - loc.Column + 1; // including semicolon
-        def shortStr = fullStr.Substring(start, width)/* + Environment.NewLine*/ ;
+      def usings = SCG.List.[Decl.Using]();
+      mutable usingsLocation = Location.Default;
     
-        def result = FormatterResult(0, loc.Line - 1, loc.EndColumn, loc.EndLine - 1, shortStr);
-        results.Add(result);
+      def processUsing(ns : Decl.Using)
+      {
+        usings.Add(ns);
+        usingsLocation += ns.Location;
       }
       
       def processDecls(decls : list[Decl])
       {
         match(decls)
         {
-        | (Decl.Using as d) :: rest => formatNS(d); processDecls(rest);
+        | (Decl.Using as d) :: rest => processUsing(d); processDecls(rest);
         | _ => ();
         }
       }
       
+      def writeFormattedUsings()
+      {
+        def replacement = System.Text.StringBuilder();
+        foreach(usingDecl in usings)
+        {
+          def namespaceName = usingDecl.Name.ToString(".");
+          replacement.Append($"using $namespaceName;$(Environment.NewLine)");
+        }
+          
+        def fr = FormatterResult(usingsLocation.Column - 1, usingsLocation.Line - 1, 
+                                  usingsLocation.EndColumn, usingsLocation.EndLine - 1,
+                                  replacement.ToString());
+        results.Add(fr);
+      }
+      
       processDecls(declNS.Decls);
+      writeFormattedUsings();
       
       results;
     



More information about the svn mailing list