Skip to content

Commit 58e1c06

Browse files
committed
feat: attach basic descriptions and links to HTML report
1 parent c00cc20 commit 58e1c06

File tree

11 files changed

+162
-39
lines changed

11 files changed

+162
-39
lines changed

rs/src/export/proto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl From<&extension::simple::type_class::Reference> for validator::data_type::U
347347
extension_id: node
348348
.definition
349349
.as_ref()
350-
.map(|x| x.extension_id)
350+
.map(|x| x.identifier.extension_id)
351351
.unwrap_or_default(),
352352
}
353353
}
@@ -369,7 +369,7 @@ impl From<&data::Variation> for validator::data_type::Variation {
369369
extension_id: variation
370370
.definition
371371
.as_ref()
372-
.map(|x| x.extension_id)
372+
.map(|x| x.identifier.extension_id)
373373
.unwrap_or_default(),
374374
},
375375
)

rs/src/input/config.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn resolve_with_curl(uri: &str) -> Result<Vec<u8>, curl::Error> {
3939
}
4040

4141
/// Configuration structure.
42+
#[derive(Default)]
4243
pub struct Config {
4344
/// When set, do not generate warnings for unknown protobuf fields that are
4445
/// set to their protobuf-defined default value.
@@ -86,21 +87,6 @@ pub struct Config {
8687
pub max_uri_resolution_depth: Option<usize>,
8788
}
8889

89-
// TODO: enable URI resolution by default once all that works. Then this can
90-
// be derived again. Also still need to expose the depth option in extensions.
91-
impl Default for Config {
92-
fn default() -> Self {
93-
Self {
94-
ignore_unknown_fields: Default::default(),
95-
allowed_proto_any_urls: Default::default(),
96-
diagnostic_level_overrides: Default::default(),
97-
uri_overrides: Default::default(),
98-
uri_resolver: Default::default(),
99-
max_uri_resolution_depth: Some(0),
100-
}
101-
}
102-
}
103-
10490
impl Config {
10591
/// Creates a default configuration.
10692
pub fn new() -> Self {

rs/src/output/extension/namespace.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,4 +583,12 @@ impl<T> ResolutionResult<T> {
583583
.next()
584584
.flatten()
585585
}
586+
587+
/// Calls the given function for each visible item.
588+
pub fn for_each_visible_item<F: FnMut(&T)>(&self, mut f: F) {
589+
self.visible
590+
.iter()
591+
.filter_map(|x| x.1.as_item())
592+
.for_each(|x| f(&x))
593+
}
586594
}

rs/src/output/extension/simple/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! Module for the common types involved with representing extension
44
//! definitions.
55
6+
use crate::output;
7+
68
/// Identifying information associated with an extension, that can be used to
79
/// refer to the extension from elsewhere.
810
#[derive(Clone, Debug)]
@@ -18,6 +20,9 @@ pub struct Identifier {
1820
/// number is only unique within the scope of a single run of the
1921
/// validator, and may change between runs.
2022
pub extension_id: u64,
23+
24+
/// The path that the extension is defined in.
25+
pub definition_path: output::path::PathBuf,
2126
}
2227

2328
/// Non-functional metadata common to all extension types.

rs/src/output/extension/simple/function.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ use std::sync::Arc;
1111
/// The definition of a function implementation.
1212
#[derive(Clone, Debug)]
1313
pub struct Definition {
14-
/// Unique number within the tree that can be used to refer to this
15-
/// extension when exporting in protobuf form.
16-
pub extension_id: u64,
14+
/// Identifier for the extension.
15+
pub identifier: extension::simple::common::Identifier,
16+
17+
/// Common metadata for the extension.
18+
pub metadata: extension::simple::common::Metadata,
1719

1820
/// Link to information common to a set of function implementations going by
1921
/// the same name.

rs/src/output/extension/simple/type_class.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ use crate::output::type_system::meta;
1010
use crate::output::type_system::meta::pattern::Pattern;
1111

1212
/// A definition of a user-defined type class.
13-
#[derive(Clone, Debug, PartialEq, Eq, Default)]
13+
#[derive(Clone, Debug)]
1414
pub struct Definition {
15-
/// Unique number within the tree that can be used to refer to this
16-
/// extension when exporting in protobuf form.
17-
pub extension_id: u64,
15+
/// Identifier for the extension.
16+
pub identifier: extension::simple::common::Identifier,
1817

19-
/// Description of the type class.
20-
pub description: String,
18+
/// Common metadata for the extension.
19+
pub metadata: extension::simple::common::Metadata,
2120

2221
/// The parameters expected by the data type.
2322
pub parameter_slots: Vec<ParameterSlot>,
@@ -32,8 +31,21 @@ pub struct Definition {
3231
pub structure: Option<meta::pattern::Value>,
3332
}
3433

34+
impl From<extension::simple::common::Identifier> for Definition {
35+
fn from(identifier: extension::simple::common::Identifier) -> Self {
36+
Definition {
37+
identifier,
38+
metadata: Default::default(),
39+
parameter_slots: Default::default(),
40+
parameters_variadic: Default::default(),
41+
contraints: Default::default(),
42+
structure: Default::default(),
43+
}
44+
}
45+
}
46+
3547
/// A parameter slot for a user-defined data type.
36-
#[derive(Clone, Debug, Default, PartialEq, Eq)]
48+
#[derive(Clone, Debug, Default)]
3749
pub struct ParameterSlot {
3850
/// Name of the parameter.
3951
pub name: String,

rs/src/output/extension/simple/type_variation.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ use crate::output::extension;
66
use crate::output::type_system::data;
77

88
/// Type variation extension.
9-
#[derive(Clone, Debug, PartialEq, Eq, Default)]
9+
#[derive(Clone, Debug)]
1010
pub struct Definition {
11-
/// Unique number within the tree that can be used to refer to this
12-
/// extension when exporting in protobuf form.
13-
pub extension_id: u64,
11+
/// Identifier for the extension.
12+
pub identifier: extension::simple::common::Identifier,
13+
14+
/// Common metadata for the extension.
15+
pub metadata: extension::simple::common::Metadata,
1416

1517
/// Description of the type variation.
1618
pub description: String,

rs/src/parse/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ impl<'a> Context<'a> {
439439
uri: Default::default(),
440440
names: Default::default(),
441441
extension_id: self.state.extension_id_counter,
442+
definition_path: self.path_buf(),
442443
}
443444
}
444445
}

rs/src/parse/extensions/simple/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ fn parse_extension_mapping_data(
253253
extension::namespace::ResolutionResult::new(reference_data)
254254
});
255255

256+
// Link to YAML definitions.
257+
resolution_result.for_each_visible_item(|item| {
258+
link!(y, item.identifier.definition_path.clone(), "Possible YAML definition was here.");
259+
});
260+
256261
// If the specified anchor is valid, insert a mapping for it.
257262
if let Some(anchor) = anchor {
258263
if let Err((prev_data, prev_path)) = y.define_type(anchor, resolution_result) {
@@ -300,6 +305,11 @@ fn parse_extension_mapping_data(
300305
extension::namespace::ResolutionResult::new(reference_data)
301306
});
302307

308+
// Link to YAML definitions.
309+
resolution_result.for_each_visible_item(|item| {
310+
link!(y, item.identifier.definition_path.clone(), "Possible YAML definition was here.");
311+
});
312+
303313
// If the specified anchor is valid, insert a mapping for it.
304314
if let Some(anchor) = anchor {
305315
if let Err((prev_data, prev_path)) = y.define_type_variation(anchor, resolution_result) {
@@ -367,6 +377,11 @@ fn parse_extension_mapping_data(
367377
extension::namespace::ResolutionResult::new(reference_data)
368378
});
369379

380+
// Link to YAML definitions.
381+
resolution_result.for_each_visible_item(|item| {
382+
link!(y, item.identifier.definition_path.clone(), "Possible YAML definition was here.");
383+
});
384+
370385
// If the specified anchor is valid, insert a mapping for it.
371386
if let Some(anchor) = anchor {
372387
if let Err((prev_data, prev_path)) = y.define_function(anchor, resolution_result) {

rs/src/parse/extensions/simple/type_classes.rs

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use crate::parse::context;
1515
use crate::parse::extensions::simple::common;
1616
use crate::parse::extensions::simple::derivations;
1717
use crate::parse::extensions::simple::modules;
18+
use crate::util;
1819
use std::collections::HashSet;
20+
use std::fmt::Write;
1921
use std::sync::Arc;
2022

2123
/// Builder for type classes.
@@ -286,11 +288,6 @@ pub fn parse_type_class(
286288
y: &mut context::Context,
287289
z: &mut modules::Builder,
288290
) -> Result<()> {
289-
let mut builder = Builder {
290-
definition: Default::default(),
291-
analysis_context: derivations::AnalysisContext::new(Some(z)),
292-
};
293-
294291
// Parse name.
295292
let name = yaml_required_field!(
296293
x,
@@ -307,6 +304,17 @@ pub fn parse_type_class(
307304
.expect_not_yet_defined(y);
308305
}
309306

307+
// Make identifier and builder.
308+
let mut identifier = y.make_extension_id();
309+
if let Some(name) = &name {
310+
identifier.names.push(name.to_string());
311+
}
312+
identifier.uri = z.identifier.uri.clone();
313+
let mut builder = Builder {
314+
definition: identifier.into(),
315+
analysis_context: derivations::AnalysisContext::new(Some(z)),
316+
};
317+
310318
// Parse parameters.
311319
builder.definition.parameter_slots =
312320
yaml_repeated_field!(x, y, "parameters", parse_parameter, 0, &mut builder)?
@@ -333,14 +341,63 @@ pub fn parse_type_class(
333341
// Parse structure.
334342
yaml_field!(x, y, "structure", parse_structure, &mut builder)?;
335343

344+
// Describe the type class.
345+
let mut description = if builder.definition.structure.is_none() {
346+
if builder.definition.parameter_slots.is_empty() {
347+
"Opaque simple"
348+
} else {
349+
"Opaque compound"
350+
}
351+
} else if builder.definition.parameter_slots.is_empty() {
352+
"Simple"
353+
} else {
354+
"Compound"
355+
}
356+
.to_string();
357+
write!(description, " type class declaration: ").unwrap();
358+
if let Some(name) = &name {
359+
write!(description, "{name}").unwrap();
360+
} else {
361+
write!(description, "!").unwrap();
362+
}
363+
if !builder.definition.parameter_slots.is_empty() {
364+
let mut parameters = builder
365+
.definition
366+
.parameter_slots
367+
.iter()
368+
.map(|slot| {
369+
let mut description = String::new();
370+
if !slot.name.is_empty() {
371+
write!(
372+
description,
373+
"{}: ",
374+
util::string::as_ident_or_string(&slot.name)
375+
)
376+
.unwrap();
377+
};
378+
if slot.optional {
379+
write!(description, "opt ").unwrap();
380+
};
381+
if let meta::pattern::Value::Intersection(isec) = &slot.pattern {
382+
write!(description, "{}", isec.last().unwrap()).unwrap();
383+
} else {
384+
write!(description, "{}", slot.pattern).unwrap();
385+
};
386+
description
387+
})
388+
.join(", ");
389+
if builder.definition.parameters_variadic {
390+
write!(parameters, "...").unwrap();
391+
}
392+
write!(description, "<{parameters}>").unwrap();
393+
}
394+
describe!(y, Misc, "{description}");
395+
336396
// Register the type class.
337397
if let Some(name) = name {
338398
z.type_classes
339399
.define_item(name, Arc::new(builder.definition), true);
340400
}
341401

342-
// Describe the type class.
343-
// TODO
344-
345402
Ok(())
346403
}

0 commit comments

Comments
 (0)