Skip to content

Commit 0fed156

Browse files
authored
Merge branch 'next' into next
2 parents 652e4e6 + e4b06ac commit 0fed156

40 files changed

+747
-179
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Inspections.Abstract;
4+
using Rubberduck.Inspections.Resources;
5+
using Rubberduck.Inspections.Results;
6+
using Rubberduck.Parsing.Symbols;
7+
using Rubberduck.Parsing.VBA;
8+
9+
namespace Rubberduck.Inspections
10+
{
11+
public sealed class HostSpecificExpressionInspection : InspectionBase
12+
{
13+
public HostSpecificExpressionInspection(RubberduckParserState state)
14+
: base(state)
15+
{
16+
}
17+
18+
public override string Meta { get { return InspectionsUI.HostSpecificExpressionInspectionMeta; } }
19+
public override string Description { get { return InspectionsUI.HostSpecificExpressionInspectionName; } }
20+
public override CodeInspectionType InspectionType { get { return CodeInspectionType.LanguageOpportunities; } }
21+
22+
public override IEnumerable<InspectionResultBase> GetInspectionResults()
23+
{
24+
return Declarations.Where(item => item.DeclarationType == DeclarationType.BracketedExpression)
25+
.Select(item => new HostSpecificExpressionInspectionResult(this, item)).ToList();
26+
}
27+
}
28+
}

RetailCoder.VBE/Inspections/Resources/InspectionsUI.Designer.cs

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

RetailCoder.VBE/Inspections/Resources/InspectionsUI.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,13 @@ If the parameter can be null, ignore this inspection result; passing a null valu
625625
<value>Member '{0}' is not declared on the interface for type '{1}'.</value>
626626
<comment>{0} Member used, {1} type being accessed.</comment>
627627
</data>
628+
<data name="HostSpecificExpressionInspectionMeta" xml:space="preserve">
629+
<value>Bracketed expressions are evaluated by the host application at runtime, which means VBA can't validate the expression at compile-time. Consider using the host application's object model instead.</value>
630+
</data>
631+
<data name="HostSpecificExpressionInspectionName" xml:space="preserve">
632+
<value>Host-specific bracketed expression is only evaluated at runtime</value>
633+
</data>
634+
<data name="HostSpecificExpressionInspectionResultFormat" xml:space="preserve">
635+
<value>Expression '{0}' cannot be validated at compile-time.</value>
636+
</data>
628637
</root>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Rubberduck.Inspections.Abstract;
2+
using Rubberduck.Inspections.Resources;
3+
using Rubberduck.Parsing.Symbols;
4+
5+
namespace Rubberduck.Inspections.Results
6+
{
7+
public class HostSpecificExpressionInspectionResult : InspectionResultBase
8+
{
9+
public HostSpecificExpressionInspectionResult(IInspection inspection, Declaration target)
10+
: base(inspection, target)
11+
{
12+
}
13+
14+
public override string Description
15+
{
16+
get
17+
{
18+
return string.Format(InspectionsUI.HostSpecificExpressionInspectionResultFormat, Target.IdentifierName);
19+
}
20+
}
21+
}
22+
}

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public override void Load()
9191
Bind<Func<IIndenterSettings>>().ToMethod(t => () => KernelInstance.Get<IGeneralConfigService>().LoadConfiguration().UserSettings.IndenterSettings);
9292

9393
BindCustomDeclarationLoadersToParser();
94-
Rebind<IParseCoordinator>().To<ParseCoordinator>().InSingletonScope();
94+
Rebind<IParseCoordinator>().To<ParseCoordinator>().InSingletonScope().WithConstructorArgument("serializedDeclarationsPath", (string)null);
9595
Bind<Func<IVBAPreprocessor>>().ToMethod(p => () => new VBAPreprocessor(double.Parse(_vbe.Version, CultureInfo.InvariantCulture)));
9696

9797
Rebind<ISearchResultsWindowViewModel>().To<SearchResultsWindowViewModel>().InSingletonScope();

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@
365365
<Compile Include="Common\WinAPI\WM.cs" />
366366
<Compile Include="Common\WindowsOperatingSystem.cs" />
367367
<Compile Include="Common\UndocumentedAttribute.cs" />
368+
<Compile Include="Inspections\HostSpecificExpressionInspection.cs" />
368369
<Compile Include="Inspections\HungarianNotationInspection.cs" />
369370
<Compile Include="Inspections\ImplicitDefaultMemberAssignmentInspection.cs" />
370371
<Compile Include="Inspections\MemberNotOnInterfaceInspection.cs" />
@@ -375,6 +376,7 @@
375376
<DependentUpon>InspectionsUI.resx</DependentUpon>
376377
</Compile>
377378
<Compile Include="Inspections\Results\AggregateInspectionResult.cs" />
379+
<Compile Include="Inspections\Results\HostSpecificExpressionInspectionResult.cs" />
378380
<Compile Include="Inspections\Results\ImplicitDefaultMemberAssignmentInspectionResult.cs" />
379381
<Compile Include="Inspections\QuickFixes\IntroduceLocalVariableQuickFix.cs" />
380382
<Compile Include="Inspections\QuickFixes\OptionExplicitQuickFix.cs" />

