[svn] r7224: vs-plugin/trunk: ConsoleTest/Program.cs Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/...

VladD2 svnadmin at nemerle.org
Sat Jan 6 06:57:55 CET 2007


Log:
Work on method return type completion.


Author: VladD2
Date: Sat Jan  6 06:57:51 2007
New Revision: 7224

Modified:
   vs-plugin/trunk/ConsoleTest/Program.cs
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
   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.Init.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.n
   vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n

Modified: vs-plugin/trunk/ConsoleTest/Program.cs
==============================================================================
--- vs-plugin/trunk/ConsoleTest/Program.cs	(original)
+++ vs-plugin/trunk/ConsoleTest/Program.cs	Sat Jan  6 06:57:51 2007
@@ -12,6 +12,10 @@
 			Test1 test = new Test1();
 			test.Init();
 
+			test.Complete_in_return_type_1();
+			test.Complete_in_return_type_2();
+			test.Complete_in_return_type_3();
+			test.Complete_in_return_type_4();
 			test.QuickTip_ForMacro();
 			test.Complete_in_match_variant_6();
 			test.Complete_in_match_variant_5();

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n	Sat Jan  6 06:57:51 2007
@@ -61,20 +61,23 @@
             def retLoc = header.ret_type.Location + method.BodyLocation.FromStart();
             if (retLoc.Contains(line, col))
             {
-              def code = source.GetRegion(retLoc);
-              Trace.WriteLine(code);
-              //header.ret_type.
-              array(0); // completion outside body (try conplete types)
+              def prefix = "_ : ";
+              def loc = Location(retLoc.FileIndex, retLoc.Line, retLoc.Column, line, col);
+              def typeName = source.GetRegion(loc);
+              def code = prefix + typeName;
+              def result = _engine.RunCompletionEngine(method, code, loc, line, col + prefix.Length);
+              if ("void".StartsWithIgnoreCace(typeName) || typeName.TrimEnd() == "")
+                MakeCompletionList(result).Append(CompletionElem(0, "void", "type System.Void", null));
+              else
+                MakeCompletionList(result)
             }
             else
-              array(0); // completion outside body (try conplete types)
+              _topKeywords; // completion outside body (try conplete types)
           }
           else
           {
-            //_topKeywords;
             Trace.WriteLine($"# Completion outside body");
             _topKeywords
-            //array(0); // completion outside body (try conplete types)
           }
         }
       }

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	Sat Jan  6 06:57:51 2007
@@ -147,6 +147,9 @@
           def name = name;
           def obj = obj;
           def elems = SCG.List ();
+          
+          elems.Add(Elem.Simple("_", "wildcard", 0));
+
           match (matched_value_type.Hint)
           {
             | Some(ty) =>
@@ -179,8 +182,6 @@
                             tryAddName (ti.NamespaceNode.GetDisplayName());
                         }
                       
-                      elems.Add(Elem.Simple("_", "wildcard", 0));
-                      
                       throw CompletionResult(elems, name.Id);
 
                   //| TypeDeclaration.VariantOption =>
@@ -196,8 +197,6 @@
             :: name.GetEnv(this.CoreEnv).OpenNamespaces;
           Completion.AddTypesAndNamespaces (elems, nss, obj, name, true);
 
-          elems.Add(Elem.Simple("_", "wildcard", 0));
-          
           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	Sat Jan  6 06:57:51 2007
@@ -14,6 +14,22 @@
     {
       class ClassInNestenNs
       {
+        public Method24() : /*Complete in return type 1:-0*/
+        {
+        }
+
+        public Method25() : voi/*Complete in return type 2:-0*/
+        {
+        }
+
+        public Method26() : int/*Complete in return type 3:-0*/
+        {
+        }
+
+        public Method27() : System.Int/*Complete in return type 4:-0*/
+        {
+        }
+
         public Method() : void
         {
           Sy/*Complete glabal ns:-0*/;

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Tests.Init.n	Sat Jan  6 06:57:51 2007
@@ -35,13 +35,13 @@
         _engine.Sources.AddOrUpdate(source, File.ReadAllText(source));
       }
 
-      addSource(FilePath3);
+      addSource(FilePath1);
       Assert.AreEqual(1, _engine.Sources.Count, "Expected Failure.");
 
-      addSource(FilePath2);
+      addSource(FilePath3);
       Assert.AreEqual(2, _engine.Sources.Count, "Expected Failure.");
 
-      addSource(FilePath1);
+      addSource(FilePath2);
       Assert.AreEqual(3, _engine.Sources.Count, "Expected Failure.");
 
       addSource(FileQuickTip);

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	Sat Jan  6 06:57:51 2007
@@ -16,6 +16,49 @@
   public partial class Test1
   {
     [Test]
+    public Complete_in_return_type_1() : void
+    {
+      def file = FilePath1;
+      def (line, col) = ReadLocation(file, "Complete in return type 1");
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+      Assert.IsNotNull(result, "result is null");
+      Assert.AreEqual(result[0].DisplayName, "Microsoft");
+    }
+
+    [Test]
+    public Complete_in_return_type_2() : void
+    {
+      def file = FilePath1;
+      def (line, col) = ReadLocation(file, "Complete in return type 2");
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+      Assert.IsNotNull(result, "result is null");
+      Assert.AreEqual(result.Length, 1);
+      Assert.AreEqual(result[0].DisplayName, "void");
+    }
+
+    [Test]
+    public Complete_in_return_type_3() : void
+    {
+      def file = FilePath1;
+      def (line, col) = ReadLocation(file, "Complete in return type 3");
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+      Assert.IsNotNull(result, "result is null");
+      Assert.AreEqual(result.Length, 1);
+      Assert.AreEqual(result[0].DisplayName, "int");
+    }
+
+    [Test]
+    public Complete_in_return_type_4() : void
+    {
+      def file = FilePath1;
+      def (line, col) = ReadLocation(file, "Complete in return type 4");
+      def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
+      Assert.IsNotNull(result, "result is null");
+      Assert.AreEqual(result.Length, 3);
+      Assert.AreEqual(result[0].DisplayName, "System.Int16");
+    }
+
+    [Test]
     public Complete_in_match_variant_6() : void
     {
       def file = FilePath1;
@@ -34,8 +77,8 @@
       def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.AreEqual(result.Length, 2);
-      Assert.AreEqual(result[0].ToString(), "TestVariant2");
-      Assert.AreEqual(result[1].ToString(), "_");
+      Assert.AreEqual(result[0].ToString(), "_");
+      Assert.AreEqual(result[1].ToString(), "TestVariant2");
     }
 
     [Test]
@@ -46,8 +89,8 @@
       def result = _project.CompleteWord(file, line, col, TestSourceTextManager(file));
       Assert.IsNotNull(result, "result is null");
       Assert.AreEqual(result.Length, 2);
-      Assert.AreEqual(result[0].ToString(), "CValue");
-      Assert.AreEqual(result[1].ToString(), "_");
+      Assert.AreEqual(result[0].ToString(), "_");
+      Assert.AreEqual(result[1].ToString(), "CValue");
     }
 
     [Test]

Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n	(original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Utils.n	Sat Jan  6 06:57:51 2007
@@ -18,6 +18,14 @@
   {
     InvariantCultureCompareInfo : CompareInfo = CultureInfo.InvariantCulture.CompareInfo;
 
+    public Append[T](mutable this source : array[T], value : T) : array[T]
+    {
+      def oldLen = source.Length;
+      Array.Resize(ref source, oldLen + 1);
+      source[oldLen] = value;
+      source
+    }
+
     // Returns whether the first location is strictly inside the second
     public StrictlyContains(this firstLocation : Location, secondLocation : Location) : bool
     {
@@ -67,12 +75,16 @@
         startIndex, CompareOptions.Ordinal);
     }
 
+    public StartsWithIgnoreCace(this source : string, value : string) : bool
+    {
+      InvariantCultureCompareInfo.IsPrefix(source, value, CompareOptions.IgnoreCase)
+    }
+
     public OrdinalStartsWith(this source : string, value : string) : bool
     {
       source.StartsWith(value, StringComparison.Ordinal)
     }
 
-
     public IsNullOrEmpty(this value : string) : bool
     {
       if (value == null) true else value.Length == 0



More information about the svn mailing list