[svn] r7094: vs-plugin/trunk: ConsoleTest/Program.cs Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Eng...

VladD2 svnadmin at nemerle.org
Fri Dec 15 12:48:55 CET 2006


Log:
1. Improve completion in pattern.
2. Add tests.

Author: VladD2
Date: Fri Dec 15 12:48:53 2006
New Revision: 7094

Modified:
   vs-plugin/trunk/ConsoleTest/Program.cs
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/Class1.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n

Modified: vs-plugin/trunk/ConsoleTest/Program.cs
==============================================================================
--- vs-plugin/trunk/ConsoleTest/Program.cs	(original)
+++ vs-plugin/trunk/ConsoleTest/Program.cs	Fri Dec 15 12:48:53 2006
@@ -12,6 +12,9 @@
 			Test1 test = new Test1();
 			test.Init();
 
+			test.Complete_in_match_variant_6();
+			test.Complete_in_match_variant_5();
+			test.Complete_in_match_variant_4();
 			test.Complete_System_Collections_Generic_List__Collections();
 			test.Complete_namespace_2();
 			test.Complete_2();

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Engine/Engine.Completion.n	Fri Dec 15 12:48:53 2006
@@ -122,10 +122,11 @@
       expression         : PExpr,
       matched_value_type : TyVar,
       _patternTyper       : Typer.PatternTyper,
-      _env                : GlobalEnv
+      env                : GlobalEnv
     )
       : void //
     {
+      assert(true);
       match (expression)
       {
         | PExpr.Is (_nested, PExpr.ToComplete (name)) with obj = null
@@ -140,8 +141,11 @@
 
           throw CompletionResult (elems, name.Id);
 
+        | PExpr.Call(PExpr.ToComplete(name), _) with obj = null
         | PExpr.ToComplete (name) with obj = null
         | PExpr.Member (obj, Parsetree.Splicable.HalfId (name)) =>
+          def name = name;
+          def obj = obj;
           def elems = SCG.List ();
           match (matched_value_type.Hint)
           {
@@ -150,14 +154,34 @@
               def option = System.StringComparison.InvariantCultureIgnoreCase;
               match (ty)
               {
-                | MType.Class (ti, _args) =>
-                  match (ti.GetTydecl ())
+                | MType.Class (ti, args) =>
+                  match (ti.GetTydecl())
                   {
-                    | TT.TypeDeclaration.Variant (members) =>
+                    | TT.TypeDeclaration.Variant (members) => // Pattern is VariantOption.
+                      // Add VariantOption's to completion list.
                       foreach (m when m.Name.StartsWith (prefix, option) in members)
-                        elems.Add (Elem.Node (m.Name, m.NamespaceNode));
+                        elems.Add(Elem.Node(m.Name, m.NamespaceNode));
 
-                      throw CompletionResult (elems, name.Id);
+                      def tryAddName(name)
+                      {
+                        when (name.StartsWith (prefix, option))
+                          elems.Add(Elem.Node(name, ti.NamespaceNode))
+                      }
+
+                      assert(true);
+
+                      // If namespace which define matched_value_type open
+                      // add the type name to completion list.
+                      when (obj == null)
+                        match (env.LookupType([ti.Name], null, args.Length))
+                        {
+                          | Some => tryAddName(ti.Name)
+                          | _    =>
+                            // Add full name of matched_value_type to completion list.
+                            tryAddName (ti.NamespaceNode.GetDisplayName());
+                        }
+                      
+                      throw CompletionResult(elems, name.Id);
 
                   //| TypeDeclaration.VariantOption =>
                     | _ => System.Console.WriteLine(ty);
@@ -173,7 +197,8 @@
           Completion.AddTypesAndNamespaces (elems, nss, obj, name, true);
 
           throw CompletionResult (elems, name.Id);
-        | _ => ()
+
+        | _ => assert(true);
       }
     }
 

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/Class1.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/Class1.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Content/Class1.n	Fri Dec 15 12:48:53 2006
@@ -48,7 +48,6 @@
             | _ => ()
             //| TestVariant.B
           }
-          
         }
 
         public Method6() : void
@@ -152,6 +151,32 @@
 
         }
 
+        public Method21() : void
+        {
+          match (xxx)
+          {
+            | CValue/*Complete in match variant 4:-2*/(TestVariant1.Aaa) => WriteLine("CValue(TestVariant1.Aaa)");
+            | _ => ()
+            //| TestVariant.B
+          }
+        }
+
+        public Method22() : void
+        {
+          match (xxx)
+          {
+            | TestVari/*Complete in match variant 5:-0*/
+          }
+        }
+
+        public Method23() : void
+        {
+          match (xxx)
+          {
+            | TestVariant2.TestVari/*Complete in match variant 6:-0*/
+          }
+        }
+
         xxx : TestVariant2;
       }
     }

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n	Fri Dec 15 12:48:53 2006
@@ -16,6 +16,38 @@
   public partial class Test1
   {
     [Test]
+    public Complete_in_match_variant_6() : void
+    {
+      def file = FilePath1;
+      def (line, col) = ReadLocation(file, "Complete in match variant 6");
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+      Assert.IsNotNull(result, "result is null");
+      Assert.AreEqual(result.Length, 0);
+    }
+
+    [Test]
+    public Complete_in_match_variant_5() : void
+    {
+      def file = FilePath1;
+      def (line, col) = ReadLocation(file, "Complete in match variant 5");
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+      Assert.IsNotNull(result, "result is null");
+      Assert.AreEqual(result.Length, 1);
+      Assert.AreEqual(result[0].ToString(), "TestVariant2");
+    }
+
+    [Test]
+    public Complete_in_match_variant_4() : void
+    {
+      def file = FilePath1;
+      def (line, col) = ReadLocation(file, "Complete in match variant 4");
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+      Assert.IsNotNull(result, "result is null");
+      Assert.AreEqual(result.Length, 1);
+      Assert.AreEqual(result[0].ToString(), "CValue");
+    }
+
+    [Test]
     public Complete_2() : void
     {
       def file = FilePath1;



More information about the svn mailing list