Skip to content

Commit 674790d

Browse files
committed
update-scripts: Correctly handle propreties without a 'type'
1 parent 8e9458e commit 674790d

File tree

1 file changed

+54
-50
lines changed

1 file changed

+54
-50
lines changed

update-scripts/rust-analyzer/default.nix

+54-50
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let
4141
let
4242
inner =
4343
{
44-
type,
44+
type ? null,
4545
enum ? null,
4646
minimum ? null,
4747
maximum ? null,
@@ -66,58 +66,62 @@ let
6666
t: mkRustAnalyzerOptionType nullable "${property_name}-sub" t
6767
) possibleTypes;
6868
}
69-
else if lib.isList type then
69+
else
7070
(
71-
if lib.head type == "null" then
72-
assert lib.assertMsg (
73-
lib.length type == 2
74-
) "Lists starting with null are assumed to mean nullOr, so length 2";
75-
let
76-
innerType = property // {
77-
type = lib.elemAt type 1;
78-
};
79-
inner = mkRustAnalyzerOptionType nullable "${property_name}-inner" innerType;
80-
in
81-
assert lib.assertMsg nullable "nullOr types are not yet handled";
82-
inner
83-
else
84-
let
85-
innerTypes = builtins.map (
86-
t: mkRustAnalyzerOptionType nullable "${property_name}-inner" (property // { type = t; })
87-
) type;
88-
in
71+
assert lib.assertMsg (type != null) "property is neither anyOf nor enum, it must have a type";
72+
if lib.isList type then
73+
(
74+
if lib.head type == "null" then
75+
assert lib.assertMsg (
76+
lib.length type == 2
77+
) "Lists starting with null are assumed to mean nullOr, so length 2";
78+
let
79+
innerType = property // {
80+
type = lib.elemAt type 1;
81+
};
82+
inner = mkRustAnalyzerOptionType nullable "${property_name}-inner" innerType;
83+
in
84+
assert lib.assertMsg nullable "nullOr types are not yet handled";
85+
inner
86+
else
87+
let
88+
innerTypes = builtins.map (
89+
t: mkRustAnalyzerOptionType nullable "${property_name}-inner" (property // { type = t; })
90+
) type;
91+
in
92+
{
93+
kind = "oneOf";
94+
subTypes = innerTypes;
95+
}
96+
)
97+
else if type == "array" then
8998
{
90-
kind = "oneOf";
91-
subTypes = innerTypes;
99+
kind = "list";
100+
item = mkRustAnalyzerOptionType false "${property_name}-item" items;
92101
}
93-
)
94-
else if type == "array" then
95-
{
96-
kind = "list";
97-
item = mkRustAnalyzerOptionType false "${property_name}-item" items;
98-
}
99-
else if type == "number" || type == "integer" then
100-
{
101-
kind = type;
102-
inherit minimum maximum;
103-
}
104-
else if type == "object" && properties != null then
105-
{
106-
kind = "submodule";
107-
options = lib.mapAttrs (
108-
name: value: mkRustAnalyzerOptionType false "${property_name}.${name}" value
109-
) properties;
110-
}
111-
else if
112-
lib.elem type [
113-
"object"
114-
"string"
115-
"boolean"
116-
]
117-
then
118-
{ kind = type; }
119-
else
120-
throw "Unhandled value in ${property_name}: ${lib.generators.toPretty { } property}";
102+
else if type == "number" || type == "integer" then
103+
{
104+
kind = type;
105+
inherit minimum maximum;
106+
}
107+
else if type == "object" && properties != null then
108+
{
109+
kind = "submodule";
110+
options = lib.mapAttrs (
111+
name: value: mkRustAnalyzerOptionType false "${property_name}.${name}" value
112+
) properties;
113+
}
114+
else if
115+
lib.elem type [
116+
"object"
117+
"string"
118+
"boolean"
119+
]
120+
then
121+
{ kind = type; }
122+
else
123+
throw "Unhandled value in ${property_name}: ${lib.generators.toPretty { } property}"
124+
);
121125
in
122126
builtins.addErrorContext "While creating type for ${property_name}:\n${lib.generators.toPretty { } property}" (
123127
inner property

0 commit comments

Comments
 (0)