Skip to content

Commit 3d129b6

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into AddModuleCommand
2 parents a2fdffc + c08afba commit 3d129b6

25 files changed

+1007
-972
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img src="https://user-images.githubusercontent.com/5751684/46327997-aeb98d00-c5d2-11e8-9de5-ba6f9cd1eea3.png" />
1+
<img alt="yellow ducky" src="https://user-images.githubusercontent.com/5751684/48655863-2d378600-e9eb-11e8-9018-cc1454ba97f6.png" />
22

33
<!-- campaign is no longer accepting donations
44
### Donate!
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
using Rubberduck.Inspections.Abstract;
6+
using Rubberduck.Inspections.Results;
7+
using Rubberduck.Parsing.Inspections;
8+
using Rubberduck.Parsing.Inspections.Abstract;
9+
using Rubberduck.Parsing.Symbols;
10+
using Rubberduck.Parsing.VBA;
11+
using Rubberduck.Resources.Inspections;
12+
13+
namespace Rubberduck.Inspections.Inspections.Concrete
14+
{
15+
[RequiredLibrary("Excel")]
16+
public class ExcelUdfNameIsValidCellReferenceInspection : InspectionBase
17+
{
18+
public ExcelUdfNameIsValidCellReferenceInspection(RubberduckParserState state) : base(state) { }
19+
20+
private static readonly Regex ValidCellIdRegex =
21+
new Regex(@"^([a-z]|[a-z]{2}|[a-w][a-z]{2}|x([a-e][a-z]|f[a-d]))(?<Row>\d+)$",
22+
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
23+
24+
private static readonly HashSet<Accessibility> VisibleAsUdf = new HashSet<Accessibility> { Accessibility.Public, Accessibility.Implicit };
25+
26+
private const uint MaximumExcelRows = 1048576;
27+
28+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
29+
{
30+
var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");
31+
if (excel == null)
32+
{
33+
return Enumerable.Empty<IInspectionResult>();
34+
}
35+
36+
var candidates = UserDeclarations.OfType<FunctionDeclaration>().Where(decl =>
37+
decl.ParentScopeDeclaration.DeclarationType == DeclarationType.ProceduralModule &&
38+
VisibleAsUdf.Contains(decl.Accessibility));
39+
40+
return (from function in candidates.Where(decl => ValidCellIdRegex.IsMatch(decl.IdentifierName))
41+
let row = Convert.ToUInt32(ValidCellIdRegex.Matches(function.IdentifierName)[0].Groups["Row"].Value)
42+
where row > 0 && row <= MaximumExcelRows && !IsIgnoringInspectionResultFor(function, AnnotationName)
43+
select new DeclarationInspectionResult(this,
44+
string.Format(InspectionResults.ExcelUdfNameIsValidCellReferenceInspection, function.IdentifierName),
45+
function))
46+
.Cast<IInspectionResult>().ToList();
47+
}
48+
}
49+
}

Rubberduck.CodeAnalysis/QuickFixes/RenameDeclarationQuickFix.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Globalization;
22
using Rubberduck.Inspections.Abstract;
33
using Rubberduck.Inspections.Concrete;
4+
using Rubberduck.Inspections.Inspections.Concrete;
45
using Rubberduck.Interaction;
56
using Rubberduck.Parsing.Inspections.Abstract;
67
using Rubberduck.Parsing.Rewriter;
@@ -20,7 +21,11 @@ public sealed class RenameDeclarationQuickFix : QuickFixBase
2021
private readonly IMessageBox _messageBox;
2122

2223
public RenameDeclarationQuickFix(IVBE vbe, RubberduckParserState state, IMessageBox messageBox, IRewritingManager rewritingManager)
23-
: base(typeof(HungarianNotationInspection), typeof(UseMeaningfulNameInspection), typeof(DefaultProjectNameInspection), typeof(UnderscoreInPublicClassModuleMemberInspection))
24+
: base(typeof(HungarianNotationInspection),
25+
typeof(UseMeaningfulNameInspection),
26+
typeof(DefaultProjectNameInspection),
27+
typeof(UnderscoreInPublicClassModuleMemberInspection),
28+
typeof(ExcelUdfNameIsValidCellReferenceInspection))
2429
{
2530
_vbe = vbe;
2631
_state = state;

Rubberduck.Core/Properties/Settings.Designer.cs

Lines changed: 300 additions & 285 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Core/Properties/Settings.settings

Lines changed: 257 additions & 236 deletions
Large diffs are not rendered by default.

Rubberduck.Core/Rubberduck.Core.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,17 @@
8181
<Version>2.0.20525</Version>
8282
</PackageReference>
8383
</ItemGroup>
84+
<ItemGroup>
85+
<Compile Update="Properties\Settings.Designer.cs">
86+
<DesignTime>True</DesignTime>
87+
<AutoGen>True</AutoGen>
88+
<DependentUpon>Settings.settings</DependentUpon>
89+
</Compile>
90+
</ItemGroup>
91+
<ItemGroup>
92+
<None Update="Properties\Settings.settings">
93+
<Generator>SettingsSingleFileGenerator</Generator>
94+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
95+
</None>
96+
</ItemGroup>
8497
</Project>

Rubberduck.Core/UI/Command/FindAllImplementationsCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,15 @@ private SearchResultsViewModel CreateViewModel(Declaration target)
180180
new NavigateCodeEventArgs(declaration.QualifiedName.QualifiedModuleName, declaration.Selection),
181181
GetModuleLine(declaration.QualifiedName.QualifiedModuleName, declaration.Selection.StartLine)));
182182

183+
var accessor = target.DeclarationType.HasFlag(DeclarationType.PropertyGet) ? "(get)"
184+
: target.DeclarationType.HasFlag(DeclarationType.PropertyLet) ? "(let)"
185+
: target.DeclarationType.HasFlag(DeclarationType.PropertySet) ? "(set)"
186+
: string.Empty;
187+
188+
var tabCaption = $"{target.IdentifierName} {accessor}".Trim();
189+
183190
var viewModel = new SearchResultsViewModel(_navigateCommand,
184-
string.Format(RubberduckUI.SearchResults_AllImplementationsTabFormat, target.IdentifierName), target, results);
191+
string.Format(RubberduckUI.SearchResults_AllImplementationsTabFormat, tabCaption), target, results);
185192

186193
return viewModel;
187194
}

Rubberduck.Core/UI/Command/FindAllReferencesCommand.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,17 @@ private SearchResultsViewModel CreateViewModel(Declaration declaration)
169169
reference.ParentNonScoping,
170170
new NavigateCodeEventArgs(reference.QualifiedModuleName, reference.Selection),
171171
GetModuleLine(reference.QualifiedModuleName, reference.Selection.StartLine)));
172-
172+
173+
var accessor = declaration.DeclarationType.HasFlag(DeclarationType.PropertyGet) ? "(get)"
174+
: declaration.DeclarationType.HasFlag(DeclarationType.PropertyLet) ? "(let)"
175+
: declaration.DeclarationType.HasFlag(DeclarationType.PropertySet) ? "(set)"
176+
: string.Empty;
177+
178+
var tabCaption = $"{declaration.IdentifierName} {accessor}".Trim();
179+
180+
173181
var viewModel = new SearchResultsViewModel(_navigateCommand,
174-
string.Format(RubberduckUI.SearchResults_AllReferencesTabFormat, declaration.IdentifierName), declaration, results);
182+
string.Format(RubberduckUI.SearchResults_AllReferencesTabFormat, tabCaption), declaration, results);
175183

176184
return viewModel;
177185
}

0 commit comments

Comments
 (0)