@@ -539,7 +539,13 @@ public FunctionDefinitionAst GetFunctionDefinitionAtLine(
539
539
return functionDefinitionAst as FunctionDefinitionAst ;
540
540
}
541
541
542
- // todo add xml doc
542
+ /// <summary>
543
+ /// Finds a function definition that follows or contains the given line number.
544
+ /// </summary>
545
+ /// <param name="scriptFile">Open script file.</param>
546
+ /// <param name="lineNumber">The 1 based line on which to look for function definition.</param>
547
+ /// <param name="helpLocation"></param>
548
+ /// <returns>If found, returns the function definition, otherwise, returns null.</returns>
543
549
public FunctionDefinitionAst GetFunctionDefinitionForHelpComment (
544
550
ScriptFile scriptFile ,
545
551
int lineNumber ,
@@ -553,10 +559,10 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
553
559
return funcDefnAst ;
554
560
}
555
561
562
+ // find all the script definitions that contain the line `lineNumber`
556
563
var foundAsts = scriptFile . ScriptAst . FindAll (
557
564
ast =>
558
565
{
559
- // find all the script definitions that contain the line `lineNumber`
560
566
var fdAst = ast as FunctionDefinitionAst ;
561
567
if ( fdAst == null )
562
568
{
@@ -570,10 +576,10 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
570
576
571
577
if ( foundAsts != null && foundAsts . Any ( ) )
572
578
{
579
+ // of all the function definitions found, return the innermost function
580
+ // definition that contains `lineNumber`
573
581
funcDefnAst = foundAsts . Cast < FunctionDefinitionAst > ( ) . Aggregate ( ( x , y ) =>
574
582
{
575
- // of all the function definitions found, return the innermost function definition that contains
576
- // `lineNumber`
577
583
if ( x . Extent . StartOffset >= y . Extent . StartOffset && x . Extent . EndOffset <= x . Extent . EndOffset )
578
584
{
579
585
return x ;
@@ -582,10 +588,7 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
582
588
return y ;
583
589
} ) ;
584
590
585
- // TODO fix help completion in nested functions
586
591
// TODO use tokens to check for non empty character instead of just checking for line offset
587
- // check if the line number is the first line in the function body
588
- // check if the line number is the last line in the function body
589
592
if ( funcDefnAst . Body . Extent . StartLineNumber == lineNumber - 1 )
590
593
{
591
594
helpLocation = "begin" ;
0 commit comments