Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4c41b73

Browse files
cloudRoutineKevinRansom
authored andcommitted
Additional comments for Structure.fs (dotnet#2444)
1 parent1a5b23d commit4c41b73

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

‎vsintegration/src/FSharp.Editor/Structure/Structure.fs‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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` = []
5759
letrangeOfTypeArgsElse other(typeArgs:SynTyparDecl list)=
5860
match 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 = ...`
8183
typeCollapse=
8284
| Below
8385
| Same
8486

87+
/// Tag to identify the constuct that can be stored alongside its associated ranges
8588
typeScope=
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>]
181186
typeScopeRange={
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
191196
let inlineprivatercheck scope collapse(fullRange:range)(collapseRange:range)=seq{
192197
if fullRange.StartLine<> fullRange.EndLinethenyield{
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 =
482487
yield! 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)->
487492
yield! 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 =
509514
yield! rcheck Scope.EnumCase Collapse.Below cr cr
510515
yield! 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
513518
for SynField.Field(attrs,_,_,_,_,_,_,fr)in fieldsdo
514519
yield! rcheck Scope.RecordField Collapse.Below fr fr
515520
yield! parseAttributes attrs
@@ -523,8 +528,8 @@ module internal Structure =
523528

524529
andprivateparseTypeDefn(TypeDefn(SynComponentInfo.ComponentInfo(_,typeArgs,_,_,_,_,_,r),objectModel,members,fullrange))=
525530
seq{
526-
letgenericRange= rangeOfTypeArgsElse r typeArgs
527-
letcollapse= Range.endToEnd(Range.modEnd1genericRange) fullrange
531+
lettypeArgsRange= rangeOfTypeArgsElse r typeArgs
532+
letcollapse= Range.endToEnd(Range.modEnd1typeArgsRange) fullrange
528533
match objectModelwith
529534
| SynTypeDefnRepr.ObjectModel(defnKind, objMembers, r)->
530535
match defnKindwith
@@ -590,8 +595,7 @@ module internal Structure =
590595
for tin typesdo
591596
yield! 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
596600
letr= Range.endToEnd cmpRange decl.Range
597601
yield! rcheck Scope.Module Collapse.Below decl.Range r
@@ -622,7 +626,7 @@ module internal Structure =
622626

623627
typeprivateLineNum= int
624628
typeprivateLineStr= string
625-
typeprivateCommentType=Regular| XmlDoc
629+
typeprivateCommentType=SingleLine| XmlDoc
626630

627631
[<NoComparison>]
628632
typeprivateCommentList=
@@ -631,9 +635,10 @@ module internal Structure =
631635
static memberNew ty lineStr=
632636
{ Type= ty; Lines= ResizeArray[| lineStr|]}
633637

638+
/// Determine if a line is a single line or xml docummentation comment
634639
letprivate(|Comment|_|)(line:string)=
635640
if line.StartsWith"///"then Some XmlDoc
636-
elif line.StartsWith"//"then SomeRegular
641+
elif line.StartsWith"//"then SomeSingleLine
637642
else None
638643

639644
letgetCommentRanges(lines:string[])=
@@ -674,7 +679,7 @@ module internal Structure =
674679

675680
letscopeType=
676681
match comment.Typewith
677-
|Regular-> Scope.Comment
682+
|SingleLine-> Scope.Comment
678683
| XmlDoc-> Scope.XmlDocComment
679684

680685
letrange= 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

693706
letlastMemberSigRangeElse r memberSigs=
694707
match memberSigswith
@@ -738,15 +751,15 @@ module internal Structure =
738751
}
739752

740753

741-
andprivateparseTypeDefnSig
754+
andprivateparseTypeDefnSig
742755
(TypeDefnSig(SynComponentInfo.ComponentInfo(attribs,typeArgs,_constraints,longId,_doc,_b,_access,r)
743756
as _componentInfo,objectModel,memberSigs,_))=seq{
744757
yield! parseAttributes attribs
745758

746759
letmakeRanges memberSigs=
747-
letgenericRange= rangeOfTypeArgsElse r typeArgs
760+
lettypeArgsRange= rangeOfTypeArgsElse r typeArgs
748761
letrangeEnd= lastMemberSigRangeElse r memberSigs
749-
letcollapse= Range.endToEnd(Range.modEnd1genericRange) rangeEnd
762+
letcollapse= Range.endToEnd(Range.modEnd1typeArgsRange) rangeEnd
750763
letfullrange= Range.startToEnd(longIdentRange longId) rangeEnd
751764
fullrange, collapse
752765

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp