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

Commitd47027d

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Color struct types with measure as value types (dotnet#5022)
* return SemanticClassificationType.ValueType for types with measure* color measured structs as structs (only)* add tests (wip)* all the tests are green* simplify code* Update service.fs
1 parent2e58c10 commitd47027d

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

‎src/fsharp/service/service.fs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,11 @@ type TypeCheckInfo
13131313
letisDisposableTy(ty:TType)=
13141314
protectAssemblyExplorationNoReraisefalsefalse(fun()-> Infos.ExistsHeadTypeInEntireHierarchy g amap range0 ty g.tcref_System_IDisposable)
13151315

1316+
letisStructTyconRef(tyconRef:TyconRef)=
1317+
letty= generalizedTyconRef tyconRef
1318+
letunderlyingTy= stripTyEqnsAndMeasureEqns g ty
1319+
isStructTy g underlyingTy
1320+
13161321
resolutions
13171322
|> Seq.choose(fun cnr->
13181323
match cnrwith
@@ -1351,6 +1356,8 @@ type TypeCheckInfo
13511356
Some(m, SemanticClassificationType.Interface)
13521357
| CNR(_, Item.Types(_, types), LegitTypeOccurence,_,_,_, m)when types|> List.exists(isStructTy g)->
13531358
Some(m, SemanticClassificationType.ValueType)
1359+
| CNR(_, Item.Types(_, TType_app(tyconRef, TType_measure_::_)::_), LegitTypeOccurence,_,_,_, m)when isStructTyconRef tyconRef->
1360+
Some(m, SemanticClassificationType.ValueType)
13541361
| CNR(_, Item.Types(_, types), LegitTypeOccurence,_,_,_, m)when types|> List.exists isDisposableTy->
13551362
Some(m, SemanticClassificationType.Disposable)
13561363
| CNR(_, Item.Types_, LegitTypeOccurence,_,_,_, m)->

‎vsintegration/tests/UnitTests/VisualFSharp.UnitTests.fsproj‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@
9999
<CompileInclude="UnusedOpensTests.fs">
100100
<Link>CompilerService\UnusedOpensTests.fs</Link>
101101
</Compile>
102-
<CompileInclude="ColorizationServiceTests.fs">
103-
<Link>Roslyn\ColorizationServiceTests.fs</Link>
102+
<CompileInclude="SyntacticColorizationServiceTests.fs">
103+
<Link>Roslyn\SyntacticColorizationServiceTests.fs</Link>
104+
</Compile>
105+
<CompileInclude="SemanticColorizationServiceTests.fs">
106+
<Link>Roslyn\SemanticColorizationServiceTests.fs</Link>
104107
</Compile>
105108
<CompileInclude="BraceMatchingServiceTests.fs">
106109
<Link>Roslyn\BraceMatchingServiceTests.fs</Link>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
namespaceMicrosoft.VisualStudio.FSharp.Editor.Tests.Roslyn
3+
4+
openSystem
5+
openNUnit.Framework
6+
openMicrosoft.VisualStudio.FSharp.Editor
7+
openMicrosoft.FSharp.Compiler.SourceCodeServices
8+
openMicrosoft.FSharp.Compiler
9+
openMicrosoft.CodeAnalysis.Text
10+
11+
[<TestFixture; Category"Roslyn Services">]
12+
typeSemanticClassificationServiceTests()=
13+
letfilePath="C:\\test.fs"
14+
15+
letprojectOptions={
16+
ProjectFileName="C:\\test.fsproj"
17+
ProjectId= None
18+
SourceFiles=[| filePath|]
19+
ReferencedProjects=[||]
20+
OtherOptions=[||]
21+
IsIncompleteTypeCheckEnvironment=true
22+
UseScriptResolutionRules=false
23+
LoadTime= DateTime.MaxValue
24+
UnresolvedReferences= None
25+
OriginalLoadReferences=[]
26+
ExtraProjectInfo= None
27+
Stamp= None
28+
}
29+
30+
letchecker= FSharpChecker.Create()
31+
32+
letgetRanges(sourceText:string):(Range.range* SemanticClassificationType)list=
33+
asyncMaybe{
34+
let!_,_,checkFileResults= checker.ParseAndCheckDocument(filePath,0, sourceText, projectOptions,false,"")
35+
return checkFileResults.GetSemanticClassification(None)
36+
}
37+
|> Async.RunSynchronously
38+
|> Option.toList
39+
|> List.collect Array.toList
40+
41+
letverifyColorizerAtEndOfMarker(fileContents:string,marker:string,classificationType:string)=
42+
lettext= SourceText.From fileContents
43+
letranges= getRanges fileContents
44+
letline= text.Lines.GetLinePosition(fileContents.IndexOf(marker)+ marker.Length-1)
45+
letmarkerPos= Range.mkPos(Range.Line.fromZ line.Line)(line.Character+ marker.Length-1)
46+
match ranges|> List.tryFind(fun(range,_)-> Range.rangeContainsPos range markerPos)with
47+
| None-> Assert.Fail("Cannot find colorization data for end of marker")
48+
| Some(_, ty)-> Assert.AreEqual(classificationType, FSharpClassificationTypes.getClassificationTypeName ty,"Classification data doesn't match for end of marker")
49+
50+
[<TestCase("(*1*)", FSharpClassificationTypes.ValueType)>]
51+
[<TestCase("(*2*)", FSharpClassificationTypes.ReferenceType)>]
52+
[<TestCase("(*3*)", FSharpClassificationTypes.ValueType)>]
53+
[<TestCase("(*4*)", FSharpClassificationTypes.ReferenceType)>]
54+
[<TestCase("(*5*)", FSharpClassificationTypes.ValueType)>]
55+
[<TestCase("(*6*)", FSharpClassificationTypes.ValueType)>]
56+
[<TestCase("(*7*)", FSharpClassificationTypes.ReferenceType)>]
57+
member__.Measured_Types(marker:string,classificationType:string)=
58+
verifyColorizerAtEndOfMarker(
59+
"""#light (*Light*)
60+
open System
61+
62+
[<MeasureAnnotatedAbbreviation>] type (*1*)Guid<[<Measure>] 'm> = Guid
63+
[<MeasureAnnotatedAbbreviation>] type (*2*)string<[<Measure>] 'm> = string
64+
65+
let inline cast<'a, 'b> (a : 'a) : 'b = (# "" a : 'b #)
66+
67+
type Uom =
68+
static member inline tag<[<Measure>]'m> (x : Guid) : (*3*)Guid<'m> = cast x
69+
static member inline tag<[<Measure>]'m> (x : string) : (*4*)string<'m> = cast x
70+
71+
type [<Measure>] Ms
72+
73+
let i: (*5*)int<Ms> = 1<Ms>
74+
let g: (*6*)Guid<Ms> = Uom.tag Guid.Empty
75+
let s: (*7*)string<Ms> = Uom.tag "foo"""",
76+
marker,
77+
classificationType)

‎vsintegration/tests/UnitTests/ColorizationServiceTests.fs‎renamed to ‎vsintegration/tests/unittests/SyntacticColorizationServiceTests.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ open Microsoft.CodeAnalysis.Text
1212
openMicrosoft.VisualStudio.FSharp.Editor
1313

1414
[<TestFixture>][<Category"Roslyn Services">]
15-
typeClassificationServiceTests()=
15+
typeSyntacticClassificationServiceTests()=
1616

1717
memberprivatethis.ExtractMarkerData(fileContents:string,marker:string,defines:string list,isScriptFile:Option<bool>)=
1818
lettextSpan= TextSpan(0, fileContents.Length)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp