@@ -93,7 +93,7 @@ public override IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string file
93
93
GetDiagnosticSeverity ( ) ,
94
94
fileName ,
95
95
null ,
96
- GetCorrection ( functionDefinitionAst ) . ToList ( ) ) ;
96
+ GetCorrection ( ast , functionDefinitionAst ) . ToList ( ) ) ;
97
97
}
98
98
}
99
99
@@ -154,7 +154,7 @@ private DiagnosticSeverity GetDiagnosticSeverity()
154
154
return DiagnosticSeverity . Information ;
155
155
}
156
156
157
- private IEnumerable < CorrectionExtent > GetCorrection ( FunctionDefinitionAst funcDefnAst )
157
+ private IEnumerable < CorrectionExtent > GetCorrection ( Ast ast , FunctionDefinitionAst funcDefnAst )
158
158
{
159
159
var helpBuilder = new CommentHelpBuilder ( ) ;
160
160
@@ -173,26 +173,45 @@ private IEnumerable<CorrectionExtent> GetCorrection(FunctionDefinitionAst funcDe
173
173
endLine ,
174
174
startColumn ,
175
175
endColumn ,
176
- ProcessCorrectionForPlacement (
177
- helpBuilder . GetCommentHelp (
178
- BlockComment ,
179
- VSCodeSnippetCorrection ) ) ,
176
+ GetCorrectionText (
177
+ helpBuilder . GetCommentHelp ( BlockComment , VSCodeSnippetCorrection ) ,
178
+ ast ,
179
+ funcDefnAst ) ,
180
180
funcDefnAst . Extent . File ) ;
181
181
}
182
182
183
- private string ProcessCorrectionForPlacement ( string correction )
183
+ private string GetCorrectionText ( string correction , Ast ast , FunctionDefinitionAst funcDefnAst )
184
184
{
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
+
185
196
switch ( placement )
186
197
{
187
198
case CommentHelpPlacement . Begin :
188
- return "{" + Environment . NewLine + correction + Environment . NewLine ;
199
+ return $ "{{{Environment.NewLine}{ correction } { Environment . NewLine } ";
200
+
189
201
case CommentHelpPlacement . End :
190
- return Environment . NewLine + correction + Environment . NewLine ;
202
+ return $ "{ Environment . NewLine } { correction } { Environment . NewLine } { indentationString } ";
203
+
191
204
default : // CommentHelpPlacement.Before
192
- return correction + Environment . NewLine ;
205
+ return $ " { correction } { Environment . NewLine } " ;
193
206
}
194
207
}
195
208
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
+
196
215
private void GetCorrectionPosition (
197
216
FunctionDefinitionAst funcDefnAst ,
198
217
out int startLine ,
@@ -220,7 +239,7 @@ private void GetCorrectionPosition(
220
239
default : // CommentHelpPlacement.Before
221
240
startLine = funcDefnAst . Extent . StartLineNumber ;
222
241
endLine = startLine ;
223
- startColumn = funcDefnAst . Extent . StartColumnNumber ;
242
+ startColumn = 1 ;
224
243
endColumn = startColumn ;
225
244
break ;
226
245
}
@@ -314,7 +333,7 @@ public string GetCommentHelp(bool blockComment, bool snippet)
314
333
{
315
334
var boundaryString = new String ( '#' , 30 ) ;
316
335
sb . AppendLine ( boundaryString ) ;
317
- var lines = helpContent . Split ( ' \n ' ) . Select ( l => l . Trim ( ' \r ' ) ) ;
336
+ var lines = GetLines ( helpContent ) ;
318
337
foreach ( var line in lines )
319
338
{
320
339
sb . Append ( "#" ) ;
0 commit comments