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

Commita8115c1

Browse files
auduchinokKevinRansom
authored andcommitted
Symbols API: add Index to active pattern case, Name to pattern group (#4222)
* Symbols API: add Index to active pattern case, Name to pattern group* Symbols API: add active pattern case use tests
1 parent452332f commita8115c1

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

‎fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<CompileInclude="$(FSharpSourcesRoot)\..\tests\service\EditorTests.fs">
4747
<Link>EditorTests.fs</Link>
4848
</Compile>
49+
<CompileInclude="$(FSharpSourcesRoot)\..\tests\service\Symbols.fs">
50+
<Link>Symbols.fs</Link>
51+
</Compile>
4952
<CompileInclude="$(FSharpSourcesRoot)\..\tests\service\FileSystemTests.fs">
5053
<Link>FileSystemTests.fs</Link>
5154
</Compile>

‎src/fsharp/symbols/Symbols.fs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,8 @@ and FSharpActivePatternCase(cenv, apinfo: PrettyNaming.ActivePatternInfo, typ, n
908908

909909
member__.Name= apinfo.ActiveTags.[n]
910910

911+
member__.Index= n
912+
911913
member__.DeclarationLocation= snd apinfo.ActiveTagsWithRanges.[n]
912914

913915
member__.Group= FSharpActivePatternGroup(cenv, apinfo, typ, valOpt)
@@ -926,7 +928,9 @@ and FSharpActivePatternCase(cenv, apinfo: PrettyNaming.ActivePatternInfo, typ, n
926928
|_->""
927929

928930
andFSharpActivePatternGroup(cenv,apinfo:PrettyNaming.ActivePatternInfo,typ,valOpt)=
929-
931+
932+
member__.Name= valOpt|> Option.map(fun vref-> vref.LogicalName)
933+
930934
member__.Names= makeReadOnlyCollection apinfo.Names
931935

932936
member__.IsTotal= apinfo.IsTotal

‎src/fsharp/symbols/Symbols.fsi‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,10 @@ and [<Class>] public FSharpActivePatternCase =
850850
inherit FSharpSymbol
851851

852852
/// The name of the active pattern case
853-
memberName:string
853+
memberName:string
854+
855+
/// Index of the case in the pattern group
856+
memberIndex:int
854857

855858
/// The location of declaration of the active pattern case
856859
memberDeclarationLocation:range
@@ -866,6 +869,10 @@ and [<Class>] public FSharpActivePatternCase =
866869

867870
/// Represents all cases within an active pattern
868871
and [<Class>]publicFSharpActivePatternGroup=
872+
873+
/// The whole group name
874+
memberName:string option
875+
869876
/// The names of the active pattern cases
870877
memberNames:IList<string>
871878

‎tests/service/Symbols.fs‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#if INTERACTIVE
2+
#r"../../Debug/fcs/net45/FSharp.Compiler.Service.dll"// note, run 'build fcs debug' to generate this, this DLL has a public API so can be used from F# Interactive
3+
#r"../../packages/NUnit.3.5.0/lib/net45/nunit.framework.dll"
4+
#load"FsUnit.fs"
5+
#load"Common.fs"
6+
#else
7+
moduleTests.Service.Symbols
8+
#endif
9+
10+
openFSharp.Compiler.Service.Tests.Common
11+
openFsUnit
12+
openNUnit.Framework
13+
openMicrosoft.FSharp.Compiler.SourceCodeServices
14+
15+
moduleActivePatterns=
16+
17+
letcompletePatternInput="""
18+
let (|True|False|) = function
19+
| true -> True
20+
| false -> False
21+
22+
match true with
23+
| True | False -> ()
24+
"""
25+
26+
letpartialPatternInput="""
27+
let (|String|_|) = function
28+
| :? String -> Some ()
29+
| _ -> None
30+
31+
match "foo" with
32+
| String
33+
| _ -> ()
34+
"""
35+
36+
letgetCaseUsages source line=
37+
letfileName,options= mkTestFileAndOptions source[||]
38+
let_,checkResults= parseAndCheckFile fileName source options
39+
40+
checkResults.GetAllUsesOfAllSymbolsInFile()
41+
|> Async.RunSynchronously
42+
|> Array.filter(fun su-> su.RangeAlternate.StartLine= line&& su.Symbol:? FSharpActivePatternCase)
43+
|> Array.map(fun su-> su.Symbol:?> FSharpActivePatternCase)
44+
45+
[<Test>]
46+
let``Active pattern case indices``()=
47+
letgetIndices= Array.map(fun(case: FSharpActivePatternCase)-> case.Index)
48+
49+
getCaseUsages completePatternInput7|> getIndices|> shouldEqual[|0;1|]
50+
getCaseUsages partialPatternInput7|> getIndices|> shouldEqual[|0|]
51+
52+
[<Test>]
53+
let``Active pattern group names``()=
54+
letgetGroupName(case:FSharpActivePatternCase)= case.Group.Name.Value
55+
56+
getCaseUsages completePatternInput7|> Array.head|> getGroupName|> shouldEqual"|True|False|"
57+
getCaseUsages partialPatternInput7|> Array.head|> getGroupName|> shouldEqual"|String|_|"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
<CompileInclude="..\..\..\tests\service\Common.fs">
6565
<Link>Common.fs</Link>
6666
</Compile>
67+
<CompileInclude="..\..\..\tests\service\Symbols.fs">
68+
<Link>ServiceAnalysis\Symbols.fs</Link>
69+
</Compile>
6770
<CompileInclude="..\..\..\tests\service\EditorTests.fs">
6871
<Link>EditorTests.fs</Link>
6972
</Compile>
@@ -376,7 +379,7 @@
376379
<HintPath>$(FSharpSourcesRoot)\..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
377380
<Private>true</Private>
378381
</Reference>
379-
<ProjectReferenceInclude="..\Salsa\VisualFSharp.Salsa.fsproj">
382+
<ProjectReferenceInclude="..\Salsa\VisualFSharp.Salsa.fsproj">
380383
<Name>VisualFSharp.Salsa</Name>
381384
<Project>{fbd4b354-dc6e-4032-8ec7-c81d8dfb1af7}</Project>
382385
<Private>True</Private>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp