2009-04-17 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Fri, 17 Apr 2009 23:20:07 +0000 (23:20 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 17 Apr 2009 23:20:07 +0000 (23:20 -0000)
* complete.cs: Include namespace resolution in simple names as
well as global types and types in the using scope in the
resolution.

* namespace.cs: Supporting infrastrcture to provide completions
based on the current using scope.

svn path=/trunk/mcs/; revision=132065

mcs/mcs/ChangeLog
mcs/mcs/README
mcs/mcs/complete.cs
mcs/mcs/eval.cs
mcs/mcs/namespace.cs
mcs/mcs/support.cs
mcs/tests/Makefile
mcs/tests/eval-test.cs

index f99288ef9c6d9f56c13232e1c7edb79eb3e81471..640d685be5b2e6a4e9ef2dda32867b87d6423023 100644 (file)
@@ -1,5 +1,12 @@
 2009-04-17  Miguel de Icaza  <miguel@novell.com>
 
+       * complete.cs: Include namespace resolution in simple names as
+       well as global types and types in the using scope in the
+       resolution. 
+
+       * namespace.cs: Supporting infrastrcture to provide completions
+       based on the current using scope. 
+
        * eval.cs: Introduce an entry point that allows for initialization
        to return a list of the files passed on the command line.
 
        * anonymous.cs (Compatible): If the exception thrown from the
        resolved expression is a CompletionResult exception let that one
        through instead of printing a diagnostic error in the try/catch. 
-       
+<      
 2009-03-22  Miguel de Icaza  <miguel@novell.com>
 
        * 
index a120c244db8f8414dcd00c6146030448160126ce..c55b6230af3209b220bf5249e66728c01c13344a 100644 (file)
@@ -4,12 +4,12 @@ Completion support
        Supported:
        
                a.<TAB>
+               a<TAB> for types and namespaces
                a.W<TAB>
                a<TAB> for local variables
 
        Unsupported:
        
-               a<TAB> for types and namespaces
                delegate { FOO.<TAB>
                using statement autocompletion
        
index 81be26ab8f3b8e86036912ae5e04d501788495cd..9ee16f9fd0da1afeb71f900d36594fd0f1e3c271 100644 (file)
@@ -50,11 +50,8 @@ namespace Mono.CSharp {
                        this.prefix = prefix;
                }
 
-               public override Expression DoResolve (EmitContext ec)
+               void AppendResults (ArrayList results, string prefix, IEnumerable names)
                {
-                       string [] names = Evaluator.GetVarNames ();
-
-                       ArrayList results = new ArrayList ();
                        foreach (string name in names){
                                if (!name.StartsWith (prefix))
                                        continue;
@@ -67,6 +64,17 @@ namespace Mono.CSharp {
                                else
                                        results.Add (name);
                        }
+
+               }
+               
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       ArrayList results = new ArrayList ();
+
+                       AppendResults (results, prefix, Evaluator.GetVarNames ());
+                       AppendResults (results, prefix, ec.TypeContainer.NamespaceEntry.CompletionGetTypesStartingWith (ec.TypeContainer, prefix));
+                       AppendResults (results, prefix, Evaluator.GetUsingList ());
+                       
                        throw new CompletionResult (prefix, (string []) results.ToArray (typeof (string)));
                }
 
index bab4244161c1ac5aadd305078b8e6c6267bf5942..453f00057ef1e94434211dc72bfb246a23e49440 100644 (file)
@@ -56,7 +56,7 @@ namespace Mono.CSharp {
                static Thread invoke_thread;
                
                static ArrayList using_alias_list = new ArrayList ();
-               static ArrayList using_list = new ArrayList ();
+               internal static ArrayList using_list = new ArrayList ();
                static Hashtable fields = new Hashtable ();
 
                static Type   interactive_base_class = typeof (InteractiveBase);
@@ -814,6 +814,14 @@ namespace Mono.CSharp {
                        }
                }
 
+               static internal ICollection GetUsingList ()
+               {
+                       ArrayList res = new ArrayList (using_list.Count);
+                       foreach (object ue in using_list)
+                               res.Add (ue.ToString ());
+                       return res;
+               }
+               
                static internal string [] GetVarNames ()
                {
                        lock (evaluator_lock){
index f8a118f8ebc202ec592edcaa432a7f8fcab4e026..78db8f556ed2c2de8c2c2432fcab922a54ef9f6c 100644 (file)
@@ -99,6 +99,30 @@ namespace Mono.CSharp {
                        return found_type;
                }
 
+               //
+               // Returns the types starting with the given prefix
+               //
+               public ICollection CompletionGetTypesStartingWith (string prefix)
+               {
+                       Hashtable result = null;
+                       
+                       foreach (Assembly a in referenced_assemblies){
+                               Type [] mtypes = a.GetTypes ();
+
+                               foreach (Type t in mtypes){
+                                       string f = t.FullName;
+
+                                       if (f.StartsWith (prefix) && (result == null || !result.Contains (f))){
+                                               if (result == null)
+                                                       result = new Hashtable ();
+
+                                               result [f] = f;
+                                       }
+                               }
+                       }
+                       return result == null ? result : result.Keys;
+               }
+               
                protected void Error_AmbiguousPredefinedType (Location loc, string name, Type type)
                {
                        Report.Warning (1685, 1, loc,
@@ -530,6 +554,38 @@ namespace Mono.CSharp {
                        return LookupType (name, loc);
                }
 
+               //
+               // Completes types with the given `prefix' and stores the results in `result'
+               //
+               public void CompletionGetTypesStartingWith (DeclSpace ds, string prefix, Hashtable result)
+               {
+                       int l = fullname.Length + 1;
+                       ICollection res = root.CompletionGetTypesStartingWith (fullname + "." + prefix);
+
+                       if (res == null)
+                               return;
+                       
+                       foreach (string match in res){
+                               string x = match.Substring (l);
+
+                               // Turn reflection nested classes foo+bar into foo.bar
+                               x = x.Replace ('+', '.');
+
+                               // Only get the first name element, no point in adding anything beyond the first dot.
+                               int p = x.IndexOf ('.');
+                               if (p != -1)
+                                       x = x.Substring (0, p);
+
+                               // Turn Foo`N into Foo<
+                               p = x.IndexOf ('`');
+                               if (p != -1)
+                                       x = x.Substring (0, p) + "<";
+
+                               if (!result.Contains (x))
+                                       result [x] = x;
+                       }
+               }
+
                public void RegisterExternalExtensionMethodClass (Type type)
                {
                        // Ignore, extension methods cannot be nested
@@ -1032,6 +1088,19 @@ namespace Mono.CSharp {
                        return resolved;
                }
 
+               public ICollection CompletionGetTypesStartingWith (DeclSpace ds, string prefix)
+               {
+                       Hashtable result = new Hashtable ();
+                       
+                       for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
+                               foreach (Namespace using_ns in GetUsingTable ()){
+                                       using_ns.CompletionGetTypesStartingWith (ds, prefix, result);
+                               }
+                       }
+
+                       return result.Keys;
+               }
+               
                static void Error_AmbiguousTypeReference (Location loc, string name, FullNamedExpression t1, FullNamedExpression t2)
                {
                        Report.SymbolRelatedToPreviousError (t1.Type);
index ddab0825bb63629611552db0078c9a0205757e1f..b31507195d77b7604c1adb14513bfdf3d6566d64 100644 (file)
@@ -438,8 +438,9 @@ namespace Mono.CSharp {
                        if (base_text == null)
                                throw new ArgumentNullException ("base_text");
                        this.base_text = base_text;
-                       
+
                        result = res;
+                       Array.Sort (result);
                }
 
                public string [] Result {
index 1504e37c595492bbc89a63bd734bb85b75ee9373..c8a7487243641ed5312432085428932273c9a633 100644 (file)
@@ -55,7 +55,7 @@ test-casts: boot-casts.out mcs-casts.out
 test-local: casts-boot.exe
 
 eval.exe: eval-tests.cs
-       
+
 ifeq (net_2_1, $(PROFILE))
 COMPILER_NAME = smcs
 TEST_PATTERN = '*test-*.cs'
index 6b75bb837aabe96444d84fbdd4a133a579ef53bf..f5be175e22d2debbba77c214b7af01d1b1229b80 100644 (file)
@@ -42,6 +42,24 @@ public class MyTest {
 
                Run ("LINQ-3", "var first_scope = new int [] {1,2,3};");
                Run ("LINQ-4", "var second_scope = from x in first_scope select x;");
+
+               string prefix = "";
+               string [] res = Evaluator.GetCompletions ("ConsoleK", out prefix);
+               if (res [0] != "ey" || res [1] != "eyInfo"){
+                       Console.WriteLine (res [0]);
+                       Console.WriteLine (res [1]);
+                       throw new Exception ("Expected two completions ConsoleKey and ConsoleKeyInfo");
+               }
+
+               res = Evaluator.GetCompletions ("Converte", out prefix);
+               if (res [0] != "r<"){
+                       throw new Exception ("Expected one completion for Conveter<");
+               }
+
+               res = Evaluator.GetCompletions ("Sys", out prefix);
+               if (res [0] != "tem"){
+                       throw new Exception ("Expected at least a conversion for System");
+               }
        }
        
 }
\ No newline at end of file