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

Commitf4c00d1

Browse files
cartermpKevinRansom
authored andcommitted
Add mutable coloring for byref, outref, and ref cells in records (dotnet#5582)
* Add mutable coloring for byref, outref, and ref cells in records* Add regression test* Make test not dumb* Address feedback and add negative test* doot* Clean up logic* Different test* i dunno
1 parentc1b5aa5 commitf4c00d1

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

‎src/fsharp/service/service.fs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,13 +1324,23 @@ type TypeCheckInfo
13241324
letunderlyingTy= stripTyEqnsAndMeasureEqns g ty
13251325
isStructTy g underlyingTy
13261326

1327+
letIsValRefMutable(vref:ValRef)=
1328+
// Mutable values, ref cells, and non-inref byrefs are mutable.
1329+
vref.IsMutable
1330+
|| Tastops.isRefCellTy g vref.Type
1331+
||(Tastops.isByrefTy g vref.Type&&not(Tastops.isInByrefTy g vref.Type))
1332+
1333+
letisRecdFieldMutable(rfinfo:RecdFieldInfo)=
1334+
(rfinfo.RecdField.IsMutable&& rfinfo.LiteralValue.IsNone)
1335+
|| Tastops.isRefCellTy g rfinfo.RecdField.FormalType
1336+
13271337
resolutions
13281338
|> Seq.choose(fun cnr->
13291339
match cnrwith
13301340
// 'seq' in 'seq { ... }' gets colored as keywords
13311341
| CNR(_,(Item.Value vref), ItemOccurence.Use,_,_,_, m)when valRefEq g g.seq_vref vref->
13321342
Some(m, SemanticClassificationType.ComputationExpression)
1333-
| CNR(_,(Item.Value vref),_,_,_,_, m)whenvref.IsMutable|| Tastops.isRefCellTy gvref.Type->
1343+
| CNR(_,(Item.Value vref),_,_,_,_, m)whenIsValRefMutablevref->
13341344
Some(m, SemanticClassificationType.MutableVar)
13351345
| CNR(_, Item.Value KeywordIntrinsicValue, ItemOccurence.Use,_,_,_, m)->
13361346
Some(m, SemanticClassificationType.IntrinsicFunction)
@@ -1343,7 +1353,7 @@ type TypeCheckInfo
13431353
Some(m, SemanticClassificationType.Operator)
13441354
else
13451355
Some(m, SemanticClassificationType.Function)
1346-
| CNR(_, Item.RecdField rfinfo,_,_,_,_, m)whenrfinfo.RecdField.IsMutable&&rfinfo.LiteralValue.IsNone->
1356+
| CNR(_, Item.RecdField rfinfo,_,_,_,_, m)whenisRecdFieldMutablerfinfo->
13471357
Some(m, SemanticClassificationType.MutableVar)
13481358
| CNR(_, Item.RecdField rfinfo,_,_,_,_, m)when isFunction g rfinfo.FieldType->
13491359
Some(m, SemanticClassificationType.Function)

‎vsintegration/tests/unittests/SemanticColorizationServiceTests.fs‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type SemanticClassificationServiceTests() =
4040
|> Option.toList
4141
|> List.collect Array.toList
4242

43-
letverifyColorizerAtEndOfMarker(fileContents:string,marker:string,classificationType:string)=
43+
letverifyClassificationAtEndOfMarker(fileContents:string,marker:string,classificationType:string)=
4444
lettext= SourceText.From fileContents
4545
letranges= getRanges fileContents
4646
letline= text.Lines.GetLinePosition(fileContents.IndexOf(marker)+ marker.Length-1)
@@ -49,6 +49,14 @@ type SemanticClassificationServiceTests() =
4949
| None-> Assert.Fail("Cannot find colorization data for end of marker")
5050
| Some(_, ty)-> Assert.AreEqual(classificationType, FSharpClassificationTypes.getClassificationTypeName ty,"Classification data doesn't match for end of marker")
5151

52+
letverifyNoClassificationDataAtEndOfMarker(fileContents:string,marker:string,classificationType:string)=
53+
lettext= SourceText.From fileContents
54+
letranges= getRanges fileContents
55+
letline= text.Lines.GetLinePosition(fileContents.IndexOf(marker)+ marker.Length-1)
56+
letmarkerPos= Range.mkPos(Range.Line.fromZ line.Line)(line.Character+ marker.Length-1)
57+
letanyData= ranges|> List.exists(fun(range,sct)-> Range.rangeContainsPos range markerPos&&((FSharpClassificationTypes.getClassificationTypeName sct)= classificationType))
58+
Assert.False(anyData,"Classification data was found when it wasn't expected.")
59+
5260
[<TestCase("(*1*)", FSharpClassificationTypes.ValueType)>]
5361
[<TestCase("(*2*)", FSharpClassificationTypes.ReferenceType)>]
5462
[<TestCase("(*3*)", FSharpClassificationTypes.ValueType)>]
@@ -57,7 +65,7 @@ type SemanticClassificationServiceTests() =
5765
[<TestCase("(*6*)", FSharpClassificationTypes.ValueType)>]
5866
[<TestCase("(*7*)", FSharpClassificationTypes.ReferenceType)>]
5967
member__.Measured_Types(marker:string,classificationType:string)=
60-
verifyColorizerAtEndOfMarker(
68+
verifyClassificationAtEndOfMarker(
6169
"""#light (*Light*)
6270
open System
6371
@@ -76,4 +84,60 @@ type SemanticClassificationServiceTests() =
7684
let g: (*6*)Guid<Ms> = Uom.tag Guid.Empty
7785
let s: (*7*)string<Ms> = Uom.tag "foo"""",
7886
marker,
79-
classificationType)
87+
classificationType)
88+
89+
[<TestCase("(*1*)", FSharpClassificationTypes.MutableVar)>]
90+
[<TestCase("(*2*)", FSharpClassificationTypes.MutableVar)>]
91+
[<TestCase("(*3*)", FSharpClassificationTypes.MutableVar)>]
92+
[<TestCase("(*4*)", FSharpClassificationTypes.MutableVar)>]
93+
[<TestCase("(*5*)", FSharpClassificationTypes.MutableVar)>]
94+
[<TestCase("(*6*)", FSharpClassificationTypes.MutableVar)>]
95+
[<TestCase("(*7*)", FSharpClassificationTypes.MutableVar)>]
96+
[<TestCase("(*8*)", FSharpClassificationTypes.MutableVar)>]
97+
[<TestCase("(*9*)", FSharpClassificationTypes.MutableVar)>]
98+
[<TestCase("(*10*)", FSharpClassificationTypes.MutableVar)>]
99+
[<TestCase("(*11*)", FSharpClassificationTypes.MutableVar)>]
100+
[<TestCase("(*12*)", FSharpClassificationTypes.MutableVar)>]
101+
member__.MutableValues(marker:string,classificationType:string)=
102+
letsourceText="""
103+
type R1 = { mutable (*1*)Doop: int}
104+
let r1 = { (*2*)Doop = 12 }
105+
r1.Doop
106+
107+
let mutable (*3*)first = 12
108+
109+
printfn "%d" (*4*)first
110+
111+
let g ((*5*)xRef: outref<int>) = (*6*)xRef <- 12
112+
113+
let f() =
114+
let (*7*)second = &first
115+
let (*8*)third: outref<int> = &first
116+
printfn "%d%d" (*9*)second (*10*)third
117+
118+
type R = { (*11*)MutableField: int ref }
119+
let r = { (*12*)MutableField = ref 12 }
120+
r.MutableField
121+
r.MutableField := 3
122+
"""
123+
verifyClassificationAtEndOfMarker(sourceText, marker, classificationType)
124+
125+
126+
[<TestCase("(*1*)", FSharpClassificationTypes.MutableVar)>]
127+
[<TestCase("(*2*)", FSharpClassificationTypes.MutableVar)>]
128+
[<TestCase("(*3*)", FSharpClassificationTypes.MutableVar)>]
129+
[<TestCase("(*4*)", FSharpClassificationTypes.MutableVar)>]
130+
[<TestCase("(*5*)", FSharpClassificationTypes.MutableVar)>]
131+
[<TestCase("(*6*)", FSharpClassificationTypes.MutableVar)>]
132+
member__.NoInrefsExpected(marker:string,classificationType:string)=
133+
letsourceText="""
134+
let f (item: (*1*)inref<int>) = printfn "%d" (*2*)item
135+
let g() =
136+
let x = 1
137+
let y = 2
138+
let (*3*)xRef = &x
139+
let (*4*)yRef: inref<int> = &y
140+
f (*5*)&xRef
141+
f (*6*)&yRef
142+
"""
143+
verifyNoClassificationDataAtEndOfMarker(sourceText, marker, classificationType)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp