Skip to content

Commit 8e9458e

Browse files
committed
update-scripts: Add more verbose errors for rust-analyzer
1 parent e448413 commit 8e9458e

File tree

1 file changed

+80
-74
lines changed

1 file changed

+80
-74
lines changed

update-scripts/rust-analyzer/default.nix

+80-74
Original file line numberDiff line numberDiff line change
@@ -37,85 +37,91 @@ let
3737
) options;
3838

3939
mkRustAnalyzerOptionType =
40-
nullable: property_name:
41-
{
42-
type,
43-
enum ? null,
44-
minimum ? null,
45-
maximum ? null,
46-
items ? null,
47-
anyOf ? null,
48-
properties ? null,
49-
# Not used in the function, but anyOf values contain it
50-
enumDescriptions ? null,
51-
}@property:
52-
if enum != null then
53-
{
54-
kind = "enum";
55-
values = enum;
56-
}
57-
else if anyOf != null then
58-
let
59-
possibleTypes = lib.filter (sub: !(sub.type == "null" && nullable)) anyOf;
60-
in
61-
{
62-
kind = "oneOf";
63-
subTypes = builtins.map (
64-
t: mkRustAnalyzerOptionType nullable "${property_name}-sub" t
65-
) possibleTypes;
66-
}
67-
else if lib.isList type then
68-
(
69-
if lib.head type == "null" then
70-
assert lib.assertMsg (
71-
lib.length type == 2
72-
) "Lists starting with null are assumed to mean nullOr, so length 2";
73-
let
74-
innerType = property // {
75-
type = lib.elemAt type 1;
76-
};
77-
inner = mkRustAnalyzerOptionType nullable "${property_name}-inner" innerType;
78-
in
79-
assert lib.assertMsg nullable "nullOr types are not yet handled";
80-
inner
81-
else
40+
nullable: property_name: property:
41+
let
42+
inner =
43+
{
44+
type,
45+
enum ? null,
46+
minimum ? null,
47+
maximum ? null,
48+
items ? null,
49+
anyOf ? null,
50+
properties ? null,
51+
# Not used in the function, but anyOf values contain it
52+
enumDescriptions ? null,
53+
}@property:
54+
if enum != null then
55+
{
56+
kind = "enum";
57+
values = enum;
58+
}
59+
else if anyOf != null then
8260
let
83-
innerTypes = builtins.map (
84-
t: mkRustAnalyzerOptionType nullable "${property_name}-inner" (property // { type = t; })
85-
) type;
61+
possibleTypes = lib.filter (sub: !(sub.type == "null" && nullable)) anyOf;
8662
in
8763
{
8864
kind = "oneOf";
89-
subTypes = innerTypes;
65+
subTypes = builtins.map (
66+
t: mkRustAnalyzerOptionType nullable "${property_name}-sub" t
67+
) possibleTypes;
68+
}
69+
else if lib.isList type then
70+
(
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
89+
{
90+
kind = "oneOf";
91+
subTypes = innerTypes;
92+
}
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;
90110
}
91-
)
92-
else if type == "array" then
93-
{
94-
kind = "list";
95-
item = mkRustAnalyzerOptionType false "${property_name}-item" items;
96-
}
97-
else if type == "number" || type == "integer" then
98-
{
99-
kind = type;
100-
inherit minimum maximum;
101-
}
102-
else if type == "object" && properties != null then
103-
{
104-
kind = "submodule";
105-
options = lib.mapAttrs (
106-
name: value: mkRustAnalyzerOptionType false "${property_name}.${name}" value
107-
) properties;
108-
}
109-
else if
110-
lib.elem type [
111-
"object"
112-
"string"
113-
"boolean"
114-
]
115-
then
116-
{ kind = type; }
117-
else
118-
throw "Unhandled value in ${property_name}: ${lib.generators.toPretty { } property}";
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}";
121+
in
122+
builtins.addErrorContext "While creating type for ${property_name}:\n${lib.generators.toPretty { } property}" (
123+
inner property
124+
);
119125

120126
mkRustAnalyzerOption =
121127
property_name:

0 commit comments

Comments
 (0)