Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Apr 24, 2021
2 parents fce9740 + 0c493cb commit 695fea0
Show file tree
Hide file tree
Showing 59 changed files with 433 additions and 250 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
@@ -0,0 +1,13 @@
[*.cs]

# CS1584: XML comment has syntactically incorrect cref attribute
dotnet_diagnostic.CS1584.severity = none

# CS1041: expected identifier, invalid keyword
dotnet_diagnostic.CS1041.severity = none

# CS1658: Warning is overriding an error
dotnet_diagnostic.CS1658.severity = none

# IDE0079: Remove unnecessary suppression
dotnet_diagnostic.IDE0079.severity = none
Expand Up @@ -35,6 +35,8 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
/// value = otherVar * value
/// End Sub
/// ]]>
/// </module>
/// </example>
/// <example hasResult="true">
/// <module name="Module1" type="Standard Module">
/// <![CDATA[
Expand Down Expand Up @@ -204,7 +206,7 @@ private static bool IsPotentiallyUsedViaJump(IdentifierReference resultCandidate

private static bool IsPotentiallyUsedAssignment<T>(T jumpContext, IdentifierReference resultCandidate, Dictionary<string, int> labelIdLineNumberPairs) where T : ParserRuleContext
{
int? executionBranchLine = null;
int? executionBranchLine;

switch (jumpContext)
{
Expand All @@ -219,9 +221,7 @@ private static bool IsPotentiallyUsedViaJump(IdentifierReference resultCandidate
break;
}

return executionBranchLine.HasValue
? AssignmentIsUsedPriorToExitStmts(resultCandidate, executionBranchLine.Value)
: false;
return executionBranchLine.HasValue && AssignmentIsUsedPriorToExitStmts(resultCandidate, executionBranchLine.Value);
}

private static bool AssignmentIsUsedPriorToExitStmts(IdentifierReference resultCandidate, int executionBranchLine)
Expand Down
Expand Up @@ -9,11 +9,11 @@
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls inside worksheet modules.
/// Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls implicitly referring to ActiveSheet.
/// </summary>
/// <reference name="Excel" />
/// <why>
/// Implicit references to the active worksheet rarely mean to be working with *whatever worksheet is currently active*.
/// Implicit references to the active worksheet (ActiveSheet) rarely mean to be working with *whatever worksheet is currently active*.
/// By explicitly qualifying these member calls with a specific Worksheet object, the assumptions are removed, the code
/// is more robust, and will be less likely to throw run-time error 1004 or produce unexpected results
/// when the active sheet isn't the expected one.
Expand Down
Expand Up @@ -13,12 +13,12 @@
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// Locates unqualified Workbook.Worksheets/Sheets/Names member calls inside workbook document modules that implicitly refer to the containing workbook.
/// Locates unqualified Workbook.Worksheets/Sheets/Names member calls inside workbook document modules, that implicitly refer to the host workbook.
/// </summary>
/// <reference name="Excel" />
/// <hostApp name="Excel" />
/// <why>
/// Implicit references inside a workbook document module can be mistakes for implicit references to the active workbook, which is the behavior in all other modules
/// By explicitly qualifying these member calls with Me, the ambiguity can be resolved.
/// Implicit references inside a workbook document module can easily be mistaken for implicit references to the active workbook (ActiveWorkbook), which is the behavior in all other module types.
/// By explicitly qualifying these member calls with 'Me', the ambiguity can be resolved. If the intent is to actually refer to the active workbook, qualify with 'ActiveWorkbook' to prevent a bug.
/// </why>
/// <example hasResult="true">
/// <module name="ThisWorkbook" type="Document Module">
Expand All @@ -40,7 +40,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
/// ]]>
/// </module>
/// </example>
[RequiredLibrary("Excel")]
[RequiredHost("Excel")]
internal sealed class ImplicitContainingWorkbookReferenceInspection : ImplicitWorkbookReferenceInspectionBase
{
public ImplicitContainingWorkbookReferenceInspection(IDeclarationFinderProvider declarationFinderProvider)
Expand Down
Expand Up @@ -10,12 +10,12 @@
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls inside worksheet modules that implicitly refer to the containing sheet.
/// Locates unqualified Worksheet.Range/Cells/Columns/Rows member calls inside worksheet modules, that implicitly refer to the containing sheet component.
/// </summary>
/// <reference name="Excel" />
/// <hostApp name="Excel" />
/// <why>
/// Implicit references inside a worksheet document module can be mistakes for implicit references to the active worksheet, which is the behavior in all other places.
/// By explicitly qualifying these member calls with Me, the ambiguity can be resolved.
/// Implicit references inside a worksheet document module can easily be mistaken for implicit references to the active worksheet (ActiveSheet), which is the behavior in all other module types.
/// By explicitly qualifying these member calls with 'Me', the ambiguity can be resolved. If the intent is to refer to the active worksheet, qualify with 'ActiveSheet' to prevent a bug.
/// </why>
/// <example hasResult="true">
/// <module name="Sheet1" type="Document Module">
Expand All @@ -37,7 +37,7 @@ namespace Rubberduck.CodeAnalysis.Inspections.Concrete
/// ]]>
/// </module>
/// </example>
[RequiredLibrary("Excel")]
[RequiredHost("Excel")]
internal sealed class ImplicitContainingWorksheetReferenceInspection : ImplicitSheetReferenceInspectionBase
{
public ImplicitContainingWorksheetReferenceInspection(IDeclarationFinderProvider declarationFinderProvider)
Expand Down
Expand Up @@ -222,7 +222,7 @@ public InvalidAnnotationInspection(IDeclarationFinderProvider declarationFinderP
{
return GetUnboundAnnotations(annotations, userDeclarations, identifierReferences)
.Where(pta => !pta.Annotation.Target.HasFlag(AnnotationTarget.General) || pta.AnnotatedLine == null)
.Concat(AttributeAnnotationsOnDeclarationsNotAllowingAttributes(annotations, userDeclarations, identifierReferences))
.Concat(AttributeAnnotationsOnDeclarationsNotAllowingAttributes(userDeclarations))
.ToList();
}

Expand All @@ -241,10 +241,7 @@ public InvalidAnnotationInspection(IDeclarationFinderProvider declarationFinderP
.Where(pta => pta.Annotation.GetType() != typeof(NotRecognizedAnnotation) && !boundAnnotationsSelections.Contains(pta.QualifiedSelection));
}

private IEnumerable<IParseTreeAnnotation> AttributeAnnotationsOnDeclarationsNotAllowingAttributes(
IEnumerable<IParseTreeAnnotation> annotations,
IEnumerable<Declaration> userDeclarations,
IEnumerable<IdentifierReference> identifierReferences)
private IEnumerable<IParseTreeAnnotation> AttributeAnnotationsOnDeclarationsNotAllowingAttributes(IEnumerable<Declaration> userDeclarations)
{
return userDeclarations
.Where(declaration => declaration.AttributesPassContext == null
Expand Down
Expand Up @@ -193,8 +193,7 @@ private static VBAParser.LiteralExpressionContext SheetNameArgumentLiteralExpres
private string CodeNameOfVBComponentMatchingSheetName(string projectId, string sheetName)
{
var components = _projectsProvider.Components(projectId);

foreach (var (module, component) in components)
foreach (var (_, component) in components)
{
if (component.Type != ComponentType.Document)
{
Expand Down
Expand Up @@ -36,9 +36,9 @@ internal struct Limit<T> where T : IComparable<T>

public static bool operator !=(Limit<T> LHS, Limit<T> RHS) => !(LHS == RHS);

public static bool operator >(Limit<T> LHS, T RHS) => LHS.HasValue ? LHS.Value.CompareTo(RHS) > 0 : false;
public static bool operator >(Limit<T> LHS, T RHS) => LHS.HasValue && LHS.Value.CompareTo(RHS) > 0;

public static bool operator <(Limit<T> LHS, T RHS) => LHS.HasValue? LHS.Value.CompareTo(RHS) < 0 : false;
public static bool operator <(Limit<T> LHS, T RHS) => LHS.HasValue && LHS.Value.CompareTo(RHS) < 0;

public static bool operator >=(Limit<T> LHS, Limit<T> RHS) => LHS == RHS || LHS > RHS;

Expand Down Expand Up @@ -106,7 +106,7 @@ public void SetExtents(T min, T max)

public bool SetMinimum(T min)
{
var setNewValue = false;
bool setNewValue;
if (_min.HasValue)
{
setNewValue = min.CompareTo(_min.Value) > 0;
Expand All @@ -123,7 +123,7 @@ public bool SetMinimum(T min)

public bool SetMaximum(T max)
{
var setNewValue = false;
bool setNewValue;
if (_max.HasValue)
{
setNewValue = max.CompareTo(_max.Value) < 0;
Expand Down Expand Up @@ -195,20 +195,22 @@ public override bool Equals(object obj)
return true;
}

public override int GetHashCode() => VBEditor.HashCode.Compute(Minimum, Maximum);

public override string ToString()
{
var minString = string.Empty;
var maxString = string.Empty;
if (_min.HasValue)
{
minString = MinimumExtent.HasValue && _min == MinimumExtent
? $"Min(typeMin)" : $"Min({_min.ToString()})";
? $"Min(typeMin)" : $"Min({_min})";
}

if (_max.HasValue)
{
maxString = MaximumExtent.HasValue && _max == MaximumExtent
? $"Max(typeMax)" : $"Max({_max.ToString()})";
? $"Max(typeMax)" : $"Max({_max})";
}
return $"{minString}{maxString}";
}
Expand Down
Expand Up @@ -225,7 +225,7 @@ private string GetBaseTypeForDeclaration(Declaration declaration)
VBAParser.SelectCaseStmtContext selectStmt,
IParseTreeVisitorResults parseTreeValues)
{
var (typeName, value) = SelectExpressionTypeNameAndValue(selectStmt, parseTreeValues);
var (typeName, _) = SelectExpressionTypeNameAndValue(selectStmt, parseTreeValues);
return typeName;
}

Expand Down
Expand Up @@ -132,8 +132,8 @@ public override string Description(IInspectionResult result)
public override bool CanFixInProject => true;
public override bool CanFixAll => true;

private string NonIdentifierCharacters = "[](){}\r\n\t.,'\"\\ |!@#$%^&*-+:=; ";
private string AdditionalNonFirstIdentifierCharacters = "0123456789_";
private readonly string NonIdentifierCharacters = "[](){}\r\n\t.,'\"\\ |!@#$%^&*-+:=; ";
private readonly string AdditionalNonFirstIdentifierCharacters = "0123456789_";

private static readonly Dictionary<string, string> DefaultMemberOverrides = new Dictionary<string, string>
{
Expand Down
Expand Up @@ -51,7 +51,7 @@ public override string NameWithSignature
}

public override bool IsObsolete =>
Declaration.Annotations.Any(annotation => annotation is ObsoleteAnnotation);
Declaration.Annotations.Any(pta => pta.Annotation is ObsoleteAnnotation);

public static readonly DeclarationType[] SubMemberTypes =
{
Expand Down
29 changes: 27 additions & 2 deletions Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs
Expand Up @@ -39,13 +39,15 @@ public enum CodeExplorerSortOrder
public sealed class CodeExplorerViewModel : ViewModelBase
{
// ReSharper disable NotAccessedField.Local - The settings providers aren't used, but several enhancement requests will need them.
#pragma warning disable IDE0052 // Remove unread private members
private readonly RubberduckParserState _state;
private readonly RemoveCommand _externalRemoveCommand;
private readonly IConfigurationService<GeneralSettings> _generalSettingsProvider;
private readonly IConfigurationService<GeneralSettings> _generalSettingsProvider;
private readonly IConfigurationService<WindowSettings> _windowSettingsProvider;
private readonly IUiDispatcher _uiDispatcher;
private readonly IVBE _vbe;
private readonly ITemplateProvider _templateProvider;
#pragma warning restore IDE0052 // Remove unread private members
// ReSharper restore NotAccessedField.Local

public CodeExplorerViewModel(
Expand Down Expand Up @@ -77,6 +79,8 @@ public sealed class CodeExplorerViewModel : ViewModelBase
CollapseAllSubnodesCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseNodes, EvaluateCanSwitchNodeState);
ExpandAllSubnodesCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandNodes, EvaluateCanSwitchNodeState);
ClearSearchCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteClearSearchCommand);
CollapseAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseAllCommand);
ExpandAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandAllCommand);
if (_externalRemoveCommand != null)
{
RemoveCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRemoveCommand, _externalRemoveCommand.CanExecute);
Expand All @@ -92,7 +96,9 @@ public sealed class CodeExplorerViewModel : ViewModelBase

public ObservableCollection<ICodeExplorerNode> Projects { get; } = new ObservableCollection<ICodeExplorerNode>();

#pragma warning disable IDE1006 // Naming Styles
private ObservableCollection<Template> templates => _templateProvider.GetTemplates();
#pragma warning restore IDE1006 // Naming Styles

public ObservableCollection<Template> BuiltInTemplates =>
new ObservableCollection<Template>(templates.Where(t => !t.IsUserDefined)
Expand Down Expand Up @@ -345,6 +351,22 @@ private void ExecuteClearSearchCommand(object parameter)
}
}

private void ExecuteCollapseAllCommand(object parameter)
{
foreach (var project in Projects)
{
ExecuteCollapseNodes(project);
}
}

private void ExecuteExpandAllCommand(object parameter)
{
foreach (var project in Projects)
{
ExecuteExpandNodes(project);
}
}

private bool EvaluateCanSwitchNodeState(object parameter)
{
return SelectedItem?.Children?.Any() ?? false;
Expand Down Expand Up @@ -420,7 +442,10 @@ private void ExecuteRemoveCommand(object param)

public CodeExplorerMoveToFolderDragAndDropCommand MoveToFolderDragAndDropCommand { get; set; }

public ICodeExplorerNode FindVisibleNodeForDeclaration(Declaration declaration)
public CommandBase CollapseAllCommand { get; }
public CommandBase ExpandAllCommand { get; }

public ICodeExplorerNode FindVisibleNodeForDeclaration(Declaration declaration)
{
if (declaration == null)
{
Expand Down
24 changes: 13 additions & 11 deletions Rubberduck.Core/Refactorings/ExtractMethod/ExtractMethodModel.cs
Expand Up @@ -60,14 +60,15 @@ public static class IEnumerableExt

public class ExtractMethodModel : IExtractMethodModel
{
private List<Declaration> _extractDeclarations;
private IExtractMethodParameterClassification _paramClassify;
private IExtractedMethod _extractedMethod;
private readonly List<Declaration> _extractDeclarations = new List<Declaration>();
private readonly IExtractMethodParameterClassification _paramClassify;
private readonly IExtractedMethod _extractedMethod;

public ExtractMethodModel(IExtractedMethod extractedMethod, IExtractMethodParameterClassification paramClassify)
{
_extractedMethod = extractedMethod;
_paramClassify = paramClassify;
_sourceMember = null;
}

public void extract(IEnumerable<Declaration> declarations, QualifiedSelection selection, string selectedCode)
Expand Down Expand Up @@ -101,7 +102,7 @@ public void extract(IEnumerable<Declaration> declarations, QualifiedSelection se
}
_declarationsToMove = _paramClassify.DeclarationsToMove.ToList();

_rowsToRemove = splitSelection(selection.Selection, _declarationsToMove).ToList();
_rowsToRemove = SplitSelection(selection.Selection, _declarationsToMove).ToList();

var methodCallPositionStartLine = selectionStartLine - _declarationsToMove.Count(d => d.Selection.StartLine < selectionStartLine);
_positionForMethodCall = new Selection(methodCallPositionStartLine, 1, methodCallPositionStartLine, 1);
Expand Down Expand Up @@ -136,7 +137,7 @@ private static Declaration FindSelectedDeclaration(IEnumerable<Declaration> decl
return declaration;
}

public IEnumerable<Selection> splitSelection(Selection selection, IEnumerable<Declaration> declarations)
public IEnumerable<Selection> SplitSelection(Selection selection, IEnumerable<Declaration> declarations)
{
var tupleList = new List<Tuple<int, int>>();
var declarationRows = declarations
Expand All @@ -152,7 +153,7 @@ public IEnumerable<Selection> splitSelection(Selection selection, IEnumerable<De
return returnList;
}

private Declaration _sourceMember;
private readonly Declaration _sourceMember;
public Declaration SourceMember { get { return _sourceMember; } }

private QualifiedSelection _selection;
Expand All @@ -161,15 +162,15 @@ public IEnumerable<Selection> splitSelection(Selection selection, IEnumerable<De
private string _selectedCode;
public string SelectedCode { get { return _selectedCode; } }

private List<Declaration> _locals;
private readonly List<Declaration> _locals = new List<Declaration>();
public IEnumerable<Declaration> Locals { get { return _locals; } }

private IEnumerable<ExtractedParameter> _input;
private readonly IEnumerable<ExtractedParameter> _input = new List<ExtractedParameter>();
public IEnumerable<ExtractedParameter> Inputs { get { return _input; } }
private IEnumerable<ExtractedParameter> _output;
private readonly IEnumerable<ExtractedParameter> _output = new List<ExtractedParameter>();
public IEnumerable<ExtractedParameter> Outputs { get { return _output; } }

private List<Declaration> _declarationsToMove;
private List<Declaration> _declarationsToMove = new List<Declaration>();
public IEnumerable<Declaration> DeclarationsToMove { get { return _declarationsToMove; } }

public IExtractedMethod Method { get { return _extractedMethod; } }
Expand All @@ -181,7 +182,8 @@ public IEnumerable<Selection> splitSelection(Selection selection, IEnumerable<De

private Selection _positionForNewMethod;
public Selection PositionForNewMethod { get { return _positionForNewMethod; } }
IList<Selection> _rowsToRemove;

private IList<Selection> _rowsToRemove;
public IEnumerable<Selection> RowsToRemove
{
// we need to split selectionToRemove around any declarations that
Expand Down

0 comments on commit 695fea0

Please sign in to comment.