@@ -539,7 +539,13 @@ public FunctionDefinitionAst GetFunctionDefinitionAtLine(
539539 return functionDefinitionAst as FunctionDefinitionAst ;
540540 }
541541
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>
543549 public FunctionDefinitionAst GetFunctionDefinitionForHelpComment (
544550 ScriptFile scriptFile ,
545551 int lineNumber ,
@@ -553,10 +559,10 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
553559 return funcDefnAst ;
554560 }
555561
562+ // find all the script definitions that contain the line `lineNumber`
556563 var foundAsts = scriptFile . ScriptAst . FindAll (
557564 ast =>
558565 {
559- // find all the script definitions that contain the line `lineNumber`
560566 var fdAst = ast as FunctionDefinitionAst ;
561567 if ( fdAst == null )
562568 {
@@ -570,10 +576,10 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
570576
571577 if ( foundAsts != null && foundAsts . Any ( ) )
572578 {
579+ // of all the function definitions found, return the innermost function
580+ // definition that contains `lineNumber`
573581 funcDefnAst = foundAsts . Cast < FunctionDefinitionAst > ( ) . Aggregate ( ( x , y ) =>
574582 {
575- // of all the function definitions found, return the innermost function definition that contains
576- // `lineNumber`
577583 if ( x . Extent . StartOffset >= y . Extent . StartOffset && x . Extent . EndOffset <= x . Extent . EndOffset )
578584 {
579585 return x ;
@@ -582,10 +588,7 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
582588 return y ;
583589 } ) ;
584590
585- // TODO fix help completion in nested functions
586591 // 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
589592 if ( funcDefnAst . Body . Extent . StartLineNumber == lineNumber - 1 )
590593 {
591594 helpLocation = "begin" ;
0 commit comments