@@ -43,63 +43,50 @@ module internal Structure =
4343| Same= 1
4444
4545type Scope =
46- | Open= 0
47- | Namespace= 1
48- | Module= 2
49- | Type= 3
50- | Member= 4
51- | LetOrUse= 5
52- | Match= 6
53- /// MatchLambda = function | expr -> .... | expr ->...
54- | MatchLambda= 7
55- | CompExpr= 8
56- | IfThenElse= 9
57- | ThenInIfThenElse= 10
58- | ElseInIfThenElse= 11
59- | TryWith= 12
60- | TryInTryWith= 13
61- | WithInTryWith= 14
62- | TryFinally= 15
63- | TryInTryFinally= 16
64- | FinallyInTryFinally= 17
65- | ArrayOrList= 18
66- | ObjExpr= 19
67- | For= 20
68- | While= 21
69- | CompExprInternal= 22
70- | Quote= 23
71- | Record= 24
72- | Tuple= 25
73- | SpecialFunc= 26
74- | Do= 27
75- | Lambda= 28
76- | MatchClause= 29
77- | Attribute= 30
78- | Interface= 31
79- | HashDirective= 32
80- | LetOrUseBang= 33
81- | TypeExtension= 34
82- | YieldOrReturn= 35
83- | YieldOrReturnBang= 36
84- | UnionCase= 37
85- | EnumCase= 38
86- | RecordField= 39
87- | SimpleType= 40
88- | RecordDefn= 41
89- | UnionDefn= 42
90- | Comment= 43
91- | XmlDocComment= 44
46+ | Open
47+ | Namespace
48+ | Module
49+ | Type
50+ | Member
51+ | LetOrUse
52+ | CompExpr
53+ | IfThenElse
54+ | TryWith
55+ | TryFinally
56+ | ArrayOrList
57+ | ObjExpr
58+ | For
59+ | While
60+ | Match
61+ | MatchLambda
62+ | Lambda
63+ | CompExprInternal
64+ | Quote
65+ | Record
66+ | SpecialFunc
67+ | Do
68+ | Interface
69+ | HashDirective
70+ | LetOrUseBang
71+ | TypeExtension
72+ | YieldOrReturn
73+ | YieldOrReturnBang
74+ | SimpleType
75+ | RecordDefn
76+ | UnionDefn
77+ | Comment
78+ | XmlDocComment
9279
9380[<NoComparison; Struct>]
94- type internal ScopeRange ( scope : Scope , collapse : Collapse , r : range ) =
95- member __. Scope= scope
96- member __. Collapse= collapse
97- member __. Range= r
81+ type internal ScopeRange =
82+ { Scope: Scope
83+ Collapse: Collapse
84+ Range: range }
9885
9986// Only yield a range that spans 2 or more lines
10087let inline private rcheck scope collapse ( r : range ) =
10188seq { if r.StartLine<> r.EndLinethen
102- yield ScopeRange ( scope, collapse, r ) }
89+ yield { Scope = scope; Collapse = collapse; Range = r } }
10390
10491let rec private parseExpr expression =
10592seq {
@@ -141,12 +128,12 @@ module internal Structure =
141128yield ! parseExpr body
142129| SynExpr.Match( seqPointAtBinding,_, clauses,_, r) ->
143130match seqPointAtBindingwith
144- | SequencePointAtBindingpr ->
145- yield ! rcheck Scope.Match Collapse.Below <| Range.endToEnd pr r
131+ | SequencePointAtBinding_ ->
132+ yield ! rcheck Scope.Match Collapse.Same r
146133| _ -> ()
147134yield ! parseMatchClauses clauses
148135| SynExpr.MatchLambda(_,_, clauses,_, r) ->
149- yield ! rcheck Scope.MatchLambda Collapse.Below <| Range.modStart r 8
136+ yield ! rcheck Scope.MatchLambda Collapse.Same r
150137yield ! parseMatchClauses clauses
151138| SynExpr.App( atomicFlag, isInfix, funcExpr, argExpr, r) ->
152139// seq exprs, custom operators, etc
@@ -174,46 +161,24 @@ module internal Structure =
174161let r = mkFileIndexRange newRange.FileIndex newRange.End( Range.mkPos wholeRange.EndLine( wholeRange.EndColumn- 1 ))
175162yield ! rcheck Scope.ObjExpr Collapse.Below r
176163yield ! parseBindings bindings
177- | SynExpr.TryWith( e,_, matchClauses, tryRange, withRange, tryPoint, withPoint) ->
178- match tryPointwith
179- | SequencePointAtTry r->
180- yield ! rcheck Scope.TryWith Collapse.Below<| Range.endToEnd r tryRange
181- | _ -> ()
182- match withPointwith
183- | SequencePointAtWith r->
184- yield ! rcheck Scope.WithInTryWith Collapse.Below<| Range.endToEnd r withRange
185- | _ -> ()
164+ | SynExpr.TryWith( e,_, matchClauses,_, range,_,_) ->
165+ yield ! rcheck Scope.TryWith Collapse.Same range
186166yield ! parseExpr e
187167yield ! parseMatchClauses matchClauses
188- | SynExpr.TryFinally( tryExpr, finallyExpr, r, tryPoint, finallyPoint ) ->
168+ | SynExpr.TryFinally( tryExpr, finallyExpr, r, tryPoint,_ ) ->
189169match tryPointwith
190170| SequencePointAtTry tryRange->
191171yield ! rcheck Scope.TryFinally Collapse.Below<| Range.endToEnd tryRange r
192172| _ -> ()
193- match finallyPointwith
194- | SequencePointAtFinally finallyRange->
195- yield ! rcheck Scope.FinallyInTryFinally Collapse.Below<| Range.endToEnd finallyRange r
196- | _ -> ()
197173yield ! parseExpr tryExpr
198174yield ! parseExpr finallyExpr
199- | SynExpr.IfThenElse( e1, e2, e3, seqPointInfo ,_,_, r) ->
175+ | SynExpr.IfThenElse( e1, e2, e3,_ ,_,_, r) ->
200176// Outline the entire IfThenElse
201177yield ! rcheck Scope.IfThenElse Collapse.Below r
202- // Outline the `then` scope
203- match seqPointInfowith
204- | SequencePointInfoForBinding.SequencePointAtBinding rt->
205- yield ! rcheck Scope.ThenInIfThenElse Collapse.Below<| Range.endToEnd rt e2.Range
206- | _ -> ()
207178yield ! parseExpr e1
208179yield ! parseExpr e2
209180match e3with
210- | Some e->
211- match ewith // prevent double collapsing on elifs
212- | SynExpr.IfThenElse(_,_,_,_,_,_,_) ->
213- yield ! parseExpr e
214- | _ ->
215- yield ! rcheck Scope.ElseInIfThenElse Collapse.Same e.Range
216- yield ! parseExpr e
181+ | Some e-> yield ! parseExpr e
217182| None-> ()
218183| SynExpr.While(_,_, e, r) ->
219184yield ! rcheck Scope.While Collapse.Below r
@@ -231,8 +196,7 @@ module internal Structure =
231196// subtract columns so the @@> or @> is not collapsed
232197yield ! rcheck Scope.Quote Collapse.Same<| Range.modBoth r( if isRawthen 3 else 2 ) ( if isRawthen 3 else 2 )
233198yield ! parseExpr e
234- | SynExpr.Tuple( es,_, r) ->
235- yield ! rcheck Scope.Tuple Collapse.Same r
199+ | SynExpr.Tuple( es,_,_) ->
236200yield ! Seq.collect parseExpr es
237201| SynExpr.Paren( e,_,_,_) ->
238202yield ! parseExpr e
@@ -249,30 +213,10 @@ module internal Structure =
249213| _ -> ()
250214}
251215
252- and private parseMatchClause ( SynMatchClause.Clause ( synPat , _ , e , _ , _ )) =
253- seq { yield ! rcheck Scope.MatchClause Collapse.Same<| Range.startToEnd synPat.Range e.Range// Collapse the scope after `->`
254- yield ! parseExpr e}
255-
216+ and private parseMatchClause ( SynMatchClause.Clause ( _ , _ , e , _ , _ )) = parseExpr e
256217and private parseMatchClauses = Seq.collect parseMatchClause
257218
258- and private parseAttributes ( attrs : SynAttributes ) =
259- seq {
260- let attrListRange =
261- if List.isEmpty attrsthen Seq.emptyelse
262- rcheck Scope.Attribute Collapse.Same<| Range.startToEnd( attrs.[ 0 ]. Range) ( attrs.[ attrs.Length-1 ]. ArgExpr.Range)
263- match attrswith
264- | [] -> ()
265- | [_] -> yield ! attrListRange
266- | hd:: tl->
267- yield ! attrListRange
268- yield ! parseExpr hd.ArgExpr
269- // If there are more than 2 attributes only add tags to the 2nd and beyond, to avoid double collapsing on the first attribute
270- yield ! tl|> Seq.collect( fun attr -> rcheck Scope.Attribute Collapse.Same<| Range.startToEnd attr.Range attr.ArgExpr.Range)
271- // visit the expressions inside each attribute
272- yield ! attrs|> Seq.collect( fun attr -> parseExpr attr.ArgExpr)
273- }
274-
275- and private parseBinding ( Binding ( _ , kind , _ , _ , attrs , _ , _ , _ , _ , e , br , _ ) as b ) =
219+ and private parseBinding ( Binding ( _ , kind , _ , _ , _ , _ , _ , _ , _ , e , br , _ ) as b ) =
276220seq {
277221// let r = Range.endToEnd b.RangeOfBindingSansRhs b.RangeOfBindingAndRhs
278222match kindwith
@@ -281,7 +225,6 @@ module internal Structure =
281225| SynBindingKind.DoBinding->
282226yield ! rcheck Scope.Do Collapse.Below<| Range.modStart br2
283227| _ -> ()
284- yield ! parseAttributes attrs
285228yield ! parseExpr e
286229}
287230
@@ -332,29 +275,12 @@ module internal Structure =
332275| SynAccess.Internal-> 8
333276seq {
334277match simplewith
335- | SynTypeDefnSimpleRepr.Enum( cases , er) ->
278+ | SynTypeDefnSimpleRepr.Enum(_ , er) ->
336279yield ! rcheck Scope.SimpleType Collapse.Below er
337- yield !
338- cases
339- |> Seq.collect( fun ( SynEnumCase.EnumCase ( attrs , _ , _ , _ , cr )) ->
340- seq { yield ! rcheck Scope.EnumCase Collapse.Below cr
341- yield ! parseAttributes attrs})
342- | SynTypeDefnSimpleRepr.Record(_ opt, fields, rr) ->
343- //yield! rcheck Scope.SimpleType Collapse.Same <| Range.modBoth rr (accessRange opt+1) 1
344- yield ! rcheck Scope.RecordDefn Collapse.Same rr//<| Range.modBoth rr 1 1
345- yield ! fields
346- |> Seq.collect( fun ( SynField.Field ( attrs , _ , _ , _ , _ , _ , _ , fr )) ->
347- seq { yield ! rcheck Scope.RecordField Collapse.Below fr
348- yield ! parseAttributes attrs
349- })
350- | SynTypeDefnSimpleRepr.Union(_ opt, cases, ur) ->
351- // yield! rcheck Scope.SimpleType Collapse.Same <| Range.modStart ur (accessRange opt)
280+ | SynTypeDefnSimpleRepr.Record(_ opt,_, rr) ->
281+ yield ! rcheck Scope.RecordDefn Collapse.Same rr
282+ | SynTypeDefnSimpleRepr.Union(_ opt,_, ur) ->
352283yield ! rcheck Scope.UnionDefn Collapse.Same ur
353- yield ! cases
354- |> Seq.collect( fun ( SynUnionCase.UnionCase ( attrs , _ , _ , _ , _ , cr )) ->
355- seq { yield ! rcheck Scope.UnionCase Collapse.Below cr
356- yield ! parseAttributes attrs
357- })
358284| _ -> ()
359285}
360286
@@ -393,10 +319,10 @@ module internal Structure =
393319match rangeswith
394320| [] -> None
395321| [ r] when r.StartLine= r.EndLine-> None
396- | [ r] -> Some<| ScopeRange ( scope, Collapse.Same, ( Range.mkRange" " r.Start r.End))
322+ | [ r] -> Some{ Scope = scope; Collapse= Collapse .Same; Range= Range .mkRange" " r.Start r.End}
397323| lastRange:: rest->
398324let firstRange = Seq.last rest
399- Some<| ScopeRange ( scope, Collapse.Same, ( Range.mkRange" " firstRange.Start lastRange.End))
325+ Some{ Scope = scope; Collapse= Collapse .Same; Range= Range .mkRange" " firstRange.Start lastRange.End}
400326
401327 decls|> ( List.choose predicate>> groupConsecutiveDecls>> List.choose selectRanges)
402328
@@ -420,17 +346,14 @@ module internal Structure =
420346| SynModuleDecl.Types( types,_) ->
421347yield ! Seq.collect parseTypeDefn types
422348// Fold the attributes above a module
423- | SynModuleDecl.NestedModule( SynComponentInfo.ComponentInfo( attrs ,_,_,_,_,_,_, cmpRange),_, decls,_,_) ->
349+ | SynModuleDecl.NestedModule( SynComponentInfo.ComponentInfo(_ ,_,_,_,_,_,_, cmpRange),_, decls,_,_) ->
424350// Outline the full scope of the module
425351yield ! rcheck Scope.Module Collapse.Below<| Range.endToEnd cmpRange decl.Range
426352// A module's component info stores the ranges of its attributes
427- yield ! parseAttributes attrs
428353yield ! collectOpens decls
429354yield ! Seq.collect parseDeclaration decls
430355| SynModuleDecl.DoExpr(_, e,_) ->
431356yield ! parseExpr e
432- | SynModuleDecl.Attributes( attrs,_) ->
433- yield ! parseAttributes attrs
434357| _ -> ()
435358}
436359
@@ -472,7 +395,7 @@ module internal Structure =
472395 loop( lineNum, Some( CommentList.New commentType( lineNum, lineStr)), result) rest( lineNum+ 1 )
473396| _, Some comment->
474397 loop( lineNum, None, comment:: result) rest( lineNum+ 1 )
475- | _ -> state
398+ | _ -> loop ( lineNum , None , result ) rest ( lineNum + 1 )
476399
477400let comments : CommentList list =
478401 loop(- 1 , None, []) ( List.ofArray lines) 0
@@ -496,13 +419,13 @@ module internal Structure =
496419match comment.Typewith
497420| Regular-> Scope.Comment
498421| XmlDoc-> Scope.XmlDocComment
499- ScopeRange (
500- scopeType,
501- Collapse.Same,
502- Range.mkRange
503- " "
504- ( Range.mkPos( startLine+ 1 ) startCol)
505- ( Range.mkPos( endLine+ 1 ) endCol)) )
422+
423+ { Scope = scopeType
424+ Collapse = Collapse.Same
425+ Range = Range.mkRange
426+ " "
427+ ( Range.mkPos( startLine+ 1 ) startCol)
428+ ( Range.mkPos( endLine+ 1 ) endCol) } )
506429
507430let getOutliningRanges ( sourceLines : string []) ( parsedInput : ParsedInput ) =
508431match parsedInputwith