Skip to content

Commit

Permalink
- [Added] Support for external extensions tooltip highlighting.
Browse files Browse the repository at this point in the history
- [Added] More colorizings over the tooltip
- [Fixed] hide redundant Roslyn analizers tooltip items
  • Loading branch information
DimitarCC committed Sep 14, 2023
1 parent 49f6eda commit 0f32a2f
Show file tree
Hide file tree
Showing 18 changed files with 315 additions and 18 deletions.
10 changes: 8 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ root = true
end_of_line = crlf
charset = utf-8

# ReSharper properties
resharper_csharp_indent_size = 2
resharper_csharp_indent_style = space
resharper_csharp_tab_width = 2

[*.cs]
indent_style = tab
indent_size = 4
indent_style = space
indent_size = 2
tab_width = 2

[*.csproj]
indent_style = tab
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.21.1.14
- [Added] Support for external extensions tooltip highlighting.
- [Added] More colorizings over the tooltip
- [Fixed] hide redundant Roslyn analizers tooltip items

## 3.21.0.32
- [Added] Imported nullability state text from visual studio tooltip.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ private static IEnumerable<ParamContent> GetParams(
if (string.IsNullOrEmpty(name))
return null;

var paramContent = new ParamContent(XmlDocRichTextPresenterEx.EnhanceColorizingTooltip(name!,settings,highlighterIdProviderFactory,textStyleHighlighterManager,codeAnnotationsConfiguration,false));
var paramContent = new ParamContent(XmlDocRichTextPresenterEx.EnhanceColorizingTooltip(name!, settings, highlighterIdProviderFactory, textStyleHighlighterManager, codeAnnotationsConfiguration, false));

RichText richText = XmlDocRichTextPresenterEx.Run(paramElement!, false, languageType, DeclaredElementPresenterTextStyles.Empty, psiModule, settings, highlighterIdProviderFactory, colorizerPresenter, textStyleHighlighterManager, codeAnnotationsConfiguration).RichText;
if (!richText.IsNullOrEmpty())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


namespace GammaJul.ReSharper.EnhancedTooltip.ExceptionalHighlightings {

using GammaJul.ReSharper.EnhancedTooltip.ExternalHighlightings;

public interface IExceptionNotDocumentedHighlighting : IExternalHighlighting { }
public interface IExceptionNotDocumentedOptionalHighlighting : IExternalHighlighting { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using JetBrains.ReSharper.Feature.Services.Daemon;

namespace GammaJul.ReSharper.EnhancedTooltip.ExternalHighlightings {
public interface IExternalHighlighting : IHighlighting {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,26 @@ internal sealed class CSharpPresentableNodeFinder : IPresentableNodeFinder {
return FindElementFromDotKeyword(node, file, out sourceRange);
}

if (tokenType == CSharpTokenType.OVERRIDE_KEYWORD || tokenType == CSharpTokenType.VIRTUAL_KEYWORD ) {
return FindElementFromModifiersKeyword(node, file, out sourceRange);
}

sourceRange = TextRange.InvalidRange;
return null;
}

private static DeclaredElementInstance? FindElementFromModifiersKeyword(ITreeNode modifiersKeyword, IFile file, out TextRange sourceRange) {
sourceRange = TextRange.InvalidRange;
IDeclaredElement? declaredElement = (modifiersKeyword.Parent?.Parent as IMethodDeclaration)
?.DeclaredElement;

if (declaredElement is null)
return null;

sourceRange = file.GetDocumentRange(modifiersKeyword.GetTreeTextRange()).TextRange;
return new DeclaredElementInstance(declaredElement, EmptySubstitution.INSTANCE);
}

private static DeclaredElementInstance? FindElementFromDotKeyword(ITreeNode dotKeyword, IFile file, out TextRange sourceRange) {
sourceRange = TextRange.InvalidRange;
IDeclaredElement? declaredElement = (dotKeyword.Parent as IReferenceExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ public Type HighlightingType
=> typeof(T);

public RichText? TryEnhance(IHighlighting highlighting, IContextBoundSettingsStore settings) {
if (highlighting is not T typedHighlighting)
return null;

var typedHighlighting = highlighting as T;
var richText = new RichText();
var highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings);
var colorizer = new CSharpColorizer(richText, _textStyleHighlighterManager, _codeAnnotationsConfiguration, highlighterIdProvider);
AppendTooltip(typedHighlighting, colorizer);
return richText;
if (typedHighlighting != null) {
AppendTooltip(typedHighlighting, colorizer);
} else {
AppendTooltip(highlighting, colorizer);
}

return richText;
}

protected abstract void AppendTooltip(T highlighting, CSharpColorizer colorizer);

protected virtual void AppendTooltip(IHighlighting highlighting, CSharpColorizer colorizer) { }

protected CSharpHighlightingEnhancer(
TextStyleHighlighterManager textStyleHighlighterManager,
CodeAnnotationsConfiguration codeAnnotationsConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using GammaJul.ReSharper.EnhancedTooltip.DocumentMarkup;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi.CodeAnnotations;

namespace GammaJul.ReSharper.EnhancedTooltip.Presentation.Highlightings.CSharp {

using GammaJul.ReSharper.EnhancedTooltip.ExceptionalHighlightings;
using GammaJul.ReSharper.EnhancedTooltip.Utils;
using JetBrains.ReSharper.Feature.Services.Daemon;

[SolutionComponent]
internal sealed class ExceptionNotDocumentedHighlightingEnhancer : CSharpHighlightingEnhancer<IExceptionNotDocumentedHighlighting> {

protected override void AppendTooltip(IExceptionNotDocumentedHighlighting highlighting, CSharpColorizer colorizer) { }

protected override void AppendTooltip(IHighlighting highlighting, CSharpColorizer colorizer) {
var typeName = highlighting.GetDynamicFieldOrPropertySafe("ExceptionTypeName");
if (typeName != null) {
colorizer.AppendPlainText("(optional) Exception '");
colorizer.AppendClassName(typeName.ToString());
colorizer.AppendPlainText("' is not documented [Exceptional]");
} else {
colorizer.AppendPlainText(highlighting.ToolTip);
}
}

public ExceptionNotDocumentedHighlightingEnhancer(
TextStyleHighlighterManager textStyleHighlighterManager,
CodeAnnotationsConfiguration codeAnnotationsConfiguration,
HighlighterIdProviderFactory highlighterIdProviderFactory)
: base(textStyleHighlighterManager, codeAnnotationsConfiguration, highlighterIdProviderFactory) {
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using GammaJul.ReSharper.EnhancedTooltip.DocumentMarkup;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi.CodeAnnotations;

namespace GammaJul.ReSharper.EnhancedTooltip.Presentation.Highlightings.CSharp {

using GammaJul.ReSharper.EnhancedTooltip.ExceptionalHighlightings;
using GammaJul.ReSharper.EnhancedTooltip.Utils;

using JetBrains.Reflection;
using JetBrains.ReSharper.Feature.Services.Daemon;

[SolutionComponent]
internal sealed class ExceptionNotDocumentedOptionalHighlightingEnhancer : CSharpHighlightingEnhancer<IExceptionNotDocumentedOptionalHighlighting> {

protected override void AppendTooltip(IExceptionNotDocumentedOptionalHighlighting highlighting, CSharpColorizer colorizer) {

}

/// <inheritdoc />
protected override void AppendTooltip(IHighlighting highlighting, CSharpColorizer colorizer) {
var typeName = highlighting.GetDynamicFieldOrPropertySafe("ExceptionTypeName");
if (typeName != null) {
colorizer.AppendPlainText("(optional) Exception '");
colorizer.AppendClassName(typeName.ToString());
colorizer.AppendPlainText("' is not documented [Exceptional]");
} else {
colorizer.AppendPlainText(highlighting.ToolTip);
}
}

public ExceptionNotDocumentedOptionalHighlightingEnhancer(
TextStyleHighlighterManager textStyleHighlighterManager,
CodeAnnotationsConfiguration codeAnnotationsConfiguration,
HighlighterIdProviderFactory highlighterIdProviderFactory)
: base(textStyleHighlighterManager, codeAnnotationsConfiguration, highlighterIdProviderFactory) {
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using GammaJul.ReSharper.EnhancedTooltip.DocumentMarkup;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon.CSharp.Errors;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CodeAnnotations;

namespace GammaJul.ReSharper.EnhancedTooltip.Presentation.Highlightings.CSharp {

[SolutionComponent]
internal sealed class NullReferenceArgumentWarningEnhancer : CSharpHighlightingEnhancer<NullReferenceArgumentWarning> {

protected override void AppendTooltip(NullReferenceArgumentWarning highlighting, CSharpColorizer colorizer) {
colorizer.AppendPlainText("Possible '");
colorizer.AppendKeyword("null");
colorizer.AppendPlainText("' reference argument for parameter '");
colorizer.AppendParameterName(highlighting.Parameter.ShortName);
colorizer.AppendPlainText("' in '");
var declaredElement = new DeclaredElementInstance(highlighting.ParametersOwner, highlighting.Parameter.IdSubstitution);
colorizer.AppendDeclaredElement(
declaredElement.Element,
declaredElement.Substitution,
PresenterOptions.QualifiedName,
highlighting.Node);
colorizer.AppendPlainText("'");
}

public NullReferenceArgumentWarningEnhancer(
TextStyleHighlighterManager textStyleHighlighterManager,
CodeAnnotationsConfiguration codeAnnotationsConfiguration,
HighlighterIdProviderFactory highlighterIdProviderFactory)
: base(textStyleHighlighterManager, codeAnnotationsConfiguration, highlighterIdProviderFactory) {
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using GammaJul.ReSharper.EnhancedTooltip.DocumentMarkup;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon.CSharp.Errors;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CodeAnnotations;

namespace GammaJul.ReSharper.EnhancedTooltip.Presentation.Highlightings.CSharp {

[SolutionComponent]
internal sealed class PossibleNullReferenceExceptionWarningEnhancer : CSharpHighlightingEnhancer<PossibleNullReferenceExceptionWarning> {

protected override void AppendTooltip(PossibleNullReferenceExceptionWarning highlighting, CSharpColorizer colorizer) {
colorizer.AppendPlainText("Possible '");
colorizer.AppendNamespaceName("System");
colorizer.AppendPlainText(".");
colorizer.AppendClassName("NullReferenceException");
colorizer.AppendPlainText("'");
}

public PossibleNullReferenceExceptionWarningEnhancer(
TextStyleHighlighterManager textStyleHighlighterManager,
CodeAnnotationsConfiguration codeAnnotationsConfiguration,
HighlighterIdProviderFactory highlighterIdProviderFactory)
: base(textStyleHighlighterManager, codeAnnotationsConfiguration, highlighterIdProviderFactory) {
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using GammaJul.ReSharper.EnhancedTooltip.DocumentMarkup;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi.CodeAnnotations;

namespace GammaJul.ReSharper.EnhancedTooltip.Presentation.Highlightings.CSharp {

using System;

using JetBrains.PsiFeatures.VisualStudio.Backend.Daemon;
using JetBrains.Reflection;

[SolutionComponent]
internal sealed class RoslynDiagnosticHighlightingEnhancer : CSharpHighlightingEnhancer<RoslynDiagnosticsDaemonProcess.RoslynDiagnosticHighlighting> {

protected override void AppendTooltip(RoslynDiagnosticsDaemonProcess.RoslynDiagnosticHighlighting highlighting, CSharpColorizer colorizer) {
var originalTooltip = highlighting.GetDynamicFieldOrProperty("ToolTip").ToString();
var destinationTooltip = originalTooltip.Replace(highlighting.CompilerId + ": ", String.Empty);
colorizer.AppendPlainText(destinationTooltip);
colorizer.AppendPlainText(" [Roslyn Rule: ");
colorizer.AppendPlainText(highlighting.CompilerId);
colorizer.AppendPlainText("]");
}

public RoslynDiagnosticHighlightingEnhancer(
TextStyleHighlighterManager textStyleHighlighterManager,
CodeAnnotationsConfiguration codeAnnotationsConfiguration,
HighlighterIdProviderFactory highlighterIdProviderFactory)
: base(textStyleHighlighterManager, codeAnnotationsConfiguration, highlighterIdProviderFactory) {
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using GammaJul.ReSharper.EnhancedTooltip.DocumentMarkup;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CodeAnnotations;

namespace GammaJul.ReSharper.EnhancedTooltip.Presentation.Highlightings.CSharp {

using System;
using System.Linq;
using GammaJul.ReSharper.EnhancedTooltip.Psi;
using JetBrains.ReSharper.Daemon.UsageChecking;


[SolutionComponent]
internal sealed class UnusedMemberLocalWarningEnhancer : CSharpHighlightingEnhancer<UnusedMemberLocalWarning> {

protected override void AppendTooltip(UnusedMemberLocalWarning highlighting, CSharpColorizer colorizer) {
var kind = highlighting.Declaration.DeclaredElement.GetElementKindString(false, false, false, false, false);

colorizer.AppendPlainText(Char.ToUpper(kind.First()) + kind.Substring(1).ToLower());
colorizer.AppendPlainText(" '");
colorizer.AppendDeclaredElement(
highlighting.Declaration.DeclaredElement!,
highlighting.Declaration.DeclaredElement.GetIdSubstitutionSafe(),
PresenterOptions.NameOnly,
null);
colorizer.AppendPlainText("' is never used");
}

public UnusedMemberLocalWarningEnhancer(
TextStyleHighlighterManager textStyleHighlighterManager,
CodeAnnotationsConfiguration codeAnnotationsConfiguration,
HighlighterIdProviderFactory highlighterIdProviderFactory)
: base(textStyleHighlighterManager, codeAnnotationsConfiguration, highlighterIdProviderFactory) {
}

}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GammaJul.ReSharper.EnhancedTooltip.ExternalHighlightings;
using GammaJul.ReSharper.EnhancedTooltip.Utils;
using JetBrains.Application.Settings;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.UI.RichText;

namespace GammaJul.ReSharper.EnhancedTooltip.Presentation.Highlightings {
namespace GammaJul.ReSharper.EnhancedTooltip.Presentation.Highlightings
{

[SolutionComponent]
public sealed class HighlightingEnhancerManager {
private readonly Dictionary<Type, IHighlightingEnhancer> _HighlightingEnhancers;
public RichText? TryEnhance(IHighlighting? highlighting, IContextBoundSettingsStore settings) {
if (highlighting is null || !this._HighlightingEnhancers.TryGetValue(highlighting.GetType(), out IHighlightingEnhancer highlightingEnhancer)) {
var highlightingType = highlighting?.GetType().GetExternalHighlightingType();
if (highlighting is null || !this._HighlightingEnhancers.TryGetValue(highlightingType ?? highlighting.GetType(), out IHighlightingEnhancer highlightingEnhancer)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ public static PresenterOptions ForXmlDocToolTip(IContextBoundSettingsStore setti
ShowName = true,
ShowParametersAttributes = AttributesDisplayKind.Never,
ShowParametersAttributesArguments = false,
ShowParametersName = false,
ShowParametersType = false,
ShowQualifiers = QualifierDisplays.None,
ShowParametersName = true,
ShowParametersType = true,
ShowQualifiers = QualifierDisplays.Member,
ShowTypeParameters = true,
ShowTypeParametersVariance = false,
SolutionCodeNamespaceDisplayKind = SolutionCodeNamespaceDisplayKind.Never,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
[assembly: AssemblyTitle("GammaJul.ReSharper.EnhancedTooltip")]
[assembly: AssemblyDescription("Enhances the tooltip and parameter information with colors.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Julien Lebosquain")]
[assembly: AssemblyCompany("Julien Lebosquain, Gainedge org")]
[assembly: AssemblyProduct("GammaJul.ReSharper.EnhancedTooltip")]
[assembly: AssemblyCopyright("Copyright © 2013-2023 Julien Lebosquain")]
[assembly: AssemblyCopyright("Copyright © 2013-2023 Julien Lebosquain, Gainedge org")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("3.21.0.59")]
[assembly: AssemblyVersion("3.21.1.14")]
Loading

0 comments on commit 0f32a2f

Please sign in to comment.