From 7a38275c8eaff32ad598c35e4b7f35c1e7fdc509 Mon Sep 17 00:00:00 2001 From: Dimitar Tsenev Date: Fri, 15 Nov 2024 12:32:50 +0200 Subject: [PATCH] [Fixed] Tooltips not displaying in C++. [Added] New section on top of the tooltip for non C# tooltip content. --- CHANGELOG.md | 4 + .../Presentation/NonCSharpTooltipContent.cs | 15 ++ .../Presentation/UIResources.xaml | 5 + .../Properties/AssemblyInfo.cs | 2 +- .../VisualStudio/MainQuickInfoSource.cs | 29 ++- .../MultipleTooltipContentPresenter.cs | 235 +++++++++--------- 6 files changed, 171 insertions(+), 119 deletions(-) create mode 100644 source/GammaJul.ReSharper.EnhancedTooltip/Presentation/NonCSharpTooltipContent.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dc2195..95f4d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.27.1.8 +- [Fixed] Tooltips not displaying in C++. +- [Added] New section on top of the tooltip for non C# tooltip content. + ## 3.27.0.0 - [Updated] Updated ReSharper SDK to 2024.3.0. diff --git a/source/GammaJul.ReSharper.EnhancedTooltip/Presentation/NonCSharpTooltipContent.cs b/source/GammaJul.ReSharper.EnhancedTooltip/Presentation/NonCSharpTooltipContent.cs new file mode 100644 index 0000000..48a59b7 --- /dev/null +++ b/source/GammaJul.ReSharper.EnhancedTooltip/Presentation/NonCSharpTooltipContent.cs @@ -0,0 +1,15 @@ +using System; +using JetBrains.UI.RichText; +using JetBrains.Util; +using JetBrains.VsIntegration.TextControl; + +namespace GammaJul.ReSharper.EnhancedTooltip.Presentation { + + public class NonCSharpTooltipContent { + public Object Content { get; set; } + public NonCSharpTooltipContent(Object content) { + this.Content = content; + } + } + +} \ No newline at end of file diff --git a/source/GammaJul.ReSharper.EnhancedTooltip/Presentation/UIResources.xaml b/source/GammaJul.ReSharper.EnhancedTooltip/Presentation/UIResources.xaml index 9362669..ae2407b 100644 --- a/source/GammaJul.ReSharper.EnhancedTooltip/Presentation/UIResources.xaml +++ b/source/GammaJul.ReSharper.EnhancedTooltip/Presentation/UIResources.xaml @@ -373,6 +373,11 @@ + + + + + diff --git a/source/GammaJul.ReSharper.EnhancedTooltip/Properties/AssemblyInfo.cs b/source/GammaJul.ReSharper.EnhancedTooltip/Properties/AssemblyInfo.cs index 5ea2d06..2f3a6ad 100644 --- a/source/GammaJul.ReSharper.EnhancedTooltip/Properties/AssemblyInfo.cs +++ b/source/GammaJul.ReSharper.EnhancedTooltip/Properties/AssemblyInfo.cs @@ -9,4 +9,4 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -[assembly: AssemblyVersion("3.27.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("3.27.1.8")] \ No newline at end of file diff --git a/source/GammaJul.ReSharper.EnhancedTooltip/VisualStudio/MainQuickInfoSource.cs b/source/GammaJul.ReSharper.EnhancedTooltip/VisualStudio/MainQuickInfoSource.cs index 553dba7..7d83be9 100644 --- a/source/GammaJul.ReSharper.EnhancedTooltip/VisualStudio/MainQuickInfoSource.cs +++ b/source/GammaJul.ReSharper.EnhancedTooltip/VisualStudio/MainQuickInfoSource.cs @@ -14,12 +14,16 @@ using JetBrains.Metadata.Reader.API; using JetBrains.Platform.VisualStudio.SinceVs10.Interop.Shim.TextControl; using JetBrains.ProjectModel; +using JetBrains.PsiFeatures.VisualStudio.Core.TextControl.Intellisense; using JetBrains.PsiFeatures.VisualStudio.SinceVs10.TextControl.Intellisense; using JetBrains.ReSharper.Feature.Services.Daemon; using JetBrains.ReSharper.Psi; +using JetBrains.ReSharper.Psi.Cpp.Language; +using JetBrains.ReSharper.Psi.CSharp; using JetBrains.ReSharper.Resources.Shell; using JetBrains.TextControl; using JetBrains.TextControl.DocumentMarkup; +using JetBrains.UI.Controls; using JetBrains.UI.RichText; using JetBrains.Util; using JetBrains.VsIntegration.ProjectDocuments; @@ -94,11 +98,13 @@ protected override void AugmentQuickInfoSessionCore( void GetEnhancedTooltips() { using (shellLocks.UsingReadLock()) { var compilerIds = HighlightingSettingsManager.Instance.GetAllCompilerIds(); - IDocument document = documentMarkup.Document; + var solution = MainQuickInfoSource.TryGetCurrentSolution(); + var document = documentMarkup.Document; + var isCSharp = document.GetPsiSourceFile(solution).LanguageType.Name == "CSHARP"; var presenter = new MultipleTooltipContentPresenter(tooltipFormattingProvider.GetTooltipFormatting(), document); - IContextBoundSettingsStore settings = document.GetSettings(); - ISolution? solution = MainQuickInfoSource.TryGetCurrentSolution(); - bool hasIdentifierTooltipContent = false; + var settings = document.GetSettings(); + + var hasIdentifierTooltipContent = !isCSharp; var resolveContext = solution is null ? UniversalModuleReferenceContext.Instance : document.GetContext(solution); var issueContents = new List(); @@ -129,6 +135,21 @@ void GetEnhancedTooltips() { } } + if (!isCSharp) { + foreach (object? content in quickInfoContent) { + if (content is IQuickInfoContent) { + if (content is RichContentPresenter rcp) { + var textPresenter = rcp.Content as RichTextPresenter; + if (!issueContents.Any(w => textPresenter != null && w.Text?.Text.Contains(textPresenter.RichText.Text) == true) && !String.IsNullOrEmpty(textPresenter?.RichText.Text.Trim())) { + presenter.AddNonCSharpContent(new NonCSharpTooltipContent(content)); + } + } else { + presenter.AddNonCSharpContent(new NonCSharpTooltipContent(content)); + } + } + } + } + } var vsSquiggleContents = session.RetrieveVsSquiggleContents() diff --git a/source/GammaJul.ReSharper.EnhancedTooltip/VisualStudio/MultipleTooltipContentPresenter.cs b/source/GammaJul.ReSharper.EnhancedTooltip/VisualStudio/MultipleTooltipContentPresenter.cs index 05342c3..6e57bb0 100644 --- a/source/GammaJul.ReSharper.EnhancedTooltip/VisualStudio/MultipleTooltipContentPresenter.cs +++ b/source/GammaJul.ReSharper.EnhancedTooltip/VisualStudio/MultipleTooltipContentPresenter.cs @@ -10,120 +10,127 @@ namespace GammaJul.ReSharper.EnhancedTooltip.VisualStudio { - public class MultipleTooltipContentPresenter { - - private readonly List _identifierContents = new(); - private readonly List _argumentRoleContents = new(); - private readonly List _issueContents = new(); - private readonly List _miscContents = new(); - private readonly List _vsIdentifierContents = new(); - private readonly List _vsSquiggleContents = new(); - private readonly List _vsUnknownContents = new(); - private readonly TextFormattingRunProperties _formatting; - private readonly IDocument? _document; - - [ContractAnnotation("null => false")] - public bool TryAddReSharperContent(IReSharperTooltipContent? content) { - if (content is null || content.Text.IsNullOrEmpty()) - return false; - - switch (content) { - case IdentifierTooltipContent identifierContent: - AddIdentifierTooltipContent(identifierContent); - return true; - case ArgumentRoleTooltipContent argumentRoleContent: - AddArgumentRoleTooltipContent(argumentRoleContent); - return true; - case IssueTooltipContent issueContent: - AddIssueTooltipContent(issueContent); - return true; - case MiscTooltipContent miscContent: - AddMiscTooltipContent(miscContent); - return true; - default: - return false; - } - } - - public void AddIdentifierTooltipContent(IdentifierTooltipContent content) - => _identifierContents.Add(content); - - public void AddArgumentRoleTooltipContent(ArgumentRoleTooltipContent content) - => _argumentRoleContents.Add(content); - - public void AddIssueTooltipContent(IssueTooltipContent content) - => _issueContents.Add(content); - - public void AddMiscTooltipContent(MiscTooltipContent content) - => _miscContents.Add(content); - - public void AddVsSquiggleContent(VsSquiggleContent content) - => _vsSquiggleContents.Add(content); - - public void AddVsIdentifierContent(VsIdentifierContent content) - => _vsIdentifierContents.Add(content); - - public void AddVsUnknownContent(object content) - => _vsUnknownContents.Add(content); - - public IEnumerable PresentContents() { - foreach (IdentifierTooltipContent identifierContent in _identifierContents) - yield return PresentTooltipContents("Id", new[] { identifierContent }, this._vsIdentifierContents.Count == 0 && this._argumentRoleContents.Count == 0 && this._issueContents.Count == 0 && this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); - - foreach (VsIdentifierContent identifierContent in _vsIdentifierContents) - yield return PresentTooltipContents("Id", new[] { identifierContent }, this._argumentRoleContents.Count == 0 && this._issueContents.Count == 0 && this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); - - foreach (ArgumentRoleTooltipContent argumentRoleContent in _argumentRoleContents) - yield return PresentTooltipContents("Role", new[] { argumentRoleContent }, this._issueContents.Count == 0 && this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); - - if (_issueContents.Count > 0) - yield return PresentTooltipContents(_issueContents.Count == 1 ? "Issue" : "Issues", _issueContents, this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); - - foreach (MiscTooltipContent miscContent in _miscContents) - yield return PresentTooltipContents("Misc", new[] { miscContent }, this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); - - if (_vsSquiggleContents.Count > 0) - yield return PresentTooltipContents("VS", _vsSquiggleContents, this._vsUnknownContents.Count == 0); - - foreach (object vsUnknownContent in _vsUnknownContents) + public class MultipleTooltipContentPresenter { + + private readonly List _identifierContents = new(); + private readonly List _argumentRoleContents = new(); + private readonly List _issueContents = new(); + private readonly List _miscContents = new(); + private readonly List _vsIdentifierContents = new(); + private readonly List _vsSquiggleContents = new(); + private readonly List _vsUnknownContents = new(); + private readonly List _vsNonCsharpContents = new(); + private readonly TextFormattingRunProperties _formatting; + private readonly IDocument? _document; + + [ContractAnnotation("null => false")] + public bool TryAddReSharperContent(IReSharperTooltipContent? content) { + if (content is null || content.Text.IsNullOrEmpty()) + return false; + + switch (content) { + case IdentifierTooltipContent identifierContent: + this.AddIdentifierTooltipContent(identifierContent); + return true; + case ArgumentRoleTooltipContent argumentRoleContent: + this.AddArgumentRoleTooltipContent(argumentRoleContent); + return true; + case IssueTooltipContent issueContent: + this.AddIssueTooltipContent(issueContent); + return true; + case MiscTooltipContent miscContent: + this.AddMiscTooltipContent(miscContent); + return true; + default: + return false; + } + } + + public void AddIdentifierTooltipContent(IdentifierTooltipContent content) + => this._identifierContents.Add(content); + + public void AddArgumentRoleTooltipContent(ArgumentRoleTooltipContent content) + => this._argumentRoleContents.Add(content); + + public void AddIssueTooltipContent(IssueTooltipContent content) + => this._issueContents.Add(content); + + public void AddMiscTooltipContent(MiscTooltipContent content) + => this._miscContents.Add(content); + + public void AddVsSquiggleContent(VsSquiggleContent content) + => this._vsSquiggleContents.Add(content); + + public void AddVsIdentifierContent(VsIdentifierContent content) + => this._vsIdentifierContents.Add(content); + + public void AddVsUnknownContent(object content) + => this._vsUnknownContents.Add(content); + public void AddNonCSharpContent(NonCSharpTooltipContent content) + => this._vsNonCsharpContents.Add(content); + + public IEnumerable PresentContents() { + if (this._vsNonCsharpContents.Count > 0) { + yield return this.PresentTooltipContents("VSNonC#", this._vsNonCsharpContents, this._vsIdentifierContents.Count == 0 && this._argumentRoleContents.Count == 0 && this._issueContents.Count == 0 && this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); + } + + foreach (IdentifierTooltipContent identifierContent in this._identifierContents) + yield return this.PresentTooltipContents("Id", new[] { identifierContent }, this._vsNonCsharpContents.Count == 0 && this._vsIdentifierContents.Count == 0 && this._argumentRoleContents.Count == 0 && this._issueContents.Count == 0 && this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); + + foreach (VsIdentifierContent identifierContent in this._vsIdentifierContents) + yield return this.PresentTooltipContents("Id", new[] { identifierContent }, this._argumentRoleContents.Count == 0 && this._issueContents.Count == 0 && this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); + + foreach (ArgumentRoleTooltipContent argumentRoleContent in this._argumentRoleContents) + yield return this.PresentTooltipContents("Role", new[] { argumentRoleContent }, this._issueContents.Count == 0 && this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); + + if (this._issueContents.Count > 0) + yield return this.PresentTooltipContents(this._issueContents.Count == 1 ? "Issue" : "Issues", this._issueContents, this._miscContents.Count == 0 && this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); + + foreach (MiscTooltipContent miscContent in this._miscContents) + yield return this.PresentTooltipContents("Misc", new[] { miscContent }, this._vsUnknownContents.Count == 0 && this._vsSquiggleContents.Count == 0); + + if (this._vsSquiggleContents.Count > 0) + yield return this.PresentTooltipContents("VS", this._vsSquiggleContents, this._vsUnknownContents.Count == 0); + + foreach (object vsUnknownContent in this._vsUnknownContents) yield return vsUnknownContent; - } - - [Pure] - private HeaderedContentControl PresentTooltipContents(object? header, IEnumerable tooltipContents, Boolean isLast = true) { - var control = new HeaderedContentControl { - Style = UIResources.Instance.HeaderedContentControlStyle, - Focusable = false, - Tag = isLast ? "Last" : "", - Header = header, - Content = new ItemsControl { - Focusable = false, - ItemsSource = tooltipContents - } - }; - ApplyFormatting(control); - Styling.SetDocument(control, new WeakReference(_document)); - return control; - } - - private void ApplyFormatting(Control control) { - if (!_formatting.TypefaceEmpty) { - Typeface typeface = _formatting.Typeface; - control.FontFamily = typeface.FontFamily; - control.FontWeight = typeface.Weight; - control.FontStretch = typeface.Stretch; - control.FontStyle = typeface.Style; - } - - if (!_formatting.FontRenderingEmSizeEmpty) - control.FontSize = _formatting.FontRenderingEmSize; - } - - public MultipleTooltipContentPresenter(TextFormattingRunProperties formatting, IDocument? document) { - _formatting = formatting; - _document = document; - } - - } + } + + [Pure] + private HeaderedContentControl PresentTooltipContents(object? header, IEnumerable tooltipContents, Boolean isLast = true) { + var control = new HeaderedContentControl { + Style = UIResources.Instance.HeaderedContentControlStyle, + Focusable = false, + Tag = isLast ? "Last" : "", + Header = header, + Content = new ItemsControl { + Focusable = false, + ItemsSource = tooltipContents + } + }; + this.ApplyFormatting(control); + Styling.SetDocument(control, new WeakReference(this._document)); + return control; + } + + private void ApplyFormatting(Control control) { + if (!this._formatting.TypefaceEmpty) { + Typeface typeface = this._formatting.Typeface; + control.FontFamily = typeface.FontFamily; + control.FontWeight = typeface.Weight; + control.FontStretch = typeface.Stretch; + control.FontStyle = typeface.Style; + } + + if (!this._formatting.FontRenderingEmSizeEmpty) + control.FontSize = this._formatting.FontRenderingEmSize; + } + + public MultipleTooltipContentPresenter(TextFormattingRunProperties formatting, IDocument? document) { + this._formatting = formatting; + this._document = document; + } + + } } \ No newline at end of file