Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7445429
code inspection results are displayed without a manual refresh, and r…
retailcoder Dec 29, 2015
2db56c0
added ParserState to ParseProgressEventArgs to ModuleStateChanged can…
retailcoder Dec 29, 2015
f26135e
removed junk classes, added skeleton for RefreshCommand
retailcoder Dec 29, 2015
f6ac72b
code explorer window builds and shows up... still without any content.
retailcoder Dec 30, 2015
89373c7
stashing changes
retailcoder Dec 31, 2015
2440025
made CodeExplorerCommand depend on IPresenter instead of concrete imp…
retailcoder Dec 31, 2015
b012989
Fixed reporting of error state and a bug in the collecting of module …
retailcoder Dec 31, 2015
ad50414
parser is now async only when a reparse is requested - that should he…
retailcoder Jan 5, 2016
190409e
fixed command.CanExecute; sealed inspection classes, introduced Inspe…
retailcoder Jan 10, 2016
f796e43
fixed bug with continued lines in StripLineNumbers
retailcoder Jan 10, 2016
421447c
fixed bug where renamed declaration remained in parser state
retailcoder Jan 10, 2016
838bcc4
added MultipleNamespaceDeclarationInspection
retailcoder Jan 10, 2016
266e359
moved InspectionBase to its own file, added CanIgnoreOnce virtual pro…
retailcoder Jan 10, 2016
4b1b431
implemented IgnoreOnce quickfix, added to all inspections that should…
retailcoder Jan 10, 2016
ccfbf81
fixed bug in ExecuteCopyResultsCommand implementation
retailcoder Jan 10, 2016
ed7fd66
implemented rough hierarchical templates for code explorer.
retailcoder Jan 10, 2016
283f2e2
fixed results sorting issue
retailcoder Jan 11, 2016
dadb2e4
non-nestable custom folders are now supported in Code Explorer. bette…
retailcoder Jan 11, 2016
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 RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private async void hooks_MessageReceived(object sender, HookEventArgs e)
}

var component = _vbe.ActiveCodePane.CodeModule.Parent;
_parser.ParseComponentAsync(component);
_parser.ParseComponent(component);

AwaitNextKey();
return;
Expand Down
23 changes: 8 additions & 15 deletions RetailCoder.VBE/Inspections/AssignedByValParameterInspection.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.UI;

namespace Rubberduck.Inspections
{
public class AssignedByValParameterInspection : IInspection
public sealed class AssignedByValParameterInspection : InspectionBase
{
public AssignedByValParameterInspection()
public AssignedByValParameterInspection(RubberduckParserState state)
: base(state)
{
Severity = CodeInspectionSeverity.Warning;
}

public string Name { get { return "AssignedByValParameterInspection"; } }
public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } }
public string Description { get { return RubberduckUI.ByValParameterIsAssigned_; } }
public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
public CodeInspectionSeverity Severity { get; set; }
public override string Description { get { return InspectionsUI.AssignedByValParameterInspectionName; } }
public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }

private string AnnotationName { get { return Name.Replace("Inspection", string.Empty); } }

public IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state)
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
{
var name = AnnotationName;
var assignedByValParameters =
state.AllUserDeclarations.Where(declaration => !declaration.IsInspectionDisabled(name)
&& declaration.DeclarationType == DeclarationType.Parameter
var assignedByValParameters = UserDeclarations.Where(declaration =>
declaration.DeclarationType == DeclarationType.Parameter
&& ((VBAParser.ArgContext)declaration.Context).BYVAL() != null
&& declaration.References.Any(reference => reference.IsAssignment));

Expand Down
25 changes: 24 additions & 1 deletion RetailCoder.VBE/Inspections/CodeInspectionResultBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
using Rubberduck.Parsing;
Expand Down Expand Up @@ -82,6 +83,11 @@ public QualifiedSelection QualifiedSelection

public virtual CodeInspectionQuickFix DefaultQuickFix { get { return QuickFixes.FirstOrDefault(); } }

public int CompareTo(ICodeInspectionResult other)
{
return Inspection.CompareTo(other.Inspection);
}

public override string ToString()
{
var module = QualifiedSelection.QualifiedName;
Expand All @@ -93,5 +99,22 @@ public override string ToString()
module.ComponentName,
QualifiedSelection.Selection.StartLine);
}

public int CompareTo(object obj)
{
return CompareTo(obj as ICodeInspectionResult);
}

public string ToCsvString()
{
var module = QualifiedSelection.QualifiedName;
return string.Format(
"{0}, {1}, {2}, {3}, {4}",
Inspection.Severity,
Name,
module.ProjectName,
module.ComponentName,
QualifiedSelection.Selection.StartLine);
}
}
}
16 changes: 7 additions & 9 deletions RetailCoder.VBE/Inspections/ConstantNotUsedInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@

