@@ -50,14 +50,14 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
50
50
System . Diagnostics . Debug . Assert (
51
51
errorRecord . Exception != null && ! String . IsNullOrWhiteSpace ( errorRecord . Exception . Message ) ,
52
52
Strings . NullErrorMessage ) ;
53
- var hashTableAsts = ast . Find ( x => x is HashtableAst , false ) ;
53
+ var hashTableAst = ast . Find ( x => x is HashtableAst , false ) ;
54
54
yield return new DiagnosticRecord (
55
55
errorRecord . Exception . Message ,
56
- ast . Extent ,
56
+ hashTableAst . Extent ,
57
57
GetName ( ) ,
58
58
DiagnosticSeverity . Warning ,
59
59
fileName ,
60
- suggestedCorrections : GetCorrectionExtent ( hashTableAsts as HashtableAst ) ) ;
60
+ suggestedCorrections : GetCorrectionExtent ( hashTableAst as HashtableAst ) ) ;
61
61
}
62
62
63
63
}
@@ -66,33 +66,54 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
66
66
67
67
}
68
68
69
-
70
69
/// <summary>
71
70
/// Gets the correction extent
72
71
/// </summary>
73
72
/// <param name="ast"></param>
74
73
/// <returns>A List of CorrectionExtent</returns>
75
74
private List < CorrectionExtent > GetCorrectionExtent ( HashtableAst ast )
76
75
{
77
- // we assume the extent begins with "@{"
78
- if ( ast . Extent . Text . IndexOf ( "@{" ) != 0 )
79
- {
80
- return null ;
76
+ int startLineNumber ;
77
+ int startColumnNumber ;
78
+
79
+ // for empty hashtable insert after after "@{"
80
+ if ( ast . KeyValuePairs . Count == 0 )
81
+ {
82
+ // check if ast starts with "@{"
83
+ if ( ast . Extent . Text . IndexOf ( "@{" ) != 0 )
84
+ {
85
+ return null ;
86
+ }
87
+ startLineNumber = ast . Extent . StartLineNumber ;
88
+ startColumnNumber = ast . Extent . StartColumnNumber + 2 ; // 2 for "@{",
89
+ }
90
+ else // for non-empty hashtable insert after the last element
91
+ {
92
+ int maxLine = 0 ;
93
+ int lastCol = 0 ;
94
+ foreach ( var keyVal in ast . KeyValuePairs )
95
+ {
96
+ if ( keyVal . Item2 . Extent . EndLineNumber > maxLine )
97
+ {
98
+ maxLine = keyVal . Item2 . Extent . EndLineNumber ;
99
+ lastCol = keyVal . Item2 . Extent . EndColumnNumber ;
100
+ }
101
+ }
102
+ startLineNumber = maxLine ;
103
+ startColumnNumber = lastCol ;
81
104
}
82
105
83
106
var correctionExtents = new List < CorrectionExtent > ( ) ;
84
107
string fieldName = "ModuleVersion" ;
85
108
string fieldValue = "1.0.0.0" ;
86
- int startLineNumber = ast . Extent . StartLineNumber ;
87
- int startColumnNumber = ast . Extent . StartColumnNumber + 2 ; // 2 for "@{",
88
109
string description = string . Format (
89
110
CultureInfo . CurrentCulture ,
90
111
Strings . MissingModuleManifestFieldCorrectionDescription ,
91
112
fieldName ,
92
113
fieldValue ) ;
93
114
var correctionTextTemplate = @"
94
115
# Version number of this module.
95
- {0} = {1}
116
+ {0} = ' {1}'
96
117
" ;
97
118
var correctionText = string . Format (
98
119
correctionTextTemplate ,
@@ -102,7 +123,7 @@ private List<CorrectionExtent> GetCorrectionExtent(HashtableAst ast)
102
123
startLineNumber ,
103
124
startLineNumber ,
104
125
startColumnNumber ,
105
- startColumnNumber + 1 ,
126
+ startColumnNumber ,
106
127
correctionText ,
107
128
ast . Extent . File ,
108
129
description ) ;
0 commit comments