Skip to content

Commit a4ff0ec

Browse files
committed
Merge branch 'next' into RefactoringDialogRefactor
2 parents 0703ac8 + 406bbb0 commit a4ff0ec

File tree

464 files changed

+11803
-9801
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

464 files changed

+11803
-9801
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ Our Ducky has come quite the long way and is intimidatingly large for a first-ti
6161
To make it easier to find something you can do, all issues with that label are additionally labelled with a difficulty.
6262
That difficulty level is a best-guess by the dev-team how complex or evil an issue will be.
6363

64-
If you're new to C#, we recommend you start with \[difficulty-01-duckling\]. The next step \[difficulty-02-ducky\] requires some knowledge about C#, but not so much about how Rubberduck works
64+
If you're new to C#, we recommend you start with \[difficulty-01-duckling\]. The next step \[difficulty-02-ducky\] requires some knowledge about C#, but not so much about how Rubberduck works - 02/ducky issues usually make a good introduction to using Rubberduck's internal API.
6565

66-
Then there's \[difficulty-03-duck\] which requires a good handle on C# and at least an idea of how the components of Rubberduck play toghether.
66+
Then there's \[difficulty-03-duck\] which requires a good handle on C# and how the components of Rubberduck play toghether.
6767
And finally there's \[difficulty-04-quackhead\] for when you really want to bang your head against the wall.
68-
They require both good knowledge of C# and a deep understanding of how Rubberduck works.
68+
They require both good knowledge of C# and a deep understanding of how not only Rubberduck, but also COM and well, the VBE, works.
6969

7070
In addition to this, a few people have put together some helpful resources about how Rubberduck works internally and help contributors tell left from right in the ~250k Lines of Code.
7171

