Skip to content

Commit ae5f77c

Browse files
committed
Merge pull request #562 from Jand42/master
add FSharpEntity.ArrayRank
2 parents 6aee90f + 1e4d162 commit ae5f77c

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/fsharp/vs/Symbols.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ and FSharpEntity(cenv:cenv, entity:EntityRef) =
297297
isResolved() &&
298298
isArrayTyconRef cenv.g entity
299299

300+
member __.ArrayRank =
301+
checkIsResolved()
302+
rankOfArrayTyconRef cenv.g entity
303+
300304
member __.IsProvided =
301305
isResolved() &&
302306
entity.IsProvided

src/fsharp/vs/Symbols.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ and [<Class>] FSharpEntity =
167167
/// Indicates if the entity is an array type
168168
member IsArrayType : bool
169169

170+
/// Get the rank of an array type
171+
member ArrayRank : int
172+
170173
/// Indicates if the entity is a 'fake' symbol related to a static instantiation of a type provider
171174
member IsStaticInstantiation : bool
172175

tests/service/ProjectAnalysisTests.fs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,8 @@ type AnotherMutableList() =
30263026
let f1 (x: System.Collections.Generic.IList<'T>) = () // grab the IList symbol and look into it
30273027
let f2 (x: AnotherMutableList) = () // grab the AnotherMutableList symbol and look into it
30283028
let f3 (x: System.Collections.ObjectModel.ObservableCollection<'T>) = () // grab the ObservableCollection symbol and look into it
3029+
let f4 (x: int[]) = () // test a one-dimensional array
3030+
let f5 (x: int[,,]) = () // test a multi-dimensional array
30293031
"""
30303032
File.WriteAllText(fileName1, fileSource1)
30313033
let cleanFileName a = if a = fileName1 then "file1" else "??"
@@ -3048,21 +3050,33 @@ let ``Test Project22 IList contents`` () =
30483050

30493051
let wholeProjectResults = checker.ParseAndCheckProject(Project22.options) |> Async.RunSynchronously
30503052

3051-
let ilistTypeUse =
3053+
let allUsesOfAllSymbols =
30523054
wholeProjectResults.GetAllUsesOfAllSymbols()
30533055
|> Async.RunSynchronously
3056+
3057+
let ilistTypeUse =
3058+
allUsesOfAllSymbols
30543059
|> Array.find (fun su -> su.Symbol.DisplayName = "IList")
30553060

30563061
let ocTypeUse =
3057-
wholeProjectResults.GetAllUsesOfAllSymbols()
3058-
|> Async.RunSynchronously
3062+
allUsesOfAllSymbols
30593063
|> Array.find (fun su -> su.Symbol.DisplayName = "ObservableCollection")
30603064

30613065
let alistTypeUse =
3062-
wholeProjectResults.GetAllUsesOfAllSymbols()
3063-
|> Async.RunSynchronously
3066+
allUsesOfAllSymbols
30643067
|> Array.find (fun su -> su.Symbol.DisplayName = "AnotherMutableList")
30653068

3069+
let allTypes =
3070+
allUsesOfAllSymbols
3071+
|> Array.choose (fun su -> match su.Symbol with :? FSharpMemberOrFunctionOrValue as s -> Some s.FullType | _ -> None )
3072+
3073+
let arrayTypes =
3074+
allTypes
3075+
|> Array.choose (fun t ->
3076+
if t.HasTypeDefinition then
3077+
let td = t.TypeDefinition
3078+
if td.IsArrayType then Some (td.DisplayName, td.ArrayRank) else None
3079+
else None )
30663080

30673081
let ilistTypeDefn = ilistTypeUse.Symbol :?> FSharpEntity
30683082
let ocTypeDefn = ocTypeUse.Symbol :?> FSharpEntity
@@ -3111,6 +3125,8 @@ let ``Test Project22 IList contents`` () =
31113125
(set [("IList", ["interface"]); ("ICollection", ["interface"]);
31123126
("IEnumerable", ["interface"]); ("IEnumerable", ["interface"])])
31133127

3128+
arrayTypes |> shouldEqual [|("[]", 1); ("[,,]", 3)|]
3129+
31143130
[<Test>]
31153131
let ``Test Project22 IList properties`` () =
31163132

0 commit comments

Comments
 (0)