Skip to content

Commit 1d8b60e

Browse files
committed
Merge pull request #1139 from retailcoder/CodeExplorer
resolver / inspection fixes
2 parents 76c8731 + 053e267 commit 1d8b60e

15 files changed

+75
-237
lines changed

RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3131
where !item.IsInspectionDisabled(AnnotationName)
3232
&& ProcedureTypes.Contains(item.DeclarationType)
3333
&& !item.IsTypeSpecified()
34-
let issue = new {Declaration = item, QualifiedContext = new QualifiedContext<ParserRuleContext>(item.QualifiedName, item.Context)}
35-
select new ImplicitVariantReturnTypeInspectionResult(this, string.Format(Description, issue.Declaration.IdentifierName), issue.QualifiedContext);
34+
select new ImplicitVariantReturnTypeInspectionResult(this, item);
3635
return issues;
3736
}
3837
}

RetailCoder.VBE/Inspections/ImplicitVariantReturnTypeInspectionResult.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
using Antlr4.Runtime;
33
using Rubberduck.Parsing;
44
using Rubberduck.Parsing.Grammar;
5+
using Rubberduck.Parsing.Symbols;
56
using Rubberduck.Parsing.VBA.Nodes;
67
using Rubberduck.VBEditor;
78

89
namespace Rubberduck.Inspections
910
{
10-
public class ImplicitVariantReturnTypeInspectionResult : InspectionResultBase
11+
public sealed class ImplicitVariantReturnTypeInspectionResult : InspectionResultBase
1112
{
1213
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;
1314

14-
public ImplicitVariantReturnTypeInspectionResult(IInspection inspection, string name, QualifiedContext<ParserRuleContext> qualifiedContext)
15-
: base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context)
15+
public ImplicitVariantReturnTypeInspectionResult(IInspection inspection, Declaration target)
16+
: base(inspection, target)
1617
{
1718
_quickFixes = new CodeInspectionQuickFix[]
1819
{
1920
new SetExplicitVariantReturnTypeQuickFix(Context, QualifiedSelection, InspectionsUI.SetExplicitVariantReturnTypeQuickFix),
20-
new IgnoreOnceQuickFix(qualifiedContext.Context, QualifiedSelection, Inspection.AnnotationName),
21+
new IgnoreOnceQuickFix(Target.Context, QualifiedSelection, Inspection.AnnotationName),
2122
};
2223
}
2324

@@ -27,8 +28,7 @@ public override string Description
2728
{
2829
get
2930
{
30-
return string.Format(InspectionsUI.ImplicitVariantReturnTypeInspectionResultFormat,
31-
Target.IdentifierName);
31+
return string.Format(InspectionsUI.ImplicitVariantReturnTypeInspectionResultFormat, Target.IdentifierName);
3232
}
3333
}
3434
}

RetailCoder.VBE/Inspections/NonReturningFunctionInspection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public override IEnumerable<InspectionResultBase> GetInspectionResults()
3737
&& !interfaceMembers.Contains(declaration)).ToList();
3838

3939
var issues = functions
40-
.Where(declaration => declaration.References.All(r => !r.IsAssignment))
41-
.Select(issue => new NonReturningFunctionInspectionResult(this, new QualifiedContext<ParserRuleContext>(issue.QualifiedName, issue.Context), interfaceImplementationMembers.Select(m => m.Scope).Contains(issue.Scope)));
42-
43-
return issues;
40+
.Where(declaration => !declaration.References.Any(reference => reference.IsAssignment && reference.ParentScoping.Equals(declaration)))
41+
.ToList();
42+
43+
return issues.Select(issue => new NonReturningFunctionInspectionResult(this, issue, interfaceImplementationMembers.Select(m => m.Scope).Contains(issue.Scope)));
4444
}
4545
}
4646
}

RetailCoder.VBE/Inspections/NonReturningFunctionInspectionResult.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
using System.Collections.Generic;
2-
using Antlr4.Runtime;
3-
using Rubberduck.Parsing;
2+
using Rubberduck.Parsing.Symbols;
43

