diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index 15f01224e78..dc704d12fd8 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -6,6 +6,7 @@ open System open System.Diagnostics open Internal.Utilities.Library open FSharp.Compiler.CodeAnalysis +open FSharp.Compiler.EditorServices.ParsedInput open FSharp.Compiler.Symbols open FSharp.Compiler.Syntax open FSharp.Compiler.SyntaxTreeOps @@ -47,13 +48,6 @@ module internal CodeGenerationUtils = stringWriter.Dispose() indentWriter.Dispose() - /// An recursive pattern that collect all sequential expressions to avoid StackOverflowException - let rec (|Sequentials|_|) = - function - | SynExpr.Sequential (_, _, e, Sequentials es, _) -> Some(e :: es) - | SynExpr.Sequential (_, _, e1, e2, _) -> Some [ e1; e2 ] - | _ -> None - /// Represent environment where a captured identifier should be renamed type NamesWithIndices = Map> diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index d41426a5e70..a8344a59e97 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -233,6 +233,19 @@ module Entity = module ParsedInput = + /// A pattern that collects all sequential expressions to avoid StackOverflowException + let internal (|Sequentials|_|) expr = + + let rec collect expr acc = + match expr with + | SynExpr.Sequential (_, _, e1, (SynExpr.Sequential _ as e2), _) -> collect e2 (e1 :: acc) + | SynExpr.Sequential (_, _, e1, e2, _) -> e2 :: e1 :: acc + | _ -> acc + + match collect expr [] with + | [] -> None + | exprs -> Some(List.rev exprs) + let emptyStringSet = HashSet() let GetRangeOfExprLeftOfDot (pos: pos, parsedInput) = @@ -558,13 +571,6 @@ module ParsedInput = | SynArgPats.Pats ps -> ps | SynArgPats.NamePatPairs (pats = xs) -> List.map (fun (_, _, pat) -> pat) xs - /// A recursive pattern that collect all sequential expressions to avoid StackOverflowException - let rec (|Sequentials|_|) expr = - match expr with - | SynExpr.Sequential (_, _, e, Sequentials es, _) -> Some(e :: es) - | SynExpr.Sequential (_, _, e1, e2, _) -> Some [ e1; e2 ] - | _ -> None - let inline isPosInRange range = rangeContainsPos range pos let inline ifPosInRange range f = @@ -1557,13 +1563,6 @@ module ParsedInput = SyntaxTraversal.Traverse(pos, parsedInput, visitor) |> ignore path |> List.map (fun x -> x.idText) |> List.toArray - /// An recursive pattern that collect all sequential expressions to avoid StackOverflowException - let rec (|Sequentials|_|) expr = - match expr with - | SynExpr.Sequential (_, _, e, Sequentials es, _) -> Some(e :: es) - | SynExpr.Sequential (_, _, e1, e2, _) -> Some [ e1; e2 ] - | _ -> None - let (|ConstructorPats|) pats = match pats with | SynArgPats.Pats ps -> ps diff --git a/src/Compiler/Service/ServiceParsedInputOps.fsi b/src/Compiler/Service/ServiceParsedInputOps.fsi index 36bed4d46fb..f0542957759 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fsi +++ b/src/Compiler/Service/ServiceParsedInputOps.fsi @@ -120,6 +120,9 @@ type public InsertionContextEntity = /// Operations querying the entire syntax tree module public ParsedInput = + /// A pattern that collects all sequential expressions to avoid StackOverflowException + val internal (|Sequentials|_|): SynExpr -> SynExpr list option + val TryFindExpressionASTLeftOfDotLeftOfCursor: pos: pos * parsedInput: ParsedInput -> (pos * bool) option val GetRangeOfExprLeftOfDot: pos: pos * parsedInput: ParsedInput -> range option