protected AutocompleteInfo[] FromPythonType(AutocompleteInput input) { List<AutocompleteInfo> ret = new List<AutocompleteInfo>(); string dirCommand = "dir(" + input.name + ")"; object value = engine.CreateScriptSourceFromString(dirCommand, SourceCodeKind.Expression).Execute(this.scope); foreach (object member in (value as IronPython.Runtime.List)) { string member_str = (string)member; if (input.have_filter && !member_str.StartsWith (input.filter)) continue; AutocompleteInfo temp = new AutocompleteInfo(); temp.name = input.name; temp.stub = member_str; temp.complete = member_str.Substring (input.filter.Length); ret.Add(temp); } if (ret.Count != 0 && ret.Count != 1) { string common_starter = this.GetCommonStarter (ret.ToArray ()); AutocompleteInfo temp = ret [0]; temp.common_starter = common_starter; temp.common_starter_complete = common_starter.Substring (input.filter.Length); ret [0] = temp; } return ret.ToArray(); }
protected string GetCommonStarter(AutocompleteInfo[] infos) { if (infos.Length == 0) return string.Empty; if (infos.Length == 1) return infos [0].complete; string ret = string.Empty; for (int i = 0; i < infos[0].stub.Length; i++) { char c = infos [0].stub [i]; bool failed = false; foreach (AutocompleteInfo aci in infos) { if (aci.stub.Length <= i) failed = true; if (aci.stub [i] != c) failed = true; } if (failed) break; ret += c; } return ret; }
protected AutocompleteInfo[] FromCLRType(Type type, AutocompleteInput input) { List<AutocompleteInfo> ret = new List<AutocompleteInfo>(); List<string> completionsList = new List<string> (); MethodInfo[] methodInfo = type.GetMethods (); PropertyInfo[] propertyInfo = type.GetProperties (); FieldInfo[] fieldInfo = type.GetFields (); foreach (MethodInfo methodInfoItem in methodInfo) { if ((methodInfoItem.IsPublic) && (methodInfoItem.Name.IndexOf ("get_") != 0) && (methodInfoItem.Name.IndexOf ("set_") != 0) && (methodInfoItem.Name.IndexOf ("add_") != 0) && (methodInfoItem.Name.IndexOf ("remove_") != 0) && (methodInfoItem.Name.IndexOf ("__") != 0)) completionsList.Add (methodInfoItem.Name); } foreach (PropertyInfo propertyInfoItem in propertyInfo) { completionsList.Add (propertyInfoItem.Name); } foreach (FieldInfo fieldInfoItem in fieldInfo) { completionsList.Add (fieldInfoItem.Name); } completionsList.Sort (); string last = ""; for (int i = completionsList.Count - 1; i > 0; --i) { if (completionsList [i] == last) completionsList.RemoveAt (i); else last = completionsList [i]; } foreach (string completion in completionsList) { if (input.have_filter && !completion.StartsWith (input.filter)) continue; AutocompleteInfo temp = new AutocompleteInfo(); temp.name = input.name; temp.stub = completion; temp.complete = completion.Substring (input.filter.Length); ret.Add (temp); } if (ret.Count != 0 && ret.Count != 1) { string common_starter = this.GetCommonStarter (ret.ToArray ()); AutocompleteInfo temp = ret [0]; temp.common_starter = common_starter; temp.common_starter_complete = common_starter.Substring (input.filter.Length); ret [0] = temp; } return ret.ToArray (); }