@@ -54,6 +54,8 @@ module internal Structure =
5454| [] -> Range.range0
5555| head::_ -> Range.startToEnd head.idRange( List.last longId) .idRange
5656
57+ /// Caclulate the range of the provided type arguments (<'a,...,'z>)
58+ /// or return the range `other` when `typeArgs` = []
5759let rangeOfTypeArgsElse other ( typeArgs : SynTyparDecl list ) =
5860match typeArgswith
5961| [] -> other
@@ -75,13 +77,14 @@ module internal Structure =
7577|> List.reduce Range.unionRanges
7678
7779
78- ///Scope indicates the way a range/snapshot should be collapsed.|Scope.Scope. Same| is for a scope inside
79- /// some kind of scope delimiter, e.g. `[| ... |]`, `[ ... ]`, `{ ... }`, etc.|Scope. Below| is for expressions
80+ ///Collapse indicates the way a range/snapshot should be collapsed.` Same` is for a scope inside
81+ /// some kind of scope delimiter, e.g. `[| ... |]`, `[ ... ]`, `{ ... }`, etc.` Below` is for expressions
8082/// following a binding or the right hand side of a pattern, e.g. `let x = ...`
8183type Collapse =
8284| Below
8385| Same
8486
87+ /// Tag to identify the constuct that can be stored alongside its associated ranges
8588type Scope =
8689| Open
8790| Namespace
@@ -177,6 +180,8 @@ module internal Structure =
177180| Comment-> " Comment"
178181| XmlDocComment-> " XmlDocComment"
179182
183+ /// Stores the range for a construct, the sub-range that should be collapsed for outlinging,
184+ /// a tag for the construct type, and a tag for the collapse style
180185[<NoComparison>]
181186type ScopeRange = {
182187 Scope: Scope
@@ -187,7 +192,7 @@ module internal Structure =
187192 CollapseRange: range
188193}
189194
190- // Only yield a range thatspans 2 or more lines
195+ /// Validation function to ensure thatranges yielded for outlinging span 2 or more lines
191196let inline private rcheck scope collapse ( fullRange : range ) ( collapseRange : range ) = seq {
192197if fullRange.StartLine<> fullRange.EndLinethen yield {
193198 Scope= scope
@@ -208,8 +213,8 @@ module internal Structure =
208213| SynExpr.Upcast( e,_,_)
209214| SynExpr.Downcast( e,_,_)
210215| SynExpr.AddressOf(_, e,_,_)
211- | SynExpr.InferredDowncast( e,_) // add scope for this?
212- | SynExpr.InferredUpcast( e,_) // add scope for this?
216+ | SynExpr.InferredDowncast( e,_)
217+ | SynExpr.InferredUpcast( e,_)
213218| SynExpr.DotGet( e,_,_,_)
214219| SynExpr.Do( e,_)
215220| SynExpr.DotSet( e,_,_,_)
@@ -482,7 +487,7 @@ module internal Structure =
482487yield ! Seq.collect( parseSynMemberDefn r) members
483488| None-> ()
484489| SynMemberDefn.NestedType( td, _, _) ->
485- yield ! parseTypeDefn td//d.Range
490+ yield ! parseTypeDefn td
486491| SynMemberDefn.AbstractSlot( ValSpfn( synType= synt), _, r) ->
487492yield ! rcheck Scope.Member Collapse.Below d.Range( Range.startToEnd synt.Range r)
488493| SynMemberDefn.AutoProperty( synExpr= e; range= r) ->
@@ -509,7 +514,7 @@ module internal Structure =
509514yield ! rcheck Scope.EnumCase Collapse.Below cr cr
510515yield ! parseAttributes attrs
511516| SynTypeDefnSimpleRepr.Record(_, fields, rr) ->
512- yield ! rcheck Scope.RecordDefn Collapse.Same rr rr//<| Range.modBoth rr 1 1
517+ yield ! rcheck Scope.RecordDefn Collapse.Same rr rr
513518for SynField.Field( attrs,_,_,_,_,_,_, fr) in fieldsdo
514519yield ! rcheck Scope.RecordField Collapse.Below fr fr
515520yield ! parseAttributes attrs
@@ -523,8 +528,8 @@ module internal Structure =
523528
524529and private parseTypeDefn ( TypeDefn ( SynComponentInfo.ComponentInfo ( _ , typeArgs , _ , _ , _ , _ , _ , r ), objectModel , members , fullrange )) =
525530seq {
526- let genericRange = rangeOfTypeArgsElse r typeArgs
527- let collapse = Range.endToEnd( Range.modEnd1 genericRange ) fullrange
531+ let typeArgsRange = rangeOfTypeArgsElse r typeArgs
532+ let collapse = Range.endToEnd( Range.modEnd1 typeArgsRange ) fullrange
528533match objectModelwith
529534| SynTypeDefnRepr.ObjectModel( defnKind, objMembers, r) ->
530535match defnKindwith
@@ -590,8 +595,7 @@ module internal Structure =
590595for tin typesdo
591596yield ! parseTypeDefn t
592597// Fold the attributes above a module
593- | SynModuleDecl.NestedModule( SynComponentInfo.ComponentInfo( attrs,_,_,_,_,_,_, cmpRange),_, decls,_,_) ->
594- // cmpInfo.
598+ | SynModuleDecl.NestedModule( SynComponentInfo.ComponentInfo( attrs,_,_,_,_,_,_, cmpRange),_, decls,_,_) ->
595599// Outline the full scope of the module
596600let r = Range.endToEnd cmpRange decl.Range
597601yield ! rcheck Scope.Module Collapse.Below decl.Range r
@@ -622,7 +626,7 @@ module internal Structure =
622626
623627type private LineNum = int
624628type private LineStr = string
625- type private CommentType = Regular | XmlDoc
629+ type private CommentType = SingleLine | XmlDoc
626630
627631[<NoComparison>]
628632type private CommentList =
@@ -631,9 +635,10 @@ module internal Structure =
631635static member New ty lineStr =
632636{ Type= ty; Lines= ResizeArray[| lineStr|] }
633637
638+ /// Determine if a line is a single line or xml docummentation comment
634639let private (| Comment | _ |) ( line : string ) =
635640if line.StartsWith" ///" then Some XmlDoc
636- elif line.StartsWith" //" then SomeRegular
641+ elif line.StartsWith" //" then SomeSingleLine
637642else None
638643
639644let getCommentRanges ( lines : string []) =
@@ -674,7 +679,7 @@ module internal Structure =
674679
675680let scopeType =
676681match comment.Typewith
677- | Regular -> Scope.Comment
682+ | SingleLine -> Scope.Comment
678683| XmlDoc-> Scope.XmlDocComment
679684
680685let range = Range.mkRange" " ( Range.mkPos( startLine+ 1 ) startCol) ( Range.mkPos( endLine+ 1 ) endCol)
@@ -689,6 +694,14 @@ module internal Structure =
689694// Signature File AST Traversal //
690695//=======================================//
691696
697+ (*
698+ The following helper functions are necessary due to a bug in the Parsed UAST within a
699+ signature file that causes the scopes to extend past the end of the construct and overlap
700+ with the following construct. This necessitates inspecting the children of the construct and
701+ finding the end of the last child's range to use instead.
702+
703+ Detailed further in - https://github.com/Microsoft/visualfsharp/issues/2094
704+ *)
692705
693706let lastMemberSigRangeElse r memberSigs =
694707match memberSigswith
@@ -738,15 +751,15 @@ module internal Structure =
738751}
739752
740753
741- and private parseTypeDefnSig
754+ and private parseTypeDefnSig
742755( TypeDefnSig ( SynComponentInfo.ComponentInfo ( attribs , typeArgs , _constraints , longId , _doc , _b , _access , r )
743756as _componentInfo , objectModel , memberSigs , _ )) = seq {
744757yield ! parseAttributes attribs
745758
746759let makeRanges memberSigs =
747- let genericRange = rangeOfTypeArgsElse r typeArgs
760+ let typeArgsRange = rangeOfTypeArgsElse r typeArgs
748761let rangeEnd = lastMemberSigRangeElse r memberSigs
749- let collapse = Range.endToEnd( Range.modEnd1 genericRange ) rangeEnd
762+ let collapse = Range.endToEnd( Range.modEnd1 typeArgsRange ) rangeEnd
750763let fullrange = Range.startToEnd( longIdentRange longId) rangeEnd
751764 fullrange, collapse
752765