public string GetPackage() { AProtobufFile file = m_file as AProtobufFile; if (file == null) { return(""); } return(file.GetPackage()); }
public override bool QueryCompletion(int offset, List <ALanguageCompletionInfo> list) { var project = m_element.GetFile().GetProjectInfo() as AProtobufProjectInfo; if (project == null) { list.Add(new ALanguageCompletionInfo("将当前文件放入工程,会全工程范围提示", null)); return(true); } AProtobufFile file = m_element.GetFile() as AProtobufFile; var analysis_text = m_element.GetElementText(); var length = offset + 1 - m_element.GetStart(); analysis_text = analysis_text.Substring(0, length); var split_text = analysis_text.Split('.'); var id_child_list = new List <string>(); foreach (var v in split_text) { id_child_list.Add(v); } var input = ""; string package = ""; if (id_child_list.Count > 0) { input = id_child_list[id_child_list.Count - 1]; id_child_list.RemoveAt(id_child_list.Count - 1); List <string> name_list = new List <string>(); foreach (var id_child in id_child_list) { name_list.Add(id_child); } package = string.Join(".", name_list); } var input_package = package; if (package == "") { package = file.GetPackage(); } List <string> match_name_list = null; var message_set = new HashSet <string>(); var enum_set = new HashSet <string>(); // If the parent node is MessageOption if (m_element.GetParent() is AProtobufMessageOptionElement) { match_name_list = project.MatchExtendList(package, input); foreach (var name_value in match_name_list) { list.Add(new ALanguageCompletionInfo(name_value, null)); } if (input_package.Length == 0) { match_name_list = project.MatchExtendList("", input); foreach (var name_value in match_name_list) { list.Add(new ALanguageCompletionInfo(name_value, null)); } } } else { match_name_list = project.MatchMessageList(package, input); foreach (var name_value in match_name_list) { if (message_set.Contains(name_value)) { continue; } message_set.Add(name_value); list.Add(new ALanguageCompletionInfo(name_value, AProtobufFactoryClass.inst.sMessageIcon)); } if (input_package.Length == 0) { match_name_list = project.MatchMessageList(input, ""); foreach (var name_value in match_name_list) { if (message_set.Contains(name_value)) { continue; } message_set.Add(name_value); list.Add(new ALanguageCompletionInfo(name_value, AProtobufFactoryClass.inst.sMessageIcon)); } match_name_list = project.MatchMessageList("", input); foreach (var name_value in match_name_list) { if (message_set.Contains(name_value)) { continue; } message_set.Add(name_value); list.Add(new ALanguageCompletionInfo(name_value, AProtobufFactoryClass.inst.sMessageIcon)); } } match_name_list = project.MatchEnumList(package, input); foreach (var name_value in match_name_list) { if (enum_set.Contains(name_value)) { continue; } enum_set.Add(name_value); list.Add(new ALanguageCompletionInfo(name_value, AProtobufFactoryClass.inst.sEnumIcon)); } if (input_package.Length == 0) { match_name_list = project.MatchEnumList("", input); foreach (var name_value in match_name_list) { if (enum_set.Contains(name_value)) { continue; } enum_set.Add(name_value); list.Add(new ALanguageCompletionInfo(name_value, AProtobufFactoryClass.inst.sEnumIcon)); } } } // Find the package name according to the current input var package_list = project.MatchPackageList(analysis_text.Trim()); foreach (var name in package_list) { if (input_package.Length > 0) { var new_name = name.Substring(input_package.Length); if (new_name.Length > 0 && new_name[0] == '.') { new_name = new_name.Substring(1); } list.Add(new ALanguageCompletionInfo(new_name, AProtobufFactoryClass.inst.sPackageIcon)); } else { list.Add(new ALanguageCompletionInfo(name, AProtobufFactoryClass.inst.sPackageIcon)); } } return(true); }