Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code metrics moving and redesign #3934

Merged
merged 28 commits into from
Jun 7, 2018

Conversation

Vogel612
Copy link
Member

@Vogel612 Vogel612 commented Apr 14, 2018

The following things are done:

  • Move Rubberduck.Inspections to Rubberduck.CodeAnalysis
  • Move CodeMetrics from Rubberduck.Core into Rubberduck.CodeAnalysis
  • Overhaul the design for CodeMetrics' internal workings
  • Reimplement the existing CodeMetrics with the new design (CC, LineCount and Nesting done)

TBD:

  • UI. A metric ton of UI work is necessary here. As of now the UI is broken, help wanted.

See #3862 for a bit of background, as well as #403 and #3522's review comments for why this is done

@Vogel612 Vogel612 added technical-debt This makes development harder or is leftover from a PullRequest. Needs to be adressed at some point. PR-Status: WIP Pull request is work-in-progress, more commits should be expected. PR-Status: Review Requested No more commits, PR is ready for the eyes that need to see it. feature-code-metrics labels Apr 14, 2018
Copy link
Contributor

@bclothier bclothier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; two questions.

{
internal abstract class CodeMetricResultBase : ICodeMetricResult
{
public CodeMetricResultBase(Declaration declaration, CodeMetric metric)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it weird to have a internal class that contains a public ctor?


public override IEnumerable<ICodeMetricResult> Results() => new[] { new LineCountModuleMetricResult(_finder.ModuleDeclaration(_qmn), ownerReference, workingValue) };

public override void EnterEndOfLine([NotNull] VBAParser.EndOfLineContext _) => workingValue++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we wanna to count blank and comment lines? Or better, enhance to return a struct with counts of each types Declarations, Blank, Comment line, and Module body line with a total?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ... the current design doesn't really support anything that closely coupled and rich as result type.
Most notably it can only really represent strings properly.

Each of these can be spawning their own result type though ...

@Vogel612 Vogel612 force-pushed the codeMetrics-fixes branch 2 times, most recently from bd90b4a to 32ddfda Compare April 18, 2018 21:25
@Vogel612 Vogel612 added help wanted PR-Status: Conflicting PR can't be merged as it stands, conflicts must be resolved by the author. and removed PR-Status: Review Requested No more commits, PR is ready for the eyes that need to see it. labels Apr 24, 2018
{
try
{
return (CodeMetric)Activator.CreateInstance(t, new object[] { });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda want a cleaner way than instantiating these at registration time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you not just register all the code metrics with CodeMetric? Then the collection of all of them will be registered with IEnumerable<CodeMetric>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that before, it didn't work :/

}
container.Register(Component.For<ICodeMetricsAnalyst>()
.ImplementedBy<CodeMetricsAnalyst>()
.DependsOn(Dependency.OnValue<IEnumerable<CodeMetric>>(metricImplementations))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a rare case of explicit dependency configuration. Is that okay?

@Vogel612 Vogel612 added PR-Status: Review Requested No more commits, PR is ready for the eyes that need to see it. and removed PR-Status: Conflicting PR can't be merged as it stands, conflicts must be resolved by the author. PR-Status: WIP Pull request is work-in-progress, more commits should be expected. labels Jun 4, 2018
@codecov
Copy link

codecov bot commented Jun 5, 2018

Codecov Report

Merging #3934 into next will decrease coverage by 0.16%.
The diff coverage is 38.64%.

@@            Coverage Diff            @@
##             next   #3934      +/-   ##
=========================================
- Coverage   52.96%   52.8%   -0.16%     
=========================================
  Files         955     960       +5     
  Lines       32838   32960     +122     
=========================================
+ Hits        17390   17403      +13     
- Misses      15448   15557     +109
Impacted Files Coverage Δ
...UnreachableCaseInspection/ParseTreeValueFactory.cs 100% <ø> (ø)
...ons/Results/IdentifierReferenceInspectionResult.cs 100% <ø> (ø)
...crete/ImplicitDefaultMemberAssignmentInspection.cs 5.56% <ø> (ø)
...is/Inspections/Abstract/ParseTreeInspectionBase.cs 100% <ø> (ø)
...Concrete/ApplicationWorksheetFunctionInspection.cs 100% <ø> (ø)
...QuickFixes/SpecifyExplicitByRefModifierQuickFix.cs 87.5% <ø> (ø)
...ections/Concrete/ObjectVariableNotSetInspection.cs 100% <ø> (ø)
...lysis/QuickFixes/IntroduceLocalVariableQuickFix.cs 0% <ø> (ø)
...ections/Concrete/ImplicitPublicMemberInspection.cs 100% <ø> (ø)
...ableCaseInspection/ParseTreeExpressionEvaluator.cs 92.08% <ø> (ø)
... and 158 more

@retailcoder retailcoder changed the title Code metrics moving and redesign (WIP) Code metrics moving and redesign Jun 5, 2018
@@ -53,7 +55,6 @@ private void UpdateInspectionSeverity(Configuration config)
if (inspection.Name == setting.Name)
{
inspection.Severity = setting.Severity;
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a break?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even know where this is coming from ... let me investigate that bit of change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to have been added on next with commit 459d322 ... :cough:

get => _selectedItem;
set
{
_selectedItem = value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if value == _selectedItem, we're firing extraneous PropertyChanged events here.

@@ -8,8 +9,8 @@ namespace Rubberduck.UI.CodeExplorer
[ExcludeFromCodeCoverage]
public partial class CodeExplorerWindow : UserControl, IDockableUserControl
{
private const string ClassId = "C5318B59-172F-417C-88E3-B377CDA2D809";
string IDockableUserControl.ClassId { get { return ClassId; } }
private readonly string RandomGuid = Guid.NewGuid().ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☠️ makes me wonder what the purpose of IDockableUserControl.GuidIdentifier really is... do we really need this?

{
get { return "BFD04A86-CACA-4F95-9656-A0BF7D3AE254"; }
}
private readonly string RandomGuid = Guid.NewGuid().ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do need a GUID, then why can't it be a RubberduckGuid constant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular GUID is just used as an unique identifier for an instance created by the CreateToolWindow, as per documentation for GuidPosition parameter.

{
var signature = $"{GetMethodType(member)} {member.IdentifierName}({string.Join(", ", GetMemberParameters(member))})";

return member.AsTypeName == null ? signature : $"{signature} As {member.AsTypeName}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tempted to swap As for {Tokens.As} here 😉

return new List<Parameter>();
}

if (GetMethodType(member) == "Property Get")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels wrong when the method returns $"{Tokens.Property} {Tokens.Get}", would prefer to have string interpolation here too... but why can we assume parameters.Count is >= 1 here? Most Property Get members are parameterless... 😕

@Vogel612 Vogel612 merged commit 7a2eaaf into rubberduck-vba:next Jun 7, 2018
@Vogel612 Vogel612 mentioned this pull request Jun 7, 2018
@Vogel612 Vogel612 deleted the codeMetrics-fixes branch June 12, 2018 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-code-metrics help wanted PR-Status: Review Requested No more commits, PR is ready for the eyes that need to see it. technical-debt This makes development harder or is leftover from a PullRequest. Needs to be adressed at some point.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants