Skip to content

Commit 64d50ea

Browse files
committed
Sync with next
2 parents 3309ff3 + 7e196a1 commit 64d50ea

File tree

124 files changed

+3948
-891
lines changed

Some content is hidden

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

124 files changed

+3948
-891
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ If you like this project and would like to thank its contributors, you are welco
3737

3838
Rubberduck is a COM add-in for the VBA IDE (VBE).
3939

40-
Copyright (C) 2014-2018 Mathieu Guindon & Christopher McClellan
40+
Copyright (C) 2014-2018 Rubberduck project contributors
4141

4242
This program is free software: you can redistribute it and/or modify
4343
it under the terms of the GNU General Public License as published by

Rubberduck.API/VBA/Parser.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Globalization;
55
using System.Linq;
66
using System.Runtime.InteropServices;
7+
using System.Threading;
78
using Rubberduck.Common;
89
using Rubberduck.Parsing.PreProcessing;
910
using Rubberduck.Parsing.Symbols.DeclarationLoaders;
@@ -60,15 +61,17 @@ public sealed class Parser : IParser, IDisposable
6061
{
6162
private RubberduckParserState _state;
6263
private AttributeParser _attributeParser;
63-
private ParseCoordinator _parser;
64+
private SynchronousParseCoordinator _parser;
6465
private IVBE _vbe;
6566
private IVBEEvents _vbeEvents;
6667
private readonly IUiDispatcher _dispatcher;
68+
private readonly CancellationTokenSource _tokenSource;
6769

6870
internal Parser()
6971
{
7072
UiContextProvider.Initialize();
7173
_dispatcher = new UiDispatcher(UiContextProvider.Instance());
74+
_tokenSource = new CancellationTokenSource();
7275
}
7376

7477
// vbe is the com coclass interface from the interop assembly.
@@ -137,22 +140,21 @@ internal Parser(object vbe) : this()
137140
supertypeClearer
138141
);
139142

140-
_parser = new ParseCoordinator(
143+
_parser = new SynchronousParseCoordinator(
141144
_state,
142145
parsingStageService,
143146
parsingCacheService,
144147
projectManager,
145148
parserStateManager
146149
);
147150
}
148-
151+
149152
/// <summary>
150153
/// Blocking call, for easier unit-test code
151154
/// </summary>
152155
public void Parse()
153156
{
154-
// blocking call
155-
_parser.Parse(new System.Threading.CancellationTokenSource());
157+
_parser.Parse(_tokenSource);
156158
}
157159

158160
/// <summary>
@@ -163,7 +165,7 @@ public void BeginParse()
163165
// non-blocking call
164166
_dispatcher.Invoke(() => _state.OnParseRequested(this));
165167
}
166-
168+
167169
public delegate void OnStateChangedDelegate(ParserState ParserState);
168170
public event OnStateChangedDelegate OnStateChanged;
169171

Rubberduck.CodeAnalysis/Inspections/Concrete/MultilineParameterInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3030
.Select(context => new QualifiedContextInspectionResult(this,
3131
string.Format(context.Context.GetSelection().LineCount > 3
3232
? RubberduckUI.EasterEgg_Continuator
33-
: Resources.Inspections.InspectionResults.MultilineParameterInspection, ((VBAParser.ArgContext)context.Context).unrestrictedIdentifier().ToString()),
33+
: Resources.Inspections.InspectionResults.MultilineParameterInspection, ((VBAParser.ArgContext)context.Context).unrestrictedIdentifier().GetText()),
3434
context));
3535
}
3636

Rubberduck.CodeAnalysis/Inspections/Concrete/ParameterCanBeByValInspection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ private IEnumerable<IInspectionResult> GetResults(Declaration[] declarations, De
9090
.ThenBy(t => t.Selection.StartColumn)
9191
.ToList();
9292

93+
//If you hit this assert, reopen https://github.com/rubberduck-vba/Rubberduck/issues/3906
94+
Debug.Assert(parametersAreByRef.Count == parameters.Count);
95+
9396
for (var i = 0; i < parameters.Count; i++)
9497
{
95-
//If you hit this assert, congratulations! you've found a test case for https://github.com/rubberduck-vba/Rubberduck/issues/3906
96-
//Please examine the code, and if possible, either fix the indexing on this or upload your failing code to the GitHub issue.
97-
Debug.Assert(parametersAreByRef.Count == parameters.Count);
9898
parametersAreByRef[i] = parametersAreByRef[i] &&
9999
!IsUsedAsByRefParam(declarations, parameters[i]) &&
100100
((VBAParser.ArgContext) parameters[i].Context).BYVAL() == null &&

Rubberduck.CodeAnalysis/QuickFixes/IntroduceLocalVariableQuickFix.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
2+
using System.Text.RegularExpressions;
23
using Rubberduck.Inspections.Abstract;
34
using Rubberduck.Inspections.Concrete;
5+
using Rubberduck.Parsing;
6+
using Rubberduck.Parsing.Grammar;
47
using Rubberduck.Parsing.Inspections.Abstract;
58
using Rubberduck.Parsing.VBA;
69

@@ -22,8 +25,60 @@ public IntroduceLocalVariableQuickFix(RubberduckParserState state)
2225

2326
public override void Fix(IInspectionResult result)
2427
{
25-
var instruction = $"{Environment.NewLine}Dim {result.Target.IdentifierName} As Variant{Environment.NewLine}";
26-
_state.GetRewriter(result.Target).InsertBefore(result.Target.Context.Start.TokenIndex, instruction);
28+
var identifierContext = result.Target.Context;
29+
var enclosingStatmentContext = identifierContext.GetAncestor<VBAParser.BlockStmtContext>();
30+
var instruction = IdentifierDeclarationText(result.Target.IdentifierName, EndOfStatementText(enclosingStatmentContext), FrontPadding(enclosingStatmentContext));
31+
_state.GetRewriter(result.Target).InsertBefore(enclosingStatmentContext.Start.TokenIndex, instruction);
32+
}
33+
34+
private string EndOfStatementText(VBAParser.BlockStmtContext context)
35+
{
36+
if (!context.TryGetPrecedingContext<VBAParser.IndividualNonEOFEndOfStatementContext>(out var individualEndOfStmtContext))
37+
{
38+
return Environment.NewLine;
39+
}
40+
41+
var endOfLine = individualEndOfStmtContext.endOfLine();
42+
43+
if (endOfLine?.commentOrAnnotation() == null)
44+
{
45+
return individualEndOfStmtContext.GetText();
46+
}
47+
48+
//There is a comment inside the preceding endOfLine, which we do not want to duplicate.
49+
var whitespaceContext = individualEndOfStmtContext.whiteSpace(0);
50+
return Environment.NewLine + (whitespaceContext?.GetText() ?? string.Empty);
51+
}
52+
53+
private string FrontPadding(VBAParser.BlockStmtContext context)
54+
{
55+
var statementLabelContext = context.statementLabelDefinition();
56+
if (statementLabelContext == null)
57+
{
58+
return string.Empty;
59+
}
60+
61+
var statementLabelTextAsWhitespace = ReplaceNonWhitespaceWithSpace(statementLabelContext.GetText());
62+
var whitespaceContext = context.whiteSpace();
63+
return statementLabelTextAsWhitespace + (whitespaceContext?.GetText() ?? string.Empty);
64+
}
65+
66+
private string ReplaceNonWhitespaceWithSpace(string input)
67+
{
68+
if (input == null || input.Equals(string.Empty))
69+
{
70+
return string.Empty;
71+
}
72+
73+
var pattern = @"[^\r\n\t ]";
74+
var replacement = " ";
75+
var regex = new Regex(pattern);
76+
return regex.Replace(input, replacement);
77+
}
78+
79+
private string IdentifierDeclarationText(string identifierName, string endOfStatementText, string prefix)
80+
{
81+
return $"{prefix}Dim {identifierName} As Variant{endOfStatementText}";
2782
}
2883

2984
public override string Description(IInspectionResult result) => Resources.Inspections.QuickFixes.IntroduceLocalVariableQuickFix;

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ private static string DetermineMemberName(Declaration declaration)
154154
return declaration.IdentifierName + "()";
155155
}
156156
return declaration.IdentifierName;
157+
case DeclarationType.EnumerationMember:
157158
case DeclarationType.Constant:
158-
var valuedDeclaration = (ConstantDeclaration)declaration;
159-
return valuedDeclaration.IdentifierName + " = " + valuedDeclaration.Expression;
160-
159+
var valuedDeclaration = (ValuedDeclaration)declaration;
160+
return (!string.IsNullOrEmpty(valuedDeclaration.Expression))
161+
? valuedDeclaration.IdentifierName + " = " + valuedDeclaration.Expression
162+
: valuedDeclaration.IdentifierName;
161163
default:
162164
return declaration.IdentifierName;
163165
}

Rubberduck.Core/Rubberduck.Core.csproj

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,9 @@
231231
<Reference Include="Antlr4.Runtime, Version=4.6.0.0, Culture=neutral, PublicKeyToken=09abb75b9ed49849, processorArchitecture=MSIL">
232232
<HintPath>..\packages\Antlr4.Runtime.4.6.4\lib\net45\Antlr4.Runtime.dll</HintPath>
233233
</Reference>
234-
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
235-
<HintPath>..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
236-
</Reference>
237-
<Reference Include="Castle.Windsor, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
238-
<HintPath>..\packages\Castle.Windsor.4.1.0\lib\net45\Castle.Windsor.dll</HintPath>
239-
</Reference>
240234
<Reference Include="EasyHook, Version=2.7.6684.0, Culture=neutral, PublicKeyToken=4b580fca19d0b0c5, processorArchitecture=MSIL">
241235
<HintPath>..\packages\EasyHook.2.7.6684\lib\net40\EasyHook.dll</HintPath>
242236
</Reference>
243-
<Reference Include="extensibility, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
244-
<EmbedInteropTypes>True</EmbedInteropTypes>
245-
</Reference>
246237
<Reference Include="HtmlAgilityPack, Version=1.8.4.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
247238
<HintPath>..\packages\HtmlAgilityPack.1.8.4\lib\Net45\HtmlAgilityPack.dll</HintPath>
248239
</Reference>
@@ -262,26 +253,14 @@
262253
<Reference Include="PresentationCore" />
263254
<Reference Include="PresentationFramework" />
264255
<Reference Include="PresentationFramework.Aero" />
265-
<Reference Include="ReachFramework" />
266-
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
267-
<EmbedInteropTypes>False</EmbedInteropTypes>
268-
</Reference>
269256
<Reference Include="System" />
270-
<Reference Include="System.Configuration" />
271257
<Reference Include="System.Core" />
272-
<Reference Include="System.Data" />
273258
<Reference Include="System.Drawing" />
274259
<Reference Include="System.IO.Compression" />
275260
<Reference Include="System.Net.Http" />
276-
<Reference Include="System.Printing" />
277-
<Reference Include="System.Runtime.Remoting" />
278-
<Reference Include="System.Runtime.Serialization" />
279-
<Reference Include="System.ServiceModel" />
280-
<Reference Include="System.Transactions" />
281261
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
282262
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
283263
</Reference>
284-
<Reference Include="System.Web" />
285264
<Reference Include="System.Windows.Forms" />
286265
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
287266
<HintPath>..\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\System.Windows.Interactivity.dll</HintPath>
@@ -536,6 +515,7 @@
536515
<Compile Include="UnitTesting\IFakes.cs" />
537516
<Compile Include="UnitTesting\ReturnTypeConverter.cs" />
538517
<Compile Include="UnitTesting\PermissiveObjectComparer.cs" />
518+
<Compile Include="UnitTesting\TestCategory.cs" />
539519
<Compile Include="VersionCheck\IVersionCheck.cs" />
540520
<Compile Include="UI\Command\MenuItems\CommandBars\AppCommandBarBase.cs" />
541521
<Compile Include="UI\Command\MenuItems\CommandBars\ContextSelectionLabelMenuItem.cs" />
@@ -923,6 +903,9 @@
923903
<Folder Include="Properties\DataSources\" />
924904
</ItemGroup>
925905
<ItemGroup>
906+
<Compile Include="AutoComplete\AutoCompleteFunctionBlock.cs" />
907+
<Compile Include="AutoComplete\AutoCompletePropertyBlock.cs" />
908+
<Compile Include="AutoComplete\AutoCompleteSubBlock.cs" />
926909
<Content Include="EasyHook32.dll">
927910
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
928911
</Content>
@@ -941,9 +924,6 @@
941924
<Content Include="EasyLoad64.dll">
942925
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
943926
</Content>
944-
<Compile Include="AutoComplete\AutoCompleteFunctionBlock.cs" />
945-
<Compile Include="AutoComplete\AutoCompletePropertyBlock.cs" />
946-
<Compile Include="AutoComplete\AutoCompleteSubBlock.cs" />
947927
<None Include="NLog.xsd">
948928
<SubType>Designer</SubType>
949929
</None>

