diff --git a/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj b/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj
index e83bc805c00..4593e56815f 100644
--- a/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj
+++ b/fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj
@@ -46,6 +46,9 @@
EditorTests.fs
+
+ Symbols.fs
+
FileSystemTests.fs
diff --git a/src/fsharp/symbols/Symbols.fs b/src/fsharp/symbols/Symbols.fs
index 4860d62fbd6..43ba54e0810 100644
--- a/src/fsharp/symbols/Symbols.fs
+++ b/src/fsharp/symbols/Symbols.fs
@@ -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
diff --git a/src/fsharp/symbols/Symbols.fsi b/src/fsharp/symbols/Symbols.fsi
index 1d69298d88e..5d9c1b9417c 100644
--- a/src/fsharp/symbols/Symbols.fsi
+++ b/src/fsharp/symbols/Symbols.fsi
@@ -850,7 +850,10 @@ and [] 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 [] public FSharpActivePatternCase =
/// Represents all cases within an active pattern
and [] public FSharpActivePatternGroup =
+
+ /// The whole group name
+ member Name: string option
+
/// The names of the active pattern cases
member Names: IList
diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs
new file mode 100644
index 00000000000..03001fe87c9
--- /dev/null
+++ b/tests/service/Symbols.fs
@@ -0,0 +1,57 @@
+#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)
+
+ []
+ 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 |]
+
+ []
+ 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|_|"
diff --git a/vsintegration/tests/unittests/VisualFSharp.UnitTests.fsproj b/vsintegration/tests/unittests/VisualFSharp.UnitTests.fsproj
index 99bfe362cfb..0eb67c32862 100644
--- a/vsintegration/tests/unittests/VisualFSharp.UnitTests.fsproj
+++ b/vsintegration/tests/unittests/VisualFSharp.UnitTests.fsproj
@@ -64,6 +64,9 @@
Common.fs
+
+ ServiceAnalysis\Symbols.fs
+
EditorTests.fs
@@ -376,7 +379,7 @@
$(FSharpSourcesRoot)\..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll
true
-
+
VisualFSharp.Salsa
{fbd4b354-dc6e-4032-8ec7-c81d8dfb1af7}
True