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

Commitdfb7950

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
fix block structure service (dotnet#2037)
1 parente232660 commitdfb7950

File tree

2 files changed

+71
-160
lines changed

2 files changed

+71
-160
lines changed

‎src/fsharp/vs/ServiceStructure.fs‎

Lines changed: 64 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -43,63 +43,50 @@ module internal Structure =
4343
| Same=1
4444

4545
typeScope=
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-
typeinternalScopeRange(scope:Scope,collapse:Collapse,r:range)=
95-
member__.Scope= scope
96-
member__.Collapse= collapse
97-
member__.Range= r
81+
typeinternalScopeRange=
82+
{Scope:Scope
83+
Collapse:Collapse
84+
Range:range}
9885

9986
// Only yield a range that spans 2 or more lines
10087
let inlineprivatercheck scope collapse(r:range)=
10188
seq{if r.StartLine<> r.EndLinethen
102-
yieldScopeRange(scope,collapse, r)}
89+
yield{ Scope=scope; Collapse=collapse; Range= r}}
10390

10491
let recprivateparseExpr expression=
10592
seq{
@@ -141,12 +128,12 @@ module internal Structure =
141128
yield! parseExpr body
142129
| SynExpr.Match(seqPointAtBinding,_,clauses,_,r)->
143130
match 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
|_->()
147134
yield! parseMatchClauses clauses
148135
| SynExpr.MatchLambda(_,_,clauses,_,r)->
149-
yield! rcheck Scope.MatchLambda Collapse.Below<| Range.modStart r8
136+
yield! rcheck Scope.MatchLambda Collapse.Same r
150137
yield! parseMatchClauses clauses
151138
| SynExpr.App(atomicFlag,isInfix,funcExpr,argExpr,r)->
152139
// seq exprs, custom operators, etc
@@ -174,46 +161,24 @@ module internal Structure =
174161
letr= mkFileIndexRange newRange.FileIndex newRange.End(Range.mkPos wholeRange.EndLine(wholeRange.EndColumn-1))
175162
yield! rcheck Scope.ObjExpr Collapse.Below r
176163
yield! 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
186166
yield! parseExpr e
187167
yield! parseMatchClauses matchClauses
188-
| SynExpr.TryFinally(tryExpr,finallyExpr,r,tryPoint,finallyPoint)->
168+
| SynExpr.TryFinally(tryExpr,finallyExpr,r,tryPoint,_)->
189169
match tryPointwith
190170
| SequencePointAtTry tryRange->
191171
yield! 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-
|_->()
197173
yield! parseExpr tryExpr
198174
yield! parseExpr finallyExpr
199-
| SynExpr.IfThenElse(e1,e2,e3,seqPointInfo,_,_,r)->
175+
| SynExpr.IfThenElse(e1,e2,e3,_,_,_,r)->
200176
// Outline the entire IfThenElse
201177
yield! 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-
|_->()
207178
yield! parseExpr e1
208179
yield! parseExpr e2
209180
match 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)->
219184
yield! rcheck Scope.While Collapse.Below r
@@ -231,8 +196,7 @@ module internal Structure =
231196
// subtract columns so the @@> or @> is not collapsed
232197
yield! rcheck Scope.Quote Collapse.Same<| Range.modBoth r(if isRawthen3else2)(if isRawthen3else2)
233198
yield! parseExpr e
234-
| SynExpr.Tuple(es,_,r)->
235-
yield! rcheck Scope.Tuple Collapse.Same r
199+
| SynExpr.Tuple(es,_,_)->
236200
yield! Seq.collect parseExpr es
237201
| SynExpr.Paren(e,_,_,_)->
238202
yield! parseExpr e
@@ -249,30 +213,10 @@ module internal Structure =
249213
|_->()
250214
}
251215

252-
andprivateparseMatchClause(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+
andprivateparseMatchClause(SynMatchClause.Clause(_,_,e,_,_))= parseExpr e
256217
andprivateparseMatchClauses= Seq.collect parseMatchClause
257218

258-
andprivateparseAttributes(attrs:SynAttributes)=
259-
seq{
260-
letattrListRange=
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-
andprivateparseBinding(Binding(_,kind,_,_,attrs,_,_,_,_,e,br,_)as b)=
219+
andprivateparseBinding(Binding(_,kind,_,_,_,_,_,_,_,e,br,_)as b)=
276220
seq{
277221
// let r = Range.endToEnd b.RangeOfBindingSansRhs b.RangeOfBindingAndRhs
278222
match kindwith
@@ -281,7 +225,6 @@ module internal Structure =
281225
| SynBindingKind.DoBinding->
282226
yield! rcheck Scope.Do Collapse.Below<| Range.modStart br2
283227
|_->()
284-
yield! parseAttributes attrs
285228
yield! parseExpr e
286229
}
287230

@@ -332,29 +275,12 @@ module internal Structure =
332275
| SynAccess.Internal->8
333276
seq{
334277
match simplewith
335-
| SynTypeDefnSimpleRepr.Enum(cases,er)->
278+
| SynTypeDefnSimpleRepr.Enum(_,er)->
336279
yield! 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)->
352283
yield! 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 =
393319
match 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->
398324
letfirstRange= 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,_)->
421347
yield! 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
425351
yield! 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
428353
yield! collectOpens decls
429354
yield! Seq.collect parseDeclaration decls
430355
| SynModuleDecl.DoExpr(_,e,_)->
431356
yield! 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

477400
letcomments:CommentList list=
478401
loop(-1, None,[])(List.ofArray lines)0
@@ -496,13 +419,13 @@ module internal Structure =
496419
match 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

507430
letgetOutliningRanges(sourceLines:string[])(parsedInput:ParsedInput)=
508431
match parsedInputwith

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,48 +55,35 @@ type internal FSharpBlockStructureService(checker: FSharpChecker, projectInfoMan
5555
| Scope.Namespace
5656
| Scope.Module-> BlockTypes.Namespace
5757
| Scope.Record
58-
| Scope.Tuple
59-
| Scope.Attribute
6058
| Scope.Interface
6159
| Scope.TypeExtension
62-
| Scope.UnionCase
63-
| Scope.EnumCase
6460
| Scope.SimpleType
6561
| Scope.RecordDefn
6662
| Scope.UnionDefn
6763
| Scope.Type-> BlockTypes.Type
6864
| Scope.Member-> BlockTypes.Member
6965
| Scope.LetOrUse
7066
| Scope.Match
71-
| Scope.IfThenElse
72-
| Scope.ThenInIfThenElse
73-
| Scope.ElseInIfThenElse
74-
| Scope.MatchLambda-> BlockTypes.Conditional
67+
| Scope.MatchLambda
68+
| Scope.IfThenElse-> BlockTypes.Conditional
7569
| Scope.CompExpr
76-
| Scope.TryInTryWith
77-
| Scope.WithInTryWith
7870
| Scope.TryFinally
79-
| Scope.TryInTryFinally
80-
| Scope.FinallyInTryFinally
8171
| Scope.ObjExpr
8272
| Scope.ArrayOrList
8373
| Scope.CompExprInternal
8474
| Scope.Quote
8575
| Scope.SpecialFunc
86-
| Scope.MatchClause
8776
| Scope.Lambda
8877
| Scope.LetOrUseBang
8978
| Scope.YieldOrReturn
9079
| Scope.YieldOrReturnBang
91-
| Scope.RecordField
9280
| Scope.TryWith-> BlockTypes.Expression
9381
| Scope.Do-> BlockTypes.Statement
9482
| Scope.While
9583
| Scope.For-> BlockTypes.Loop
9684
| Scope.HashDirective-> BlockTypes.PreprocessorRegion
9785
| Scope.Comment
9886
| Scope.XmlDocComment-> BlockTypes.Comment
99-
|_-> BlockTypes.Nonstructural
10087

10188
override__.Language= FSharpCommonConstants.FSharpLanguageName
10289

@@ -108,11 +95,12 @@ type internal FSharpBlockStructureService(checker: FSharpChecker, projectInfoMan
10895
let!fileParseResults= checker.ParseFileInProject(document.FilePath, sourceText.ToString(), options)
10996
match fileParseResults.ParseTreewith
11097
| Some parsedInput->
111-
letranges= Structure.getOutliningRanges(sourceText.Lines|> Seq.map(fun x-> x.ToString())|> Seq.toArray) parsedInput
11298
letblockSpans=
113-
ranges
114-
|> Seq.map(fun range->
115-
BlockSpan(scopeToBlockType range.Scope,true, CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, range.Range)))
99+
Structure.getOutliningRanges(sourceText.Lines|> Seq.map(fun x-> x.ToString())|> Seq.toArray) parsedInput
100+
|> Seq.distinctBy(fun x-> x.Range.StartLine)
101+
|> Seq.choose(fun range->
102+
CommonRoslynHelpers.TryFSharpRangeToTextSpan(sourceText, range.Range)
103+
|> Option.map(fun span-> BlockSpan(scopeToBlockType range.Scope,true, span)))
116104
return BlockStructure(blockSpans.ToImmutableArray())
117105
| None->return BlockStructure(ImmutableArray<_>.Empty)
118106
| None->return BlockStructure(ImmutableArray<_>.Empty)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp