Skip to content

Commit e0c5dd7

Browse files
author
Kapil Borle
committed
Fix help completion in nested functions
1 parent ef9e358 commit e0c5dd7

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/PowerShellEditorServices/Language/LanguageService.cs

+24-20
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,14 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
545545
int lineNumber,
546546
out string helpLocation)
547547
{
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+
548556
var foundAsts = scriptFile.ScriptAst.FindAll(
549557
ast =>
550558
{
@@ -560,14 +568,9 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
560568
},
561569
true);
562570

563-
// check if the next line contains a function definition
564-
if (foundAsts == null || !foundAsts.Any())
571+
if (foundAsts != null && foundAsts.Any())
565572
{
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) =>
571574
{
572575
// of all the function definitions found, return the innermost function definition that contains
573576
// `lineNumber`
@@ -579,20 +582,21 @@ public FunctionDefinitionAst GetFunctionDefinitionForHelpComment(
579582
return y;
580583
});
581584

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+
}
591594

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+
}
596600
}
597601

598602
helpLocation = null;

0 commit comments

Comments
 (0)