@@ -93,7 +93,7 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
9393 GetDiagnosticSeverity ( ) ,
9494 fileName ,
9595 null ,
96- GetCorrection ( functionDefinitionAst ) . ToList ( ) ) ;
96+ GetCorrection ( ast , functionDefinitionAst ) . ToList ( ) ) ;
9797 }
9898 }
9999
@@ -154,7 +154,7 @@ private DiagnosticSeverity GetDiagnosticSeverity()
154154 return DiagnosticSeverity . Information ;
155155 }
156156
157- private IEnumerable < CorrectionExtent > GetCorrection ( FunctionDefinitionAst funcDefnAst )
157+ private IEnumerable < CorrectionExtent > GetCorrection ( Ast ast , FunctionDefinitionAst funcDefnAst )
158158 {
159159 var helpBuilder = new CommentHelpBuilder ( ) ;
160160
@@ -173,26 +173,45 @@ private IEnumerable<CorrectionExtent> GetCorrection(FunctionDefinitionAst funcDe
173173 endLine ,
174174 startColumn ,
175175 endColumn ,
176- ProcessCorrectionForPlacement (
177- helpBuilder . GetCommentHelp (
178- BlockComment ,
179- VSCodeSnippetCorrection ) ) ,
176+ GetCorrectionText (
177+ helpBuilder . GetCommentHelp ( BlockComment , VSCodeSnippetCorrection ) ,
178+ ast ,
179+ funcDefnAst ) ,
180180 funcDefnAst . Extent . File ) ;
181181 }
182182
183- private string ProcessCorrectionForPlacement ( string correction )
183+ private string GetCorrectionText ( string correction , Ast ast , FunctionDefinitionAst funcDefnAst )
184184 {
185+ var indentationString = String . Empty ;
186+ if ( funcDefnAst . Extent . StartColumnNumber > 1 )
187+ {
188+ indentationString = GetLines ( ast . Extent . Text )
189+ . ElementAt ( funcDefnAst . Extent . StartLineNumber - 1 )
190+ . Substring ( 0 , funcDefnAst . Extent . StartColumnNumber - 1 ) ;
191+ correction = String . Join (
192+ Environment . NewLine ,
193+ GetLines ( correction ) . Select ( l => indentationString + l ) ) ;
194+ }
195+
185196 switch ( placement )
186197 {
187198 case CommentHelpPlacement . Begin :
188- return "{" + Environment . NewLine + correction + Environment . NewLine ;
199+ return $ "{{{Environment.NewLine}{ correction } { Environment . NewLine } ";
200+
189201 case CommentHelpPlacement . End :
190- return Environment . NewLine + correction + Environment . NewLine ;
202+ return $ "{ Environment . NewLine } { correction } { Environment . NewLine } { indentationString } ";
203+
191204 default : // CommentHelpPlacement.Before
192- return correction + Environment . NewLine ;
205+ return $ " { correction } { Environment . NewLine } " ;
193206 }
194207 }
195208
209+ // TODO replace with extension version
210+ private static IEnumerable < string > GetLines ( string text )
211+ {
212+ return text . Split ( '\n ' ) . Select ( l => l . Trim ( '\r ' ) ) ;
213+ }
214+
196215 private void GetCorrectionPosition (
197216 FunctionDefinitionAst funcDefnAst ,
198217 out int startLine ,
@@ -220,7 +239,7 @@ private void GetCorrectionPosition(
220239 default : // CommentHelpPlacement.Before
221240 startLine = funcDefnAst . Extent . StartLineNumber ;
222241 endLine = startLine ;
223- startColumn = funcDefnAst . Extent . StartColumnNumber ;
242+ startColumn = 1 ;
224243 endColumn = startColumn ;
225244 break ;
226245 }
@@ -314,7 +333,7 @@ public string GetCommentHelp(bool blockComment, bool snippet)
314333 {
315334 var boundaryString = new String ( '#' , 30 ) ;
316335 sb . AppendLine ( boundaryString ) ;
317- var lines = helpContent . Split ( ' \n ' ) . Select ( l => l . Trim ( ' \r ' ) ) ;
336+ var lines = GetLines ( helpContent ) ;
318337 foreach ( var line in lines )
319338 {
320339 sb . Append ( "#" ) ;
0 commit comments