@@ -50,14 +50,14 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
5050 System . Diagnostics . Debug . Assert (
5151 errorRecord . Exception != null && ! String . IsNullOrWhiteSpace ( errorRecord . Exception . Message ) ,
5252 Strings . NullErrorMessage ) ;
53- var hashTableAsts = ast . Find ( x => x is HashtableAst , false ) ;
53+ var hashTableAst = ast . Find ( x => x is HashtableAst , false ) ;
5454 yield return new DiagnosticRecord (
5555 errorRecord . Exception . Message ,
56- ast . Extent ,
56+ hashTableAst . Extent ,
5757 GetName ( ) ,
5858 DiagnosticSeverity . Warning ,
5959 fileName ,
60- suggestedCorrections : GetCorrectionExtent ( hashTableAsts as HashtableAst ) ) ;
60+ suggestedCorrections : GetCorrectionExtent ( hashTableAst as HashtableAst ) ) ;
6161 }
6262
6363 }
@@ -66,33 +66,54 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
6666
6767 }
6868
69-
7069 /// <summary>
7170 /// Gets the correction extent
7271 /// </summary>
7372 /// <param name="ast"></param>
7473 /// <returns>A List of CorrectionExtent</returns>
7574 private List < CorrectionExtent > GetCorrectionExtent ( HashtableAst ast )
7675 {
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 ;
81104 }
82105
83106 var correctionExtents = new List < CorrectionExtent > ( ) ;
84107 string fieldName = "ModuleVersion" ;
85108 string fieldValue = "1.0.0.0" ;
86- int startLineNumber = ast . Extent . StartLineNumber ;
87- int startColumnNumber = ast . Extent . StartColumnNumber + 2 ; // 2 for "@{",
88109 string description = string . Format (
89110 CultureInfo . CurrentCulture ,
90111 Strings . MissingModuleManifestFieldCorrectionDescription ,
91112 fieldName ,
92113 fieldValue ) ;
93114 var correctionTextTemplate = @"
94115# Version number of this module.
95- {0} = {1}
116+ {0} = ' {1}'
96117" ;
97118 var correctionText = string . Format (
98119 correctionTextTemplate ,
@@ -102,7 +123,7 @@ private List<CorrectionExtent> GetCorrectionExtent(HashtableAst ast)
102123 startLineNumber ,
103124 startLineNumber ,
104125 startColumnNumber ,
105- startColumnNumber + 1 ,
126+ startColumnNumber ,
106127 correctionText ,
107128 ast . Extent . File ,
108129 description ) ;
0 commit comments