@@ -545,6 +545,14 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
545
545
int lineNumber ,
546
546
out string helpLocation )
547
547
{
548
+ // check if the next line contains a function definition
549
+ var funcDefnAst = GetFunctionDefinitionAtLine ( scriptFile , lineNumber + 1 ) ;
550
+ if ( funcDefnAst != null )
551
+ {
552
+ helpLocation = "before" ;
553
+ return funcDefnAst ;
554
+ }
555
+
548
556
var foundAsts = scriptFile . ScriptAst . FindAll (
549
557
ast =>
550
558
{
@@ -560,14 +568,9 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
560
568
} ,
561
569
true ) ;
562
570
563
- // check if the next line contains a function definition
564
- if ( foundAsts == null || ! foundAsts . Any ( ) )
571
+ if ( foundAsts != null && foundAsts . Any ( ) )
565
572
{
566
- helpLocation = "before" ;
567
- return GetFunctionDefinitionAtLine ( scriptFile , lineNumber + 1 ) ;
568
- }
569
-
570
- var funcDefnAst = foundAsts . Cast < FunctionDefinitionAst > ( ) . Aggregate ( ( x , y ) =>
573
+ funcDefnAst = foundAsts . Cast < FunctionDefinitionAst > ( ) . Aggregate ( ( x , y ) =>
571
574
{
572
575
// of all the function definitions found, return the innermost function definition that contains
573
576
// `lineNumber`
@@ -579,20 +582,21 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
579
582
return y ;
580
583
} ) ;
581
584
582
- // TODO fix help completion in nested functions
583
- // TODO use tokens to check for non empty character instead of just checking for line offset
584
- // check if the line number is the first line in the function body
585
- // check if the line number is the last line in the function body
586
- if ( funcDefnAst . Body . Extent . StartLineNumber == lineNumber - 1 )
587
- {
588
- helpLocation = "begin" ;
589
- return funcDefnAst ;
590
- }
585
+ // TODO fix help completion in nested functions
586
+ // 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
+ if ( funcDefnAst . Body . Extent . StartLineNumber == lineNumber - 1 )
590
+ {
591
+ helpLocation = "begin" ;
592
+ return funcDefnAst ;
593
+ }
591
594
592
- if ( funcDefnAst . Body . Extent . EndLineNumber == lineNumber + 1 )
593
- {
594
- helpLocation = "end" ;
595
- return funcDefnAst ;
595
+ if ( funcDefnAst . Body . Extent . EndLineNumber == lineNumber + 1 )
596
+ {
597
+ helpLocation = "end" ;
598
+ return funcDefnAst ;
599
+ }
596
600
}
597
601
598
602
helpLocation = null ;
0 commit comments