private void Handle(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; DateTime time1 = DateTime.Now; ITextSnapshot snapshot = this._sourceBuffer.CurrentSnapshot; var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot); if (triggerPoint == null) { AsmDudeToolsStatic.Output_WARNING("AsmQuickInfoSource:AugmentQuickInfoSession: trigger point is null"); return; } Brush foreground = AsmDudeToolsStatic.Get_Font_Color(); var enumerator = this._aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)).GetEnumerator(); if (enumerator.MoveNext()) { var asmTokenTag = enumerator.Current; var enumerator2 = asmTokenTag.Span.GetSpans(this._sourceBuffer).GetEnumerator(); if (enumerator2.MoveNext()) { SnapshotSpan tagSpan = enumerator2.Current; string keyword = tagSpan.GetText(); string keywordUpper = keyword.ToUpper(); #region Tests // TODO: multiple tags at the provided triggerPoint is most likely the result of a bug in AsmTokenTagger, but it seems harmless... if (false) { if (enumerator.MoveNext()) { var asmTokenTagX = enumerator.Current; var enumeratorX = asmTokenTagX.Span.GetSpans(this._sourceBuffer).GetEnumerator(); enumeratorX.MoveNext(); AsmDudeToolsStatic.Output_WARNING(string.Format("{0}:AugmentQuickInfoSession. current keyword " + keyword + ": but span has more than one tag! next tag=\"{1}\"", ToString(), enumeratorX.Current.GetText())); } } #endregion //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: keyword=\""+ keyword + "\"; type=" + asmTokenTag.Tag.type +"; file="+AsmDudeToolsStatic.GetFileName(session.TextView.TextBuffer)); applicableToSpan = snapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeInclusive); TextBlock description = null; AsmTokenType type = asmTokenTag.Tag.Type; switch (type) { case AsmTokenType.Misc: { description = new TextBlock(); description.Inlines.Add(Make_Run1("Keyword ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Misc)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.Directive: { description = new TextBlock(); description.Inlines.Add(Make_Run1("Directive ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Directive)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.Register: { int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan); if (keywordUpper.StartsWith("%")) { keywordUpper = keywordUpper.Substring(1); // remove the preceding % in AT&T syntax } Rn reg = RegisterTools.ParseRn(keywordUpper, true); if (this._asmDudeTools.RegisterSwitchedOn(reg)) { var registerTooltipWindow = new RegisterTooltipWindow(foreground); registerTooltipWindow.SetDescription(reg, this._asmDudeTools); registerTooltipWindow.SetAsmSim(this._asmSimulator, reg, lineNumber, true); quickInfoContent.Add(registerTooltipWindow); } break; } case AsmTokenType.Mnemonic: case AsmTokenType.Jump: { int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan); Mnemonic mnemonic = AsmSourceTools.ParseMnemonic_Att(keywordUpper, true); if (this._asmDudeTools.MnemonicSwitchedOn(mnemonic)) { var instructionTooltipWindow = new InstructionTooltipWindow(foreground) { Session = session // set the owner of this windows such that we can manually close this window }; instructionTooltipWindow.SetDescription(mnemonic, this._asmDudeTools); instructionTooltipWindow.SetPerformanceInfo(mnemonic, this._asmDudeTools, false); instructionTooltipWindow.SetAsmSim(this._asmSimulator, lineNumber, true); quickInfoContent.Add(instructionTooltipWindow); } break; } case AsmTokenType.Label: { string label = keyword; string labelPrefix = asmTokenTag.Tag.Misc; string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(labelPrefix, label, AsmDudeToolsStatic.Used_Assembler); description = new TextBlock(); description.Inlines.Add(Make_Run1("Label ", foreground)); description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label)))); string descr = Get_Label_Description(full_Qualified_Label); if (descr.Length == 0) { descr = Get_Label_Description(label); } if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.LabelDef: { string label = keyword; string extra_Tag_Info = asmTokenTag.Tag.Misc; string full_Qualified_Label; if ((extra_Tag_Info != null) && extra_Tag_Info.Equals(AsmTokenTag.MISC_KEYWORD_PROTO)) { full_Qualified_Label = label; } else { full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(extra_Tag_Info, label, AsmDudeToolsStatic.Used_Assembler); } AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: found label def " + full_Qualified_Label); description = new TextBlock(); description.Inlines.Add(Make_Run1("Label ", foreground)); description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label)))); string descr = Get_Label_Def_Description(full_Qualified_Label, label); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.Constant: { description = new TextBlock(); description.Inlines.Add(Make_Run1("Constant ", foreground)); var(Valid, Value, NBits) = AsmSourceTools.Evaluate_Constant(keyword); string constantStr = (Valid) ? Value + "d = " + Value.ToString("X") + "h = " + AsmSourceTools.ToStringBin(Value, NBits) + "b" : keyword; description.Inlines.Add(Make_Run2(constantStr, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Constant)))); break; } case AsmTokenType.UserDefined1: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 1: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined1)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.UserDefined2: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 2: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined2)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.UserDefined3: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 3: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined3)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } default: //description = new TextBlock(); //description.Inlines.Add(makeRun1("Unused tagType " + asmTokenTag.Tag.type)); break; } if (description != null) { description.FontSize = AsmDudeToolsStatic.Get_Font_Size() + 2; description.FontFamily = AsmDudeToolsStatic.Get_Font_Type(); //AsmDudeToolsStatic.Output_INFO(string.Format("{0}:AugmentQuickInfoSession; setting description fontSize={1}; fontFamily={2}", this.ToString(), description.FontSize, description.FontFamily)); quickInfoContent.Add(description); } } } //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: applicableToSpan=\"" + applicableToSpan + "\"; quickInfoContent,Count=" + quickInfoContent.Count); AsmDudeToolsStatic.Print_Speed_Warning(time1, "QuickInfo"); }
private void Handle(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; DateTime time1 = DateTime.Now; ITextSnapshot snapshot = this.textBuffer_.CurrentSnapshot; SnapshotPoint?triggerPoint = session.GetTriggerPoint(snapshot); if (!triggerPoint.HasValue) { AsmDudeToolsStatic.Output_WARNING(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:Handle: trigger point is null", this.ToString())); return; } Brush foreground = AsmDudeToolsStatic.GetFontColor(); (AsmTokenTag tag, SnapshotSpan? keywordSpan) = AsmDudeToolsStatic.GetAsmTokenTag(this.aggregator_, triggerPoint.Value); if (keywordSpan.HasValue) { SnapshotSpan tagSpan = keywordSpan.Value; string keyword = tagSpan.GetText(); string keyword_upcase = keyword.ToUpperInvariant(); AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:Handle: keyword=\"{1}\"; type={2}; file=\"{3}\"", this.ToString(), keyword, tag.Type, AsmDudeToolsStatic.GetFilename(session.TextView.TextBuffer))); applicableToSpan = snapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeInclusive); TextBlock description = null; switch (tag.Type) { case AsmTokenType.Misc: { description = new TextBlock(); description.Inlines.Add(Make_Run1("Keyword ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Misc)))); string descr = this.asmDudeTools_.Get_Description(keyword_upcase); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips)) { Foreground = foreground, }); } break; } case AsmTokenType.Directive: { description = new TextBlock(); description.Inlines.Add(Make_Run1("Directive ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Directive)))); string descr = this.asmDudeTools_.Get_Description(keyword_upcase); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips)) { Foreground = foreground, }); } break; } case AsmTokenType.Register: { int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan); if (keyword_upcase.StartsWith("%", StringComparison.Ordinal)) { keyword_upcase = keyword_upcase.Substring(1); // remove the preceding % in AT&T syntax } Rn reg = RegisterTools.ParseRn(keyword_upcase, true); if (this.asmDudeTools_.RegisterSwitchedOn(reg)) { RegisterTooltipWindow registerTooltipWindow = new RegisterTooltipWindow(foreground); registerTooltipWindow.SetDescription(reg, this.asmDudeTools_); registerTooltipWindow.SetAsmSim(this.asmSimulator_, reg, lineNumber, true); quickInfoContent.Add(registerTooltipWindow); } break; } case AsmTokenType.Mnemonic: // intentional fall through case AsmTokenType.MnemonicOff: // intentional fall through case AsmTokenType.Jump: { (Mnemonic mnemonic, _) = AsmSourceTools.ParseMnemonic_Att(keyword_upcase, true); InstructionTooltipWindow instructionTooltipWindow = new InstructionTooltipWindow(foreground) { Session = session, // set the owner of this windows such that we can manually close this window }; instructionTooltipWindow.SetDescription(mnemonic, this.asmDudeTools_); instructionTooltipWindow.SetPerformanceInfo(mnemonic, this.asmDudeTools_); int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan); instructionTooltipWindow.SetAsmSim(this.asmSimulator_, lineNumber, true); quickInfoContent.Add(instructionTooltipWindow); break; } case AsmTokenType.Label: { string label = keyword; string labelPrefix = tag.Misc; string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(labelPrefix, label, AsmDudeToolsStatic.Used_Assembler); description = new TextBlock(); description.Inlines.Add(Make_Run1("Label ", foreground)); description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label)))); string descr = this.Get_Label_Description(full_Qualified_Label); if (descr.Length == 0) { descr = this.Get_Label_Description(label); } if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips)) { Foreground = foreground, }); } break; } case AsmTokenType.LabelDef: { string label = keyword; string extra_Tag_Info = tag.Misc; string full_Qualified_Label; if ((extra_Tag_Info != null) && extra_Tag_Info.Equals(AsmTokenTag.MISC_KEYWORD_PROTO, StringComparison.Ordinal)) { full_Qualified_Label = label; } else { full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(extra_Tag_Info, label, AsmDudeToolsStatic.Used_Assembler); } AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: found label def " + full_Qualified_Label); description = new TextBlock(); description.Inlines.Add(Make_Run1("Label ", foreground)); description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label)))); string descr = this.Get_Label_Def_Description(full_Qualified_Label, label); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips)) { Foreground = foreground, }); } break; } case AsmTokenType.Constant: { (bool valid, ulong value, int nBits) = AsmSourceTools.Evaluate_Constant(keyword); string constantStr = valid ? value + "d = " + value.ToString("X", AsmDudeToolsStatic.CultureUI) + "h = " + AsmSourceTools.ToStringBin(value, nBits) + "b" : keyword; if (false) // experiment to get text selectable { TextBoxWindow myWindow = new TextBoxWindow(); myWindow.MouseRightButtonUp += this.MyWindow_MouseRightButtonUp; myWindow.MyContent.Text = "Constant X: " + constantStr; myWindow.MyContent.Foreground = foreground; myWindow.MyContent.MouseRightButtonUp += this.MyContent_MouseRightButtonUp; quickInfoContent.Add(myWindow); } else { description = new SelectableTextBlock(); description.Inlines.Add(Make_Run1("Constant ", foreground)); description.Inlines.Add(Make_Run2(constantStr, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Constant)))); } break; } case AsmTokenType.UserDefined1: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 1: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined1)))); string descr = this.asmDudeTools_.Get_Description(keyword_upcase); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips)) { Foreground = foreground, }); } break; } case AsmTokenType.UserDefined2: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 2: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined2)))); string descr = this.asmDudeTools_.Get_Description(keyword_upcase); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips)) { Foreground = foreground, }); } break; } case AsmTokenType.UserDefined3: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 3: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined3)))); string descr = this.asmDudeTools_.Get_Description(keyword_upcase); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips)) { Foreground = foreground, }); } break; } default: //description = new TextBlock(); //description.Inlines.Add(makeRun1("Unused tagType " + asmTokenTag.Tag.type)); break; } if (description != null) { description.Focusable = true; description.FontSize = AsmDudeToolsStatic.GetFontSize() + 2; description.FontFamily = AsmDudeToolsStatic.GetFontType(); //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:AugmentQuickInfoSession; setting description fontSize={1}; fontFamily={2}", this.ToString(), description.FontSize, description.FontFamily)); quickInfoContent.Add(description); } } //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: applicableToSpan=\"" + applicableToSpan + "\"; quickInfoContent,Count=" + quickInfoContent.Count); AsmDudeToolsStatic.Print_Speed_Warning(time1, "QuickInfo"); }