RetailCoder.VBE/UI/Command/MenuItems/CommandBars/IContextFormatter.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ private string Format(Declaration declaration)
4545

4646
typeName = "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) + ")";
4747

48-
if (declaration.DeclarationType.HasFlag(DeclarationType.Project))
48+
if (declaration.DeclarationType.HasFlag(DeclarationType.Project) || declaration.DeclarationType == DeclarationType.BracketedExpression)
4949
{
50-
formattedDeclaration = System.IO.Path.GetFileName(declaration.QualifiedName.QualifiedModuleName.ProjectPath) + ";" + declaration.IdentifierName;
50+
formattedDeclaration = System.IO.Path.GetFileName(declaration.QualifiedName.QualifiedModuleName.ProjectPath) + ";" + declaration.IdentifierName + " (" + declarationType + ")";
5151
}
5252
else if (declaration.DeclarationType.HasFlag(DeclarationType.Module))
5353
{
54-
formattedDeclaration = moduleName.ToString();
54+
formattedDeclaration = moduleName + " (" + declarationType + ")";
5555
}
5656

5757
if (declaration.DeclarationType.HasFlag(DeclarationType.Member))
@@ -75,12 +75,13 @@ private string Format(Declaration declaration)
7575
else if (declaration.DeclarationType == DeclarationType.EnumerationMember
7676
|| declaration.DeclarationType == DeclarationType.UserDefinedTypeMember)
7777
{
78-
formattedDeclaration = string.Format("{0}.{1}.{2}",
78+
formattedDeclaration = string.Format("{0}.{1}.{2} {3}",
7979
declaration.IsBuiltIn
8080
? System.IO.Path.GetFileName(moduleName.ProjectPath) + ";" + moduleName.ProjectName
8181
: moduleName.ToString(),
8282
declaration.ParentDeclaration.IdentifierName,
83-
declaration.IdentifierName);
83+
declaration.IdentifierName,
84+
typeName);
8485
}
8586

8687
var subscripts = declaration.IsArray ? "()" : string.Empty;

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

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

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,4 +1908,7 @@ Would you like to import them to Rubberduck?</value>
19081908
<data name="IndenterSettings_VerticalSpacingLabel" xml:space="preserve">
19091909
<value>Vertical Spacing</value>
19101910
</data>
1911+
<data name="DeclarationType_BracketedExpression" xml:space="preserve">
1912+
<value>runtime expression</value>
1913+
</data>
19111914
</root>

Rubberduck.Parsing/Binding/SimpleNameDefaultBinding.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Antlr4.Runtime;
22
using Rubberduck.Parsing.Symbols;
33
using System.Linq;
4+
using Rubberduck.Parsing.Grammar;
45

56
namespace Rubberduck.Parsing.Binding
67
{
@@ -28,7 +29,8 @@ public SimpleNameDefaultBinding(
2829
_module = module;
2930
_parent = parent;
3031
_context = context;
31-
_name = name;
32+
// hack; SimpleNameContext.Identifier() excludes the square brackets
33+
_name = context.Start.Text == "[" && context.Stop.Text == "]" ? "[" + name + "]" : name;
3234
_propertySearchType = StatementContext.GetSearchDeclarationType(statementContext);
3335
}
3436

@@ -68,8 +70,16 @@ public IBoundExpression Resolve()
6870
return boundExpression;
6971
}
7072

71-
var undeclaredLocal = _declarationFinder.OnUndeclaredVariable(_parent, _name, _context);
72-
return new SimpleNameExpression(undeclaredLocal, ExpressionClassification.Variable, _context);
73+
if (_context.Start.Text == "[" && _context.Stop.Text == "]")
74+
{
75+
var bracketedExpression = _declarationFinder.OnBracketedExpression(_context.GetText(), _context);
76+
return new SimpleNameExpression(bracketedExpression, ExpressionClassification.Unbound, _context);
77+
}
78+
else
79+
{
80+
var undeclaredLocal = _declarationFinder.OnUndeclaredVariable(_parent, _name, _context);
81+
return new SimpleNameExpression(undeclaredLocal, ExpressionClassification.Variable, _context);
82+
}
7383
//return new ResolutionFailedExpression();
7484
}
7585

@@ -83,7 +93,9 @@ or explicit definition precedes this expression in an enclosing procedure.
8393
{
8494
return null;
8595
}
86-
var localVariable = _declarationFinder.FindMemberEnclosingProcedure(_parent, _name, DeclarationType.Variable);
96+
var localVariable = _declarationFinder.FindMemberEnclosingProcedure(_parent, _name, DeclarationType.Variable)
97+
?? _declarationFinder.FindMemberEnclosingProcedure(_parent, _name, DeclarationType.Variable)
98+
;
8799
if (IsValidMatch(localVariable, _name))
88100
{
89101
return new SimpleNameExpression(localVariable, ExpressionClassification.Variable, _context);

0 commit comments

Comments
 (0)