public override void MainThreadInit() { sEnumIcon = ALanguageUtility.ToImageSource(Properties.Resources.EnumIcon); sMessageIcon = ALanguageUtility.ToImageSource(Properties.Resources.MessageIcon); sPackageIcon = ALanguageUtility.ToImageSource(Properties.Resources.PackageIcon); sFolderIcon = ALanguageUtility.ToImageSource(Properties.Resources.FolderIcon); sFileIcon = ALanguageUtility.ToImageSource(Properties.Resources.FileIcon); // 初始化配置项 { var _ = GeneralOptions.Instance; } }
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)); }
public void Start(ABnfFactory factory) { m_factory = factory; if (m_factory == null) { return; } m_abnf = ALanguageUtility.CreateABnf(m_factory); if (m_abnf == null) { return; } StartThread(); }
public AProtobufMessageVarNameClassificationFormatDefinition() { DisplayName = "Protobuf-Extension message field name "; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 189; color.G = 183; color.B = 107; ForegroundColor = color; } else { ForegroundColor = Colors.Navy; } }
public ALittleScriptTextClassificationFormatDefinition() { DisplayName = "ALittleScript字符串"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 214; color.G = 157; color.B = 113; ForegroundColor = color; } else { ForegroundColor = Colors.DarkRed; } }
public ALittleScriptMethodNameClassificationFormatDefinition() { DisplayName = "ALittleScript方法名"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 255; color.G = 128; color.B = 0; ForegroundColor = color; } else { ForegroundColor = Colors.DarkRed; } }
public ALittleScriptCommentClassificationFormatDefinition() { DisplayName = "ALittleScript注释"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 87; color.G = 166; color.B = 74; ForegroundColor = color; } else { ForegroundColor = Colors.Green; } }
public ALittleScriptVarNameClassificationFormatDefinition() { DisplayName = "ALittleScript变量名"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 189; color.G = 183; color.B = 107; ForegroundColor = color; } else { ForegroundColor = Colors.Navy; } }
public ALittleScriptDefaultClassificationFormatDefinition() { DisplayName = "ALittleScript默认"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 180; color.G = 180; color.B = 180; ForegroundColor = color; } else { ForegroundColor = Colors.Black; } }
public ALittleScriptKeyWordClassificationFormatDefinition() { DisplayName = "ALittleScript关键字"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 86; color.G = 154; color.B = 214; ForegroundColor = color; } else { ForegroundColor = Colors.Blue; } }
public AProtobufNumberClassificationFormatDefinition() { DisplayName = "Protobuf-Extension number"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 181; color.G = 206; color.B = 168; ForegroundColor = color; } else { ForegroundColor = Colors.Black; } }
public AProtobufTextClassificationFormatDefinition() { DisplayName = "Protobuf-Extension text"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 214; color.G = 157; color.B = 113; ForegroundColor = color; } else { ForegroundColor = Colors.DarkRed; } }
public AProtobufEnumVarNameClassificationFormatDefinition() { DisplayName = "Protobuf-Extension enumeration field name "; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 185; color.G = 119; color.B = 30; ForegroundColor = color; } else { ForegroundColor = Colors.DarkSlateGray; } }
public AProtobufKeyWordClassificationFormatDefinition() { DisplayName = "Protobuf-Extension keyword "; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 86; color.G = 154; color.B = 214; ForegroundColor = color; } else { ForegroundColor = Colors.Blue; } }
public AProtobufCommentClassificationFormatDefinition() { DisplayName = "Protobuf-Extension comments"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 87; color.G = 166; color.B = 74; ForegroundColor = color; } else { ForegroundColor = Colors.Green; } }
// 检查文件路径是否发生变化 public void CheckFullPath() { string new_full_path = ALanguageUtility.GetFilePath(m_view); if (new_full_path == m_full_path) { return; } string old_full_path = m_full_path; m_full_path = new_full_path; if (m_view.Properties.TryGetProperty(nameof(ALanguageServer), out ALanguageServer server)) { server.AddTask(() => server.ChangeViewPath(old_full_path, new_full_path)); } }
/// <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 void Start() { sClassIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptClassIcon); sTemplateIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptTemplateIcon); sNamespaceIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptNamespaceIcon); sStructIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptStructIcon); sEnumIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptEnumIcon); sInstanceIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptInstanceIcon); sStaticMethodIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptStaticIcon); sGlobalMethodIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptStaticIcon); sMemberMethodIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptMethodIcon); sFieldMethodIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptFieldIcon); sParamIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptParamIcon); sVariableIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptVariableIcon); sPropertyIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptPropertyIcon); sLanguageIcon = ALanguageUtility.ToImageSource(Properties.Resources.ALittleScriptNamespaceIcon); sFileIcon = Properties.Resources.ALittleScriptFieldIcon; }
public ALittleScriptGotoDefinitionClassificationFormatDefinition() { this.DisplayName = "ALittleScriptGotoDefinition"; this.TextDecorations = System.Windows.TextDecorations.Underline; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 86; color.G = 154; color.B = 214; ForegroundColor = color; } else { this.ForegroundColor = Colors.Blue; } }
public ALittleScriptCustomNameClassificationFormatDefinition() { DisplayName = "ALittleScript类型名"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 255; color.G = 215; color.B = 0; ForegroundColor = color; } else { var color = new Color(); color.A = 255; color.R = 33; color.G = 111; color.B = 133; ForegroundColor = color; } }
public ALittleScriptCtrlKeyWordClassificationFormatDefinition() { DisplayName = "ALittleScript控制关键字"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 216; color.G = 160; color.B = 223; ForegroundColor = color; } else { var color = new Color(); color.A = 255; color.R = 143; color.G = 8; color.B = 196; ForegroundColor = color; } }
public ALittleScriptDefineNameClassificationFormatDefinition() { DisplayName = "ALittleScript定义名"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 78; color.G = 201; color.B = 176; ForegroundColor = color; } else { var color = new Color(); color.A = 255; color.R = 43; color.G = 145; color.B = 175; ForegroundColor = color; } }
public AProtobufCustomNameClassificationFormatDefinition() { DisplayName = "Protobuf-Extension message & enumeration name"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 78; color.G = 201; color.B = 176; ForegroundColor = color; } else { var color = new Color(); color.A = 0xFF; color.R = 0x21; color.G = 0x6F; color.B = 0x85; ForegroundColor = color; } }
public ALittleScriptHighlightWordFormatDefinition() { DisplayName = "ALittleScript高亮"; if (ALanguageUtility.IsDarkTheme()) { var color = new Color(); color.A = 255; color.R = 14; color.G = 69; color.B = 131; BackgroundColor = color; color = new Color(); color.A = 255; color.R = 173; color.G = 192; color.B = 211; ForegroundColor = color; } else { BackgroundColor = Colors.LightBlue; } }
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); }); }
public void Refresh(long version, List <ALanguageReferenceInfo> info_list) { // 获取版本号 if (!m_view.Properties.TryGetProperty("version", out long id)) { return; } if (version != id) { return; } if (m_view.TextSnapshot.Length == 0) { return; } var wpf_view = m_view as IWpfTextView; if (wpf_view == null) { return; } var list = new List <IntraTextAdornmentTag>(); foreach (var pair in m_reference_map) { list.Add(pair.Value.Tag); } m_reference_map.Clear(); foreach (var info in info_list) { if (m_reference_map.ContainsKey(info.line)) { continue; } int e_end = info.start; if (e_end >= m_view.TextSnapshot.Length) { e_end = m_view.TextSnapshot.Length - 1; } var span = new SnapshotSpan(m_view.TextSnapshot, e_end, 0); IntraTextAdornmentTag tag; if (list.Count > 0) { tag = list[list.Count - 1]; list.RemoveAt(list.Count - 1); var cc = tag.Adornment as Canvas; if (cc != null && cc.Children.Count > 0) { var ui = cc.Children[0] as TextBlock; if (ui != null) { ui.Text = "[" + info.count + "个引用]"; } } } else { var cc = new Canvas(); var ui = new TextBlock(); var brush = new SolidColorBrush(); var color = new System.Windows.Media.Color(); if (ALanguageUtility.IsDarkTheme()) { color.A = 255; color.R = 181; color.G = 206; color.B = 168; } else { color.A = 255; color.R = 128; color.G = 128; color.B = 128; } brush.Color = color; ui.Foreground = brush; var font_size = ui.FontSize; ui.FontSize -= 2; ui.Text = "[" + info.count + "个引用]"; ui.Foreground.Freeze(); (cc as IAddChild).AddChild(ui); Canvas.SetTop(ui, -m_view.LineHeight); tag = new IntraTextAdornmentTag(cc, null, m_view.LineHeight, font_size, 0, 0, PositionAffinity.Successor); } var tag_span = new TagSpan <IntraTextAdornmentTag>(span, tag); m_reference_map.Add(info.line, tag_span); } { var span = new SnapshotSpan(m_view.TextSnapshot, 0, m_view.TextSnapshot.Length); TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span)); } }
public void VsTextViewCreated(IVsTextView text_view) { if (ALanguageUtility.s_service_provider == null) { ALanguageUtility.s_service_provider = m_service_provider; } if (m_factory == null) { return; } SaveAdapterFactory(); m_factory.Init(m_service_provider, m_adapters_factory); // 获取系统单例,用于打开文件 if (m_open_document == null) { m_open_document = m_service_provider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument; } // 获取视窗 IWpfTextView view = m_adapters_factory.GetWpfTextView(text_view); if (view == null) { return; } // 添加关闭监听 view.Closed += OnViewClosed; // 创建ABnf if (m_abnf == null) { m_abnf = ALanguageUtility.CreateABnf(m_factory); } if (m_abnf == null) { return; } if (m_abnf_ui == null) { m_abnf_ui = ALanguageUtility.CreateABnf(m_factory); } if (m_abnf_ui == null) { return; } // 获取高亮tag if (m_highlight_tag == null) { m_highlight_tag = m_factory.CreateTextMarkerTag(); } if (m_highlight_tag != null) { view.Properties.AddProperty(nameof(TextMarkerTag), m_highlight_tag); } // 获取全路径 string full_path = ALanguageUtility.GetFilePath(view); if (full_path == null) { return; } var solution = m_factory.GetSolution(); if (solution == null) { return; } var server = solution.GetServer(); if (server != null) { view.Properties.AddProperty(nameof(ALanguageServer), server); view.TextBuffer.Properties.AddProperty(nameof(ALanguageServer), server); } view.Properties.AddProperty(nameof(IVsTextView), text_view); // 获取所在的工程 m_open_document.IsDocumentInAProject(full_path, out IVsUIHierarchy project, out uint item_id, out Microsoft.VisualStudio.OLE.Interop.IServiceProvider _ppSP, out int _pDocInProj); UIProjectInfo project_info = null; if (project != null) { solution.GetProjects().TryGetValue(project, out project_info); } // 创建信息,并作为属性给view var info = new UIViewItem(m_abnf, m_abnf_ui, view, m_service_provider, m_adapters_factory, project_info, item_id, full_path, m_factory, m_factory.GetLineCommentBegin()); view.Properties.AddProperty(nameof(UIViewItem), info); view.TextBuffer.Properties.AddProperty(nameof(UIViewItem), info); // 提前添加各种source { if (!view.TextBuffer.Properties.TryGetProperty(nameof(ALanguageCompletionSource), out ALanguageCompletionSource source)) { source = new ALanguageCompletionSource(view.TextBuffer); view.TextBuffer.Properties.AddProperty(nameof(ALanguageCompletionSource), source); } } { if (!view.TextBuffer.Properties.TryGetProperty(nameof(ALanguageQuickInfoSource), out ALanguageQuickInfoSource source)) { source = new ALanguageQuickInfoSource(view.TextBuffer); view.TextBuffer.Properties.AddProperty(nameof(ALanguageQuickInfoSource), source); } } { if (!view.TextBuffer.Properties.TryGetProperty(nameof(ALanguageSignatureHelpSource), out ALanguageSignatureHelpSource source)) { source = new ALanguageSignatureHelpSource(view.TextBuffer); view.TextBuffer.Properties.AddProperty(nameof(ALanguageSignatureHelpSource), source); } } { if (!view.Properties.TryGetProperty(nameof(ALanguageErrorTagger), out ALanguageErrorTagger tagger)) { tagger = new ALanguageErrorTagger(view); view.Properties.AddProperty(nameof(ALanguageErrorTagger), tagger); } } { if (!view.Properties.TryGetProperty(nameof(ALanguageReferenceTagger), out ALanguageReferenceTagger tagger)) { tagger = new ALanguageReferenceTagger(view); view.Properties.AddProperty(nameof(ALanguageReferenceTagger), tagger); } } { if (!view.Properties.TryGetProperty(nameof(ALanguageHighlightWordTagger), out ALanguageHighlightWordTagger tagger)) { tagger = new ALanguageHighlightWordTagger(view); view.Properties.AddProperty(nameof(ALanguageHighlightWordTagger), tagger); } } // 添加命令 { ALanguageGotoDefinitionCommand filter = new ALanguageGotoDefinitionCommand(view); text_view.AddCommandFilter(filter, out IOleCommandTarget next); filter.Next = next; view.Properties.AddProperty(nameof(ALanguageGotoDefinitionCommand) + "Target", next); } { ALanguageCompletionCommand filter = new ALanguageCompletionCommand(view, m_completion_broker); text_view.AddCommandFilter(filter, out IOleCommandTarget next); filter.Next = next; view.Properties.AddProperty(nameof(ALanguageCompletionCommand) + "Target", next); view.Properties.AddProperty(nameof(ALanguageCompletionCommand), filter); } }
// 注解和解注解 public bool Comment(ITextView view, bool comment) { return(ALanguageUtility.Comment(view, m_line_comment_begin, comment)); }