提交 a8115c15 编写于 作者: E Eugene Auduchinok 提交者: Kevin Ransom (msft)

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
上级 452332f0
......@@ -46,6 +46,9 @@
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\EditorTests.fs">
<Link>EditorTests.fs</Link>
</Compile>
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\Symbols.fs">
<Link>Symbols.fs</Link>
</Compile>
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\FileSystemTests.fs">
<Link>FileSystemTests.fs</Link>
</Compile>
......
......@@ -908,6 +908,8 @@ and FSharpActivePatternCase(cenv, apinfo: PrettyNaming.ActivePatternInfo, typ, n
member __.Name = apinfo.ActiveTags.[n]
member __.Index = n
member __.DeclarationLocation = snd apinfo.ActiveTagsWithRanges.[n]
member __.Group = FSharpActivePatternGroup(cenv, apinfo, typ, valOpt)
......@@ -926,7 +928,9 @@ and FSharpActivePatternCase(cenv, apinfo: PrettyNaming.ActivePatternInfo, typ, n
| _ -> ""
and FSharpActivePatternGroup(cenv, apinfo:PrettyNaming.ActivePatternInfo, typ, valOpt) =
member __.Name = valOpt |> Option.map (fun vref -> vref.LogicalName)
member __.Names = makeReadOnlyCollection apinfo.Names
member __.IsTotal = apinfo.IsTotal
......
......@@ -850,7 +850,10 @@ and [<Class>] public FSharpActivePatternCase =
inherit FSharpSymbol
/// The name of the active pattern case
member Name: string
member Name: string
/// Index of the case in the pattern group
member Index: int
/// The location of declaration of the active pattern case
member DeclarationLocation : range
......@@ -866,6 +869,10 @@ and [<Class>] public FSharpActivePatternCase =
/// Represents all cases within an active pattern
and [<Class>] public FSharpActivePatternGroup =
/// The whole group name
member Name: string option
/// The names of the active pattern cases
member Names: IList<string>
......
#if INTERACTIVE
#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
#r "../../packages/NUnit.3.5.0/lib/net45/nunit.framework.dll"
#load "FsUnit.fs"
#load "Common.fs"
#else
module Tests.Service.Symbols
#endif
open FSharp.Compiler.Service.Tests.Common
open FsUnit
open NUnit.Framework
open Microsoft.FSharp.Compiler.SourceCodeServices
module ActivePatterns =
let completePatternInput = """
let (|True|False|) = function
| true -> True
| false -> False
match true with
| True | False -> ()
"""
let partialPatternInput = """
let (|String|_|) = function
| :? String -> Some ()
| _ -> None
match "foo" with
| String
| _ -> ()
"""
let getCaseUsages source line =
let fileName, options = mkTestFileAndOptions source [| |]
let _, checkResults = parseAndCheckFile fileName source options
checkResults.GetAllUsesOfAllSymbolsInFile()
|> Async.RunSynchronously
|> Array.filter (fun su -> su.RangeAlternate.StartLine = line && su.Symbol :? FSharpActivePatternCase)
|> Array.map (fun su -> su.Symbol :?> FSharpActivePatternCase)
[<Test>]
let ``Active pattern case indices`` () =
let getIndices = Array.map (fun (case: FSharpActivePatternCase) -> case.Index)
getCaseUsages completePatternInput 7 |> getIndices |> shouldEqual [| 0; 1 |]
getCaseUsages partialPatternInput 7 |> getIndices |> shouldEqual [| 0 |]
[<Test>]
let ``Active pattern group names`` () =
let getGroupName (case: FSharpActivePatternCase) = case.Group.Name.Value
getCaseUsages completePatternInput 7 |> Array.head |> getGroupName |> shouldEqual "|True|False|"
getCaseUsages partialPatternInput 7 |> Array.head |> getGroupName |> shouldEqual "|String|_|"
......@@ -64,6 +64,9 @@
<Compile Include="..\..\..\tests\service\Common.fs">
<Link>Common.fs</Link>
</Compile>
<Compile Include="..\..\..\tests\service\Symbols.fs">
<Link>ServiceAnalysis\Symbols.fs</Link>
</Compile>
<Compile Include="..\..\..\tests\service\EditorTests.fs">
<Link>EditorTests.fs</Link>
</Compile>
......@@ -376,7 +379,7 @@
<HintPath>$(FSharpSourcesRoot)\..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
<Private>true</Private>
</Reference>
<ProjectReference Include="..\Salsa\VisualFSharp.Salsa.fsproj">
<ProjectReference Include="..\Salsa\VisualFSharp.Salsa.fsproj">
<Name>VisualFSharp.Salsa</Name>
<Project>{fbd4b354-dc6e-4032-8ec7-c81d8dfb1af7}</Project>
<Private>True</Private>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册