Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pluginUntilBuild=222.*
## supported IDEs : IC,IU,PC,PY,RD,CI
## default is rider
platformType=RD
platformVersion=2022.2
platformVersion=2022.2.1
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:213.7172.25
# to load IC with python support:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public class CodeLensProvider {
private static final Logger LOGGER = Logger.getInstance(CodeLensProvider.class);

private final DocumentInfoService documentInfoService;
private final Project project;

public CodeLensProvider(Project project) {
documentInfoService = project.getService(DocumentInfoService.class);
this.project = project;
}


Expand All @@ -44,11 +46,12 @@ public List<CodeLens> provideCodeLens(@NotNull PsiFile psiFile){
summaries.forEach(codeObjectSummary -> {
switch (codeObjectSummary.getType()){
case MethodSummary:{

MethodCodeObjectSummary methodCodeObjectSummary = (MethodCodeObjectSummary) codeObjectSummary;
int score = methodCodeObjectSummary.getScore();
if (score >= 70){
Log.log(LOGGER::debug, "Collecting code lese for MethodCodeObjectSummary {}",codeObjectSummary.getCodeObjectId());
CodeLens codeLens = new CodeLens(codeObjectSummary.getCodeObjectId(), CodeObjectType.Method,"Error Hotspot");
CodeLens codeLens = new CodeLens(codeObjectSummary.getCodeObjectId(), CodeObjectType.Method, CodeLens.CodeLensType.ErrorHotspot, "Error Hotspot");
codeLens.setLensTooltipText("Error Hotspot for "+codeObjectSummary.getCodeObjectId());
codeLens.setLensMoreText("Go to Error Hotspot");
codeLens.setAnchor("Top");
Expand All @@ -59,13 +62,15 @@ public List<CodeLens> provideCodeLens(@NotNull PsiFile psiFile){
break;
}
case EndpointSummary:{

EndpointCodeObjectSummary endpointCodeObjectSummary = (EndpointCodeObjectSummary) codeObjectSummary;
if (endpointCodeObjectSummary.getLowUsage() || endpointCodeObjectSummary.getHighUsage()){
Log.log(LOGGER::debug, "Collecting code lese for EndpointCodeObjectSummary {}",codeObjectSummary.getCodeObjectId());
if (endpointCodeObjectSummary.getLowUsage() || endpointCodeObjectSummary.getHighUsage()) {
Log.log(LOGGER::debug, "Collecting code lese for EndpointCodeObjectSummary {}", codeObjectSummary.getCodeObjectId());
var lensText = endpointCodeObjectSummary.getLowUsage() ? "Low Usage" : "High Usage";
CodeLens codeLens = new CodeLens(codeObjectSummary.getCodeObjectId(), CodeObjectType.Method,lensText);
codeLens.setLensTooltipText("Maximum of "+endpointCodeObjectSummary.getMaxCallsIn1Min() +" requests per minute");
codeLens.setLensMoreText("Go to "+lensText);
var lensType = endpointCodeObjectSummary.getLowUsage() ? CodeLens.CodeLensType.LowUsage : CodeLens.CodeLensType.HighUsage;
CodeLens codeLens = new CodeLens(codeObjectSummary.getCodeObjectId(), CodeObjectType.Method, lensType, lensText);
codeLens.setLensTooltipText("Maximum of " + endpointCodeObjectSummary.getMaxCallsIn1Min() + " requests per minute");
codeLens.setLensMoreText("Go to " + lensText);
codeLens.setAnchor("Top");
codeLensList.add(codeLens);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@ package org.digma.intellij.plugin.model.lens

import org.digma.intellij.plugin.model.CodeObjectType

data class CodeLens(val codeObjectId: String,
val codeObjectType: CodeObjectType,
val lensText: String,
var lensTooltipText: String,
var lensMoreText: String,
var anchor: String) {

constructor(codeObjectId: String, codeObjectType: CodeObjectType, lensText: String) : this(codeObjectId,codeObjectType,lensText,"","","")
data class CodeLens(
val codeObjectId: String,
val codeObjectType: CodeObjectType,
val type: CodeLensType,
val lensText: String,
var lensTooltipText: String,
var lensMoreText: String,
var anchor: String
) {

constructor(codeObjectId: String, codeObjectType: CodeObjectType, type: CodeLensType, lensText: String) : this(
codeObjectId,
codeObjectType,
type,
lensText,
"",
"",
""
)


enum class CodeLensType {
ErrorHotspot,
LowUsage,
HighUsage
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@

namespace Digma.Rider.Highlighting
{
[SolutionComponent]
public class MethodInsightsProvider : ICodeInsightsProvider
public abstract class BaseMethodInsightsProvider : ICodeInsightsProvider
{
private readonly ISolution _solution;
private readonly ILogger _logger;
private readonly ShowToolWindowHost _showToolWindowHost;

public MethodInsightsProvider(ISolution solution,ILogger logger,ShowToolWindowHost showToolWindowHost)
protected BaseMethodInsightsProvider(ISolution solution,ILogger logger,ShowToolWindowHost showToolWindowHost)
{
_solution = solution;
_logger = logger;
Expand All @@ -40,7 +39,10 @@ public void OnExtraActionClick(CodeInsightsHighlighting highlighting, string act
Log(_logger, "OnExtraActionClick invoked for {0}", highlighting.DeclaredElement);
NavigateToMethod(highlighting);
}


public abstract string ProviderId { get; }
public abstract string DisplayName { get; }

private void NavigateToMethod(CodeInsightsHighlighting highlighting)
{
using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet())
Expand All @@ -51,12 +53,7 @@ private void NavigateToMethod(CodeInsightsHighlighting highlighting)
}



public string ProviderId => nameof(MethodInsightsProvider);
public string DisplayName => "Method Hints";
public CodeLensAnchorKind DefaultAnchor => CodeLensAnchorKind.Top;

public ICollection<CodeLensRelativeOrdering> RelativeOrderings => new CodeLensRelativeOrdering[]
{ new CodeLensRelativeOrderingFirst() };
public abstract ICollection<CodeLensRelativeOrdering> RelativeOrderings { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,69 @@
using System;
using Digma.Rider.Discovery;
using Digma.Rider.Protocol;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon.CodeInsights;
using JetBrains.ReSharper.Feature.Services.Daemon;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.Util;
using static Digma.Rider.Logging.Logger;

namespace Digma.Rider.Highlighting
{
[ElementProblemAnalyzer(typeof(ICSharpFile))]
public class CodeObjectsHighlighter : ElementProblemAnalyzer<ICSharpFile>
[ElementProblemAnalyzer(typeof(ICSharpFunctionDeclaration))]
public class CodeObjectsHighlighter : ElementProblemAnalyzer<ICSharpFunctionDeclaration>
{
private readonly ILogger _logger;
private readonly CodeObjectsHost _codeObjectsHost;
private readonly MethodInsightsProvider _methodInsightsProvider;
private readonly ErrorHotspotMethodInsightsProvider _errorHotspotMethodInsightsProvider;
private readonly UsageMethodInsightsProvider _usageMethodInsightsProvider;

public CodeObjectsHighlighter(ILogger logger,
CodeObjectsHost codeObjectsHost,
ISolution solution,
MethodInsightsProvider methodInsightsProvider)
ErrorHotspotMethodInsightsProvider errorHotspotMethodInsightsProvider,
UsageMethodInsightsProvider usageMethodInsightsProvider)
{
_logger = logger;
_codeObjectsHost = codeObjectsHost;
_methodInsightsProvider = methodInsightsProvider;
_errorHotspotMethodInsightsProvider = errorHotspotMethodInsightsProvider;
_usageMethodInsightsProvider = usageMethodInsightsProvider;
}

protected override void Run(ICSharpFile element,
protected override void Run(ICSharpFunctionDeclaration functionDeclaration,
ElementProblemAnalyzerData data,
IHighlightingConsumer consumer)
IHighlightingConsumer highlightingConsumer)
{
Log(_logger, "CodeObjectsHighlighter.Run invoked for {0}", element.GetSourceFile());
var elementProcessor =
new CodeObjectsHighlightingProcessor(_codeObjectsHost, consumer, _methodInsightsProvider,_logger);
element.ProcessDescendants(elementProcessor);
Log(_logger, "CodeObjectsHighlighter.Run invoked for {0}", functionDeclaration);

var methodFqn = Identities.ComputeFqn(functionDeclaration);
var methodCodeLenses = _codeObjectsHost.GetRiderCodeLensInfo(methodFqn);
if (methodCodeLenses is { Count: > 0 })
{
Log(_logger, "Found {0} code lens for method {1}", methodCodeLenses.Count,methodFqn);
foreach (var riderCodeLensInfo in methodCodeLenses)
{
Log(_logger, "Installing code lens for code method {0}: {1}", methodFqn,riderCodeLensInfo);

ICodeInsightsProvider codeInsightsProvider =
riderCodeLensInfo.Type.Equals(CodeLensType.ErrorHotspot)
? _errorHotspotMethodInsightsProvider
: _usageMethodInsightsProvider;

highlightingConsumer.AddHighlighting(
new CodeInsightsHighlighting(
functionDeclaration.GetNameDocumentRange(),
riderCodeLensInfo.LensText ?? throw new InvalidOperationException("LensText must not be null"),
riderCodeLensInfo.LensTooltip ?? string.Empty, //todo: can be null
riderCodeLensInfo.MoreText ?? string.Empty, //todo: can be null
codeInsightsProvider,
functionDeclaration.DeclaredElement,null)
);
}

}
}

}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using Digma.Rider.Protocol;
using JetBrains.ProjectModel;
using JetBrains.Rider.Model;
using JetBrains.Util;

namespace Digma.Rider.Highlighting
{
[SolutionComponent]
public class ErrorHotspotMethodInsightsProvider : BaseMethodInsightsProvider
{
public ErrorHotspotMethodInsightsProvider(ISolution solution,ILogger logger,ShowToolWindowHost showToolWindowHost)
: base(solution,logger,showToolWindowHost)
{}


public override string ProviderId => nameof(ErrorHotspotMethodInsightsProvider);
public override string DisplayName => "Error Hotspot Method Hints";

public override ICollection<CodeLensRelativeOrdering> RelativeOrderings => new CodeLensRelativeOrdering[]
{ new CodeLensRelativeOrderingFirst() };

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using Digma.Rider.Protocol;
using JetBrains.ProjectModel;
using JetBrains.Rider.Model;
using JetBrains.Util;

namespace Digma.Rider.Highlighting
{
[SolutionComponent]
public class UsageMethodInsightsProvider : BaseMethodInsightsProvider
{
public UsageMethodInsightsProvider(ISolution solution,ILogger logger,ShowToolWindowHost showToolWindowHost)
: base(solution,logger,showToolWindowHost)
{}

public override string ProviderId => nameof(UsageMethodInsightsProvider);
public override string DisplayName => "Usage Method Hints";

public override ICollection<CodeLensRelativeOrdering> RelativeOrderings => new CodeLensRelativeOrdering[]
{ new CodeLensRelativeOrderingAfter(nameof(ErrorHotspotMethodInsightsProvider)) };
}
}
Loading