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>
*
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
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;
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)));
}
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);
}
}
+ 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){
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,
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
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);
if (base_text == null)
throw new ArgumentNullException ("base_text");
this.base_text = base_text;
-
+
result = res;
+ Array.Sort (result);
}
public string [] Result {
test-local: casts-boot.exe
eval.exe: eval-tests.cs
-
+
ifeq (net_2_1, $(PROFILE))
COMPILER_NAME = smcs
TEST_PATTERN = '*test-*.cs'
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