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