Skip to content

Commit f5ea97e

Browse files
author
Kapil Borle
committed
Use extension methods to find smallest ast
1 parent e8fa987 commit f5ea97e

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/PowerShellEditorServices/Language/LanguageService.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,8 @@ private Ast FindSmallestStatementAst(ScriptFile scriptFile, int lineNumber, int
624624
return null;
625625
}
626626

627-
Func<IScriptExtent, int> getExtentWitdh = extent => extent.EndOffset - extent.StartOffset;
628-
var minDiff = getExtentWitdh(scriptFile.ScriptAst.Extent);
629-
Ast minAst = scriptFile.ScriptAst;
630-
foreach (var ast in asts)
631-
{
632-
var diff = getExtentWitdh(ast.Extent);
633-
if (diff < minDiff)
634-
{
635-
minDiff = diff;
636-
minAst = ast;
637-
}
638-
}
639-
640-
return minAst;
627+
// Find ast with the smallest extent
628+
return asts.MinElement((astX, astY) => astX.Extent.ExtentWitdhComparer(astY.Extent));
641629
}
642630

643631
#endregion

0 commit comments

Comments
 (0)