Skip to content

Commit

Permalink
[Fixed] Tooltips not displaying in C++.
Browse files Browse the repository at this point in the history
 [Added] New section on top of the tooltip for non C# tooltip content.
  • Loading branch information
DimitarCC committed Nov 15, 2024
1 parent ad6beb9 commit 7a38275
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 119 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@
<ContentPresenter Content="{Binding Content}" Margin="0,1" />
</DataTemplate>

<!-- Style for VS non C# content -->
<DataTemplate DataType="{x:Type local:NonCSharpTooltipContent}">
<ContentPresenter Content="{Binding Content}" Margin="0,1" />
</DataTemplate>

</Style.Resources>

<Setter Property="Margin" Value="0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("3.27.0.0")]
[assembly: AssemblyVersion("3.27.1.8")]
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IssueTooltipContent>();
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,120 +10,127 @@

namespace GammaJul.ReSharper.EnhancedTooltip.VisualStudio {

public class MultipleTooltipContentPresenter {

private readonly List<IdentifierTooltipContent> _identifierContents = new();
private readonly List<ArgumentRoleTooltipContent> _argumentRoleContents = new();
private readonly List<IssueTooltipContent> _issueContents = new();
private readonly List<MiscTooltipContent> _miscContents = new();
private readonly List<VsIdentifierContent> _vsIdentifierContents = new();
private readonly List<VsSquiggleContent> _vsSquiggleContents = new();
private readonly List<object> _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<object> 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<IdentifierTooltipContent> _identifierContents = new();
private readonly List<ArgumentRoleTooltipContent> _argumentRoleContents = new();
private readonly List<IssueTooltipContent> _issueContents = new();
private readonly List<MiscTooltipContent> _miscContents = new();
private readonly List<VsIdentifierContent> _vsIdentifierContents = new();
private readonly List<VsSquiggleContent> _vsSquiggleContents = new();
private readonly List<object> _vsUnknownContents = new();
private readonly List<NonCSharpTooltipContent> _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<object> 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<object> 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<IDocument?>(_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<object> 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<IDocument?>(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;
}

}

}

0 comments on commit 7a38275

Please sign in to comment.