internal void InitProjectInfos(SVsServiceProvider provider, ABnfFactory factory) { if (factory == null) { return; } if (m_server != null) { return; } m_server = new ALanguageServer(); m_server.Start(factory); if (m_cookie != 0) { return; } if (m_solution != null) { return; } m_solution = provider.GetService(typeof(SVsSolution)) as IVsSolution; if (m_solution == null) { return; } m_dot_ext = factory.GetDotExt(); m_file_icon = factory.GetFileIcon(); // 读取所有工程 m_projects.Clear(); Guid rguidEnumOnlyThisType = new Guid(); IEnumHierarchies ppenum = null; m_solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref rguidEnumOnlyThisType, out ppenum); IVsHierarchy[] rgelt = new IVsHierarchy[1]; uint pceltFetched = 0; while (ppenum.Next(1, rgelt, out pceltFetched) == VSConstants.S_OK && pceltFetched == 1) { IVsSccProject2 sccProject2 = rgelt[0] as IVsSccProject2; if (sccProject2 != null) { string project_path = GetProjectPath(rgelt[0]); if (project_path != null) { if (m_server != null) { m_server.AddTask(() => m_server.AddProjectInfo(project_path)); } m_projects[rgelt[0]] = new UIProjectInfo(this, rgelt[0], project_path, m_dot_ext, m_file_icon); } } } // 监听工程变化 m_solution.AdviseSolutionEvents(this, out m_cookie); }
private void ProtoToEMsgTypes(ALanguageServer server, IWpfTextView text_view, UIViewItem view_item) { int offset = text_view.Caret.Position.BufferPosition.Position; string project_path = view_item.GetProjectPath(); string full_path = view_item.GetFullPath(); server.AddTask(() => AProtobufFactoryClass.inst.GotoEMsgTypes(server, project_path, full_path, offset)); }
public void Dispose() { if (m_server != null) { m_server.Stop(); m_server = null; } }
public override string FastGoto(ALanguageServer server, Dictionary <string, ProjectInfo> projects, string text) { // 按::切割 char[] sy = { ':', '.' }; string[] split = text.Split(sy); var temp_split = new List <string>(); foreach (var c in split) { if (c != "") { temp_split.Add(c); } } if (temp_split.Count == 0) { return(null); } var package = ""; string name = temp_split[temp_split.Count - 1]; temp_split.RemoveAt(temp_split.Count - 1); package = string.Join(".", temp_split); ABnfElement element = null; // 获取所有工程 foreach (var pair in projects) { if (GeneralOptions.Instance.ProjectTeam == ProjectTeamTypes.LW) { if (name.EndsWith("_struct")) { name = name.Substring(0, name.Length - "_struct".Length); } else if (name.EndsWith("_dirty")) { name = name.Substring(0, name.Length - "_dirty".Length); } } var project = pair.Value as AProtobufProjectInfo; if (project == null) { continue; } if (package == "") { element = project.FindElementInAllPackage(name); if (element != null) { break; } } else { element = project.FindElement(package, name); if (element != null) { break; } } } // 把package当做 enum枚举名,name当做枚举项名 if (element == null) { if (temp_split.Count == 1 || temp_split.Count == 2) { foreach (var pair in projects) { var project = pair.Value as AProtobufProjectInfo; if (project == null) { continue; } if (temp_split.Count == 1) { element = project.FindElementInAllPackage(temp_split[0]); if (element != null) { break; } } else if (temp_split.Count == 2) { element = project.FindElement(temp_split[0], temp_split[1]); if (element != null) { break; } } } } else if (GeneralOptions.Instance.ProjectTeam == ProjectTeamTypes.LW && temp_split.Count == 0) { if (name.EndsWith("_struct") || name.EndsWith("_dirty")) { var sub_name = name; if (sub_name.EndsWith("_struct")) { sub_name = sub_name.Substring(0, sub_name.Length - "_struct".Length); } else if (sub_name.EndsWith("_dirty")) { sub_name = sub_name.Substring(0, sub_name.Length - "_dirty".Length); } foreach (var pair in projects) { var project = pair.Value as AProtobufProjectInfo; if (project == null) { continue; } element = project.FindElementInAllPackage(sub_name); if (element != null) { break; } } } if (element == null) { foreach (var pair in projects) { var project = pair.Value as AProtobufProjectInfo; if (project == null) { continue; } element = project.FindElementInAllPackage(name); if (element != null) { break; } } } if (element == null) { foreach (var pair in projects) { var project = pair.Value as AProtobufProjectInfo; if (project == null) { continue; } element = project.FindElement("", "EMsgErrorCode"); if (element != null) { break; } } } } if (element is AProtobufEnumElement) { var body_dec = (element as AProtobufEnumElement).GetEnumBody(); if (body_dec != null) { foreach (var pair in body_dec.GetEnumVarList()) { if (pair.GetEnumVarName().GetElementText() == name) { element = pair.GetEnumVarName(); break; } } } } } if (element == null) { return("找不到在包(" + package + ")的协议或枚举(" + name + ")"); } if (element is AProtobufMessageElement) { element = (element as AProtobufMessageElement).GetMessageName(); } else if (element is AProtobufEnumElement) { element = (element as AProtobufEnumElement).GetEnumName(); } string full_path = element.GetFullPath(); int start = element.GetStart(); int length = element.GetLength(); Application.Current.Dispatcher.Invoke(() => { ALanguageUtility.OpenFile(m_open_document, m_adapters_factory , full_path, start, length); }); return(null); }
public void GotoEMsgTypes(ALanguageServer server, string project_path, string full_path, int offset) { var view_item = server.GetView(full_path); if (view_item == null) { return; } var project_info = server.GetProject(project_path) as AProtobufProjectInfo; if (project_info == null) { return; } var regex_element = view_item.GetException(offset) as AProtobufRegexElement; if (regex_element == null) { return; } var id_element = regex_element.GetParent() as AProtobufIdElement; if (id_element == null) { return; } var message_name_dec = id_element.GetParent() as AProtobufMessageNameElement; if (message_name_dec == null) { return; } var enum_info = project_info.FindEnumElementInfo("", "EMsgTypes"); if (enum_info == null) { return; } var enum_var_name = "_" + message_name_dec.GetElementText(); enum_info.name_map.TryGetValue(enum_var_name, out AProtobufEnumVarElement var_dec); if (var_dec == null) { full_path = enum_info.element.GetFullPath(); Application.Current.Dispatcher.Invoke(() => { ALanguageUtility.OpenFile(m_open_document, m_adapters_factory , full_path, 0, 0); }); return; } var name_dec = var_dec.GetEnumVarName(); if (name_dec == null) { return; } full_path = name_dec.GetFullPath(); int start = name_dec.GetStart(); int length = name_dec.GetLength(); Application.Current.Dispatcher.Invoke(() => { ALanguageUtility.OpenFile(m_open_document, m_adapters_factory , full_path, start, length); }); }
private void OtherToProto(ALanguageServer server, IWpfTextView text_view) { int offset = text_view.Caret.Position.BufferPosition.Position; int length = text_view.TextBuffer.CurrentSnapshot.Length; // 往前找 int start = offset; for (int i = offset - 1; i >= 0; --i) { var value = text_view.TextBuffer.CurrentSnapshot[i]; if (char.IsDigit(value)) { continue; } if (char.IsLetter(value)) { continue; } if (value == '_') { continue; } if (value == ':') { continue; } if (value == '.') { continue; } start = i + 1; break; } // 往后找 int end = offset; for (int i = offset; i < length; ++i) { var value = text_view.TextBuffer.CurrentSnapshot[i]; if (char.IsDigit(value)) { continue; } if (char.IsLetter(value)) { continue; } if (value == '_') { continue; } if (value == ':') { continue; } if (value == '.') { continue; } end = i; break; } // 获取文本 var text = text_view.TextBuffer.CurrentSnapshot.GetText(start, end - start); server.AddTask(() => server.FastGoto(text)); }
public virtual string FastGoto(ALanguageServer server, Dictionary <string, ProjectInfo> projects, string text) { return("FastGoto function is not implemented"); }
public virtual string FastGoto(ALanguageServer server, Dictionary <string, ProjectInfo> projects, string text) { return("没有实现FastGoto功能"); }