9
9
using Rubberduck . Parsing . Inspections ;
10
10
using Rubberduck . Parsing . Inspections . Abstract ;
11
11
using Rubberduck . Parsing . Rewriter ;
12
+ using Rubberduck . Parsing . Symbols ;
12
13
using Rubberduck . Parsing . VBA ;
14
+ using Rubberduck . Parsing . VBA . Parsing ;
13
15
14
16
namespace Rubberduck . Inspections . QuickFixes
15
17
{
@@ -29,32 +31,31 @@ public IgnoreOnceQuickFix(RubberduckParserState state, IEnumerable<IInspection>
29
31
30
32
public override void Fix ( IInspectionResult result , IRewriteSession rewriteSession )
31
33
{
32
- var annotationText = $ "'@Ignore { result . Inspection . AnnotationName } ";
34
+ var annotationText = result . Target ? . DeclarationType . HasFlag ( DeclarationType . Module ) == true
35
+ ? $ "'@IgnoreModule { result . Inspection . AnnotationName } "
36
+ : $ "'@Ignore { result . Inspection . AnnotationName } ";
33
37
34
38
int annotationLine ;
35
39
//TODO: Make this use the parse tree instead of the code module.
36
40
var component = _state . ProjectsProvider . Component ( result . QualifiedSelection . QualifiedName ) ;
37
- using ( var module = component . CodeModule )
41
+ using ( var codeModule = component . CodeModule )
38
42
{
39
43
annotationLine = result . QualifiedSelection . Selection . StartLine ;
40
- while ( annotationLine != 1 && module . GetLines ( annotationLine - 1 , 1 ) . EndsWith ( " _" ) )
44
+ while ( annotationLine != 1 && codeModule . GetLines ( annotationLine - 1 , 1 ) . EndsWith ( " _" ) )
41
45
{
42
46
annotationLine -- ;
43
47
}
44
48
}
45
49
46
- RuleContext treeRoot = result . Context ;
47
- while ( treeRoot . Parent != null )
48
- {
49
- treeRoot = treeRoot . Parent ;
50
- }
50
+ var module = result . QualifiedSelection . QualifiedName ;
51
+ var parseTree = _state . GetParseTree ( module , CodeKind . CodePaneCode ) ;
51
52
52
53
var listener = new CommentOrAnnotationListener ( ) ;
53
- ParseTreeWalker . Default . Walk ( listener , treeRoot ) ;
54
+ ParseTreeWalker . Default . Walk ( listener , parseTree ) ;
54
55
var commentContext = listener . Contexts . LastOrDefault ( i => i . Stop . TokenIndex <= result . Context . Start . TokenIndex ) ;
55
56
var commented = commentContext ? . Stop . Line + 1 == annotationLine ;
56
57
57
- var rewriter = rewriteSession . CheckOutModuleRewriter ( result . QualifiedSelection . QualifiedName ) ;
58
+ var rewriter = rewriteSession . CheckOutModuleRewriter ( module ) ;
58
59
59
60
if ( commented )
60
61
{
@@ -82,7 +83,7 @@ public override void Fix(IInspectionResult result, IRewriteSession rewriteSessio
82
83
else
83
84
{
84
85
var eol = new EndOfLineListener ( ) ;
85
- ParseTreeWalker . Default . Walk ( eol , treeRoot ) ;
86
+ ParseTreeWalker . Default . Walk ( eol , parseTree ) ;
86
87
87
88
// we subtract 2 here to get the insertion index to A) account for VBE's one-based indexing
88
89
// and B) to get the newline token that introduces that line
0 commit comments