public bool JumpToView(string full_path, int start, int length) { if (m_open_document == null) { m_open_document = m_provider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; } if (m_open_document == null) { return(false); } return(ALanguageUtility.OpenFile(m_open_document, m_adapters_factory, full_path, start, length)); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); // 向当前文件窗口发送一个格式化命令 if (m_text_manager == null) { return; } m_text_manager.GetActiveView(1, null, out IVsTextView view); if (view == null) { return; } if (m_adapters_factory == null) { return; } var text_view = m_adapters_factory.GetWpfTextView(view); if (text_view == null) { return; } if (!text_view.Properties.TryGetProperty(nameof(UIViewItem), out UIViewItem info)) { return; } string ext = "lua"; if (GeneralOptions.Instance.TargetLanguage == TargetLanguages.JavaScript) { ext = "js"; } string full_path = ALittleScriptUtility.CalcTargetFullPath(info.GetProjectPath(), info.GetFullPath(), ext, out _); if (full_path == null) { return; } ALanguageUtility.OpenFile(null, ALittleScriptVsTextViewCreationListener.s_adapters_factory, full_path, 0, 0); }
public override bool CompileProject() { var project_info = GetProjectInfo(); if (project_info == null) { MessageBox.Show("请将当前文件加入到工程后再进行编译"); return(true); } var target_path = ALittleScriptUtility.CalcRootFullPath(project_info.GetProjectPath(), "lua"); if (GeneralOptions.Instance.TargetLanguage == TargetLanguages.JavaScript) { target_path = ALittleScriptUtility.CalcRootFullPath(project_info.GetProjectPath(), "js"); } try { ALittleScriptUtility.DeleteDirectory(new DirectoryInfo(target_path)); } catch (Exception e) { MessageBox.Show(e.Message); return(true); } var all_file = project_info.GetAllFile(); try { foreach (var pair in all_file) { var generator = ALittleScriptTranslation.CreateTranslation(); var error = generator.Generate(pair.Value.GetFile(), true); if (error == null) { continue; } string full_path = pair.Value.GetFullPath(); if (error.GetElement() != null) { full_path = error.GetElement().GetFullPath(); } var result = MessageBox.Show(full_path + "\n" + error.GetError() + "\n是否打开错误文件?", "生成失败", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { int start = 0; int length = 0; if (error.GetElement() != null) { start = error.GetElement().GetStart(); length = error.GetElement().GetLength(); if (length <= 0) { length = 1; } } try { Application.Current.Dispatcher.Invoke(() => { ALanguageUtility.OpenFile(null, ALittleScriptVsTextViewCreationListener.s_adapters_factory, full_path, start, length); }); } catch (System.Exception) { } } return(true); } } catch (System.Exception e) { MessageBox.Show(e.Message); return(true); } MessageBox.Show("生成完毕"); return(true); }
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); }); }