Skip to content

Commit 297e22a

Browse files
committed
Improve parser handling union types
1 parent 867c237 commit 297e22a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

TypedocConverter/Helpers.fs

+17-3
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ let rec getType (typeInfo: Type): EntityBodyType =
123123
match innerTypes with
124124
| [] -> { Type = "object"; InnerTypes = []; Name = None }
125125
| _ ->
126-
printWarning ("Taking only the first type " + innerTypes.[0].Type + " for the entire union type.")
127-
getType innerTypes.[0] // TODO: generate unions
126+
let takenType =
127+
innerTypes
128+
|> List.sortWith typeSorter
129+
|> List.head
130+
match takenType.Name with
131+
| Some name -> printWarning ("Taking type " + name + " for the entire union type.")
132+
| _ -> printWarning ("Taking type " + takenType.Type + " for the entire union type.")
133+
getType takenType // TODO: generate unions
128134
| _ ->{ Type = "object"; InnerTypes = []; Name = None }
129135
| "intersection" -> { Type = "object"; InnerTypes = []; Name = None } // TODO: generate intersections
130136
| "reflection" ->
@@ -191,7 +197,15 @@ and getGenericTypeParameters (nodes: Reflection list) = // TODO: generate consta
191197
|> List.where(fun x -> x.Kind = ReflectionKind.TypeParameter)
192198
|> List.map (fun x -> x.Name)
193199
types |> List.map (fun x -> {| Type = x; Constraint = "" |})
194-
200+
and typeSorter typeA typeB =
201+
let typesOrder = ["array"; "tuple"; "reference"; "intrinsic"]
202+
let indexA = typesOrder |> List.tryFindIndex (fun x -> x = typeA.Type)
203+
let indexB = typesOrder |> List.tryFindIndex (fun x -> x = typeB.Type)
204+
match (indexA, indexB) with
205+
| (None, None) -> 0
206+
| (Some _, None) -> -1
207+
| (None, Some _) -> 1
208+
| (Some a, Some b) -> a.CompareTo b
195209
let getMethodParameters (parameters: Reflection list) =
196210
parameters
197211
|> List.where(fun x -> x.Kind = ReflectionKind.Parameter)

0 commit comments

Comments
 (0)