Skip to content

Commit 9eac437

Browse files
GearsDatapackslpil
authored andcommitted
Store record field documentation in typed AST
1 parent a81b912 commit 9eac437

File tree

15 files changed

+189
-35
lines changed

15 files changed

+189
-35
lines changed

compiler-core/generated/schema_capnp.rs

Lines changed: 111 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler-core/schema.capnp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct TypeValueConstructor {
9494
struct TypeValueConstructorParameter {
9595
type @0 :Type;
9696
label @1 :Text;
97+
documentation @2 :Text;
9798
}
9899

99100
struct TypeConstructor {
@@ -124,6 +125,7 @@ struct RecordAccessor {
124125
type @0 :Type;
125126
index @1 :UInt16;
126127
label @2 :Text;
128+
documentation @3 :Text;
127129
}
128130

129131
# UInt16 cannot be used as a generic parameter to Option,

compiler-core/src/analyse.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
10991099
label,
11001100
ast,
11011101
location,
1102+
doc,
11021103
..
11031104
} in constructor.arguments.iter()
11041105
{
@@ -1114,6 +1115,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
11141115
fields.push(TypeValueConstructorField {
11151116
type_: t.clone(),
11161117
label: label.as_ref().map(|(_location, label)| label.clone()),
1118+
documentation: doc.as_ref().map(|(_, documentation)| documentation.clone()),
11171119
});
11181120

11191121
// Register the type for this parameter
@@ -1933,6 +1935,7 @@ fn custom_type_accessors(constructors: &[TypeValueConstructor]) -> Result<Access
19331935
index: index as u64,
19341936
label: label.clone(),
19351937
type_: type_.clone(),
1938+
documentation: None,
19361939
},
19371940
);
19381941
}
@@ -1954,6 +1957,7 @@ fn custom_type_accessors(constructors: &[TypeValueConstructor]) -> Result<Access
19541957
index: index as u64,
19551958
label: label.clone(),
19561959
type_: parameter.type_.clone(),
1960+
documentation: parameter.documentation.clone(),
19571961
},
19581962
);
19591963
}

compiler-core/src/ast/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn compile_expression(src: &str) -> TypedStatement {
129129
index: 0,
130130
label: "name".into(),
131131
type_: type_::string(),
132+
documentation: None,
132133
},
133134
),
134135
(
@@ -137,6 +138,7 @@ fn compile_expression(src: &str) -> TypedStatement {
137138
index: 1,
138139
label: "age".into(),
139140
type_: type_::int(),
141+
documentation: None,
140142
},
141143
),
142144
];

compiler-core/src/ast/typed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub enum TypedExpr {
102102
label: EcoString,
103103
index: u64,
104104
record: Box<Self>,
105+
documentation: Option<EcoString>,
105106
},
106107

107108
ModuleSelect {

compiler-core/src/ast/visit.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,18 @@ pub trait Visit<'ast> {
231231
label: &'ast EcoString,
232232
index: &'ast u64,
233233
record: &'ast TypedExpr,
234+
documentation: &'ast Option<EcoString>,
234235
) {
235-
visit_typed_expr_record_access(self, location, field_start, type_, label, index, record);
236+
visit_typed_expr_record_access(
237+
self,
238+
location,
239+
field_start,
240+
type_,
241+
label,
242+
index,
243+
record,
244+
documentation,
245+
);
236246
}
237247

238248
#[allow(clippy::too_many_arguments)]
@@ -813,7 +823,16 @@ where
813823
label,
814824
index,
815825
record,
816-
} => v.visit_typed_expr_record_access(location, field_start, type_, label, index, record),
826+
documentation,
827+
} => v.visit_typed_expr_record_access(
828+
location,
829+
field_start,
830+
type_,
831+
label,
832+
index,
833+
record,
834+
documentation,
835+
),
817836
TypedExpr::ModuleSelect {
818837
location,
819838
field_start,
@@ -1054,6 +1073,7 @@ pub fn visit_typed_expr_record_access<'a, V>(
10541073
_label: &'a EcoString,
10551074
_index: &'a u64,
10561075
record: &'a TypedExpr,
1076+
_documentation: &'a Option<EcoString>,
10571077
) where
10581078
V: Visit<'a> + ?Sized,
10591079
{

0 commit comments

Comments
 (0)