namespace Rubberduck.Inspections
{
public class ConstantNotUsedInspection : IInspection
public sealed class ConstantNotUsedInspection : InspectionBase
{
public ConstantNotUsedInspection()
public ConstantNotUsedInspection(RubberduckParserState state)
: base(state)
{
Severity = CodeInspectionSeverity.Warning;
}

public string Name { get { return "ConstantNotUsedInspection"; } }
public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } }
public string Description { get { return RubberduckUI.ConstantNotUsed_; } }
public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
public CodeInspectionSeverity Severity { get; set; }
public override string Description { get { return RubberduckUI.ConstantNotUsed_; } }
public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }

public IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state)
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
{
var results = state.AllUserDeclarations.Where(declaration =>
var results = UserDeclarations.Where(declaration =>
declaration.DeclarationType == DeclarationType.Constant && !declaration.References.Any());

return results.Select(issue =>
Expand Down
18 changes: 8 additions & 10 deletions RetailCoder.VBE/Inspections/DefaultProjectNameInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@

namespace Rubberduck.Inspections
{
public class DefaultProjectNameInspection : IInspection
public sealed class DefaultProjectNameInspection : InspectionBase
{
private readonly ICodePaneWrapperFactory _wrapperFactory;

public DefaultProjectNameInspection()
public DefaultProjectNameInspection(RubberduckParserState state)
: base(state)
{
_wrapperFactory = new CodePaneWrapperFactory();
Severity = CodeInspectionSeverity.Suggestion;
}

public string Name { get { return "DefaultProjectNameInspection"; } }
public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } }
public string Description { get { return RubberduckUI.GenericProjectName_; } }
public CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } }
public CodeInspectionSeverity Severity { get; set; }
public override string Description { get { return RubberduckUI.GenericProjectName_; } }
public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } }

public IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state)
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
{
var issues = state.AllUserDeclarations
var issues = UserDeclarations
.Where(declaration => declaration.DeclarationType == DeclarationType.Project
&& declaration.IdentifierName.StartsWith("VBAProject"))
.Select(issue => new DefaultProjectNameInspectionResult(this, issue, state, _wrapperFactory))
.Select(issue => new DefaultProjectNameInspectionResult(this, issue, State, _wrapperFactory))
.ToList();

return issues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public DefaultProjectNameInspectionResult(IInspection inspection, Declaration ta
public class RenameProjectQuickFix : CodeInspectionQuickFix
{
private readonly Declaration _target;
private readonly RubberduckParserState _parseResult;
private readonly RubberduckParserState _state;
private readonly ICodePaneWrapperFactory _wrapperFactory;

public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory)
public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState state, ICodePaneWrapperFactory wrapperFactory)
: base(context, selection, string.Format(RubberduckUI.Rename_DeclarationType, RubberduckUI.ResourceManager.GetString("DeclarationType_" + DeclarationType.Project, RubberduckUI.Culture)))
{
_target = target;
_parseResult = parseResult;
_state = state;
_wrapperFactory = wrapperFactory;
}

Expand All @@ -49,8 +49,8 @@ public override void Fix()

using (var view = new RenameDialog())
{
var factory = new RenamePresenterFactory(vbe, view, _parseResult, new MessageBox(), _wrapperFactory);
var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), new MessageBox());
var factory = new RenamePresenterFactory(vbe, view, _state, new MessageBox(), _wrapperFactory);
var refactoring = new RenameRefactoring(factory, new ActiveCodePaneEditor(vbe, _wrapperFactory), new MessageBox(), _state);
refactoring.Refactor(_target);
}
}
Expand Down
22 changes: 9 additions & 13 deletions RetailCoder.VBE/Inspections/EmptyStringLiteralInspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@

namespace Rubberduck.Inspections
{
public class EmptyStringLiteralInspection : IInspection
public sealed class EmptyStringLiteralInspection : InspectionBase
{
public EmptyStringLiteralInspection()
public EmptyStringLiteralInspection(RubberduckParserState state)
: base(state)
{
Severity = CodeInspectionSeverity.Warning;
}

public string Name { get { return "EmptyStringLiteralInspection"; } }
public string Meta { get { return InspectionsUI.ResourceManager.GetString(Name + "Meta"); } }
public string Description { get { return InspectionsUI.EmptyStringLiteralInspection; } }
public CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } }
public CodeInspectionSeverity Severity { get; set; }
public override string Description { get { return InspectionsUI.EmptyStringLiteralInspection; } }
public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } }

public IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state)
{
return
state.EmptyStringLiterals.Select(
context =>
new EmptyStringLiteralInspectionResult(this,
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
{
return State.EmptyStringLiterals.Select(
context => new EmptyStringLiteralInspectionResult(this,
new QualifiedContext<ParserRuleContext>(context.ModuleName, context.Context)));
}
}
Expand Down
3 changes: 2 additions & 1 deletion RetailCoder.VBE/Inspections/ICodeInspectionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

namespace Rubberduck.Inspections
{
public interface ICodeInspectionResult
public interface ICodeInspectionResult : IComparable<ICodeInspectionResult>, IComparable
{
IEnumerable<CodeInspectionQuickFix> QuickFixes { get; }
CodeInspectionQuickFix DefaultQuickFix { get; }
ParserRuleContext Context { get; }
string Name { get; }
QualifiedSelection QualifiedSelection { get; }
IInspection Inspection { get; }
string ToCsvString();
}
}
9 changes: 5 additions & 4 deletions RetailCoder.VBE/Inspections/IInspection.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System.Collections.Generic;
using Rubberduck.Parsing.VBA;
using System;
using System.Collections.Generic;

namespace Rubberduck.Inspections
{
/// <summary>
/// An interface that abstracts a runnable code inspection.
/// </summary>
public interface IInspection : IInspectionModel
public interface IInspection : IInspectionModel, IComparable<IInspection>, IComparable
{
/// <summary>
/// Runs code inspection on specified parse trees.
/// </summary>
/// <returns>Returns inspection results, if any.</returns>
IEnumerable<CodeInspectionResultBase> GetInspectionResults(RubberduckParserState state);
IEnumerable<CodeInspectionResultBase> GetInspectionResults();

/// <summary>
/// Gets a string that contains additional/meta information about an inspection.
/// </summary>
string Meta { get; }

}
}
2 changes: 2 additions & 0 deletions RetailCoder.VBE/Inspections/IInspectionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface IInspectionModel
/// </summary>
string Name { get; }

string AnnotationName { get; }

/// <summary>
/// Gets a short description for the code inspection.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public IdentifierNotAssignedInspectionResult(IInspection inspection, Declaration
ParserRuleContext context, QualifiedModuleName qualifiedName)
: base(inspection, target, context, qualifiedName)
{
_quickFixes = new[]
_quickFixes = new CodeInspectionQuickFix[]
{
new RemoveUnassignedIdentifierQuickFix(Context, QualifiedSelection),
new IgnoreOnceQuickFix(context, QualifiedSelection, Inspection.AnnotationName),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ public IdentifierNotUsedInspectionResult(IInspection inspection, Declaration tar
ParserRuleContext context, QualifiedModuleName qualifiedName)
: base(inspection, string.Format(inspection.Description, target.IdentifierName), qualifiedName, context)
{
_quickFixes = new[]
_quickFixes = new CodeInspectionQuickFix[]
{
new RemoveUnusedDeclarationQuickFix(context, QualifiedSelection),
new IgnoreOnceQuickFix(context, QualifiedSelection, Inspection.AnnotationName),
};
}

Expand Down
44 changes: 44 additions & 0 deletions RetailCoder.VBE/Inspections/IgnoreOnceQuickFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Antlr4.Runtime;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor;

namespace Rubberduck.Inspections
{
public class IgnoreOnceQuickFix : CodeInspectionQuickFix
{
private readonly string _annotationText;
private readonly string _inspectionName;

public IgnoreOnceQuickFix(ParserRuleContext context, QualifiedSelection selection, string inspectionName)
: base(context, selection, InspectionsUI.IgnoreOnce)
{
_inspectionName = inspectionName;
_annotationText = "'" + Parsing.Grammar.Annotations.AnnotationMarker +
Parsing.Grammar.Annotations.IgnoreInspection + ' ' + inspectionName;
}

public override bool CanFixInModule { get { return false; } } // not quite "once" if applied to entire module
public override bool CanFixInProject { get { return false; } } // use "disable this inspection" instead of ignoring across the project

public override void Fix()
{
var codeModule = Selection.QualifiedName.Component.CodeModule;
var insertLine = Selection.Selection.StartLine;

var codeLine = insertLine == 1 ? string.Empty : codeModule.get_Lines(insertLine - 1, 1);
var annotationText = _annotationText;
var ignoreAnnotation = "'" + Parsing.Grammar.Annotations.AnnotationMarker + Parsing.Grammar.Annotations.IgnoreInspection;

int commentStart;
if (codeLine.HasComment(out commentStart) && codeLine.Substring(commentStart).StartsWith(ignoreAnnotation))
{
annotationText = codeLine + ' ' + _inspectionName;
codeModule.ReplaceLine(insertLine - 1, annotationText);
}
else
{
codeModule.InsertLines(insertLine, annotationText);
}
}
}
}
Loading