public ResolveExpr(ITargetDatabase db, CsGlobalNamespace globals, ResolveName nameResolver) { m_globals = globals; m_nameResolver = nameResolver; m_typeResolver = new ResolveType(db); m_memberResolver = new ResolveMembers(db); }
// This is a bit overkill if all we want to do is identify the name, but we also // need this info to do expression completion. private Variable[] DoGetVariables(string text, ICsLocalsParser locals) { var vars = new List<Variable>(); if (m_member != null) { // this if (m_member.DeclaringType != null) if ((m_member.Modifiers & MemberModifiers.Static) == 0) vars.Add(new Variable(m_member.DeclaringType.FullName, "this", null, "Locals")); // value CsProperty prop = m_member as CsProperty; if (prop != null && prop.SetterBody != null) { if (prop.SetterBody.First < m_offset && m_offset <= prop.SetterBody.Last) vars.Add(new Variable(prop.ReturnType, "value", null, "Locals")); } CsIndexer indexer = m_member as CsIndexer; if (indexer != null && indexer.SetterBody != null) { if (indexer.SetterBody.First < m_offset && m_offset <= indexer.SetterBody.Last) vars.Add(new Variable(indexer.ReturnType, "value", null, "Locals")); } } // locals CsBody body = DoGetBody(); if (body != null) { Local[] candidates = locals.Parse(text, body.Start, m_offset); for (int i = candidates.Length - 1; i >= 0; --i) { if (!vars.Exists(v => v.Name == candidates[i].Name)) vars.Add(new Variable(candidates[i].Type, candidates[i].Name, candidates[i].Value, "Locals")); } } // args CsParameter[] parms = DoGetParameters(); if (parms != null) { foreach (CsParameter p in parms) { if (!vars.Exists(v => v.Name == p.Name)) vars.Add(new Variable(p.Type, p.Name, null, "Arguments")); } } // Fields and properties (note that we have to include these here so that the common // case of a property named after a type resolves to the property instead of the type) if (m_member != null && m_member.DeclaringType != null) { ResolvedTarget target = m_typeResolver.Resolve(m_member.DeclaringType.FullName, m_context, m_globals, true, true); if (target != null) { var resolveMembers = new ResolveMembers(m_database); Item[] items = resolveMembers.Resolve(m_context, target, m_globals); foreach (Item item in items) { if (!(item is MethodItem)) if (!vars.Exists(v => v.Name == item.Text)) vars.Add(new Variable(item.Type, item.Text, null, item.Type)); } } } if (Log.IsEnabled(TraceLevel.Verbose, "AutoComplete")) { Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "Variables:"); foreach (Variable v in vars) { Log.WriteLine(TraceLevel.Verbose, "AutoComplete", " {0} {1}", v.Type, v.Name); } } return vars.ToArray(); }
public void OnPathChanged() { Boss boss = ObjectModel.Create("DirectoryEditorPlugin"); var find = boss.Get<IFindDirectoryEditor>(); boss = find.GetDirectoryEditor(m_boss); if (boss != null) { var editor = boss.Get<IDirectoryEditor>(); if (editor.Path != null) { string name = System.IO.Path.GetFileName(editor.Path); string path = Paths.GetAssemblyDatabase(name); // TODO: this doesn't help for simple queries, but maybe it would // for more complex queries (e.g. chained method calls) // database.Update("cache size", () => // { // database.Update("PRAGMA cache_size = 4000"); // }); m_database = new TargetDatabase(new Database(path, "AutoComplete-" + name)); m_members = new ResolveMembers(m_database); } } }