72-
You can find their work in the [github wiki](https://github.com/rubberduck-vba/Rubberduck/wiki). If something in there doesn't quite seem to match, it's probably because nobody got around to updating it yet. You're very welcome to **improve** the wiki by adding and correcting information. (see right above)
72+
You can find their work in the [GitHub wiki](https://github.com/rubberduck-vba/Rubberduck/wiki). If something in there doesn't quite seem to match, it's probably because nobody got around to updating it yet. You're very welcome to **improve** the wiki by adding and correcting information. (see right above)
7373

7474
In case this doesn't quite help you or the information you need hasn't been added to the wiki, you can **always** ask questions.
7575
Please do so in the ["War room"](https://chat.stackexchange.com/rooms/14929).
@@ -79,21 +79,21 @@ Other than that, you can also open an issue with the label \[support\], but it m
7979
In that room the core team talks about the duck and whatever else comes up.
8080
N.B.: The rules of the Stack Exchange Network apply to everything you say in that room. But basically those are the same rules as those in the [CoC](#Code_of_Conduct).
8181

82-
Whether you create an issue or a pull request, please avoid using `[` square brackets `]` in the title, and try to be as descriptive (but succinct) as possible. Square brackets in titles confuse our chat-bot, and end up rendering in weird broken ways in SE chat. Avoid riddles, bad puns and other would-be funny (or NSFW) titles that don't really describe the issue or PR.
82+
Whether you create an issue or a pull request, please avoid using `[` square brackets `]` in the title, and try to be as descriptive (but succinct) as possible. Square brackets in titles confuse our chat-bot, and end up rendering in weird broken ways in SE chat. Avoid riddles, bad puns and other would-be funny (or NSFW) titles that don't really *describe the issue or PR*.
8383

8484
### Translations
8585

86-
Rubberduck is Localized in multiple languages.
86+
Rubberduck is localized in multiple languages.
8787
All these translations have been provided by volunteers.
8888
We welcome both new translations as well as improvements to current translations very much.
8989

90-
The resource files are RESX/XML files easily editable in any text editor, but comparing resource keys across languages/translations is much easier done with @Vogel612's [Translation Helper](https://github.com/Vogel612/TranslationHelper) tool, which automatically adds missing keys and highlights entries that need a new translation.
90+
The resource files are RESX/XML files easily editable in any text editor, but our recommendation goes to the [ResXManager](https://marketplace.visualstudio.com/items?itemName=TomEnglert.ResXManager) Visual Studio plug-in:
9191

92-
If you contribute a translation for a brand new previously unsupported language, keep in touch with the dev team so that new resource keys can be translated when a new release is coming up; abandoned languages/translations will end up getting dropped.
92+
![ResXManager in Visual Studio](https://user-images.githubusercontent.com/5751684/48683625-1a07f000-eb7c-11e8-914a-10ed80e85e29.png)
93+
94+
If you contribute a translation for a brand new previously unsupported language, please keep in touch with the dev team so that new resource keys can be translated when a new release is coming up; abandoned languages/translations will end up getting dropped.
9395

9496
## What comes out of it for me?
9597

96-
Well ... the eternal gratitude of all Rubberduck users for one :wink:
98+
Well... the eternal gratitude of all Rubberduck users for one :wink:
9799
Aside from that, all contributors are explicitly listed by name (or alias) in the "About Rubberduck" window.
98-
99-
We ran a [fundraiser](https://gofundme.com/rubberduckvba) last summer, and had t-sihrts, mugs, pens, and stickers made - the goods are now unfortunately depleted; we'll probably run another campaign next year!

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<img src="https://user-images.githubusercontent.com/5751684/46327997-aeb98d00-c5d2-11e8-9de5-ba6f9cd1eea3.png" />
2-
1+
<img alt="Rubberduck Open-Source VBE Add-In - VBA6 | VBA7 x86/x64 | VB6" src="https://user-images.githubusercontent.com/5751684/48656196-a507af80-e9ef-11e8-9c09-1ce3c619c019.png" />
2+
33
<!-- campaign is no longer accepting donations
44
### Donate!
55

Rubberduck.API/Rubberduck.API.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Sdk="Microsoft.NET.Sdk">
2+
<Project Sdk="Sunburst.NET.Sdk.WPF/1.0.47">
33
<PropertyGroup>
44
<Product>Rubberduck.API</Product>
55
<Description>Rubberduck Reflection API</Description>

Rubberduck.API/VBA/Parser.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
using System.Linq;
66
using System.Runtime.InteropServices;
77
using System.Threading;
8-
using Rubberduck.Common;
98
using Rubberduck.Parsing.ComReflection;
109
using Rubberduck.Parsing.PreProcessing;
1110
using Rubberduck.Parsing.Rewriter;
1211
using Rubberduck.Parsing.Symbols.DeclarationLoaders;
1312
using Rubberduck.Parsing.VBA;
14-
using Rubberduck.Parsing.Symbols;
1513
using Rubberduck.Parsing.UIContext;
1614
using Rubberduck.Parsing.VBA.ComReferenceLoading;
1715
using Rubberduck.Parsing.VBA.DeclarationCaching;
@@ -69,10 +67,10 @@ public interface IParserEvents
6967
]
7068
public sealed class Parser : IParser, IDisposable
7169
{
72-
private RubberduckParserState _state;
73-
private SynchronousParseCoordinator _parser;
74-
private IVBE _vbe;
75-
private IVBEEvents _vbeEvents;
70+
private readonly RubberduckParserState _state;
71+
private readonly SynchronousParseCoordinator _parser;
72+
private readonly IVBE _vbe;
73+
private readonly IVBEEvents _vbeEvents;
7674
private readonly IUiDispatcher _dispatcher;
7775
private readonly CancellationTokenSource _tokenSource;
7876

@@ -98,8 +96,6 @@ internal Parser(object vbe) : this()
9896
var projectRepository = new ProjectsRepository(_vbe);
9997
_state = new RubberduckParserState(_vbe, projectRepository, declarationFinderFactory, _vbeEvents);
10098
_state.StateChanged += _state_StateChanged;
101-
102-
var sourceFileHandler = _vbe.TempSourceFileHandler;
10399
var vbeVersion = double.Parse(_vbe.Version, CultureInfo.InvariantCulture);
104100
var predefinedCompilationConstants = new VBAPredefinedCompilationConstants(vbeVersion);
105101
var typeLibProvider = new TypeLibWrapperProvider(projectRepository);
@@ -112,7 +108,6 @@ internal Parser(object vbe) : this()
112108
var mainTokenStreamParser = new VBATokenStreamParser(mainParseErrorListenerFactory, mainParseErrorListenerFactory);
113109
var tokenStreamProvider = new SimpleVBAModuleTokenStreamProvider();
114110
var stringParser = new TokenStreamParserStringParserAdapterWithPreprocessing(tokenStreamProvider, mainTokenStreamParser, preprocessor);
115-
var attributesSourceCodeHandler = new SourceFileHandlerSourceCodeHandlerAdapter(sourceFileHandler, projectRepository);
116111
var projectManager = new RepositoryProjectManager(projectRepository);
117112
var moduleToModuleReferenceManager = new ModuleToModuleReferenceManager();
118113
var parserStateManager = new ParserStateManager(_state);
@@ -133,14 +128,12 @@ internal Parser(object vbe) : this()
133128
}
134129
);
135130
var codePaneSourceCodeHandler = new CodePaneSourceCodeHandler(projectRepository);
136-
var moduleRewriterFactory = new ModuleRewriterFactory(
137-
codePaneSourceCodeHandler,
138-
attributesSourceCodeHandler);
131+
var sourceFileHandler = _vbe.TempSourceFileHandler;
132+
var attributesSourceCodeHandler = new SourceFileHandlerSourceCodeHandlerAdapter(sourceFileHandler, projectRepository);
139133
var moduleParser = new ModuleParser(
140134
codePaneSourceCodeHandler,
141135
attributesSourceCodeHandler,
142-
stringParser,
143-
moduleRewriterFactory);
136+
stringParser);
144137
var parseRunner = new ParseRunner(
145138
_state,
146139
parserStateManager,
@@ -235,6 +228,9 @@ public void Dispose()
235228
}
236229

237230
_disposed = true;
231+
_parser?.Dispose();
232+
_vbe?.Dispose();
233+
_tokenSource.Dispose();
238234
}
239235
}
240236
}

Rubberduck.CodeAnalysis/Inspections/Abstract/QuickFixBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
using System.Linq;
44
using NLog;
55
using Rubberduck.Parsing.Inspections.Abstract;
6-
using Rubberduck.Parsing.VBA;
6+
using Rubberduck.Parsing.Rewriter;
77
using Rubberduck.Parsing.VBA.Extensions;
8+
using Rubberduck.Parsing.VBA.Parsing;
89

910
namespace Rubberduck.Inspections.Abstract
1011
{
@@ -39,7 +40,9 @@ public void RemoveInspections(params Type[] inspections)
3940
_supportedInspections = _supportedInspections.Except(inspections).ToHashSet();
4041
}
4142

42-
public abstract void Fix(IInspectionResult result);
43+
public virtual CodeKind TargetCodeKind => CodeKind.CodePaneCode;
44+
45+
public abstract void Fix(IInspectionResult result, IRewriteSession rewriteSession);
4346
public abstract string Description(IInspectionResult result);
4447

4548
public abstract bool CanFixInProcedure { get; }

Rubberduck.CodeAnalysis/Inspections/Concrete/AssignmentNotUsedInspection.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using Rubberduck.Inspections.CodePathAnalysis.Extensions;
88
using System.Linq;
99
using Rubberduck.Inspections.Results;
10+
using Rubberduck.Parsing;
11+
using Rubberduck.Parsing.Grammar;
1012

1113
namespace Rubberduck.Inspections.Concrete
1214
{
@@ -21,7 +23,9 @@ public AssignmentNotUsedInspection(RubberduckParserState state, Walker walker)
2123

2224
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2325
{
24-
var variables = State.DeclarationFinder.UserDeclarations(DeclarationType.Variable);
26+
var variables = State.DeclarationFinder
27+
.UserDeclarations(DeclarationType.Variable)
28+
.Where(d => !d.IsArray);
2529

2630
var nodes = new List<IdentifierReference>();
2731
foreach (var variable in variables)
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/Inspections/Concrete/FunctionReturnValueNotUsedInspection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2828
var interfaceImplementationMembers = State.DeclarationFinder.FindAllInterfaceImplementingMembers();
2929
var functions = State.DeclarationFinder
3030
.UserDeclarations(DeclarationType.Function)
31-
.Where(item => !IsIgnoringInspectionResultFor(item, AnnotationName))
31+
.Where(item => !IsIgnoringInspectionResultFor(item, AnnotationName) &&
32+
item.References.Any(r => !IsReturnStatement(item, r) && !r.IsAssignment))
3233
.ToList();
3334
var interfaceMemberIssues = GetInterfaceMemberIssues(interfaceMembers);
3435
var nonInterfaceFunctions = functions.Except(interfaceMembers.Union(interfaceImplementationMembers));

Rubberduck.CodeAnalysis/Inspections/Concrete/IllegalAnnotationInspection.cs

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@ public IllegalAnnotationInspection(RubberduckParserState state)
2020

2121
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
2222
{
23-
var illegalAnnotations = new List<IAnnotation>();
24-
2523
var userDeclarations = State.DeclarationFinder.AllUserDeclarations.ToList();
2624
var identifierReferences = State.DeclarationFinder.AllIdentifierReferences().ToList();
2725
var annotations = State.AllAnnotations;
2826

29-
illegalAnnotations.AddRange(UnboundAnnotations(annotations, userDeclarations, identifierReferences));
30-
illegalAnnotations.AddRange(NonIdentifierAnnotationsOnIdentifiers(identifierReferences));
31-
illegalAnnotations.AddRange(NonModuleAnnotationsOnModules(userDeclarations));
32-
illegalAnnotations.AddRange(NonMemberAnnotationsOnMembers(userDeclarations));
33-
illegalAnnotations.AddRange(NonVariableAnnotationsOnVariables(userDeclarations));
34-
illegalAnnotations.AddRange(NonGeneralAnnotationsWhereOnlyGeneralAnnotationsBelong(userDeclarations));
27+
var illegalAnnotations = UnboundAnnotations(annotations, userDeclarations, identifierReferences)
28+
.Where(annotation => !annotation.AnnotationType.HasFlag(AnnotationType.GeneralAnnotation));
3529

3630
return illegalAnnotations.Select(annotation =>
3731
new QualifiedContextInspectionResult(
@@ -50,64 +44,5 @@ private static ICollection<IAnnotation> UnboundAnnotations(IEnumerable<IAnnotati
5044

5145
return annotations.Where(annotation => !boundAnnotationsSelections.Contains(annotation.QualifiedSelection)).ToList();
5246
}
53-
54-
private static ICollection<IAnnotation> NonIdentifierAnnotationsOnIdentifiers(IEnumerable<IdentifierReference> identifierReferences)
55-
{
56-
return identifierReferences
57-
.SelectMany(reference => reference.Annotations)
58-
.Where(annotation => !annotation.AnnotationType.HasFlag(AnnotationType.IdentifierAnnotation))
59-
.ToList();
60-
}
61-
62-
private static ICollection<IAnnotation> NonModuleAnnotationsOnModules(IEnumerable<Declaration> userDeclarations)
63-
{
64-
return userDeclarations
65-
.Where(declaration => declaration.DeclarationType.HasFlag(DeclarationType.Module))
66-
.SelectMany(moduleDeclaration => moduleDeclaration.Annotations)
67-
.Where(annotation => !annotation.AnnotationType.HasFlag(AnnotationType.ModuleAnnotation))
68-
.ToList();
69-
}
70-
71-
private static ICollection<IAnnotation> NonMemberAnnotationsOnMembers(IEnumerable<Declaration> userDeclarations)
72-
{
73-
return userDeclarations
74-
.Where(declaration => declaration.DeclarationType.HasFlag(DeclarationType.Member))
75-
.SelectMany(member => member.Annotations)
76-
.Where(annotation => !annotation.AnnotationType.HasFlag(AnnotationType.MemberAnnotation))
77-
.ToList();
78-
}
79-
80-
private static ICollection<IAnnotation> NonVariableAnnotationsOnVariables(IEnumerable<Declaration> userDeclarations)
81-
{
82-
return userDeclarations
83-
.Where(declaration => VariableAnnotationDeclarationTypes.Contains(declaration.DeclarationType))
84-
.SelectMany(declaration => declaration.Annotations)
85-
.Where(annotation => !annotation.AnnotationType.HasFlag(AnnotationType.VariableAnnotation))
86-
.ToList();
87-
}
88-
89-
private static readonly HashSet<DeclarationType> VariableAnnotationDeclarationTypes = new HashSet<DeclarationType>()
90-
{
91-
DeclarationType.Variable,
92-
DeclarationType.Control,
93-
DeclarationType.Constant,
94-
DeclarationType.Enumeration,
95-
DeclarationType.EnumerationMember,
96-
DeclarationType.UserDefinedType,
97-
DeclarationType.UserDefinedType,
98-
DeclarationType.UserDefinedTypeMember
99-
};
100-
101-
private static ICollection<IAnnotation> NonGeneralAnnotationsWhereOnlyGeneralAnnotationsBelong(IEnumerable<Declaration> userDeclarations)
102-
{
103-
return userDeclarations
104-
.Where(declaration => !declaration.DeclarationType.HasFlag(DeclarationType.Module)
105-
&& !declaration.DeclarationType.HasFlag(DeclarationType.Member)
106-
&& !VariableAnnotationDeclarationTypes.Contains(declaration.DeclarationType)
107-
&& declaration.DeclarationType != DeclarationType.Project)
108-
.SelectMany(member => member.Annotations)
109-
.Where(annotation => !annotation.AnnotationType.HasFlag(AnnotationType.GeneralAnnotation))
110-
.ToList();
111-
}
11247
}
11348
}

0 commit comments

Comments
 (0)