54
namespace Rubberduck.Inspections
65
{
7-
public class NonReturningFunctionInspectionResult : InspectionResultBase
6+
public sealed class NonReturningFunctionInspectionResult : InspectionResultBase
87
{
98
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;
109

11-
public NonReturningFunctionInspectionResult(IInspection inspection, QualifiedContext<ParserRuleContext> qualifiedContext,
12-
bool isInterfaceImplementation)
13-
: base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context)
10+
public NonReturningFunctionInspectionResult(IInspection inspection, Declaration target, bool isInterfaceImplementation)
11+
: base(inspection, target)
1412
{
1513
_quickFixes = isInterfaceImplementation
1614
? new CodeInspectionQuickFix[] { }
@@ -27,7 +25,6 @@ public override string Description
2725
{
2826
get
2927
{
30-
// bug NullReferenceException thrown here - null Target
3128
return string.Format(InspectionsUI.NonReturningFunctionInspectionResultFormat, Target.IdentifierName);
3229
}
3330
}

RetailCoder.VBE/Inspections/ProcedureShouldBeFunctionInspectionResult.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using Rubberduck.Parsing;
55
using Rubberduck.Parsing.Grammar;
6+
using Rubberduck.Parsing.Symbols;
67
using Rubberduck.Parsing.VBA;
78
using Rubberduck.VBEditor;
89

@@ -17,6 +18,10 @@ public ProcedureShouldBeFunctionInspectionResult(IInspection inspection, Rubberd
1718
subStmtQualifiedContext.ModuleName,
1819
subStmtQualifiedContext.Context.ambiguousIdentifier())
1920
{
21+
_target = state.AllUserDeclarations.Single(declaration =>
22+
declaration.DeclarationType == DeclarationType.Procedure
23+
&& declaration.Context == subStmtQualifiedContext.Context);
24+
2025
_quickFixes = new[]
2126
{
2227
new ChangeProcedureToFunction(state, argListQualifiedContext, subStmtQualifiedContext, QualifiedSelection),
@@ -25,9 +30,10 @@ public ProcedureShouldBeFunctionInspectionResult(IInspection inspection, Rubberd
2530

2631
public override IEnumerable<CodeInspectionQuickFix> QuickFixes { get { return _quickFixes; } }
2732

33+
private readonly Declaration _target;
2834
public override string Description
2935
{
30-
get { return InspectionsUI.ProcedureCanBeWrittenAsFunctionInspectionResultFormat; }
36+
get { return string.Format(InspectionsUI.ProcedureCanBeWrittenAsFunctionInspectionResultFormat, _target.IdentifierName); }
3137
}
3238
}
3339

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.ObjectModel;
2+
using System.Diagnostics;
23
using System.Linq;
34
using System.Windows.Input;
45
using System.Windows.Media.Imaging;
@@ -100,6 +101,7 @@ private void ParserState_ModuleStateChanged(object sender, Parsing.ParseProgress
100101

101102
private void ExecuteRefreshCommand(object param)
102103
{
104+
Debug.WriteLine("CodeExplorerViewModel.ExecuteRefreshCommand - requesting reparse");
103105
_state.OnParseRequested();
104106
}
105107
}

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Windows;
7-
using System.Windows.Controls;
8-
using System.Windows.Data;
9-
using System.Windows.Documents;
1+
using System.Windows.Controls;
102
using System.Windows.Input;
11-
using System.Windows.Media;
12-
using System.Windows.Media.Imaging;
13-
using System.Windows.Navigation;
14-
using System.Windows.Shapes;
153
using Rubberduck.Navigation.CodeExplorer;
16-
using Rubberduck.VBEditor;
174

185
namespace Rubberduck.UI.CodeExplorer
196
{

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerDockablePresenter.cs

Lines changed: 0 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -10,186 +10,5 @@ public CodeExplorerDockablePresenter(VBE vbe, AddIn addIn, IDockableUserControl
1010
: base(vbe, addIn, view)
1111
{
1212
}
13-
14-
//private string GetNodeText(Declaration declaration)
15-
//{
16-
// if (Control.DisplayStyle == TreeViewDisplayStyle.MemberNames)
17-
// {
18-
// var result = declaration.IdentifierName;
19-
// if (declaration.DeclarationType == DeclarationType.PropertyGet)
20-
// {
21-
// result += " (" + Tokens.Get + ")";
22-
// }
23-
// else if (declaration.DeclarationType == DeclarationType.PropertyLet)
24-
// {
25-
// result += " (" + Tokens.Let + ")";
26-
// }
27-
// else if (declaration.DeclarationType == DeclarationType.PropertySet)
28-
// {
29-
// result += " (" + Tokens.Set + ")";
30-
// }
31-
32-
// return result;
33-
// }
34-
35-
// if (declaration.DeclarationType == DeclarationType.Procedure)
36-
// {
37-
// return ((VBAParser.SubStmtContext) declaration.Context).Signature();
38-
// }
39-
40-
// if (declaration.DeclarationType == DeclarationType.Function)
41-
// {
42-
// return ((VBAParser.FunctionStmtContext)declaration.Context).Signature();
43-
// }
44-
45-
// if (declaration.DeclarationType == DeclarationType.PropertyGet)
46-
// {
47-
// return ((VBAParser.PropertyGetStmtContext)declaration.Context).Signature();
48-
// }
49-
50-
// if (declaration.DeclarationType == DeclarationType.PropertyLet)
51-
// {
52-
// return ((VBAParser.PropertyLetStmtContext)declaration.Context).Signature();
53-
// }
54-
55-
// if (declaration.DeclarationType == DeclarationType.PropertySet)
56-
// {
57-
// return ((VBAParser.PropertySetStmtContext)declaration.Context).Signature();
58-
// }
59-
60-
// return declaration.IdentifierName;
61-
//}
62-
63-
//private string GetImageKeyForDeclaration(Declaration declaration)
64-
//{
65-
// var result = string.Empty;
66-
// switch (declaration.DeclarationType)
67-
// {
68-
// case DeclarationType.Module:
69-
// break;
70-
// case DeclarationType.Class:
71-
// break;
72-
// case DeclarationType.Procedure:
73-
// case DeclarationType.Function:
74-
// if (declaration.Accessibility == Accessibility.Private)
75-
// {
76-
// result = "PrivateMethod";
77-
// break;
78-
// }
79-
// if (declaration.Accessibility == Accessibility.Friend)
80-
// {
81-
// result = "FriendMethod";
82-
// break;
83-
// }
84-
// result = "PublicMethod";
85-
// break;
86-
87-
// case DeclarationType.PropertyGet:
88-
// case DeclarationType.PropertyLet:
89-
// case DeclarationType.PropertySet:
90-
// if (declaration.Accessibility == Accessibility.Private)
91-
// {
92-
// result = "PrivateProperty";
93-
// break;
94-
// }
95-
// if (declaration.Accessibility == Accessibility.Friend)
96-
// {
97-
// result = "FriendProperty";
98-
// break;
99-
// }
100-
// result = "PublicProperty";
101-
// break;
102-
103-
// case DeclarationType.Parameter:
104-
// break;
105-
// case DeclarationType.Variable:
106-
// if (declaration.Accessibility == Accessibility.Private)
107-
// {
108-
// result = "PrivateField";
109-
// break;
110-
// }
111-
// if (declaration.Accessibility == Accessibility.Friend)
112-
// {
113-
// result = "FriendField";
114-
// break;
115-
// }
116-
// result = "PublicField";
117-
// break;
118-
119-
// case DeclarationType.Constant:
120-
// if (declaration.Accessibility == Accessibility.Private)
121-
// {
122-
// result = "PrivateConst";
123-
// break;
124-
// }
125-
// if (declaration.Accessibility == Accessibility.Friend)
126-
// {
127-
// result = "FriendConst";
128-
// break;
129-
// }
130-
// result = "PublicConst";
131-
// break;
132-
133-
// case DeclarationType.Enumeration:
134-
// if (declaration.Accessibility == Accessibility.Private)
135-
// {
136-
// result = "PrivateEnum";
137-
// break;
138-
// }
139-
// if (declaration.Accessibility == Accessibility.Friend)
140-
// {
141-
// result = "FriendEnum";
142-
// break;
143-
// }
144-
// result = "PublicEnum";
145-
// break;
146-
147-
// case DeclarationType.EnumerationMember:
148-
// result = "EnumItem";
149-
// break;
150-
151-
// case DeclarationType.Event:
152-
// if (declaration.Accessibility == Accessibility.Private)
153-
// {
154-
// result = "PrivateEvent";
155-
// break;
156-
// }
157-
// if (declaration.Accessibility == Accessibility.Friend)
158-
// {
159-
// result = "FriendEvent";
160-
// break;
161-
// }
162-
// result = "PublicEvent";
163-
// break;
164-
165-
// case DeclarationType.UserDefinedType:
166-
// if (declaration.Accessibility == Accessibility.Private)
167-
// {
168-
// result = "PrivateType";
169-
// break;
170-
// }
171-
// if (declaration.Accessibility == Accessibility.Friend)
172-
// {
173-
// result = "FriendType";
174-
// break;
175-
// }
176-
// result = "PublicType";
177-
// break;
178-
179-
// case DeclarationType.UserDefinedTypeMember:
180-
// result = "PublicField";
181-
// break;
182-
183-
// case DeclarationType.LibraryProcedure:
184-
// case DeclarationType.LibraryFunction:
185-
// result = "Identifier";
186-
// break;
187-
188-
// default:
189-
// throw new ArgumentOutOfRangeException();
190-
// }
191-
192-
// return result;
193-
//}
19413
}
19514
}

RetailCoder.VBE/UI/CodeInspections/InspectionResultsViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Diagnostics;
45
using System.Linq;
56
using System.Threading;
67
using System.Threading.Tasks;
@@ -142,6 +143,7 @@ private async void ExecuteRefreshCommandAsync(object parameter)
142143
IsBusy = true;
143144

144145
_state.StateChanged += _state_StateChanged;
146+
Debug.WriteLine("InspectionResultsViewModel.ExecuteRefreshCommand - requesting reparse");
145147
_state.OnParseRequested();
146148
}
147149

RetailCoder.VBE/UI/Command/CodeExplorerCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Runtime.InteropServices;
2-
using Rubberduck.UI.CodeExplorer;
32

43
namespace Rubberduck.UI.Command
54
{

0 commit comments

Comments
 (0)