@@ -11,24 +11,16 @@ module internal Structure =
1111/// from an untyped AST for the purposes of block structure.
1212[<RequireQualifiedAccess>]
1313module private Range =
14- let inline union ( r1 : range ) ( r2 : range ) =
15- let startPos =
16- if r1.StartLine<= r2.StartLine
17- && r1.StartColumn<= r2.StartColumnthen r1.Startelse r2.Start
18- let endPos =
19- if r1.EndLine>= r2.EndLine
20- && r1.EndColumn>= r2.EndColumnthen r1.Endelse r2.End
21- mkFileIndexRange r1.FileIndex startPos endPos
2214
2315let unionOpts ( r1 : range option ) ( r2 : range option ) =
2416match r1, r2with
2517| None, None-> None
2618| Some r, None-> Some r
2719| None, Some r-> Some r
28- | Some r1, Some r2-> union r1 r2|> Some
20+ | Some r1, Some r2-> unionRanges r1 r2|> Some
2921
3022/// Create a range starting at the end of r1 and finishing at the end of r2
31- let inline endToEnd ( r1 : range ) ( r2 : range ) = mkFileIndexRange r1.FileIndex r1.End r2.End
23+ let inline endToEnd ( r1 : range ) ( r2 : range ) = mkFileIndexRange r1.FileIndex r1.End r2.End
3224
3325/// Create a range starting at the end of r1 and finishing at the start of r2
3426let inline endToStart ( r1 : range ) ( r2 : range ) = mkFileIndexRange r1.FileIndex r1.End r2.Start
@@ -57,26 +49,30 @@ module internal Structure =
5749let rEnd = Range.mkPos r.EndLine( r.EndColumn- modEnd)
5850 mkFileIndexRange r.FileIndex rStart rEnd
5951
60-
6152let longIdentRange ( longId : LongIdent ) =
62- Range.startToEnd( List.head longId) .idRange( List.last longId) .idRange
53+ match longIdwith
54+ | [] -> Range.range0
55+ | head::_ -> Range.startToEnd head.idRange( List.last longId) .idRange
6356
6457let rangeOfTypeArgsElse other ( typeArgs : SynTyparDecl list ) =
6558match typeArgswith
6659| [] -> other
6760| ls->
68- ls|> List.map( fun ( TyparDecl ( _ , typarg )) -> typarg.Range)
69- |> List.reduce Range.union
61+ ls
62+ |> List.map( fun ( TyparDecl ( _ , typarg )) -> typarg.Range)
63+ |> List.reduce Range.unionRanges
7064
7165let rangeOfSynPatsElse other ( synPats : SynSimplePat list ) =
7266match synPatswith
7367| [] -> other
7468| ls->
75- ls|> List.map(
76- fun ( SynSimplePat.Attrib ( range = r )
77- | SynSimplePat.Id ( range = r )
78- | SynSimplePat.Typed ( range = r )) -> r)
79- |> List.reduce Range.union
69+ ls
70+ |> List.map( fun x ->
71+ match xwith
72+ | SynSimplePat.Attrib( range= r)
73+ | SynSimplePat.Id( range= r)
74+ | SynSimplePat.Typed( range= r) -> r)
75+ |> List.reduce Range.unionRanges
8076
8177
8278/// Scope indicates the way a range/snapshot should be collapsed. |Scope.Scope.Same| is for a scope inside
@@ -346,10 +342,7 @@ module internal Structure =
346342// This is not the best way to establish the position of `else`
347343// the AST doesn't provide an easy way to find the position of the keyword
348344// as such `else` will be left out of block structuring and outlining until a
349- // a suitible approach is determined
350- // let elseRange = Range.endToEnd elseExpr.Range r
351- // let elseCollapse = Range.startToEnd elseExpr.Range r
352- // yield! rcheck Scope.ElseInIfThenElse Collapse.Same elseExpr.Range elseExpr.Range
345+ // a suitable approach is determined
353346yield ! parseExpr elseExpr
354347| None-> ()
355348| SynExpr.While(_,_, e, r) ->
@@ -615,22 +608,16 @@ module internal Structure =
615608
616609let private parseModuleOrNamespace ( SynModuleOrNamespace.SynModuleOrNamespace ( longId , _ , isModule , decls , _ , attribs , _ , r )) =
617610seq {
618- match longIdwith
619- | [] -> ()
620- | _ ->
621- yield ! parseAttributes attribs
622- let idRange = longIdentRange longId
623- let fullrange = Range.startToEnd idRange r
624- let collapse = Range.endToEnd idRange r
625- if isModulethen
626- yield ! rcheck Scope.Module Collapse.Below fullrange collapse
627- //else
628- // //yield! rcheck Scope.Namespace Collapse.Below (Range.modEnd -1 fullrange) (Range.modEnd -1 collapse)
629- // yield! rcheck Scope.Namespace Collapse.Below (fullrange) (collapse)
630-
631- yield ! collectHashDirectives decls
632- yield ! collectOpens decls
633- yield ! Seq.collect parseDeclaration decls
611+ yield ! parseAttributes attribs
612+ let idRange = longIdentRange longId
613+ let fullrange = Range.startToEnd idRange r
614+ let collapse = Range.endToEnd idRange r
615+ if isModulethen
616+ yield ! rcheck Scope.Module Collapse.Below fullrange collapse
617+
618+ yield ! collectHashDirectives decls
619+ yield ! collectOpens decls
620+ yield ! Seq.collect parseDeclaration decls
634621}
635622
636623type private LineNum = int