Rubberduck.Core/UI/About/AboutControl.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
xml:space="preserve">JetBrains ReSharper Community Team
168168
Code Review Stack Exchange
169169
Stack Overflow
170+
Digital Ocean Hacktoberfest
170171
</TextBlock>
171172

172173
<TextBlock Text="{Resx ResxName=Rubberduck.Resources.About.AboutUI, Key=AboutWindow_ContributorsHeader}"
@@ -176,32 +177,40 @@ Stack Overflow
176177
xml:space="preserve">Abraham Hosch
177178
Andrew Jackson
178179
Andrew Zschetzsche
180+
Andrew Mansell
179181
Andrin Meier
182+
Anna Velcheva
180183
Brandon Barney
181184
Brian Zenger
182185
Bruno Costa
183186
Carlos J. Quintero (MZ-Tools)
184187
Clemens Lieb
185188
@Comintern
189+
Christopher McClellan
186190
@daFreeMan
187191
@Duga SE chat bot
188192
Francis Veilleux-Gaboury
189193
Frank Van Heeswijk
190194
Gareth Leachman
191195
@Heslacher
196+
Imh0t3b
192197
INOPIAE
198+
Ipshita Chatterjee
193199
@IvenBach
194200
Jeroen Vannevel
201+
Mathieu Guindon
195202
Max Dörner
196203
Michal Krzych
197204
@mjolka
205+
Nelson Vides
198206
Philip Wales
199207
Radosław Kapka
200208
Rob Bovey (Smart Indenter)
201209
Ross McLean
202210
Ross Knudsen
203211
Simon Forsberg
204212
Stephen Bullen (Smart Indenter)
213+
@tommy9
205214
Wayne Phillips (vbWatchdog)
206215
</TextBlock>
207216

Rubberduck.Core/UI/Command/MenuItems/CommandBars/IContextFormatter.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,27 @@ private string FormatDeclaration(Declaration declaration, bool multipleControls
5353
: declaration.AsTypeName;
5454
var declarationType = RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType, Settings.Settings.Culture);
5555

56-
typeName = multipleControls
57-
? RubberduckUI.ContextMultipleControlsSelection
58-
: "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) + ")";
56+
if (multipleControls)
57+
{
58+
typeName = RubberduckUI.ContextMultipleControlsSelection;
59+
}
60+
else if (declaration is ValuedDeclaration)
61+
{
62+
var valued = (ValuedDeclaration)declaration;
63+
typeName = "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) +
64+
(string.IsNullOrEmpty(valued.Expression) ? string.Empty : $" = {valued.Expression}") + ")";
65+
66+
}
67+
else if (declaration is ParameterDeclaration)
68+
{
69+
var parameter = (ParameterDeclaration)declaration;
70+
typeName = "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) +
71+
(string.IsNullOrEmpty(parameter.DefaultValue) ? string.Empty : $" = {parameter.DefaultValue}") + ")";
72+
}
73+
else
74+
{
75+
typeName = "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) + ")";
76+
}
5977

6078
if (declaration.DeclarationType.HasFlag(DeclarationType.Project) || declaration.DeclarationType == DeclarationType.BracketedExpression)
6179
{

Rubberduck.Core/UI/Command/MenuItems/CommandBars/RubberduckCommandBar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ private void OnSelectionChange(object sender, DeclarationChangedEventArgs e)
6969

7070
var refCount = e.Declaration?.References.Count() ?? 0;
7171
var description = e.Declaration?.DescriptionString ?? string.Empty;
72-
SetContextSelectionCaption(caption, refCount, description);
72+
//& renders the next character as if it was an accelerator.
73+
SetContextSelectionCaption(caption?.Replace("&", "&&"), refCount, description);
7374
EvaluateCanExecute(_parser.State, e.Declaration);
7475
}
7576

0 commit comments

Comments
 (0)