Skip to content

Commit 3ec94ed

Browse files
authored
Generate the diagnostic pages from data files (#7061)
- Updates `dart run dash_site generate-diagnostics` to generate a `src/data/diagnostics.json` file from data in the SDK. This file is not meant to be read or manually edited. It's mostly just a mechanism to cache the results calculated from the SDK data. - Stops manually generating the individual diagnostic doc pages found at `/tools/diagnostics/<diagnostic_name>`. Instead use the data from the intermediate `src/data/diagnostics.json` file to generate each page from code. The content of the generated files remains the same with this PR. These changes reduce site cloning and full build time, make updates easier to implement and review, and help avoid confusion about those files being the source of the docs.
1 parent 54eb9e0 commit 3ec94ed

File tree

775 files changed

+1063
-39832
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

775 files changed

+1063
-39832
lines changed

site/lib/src/components/common/tags.dart

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,46 @@ class Tags extends StatelessComponent {
2323
///
2424
/// Generally displayed within a [Tags] component.
2525
class Tag extends StatelessComponent {
26-
const Tag(this.content, {this.icon, this.title, this.label, this.color});
26+
const Tag(
27+
this.content, {
28+
this.icon,
29+
this.title,
30+
this.label,
31+
this.color,
32+
this.link,
33+
});
2734

2835
final String content;
2936
final String? icon;
3037
final String? title;
3138
final String? label;
3239
final String? color;
40+
final String? link;
3341

3442
@override
3543
Component build(BuildContext context) {
44+
final children = <Component>[
45+
if (icon case final iconId?) MaterialIcon(iconId),
46+
span([.text(content)]),
47+
];
48+
final attributes = {
49+
'title': ?title,
50+
'aria-label': ?(label ?? title),
51+
};
52+
53+
if (link case final link?) {
54+
return a(
55+
href: link,
56+
classes: 'tag-label',
57+
attributes: attributes,
58+
children,
59+
);
60+
}
61+
3662
return div(
3763
classes: 'tag-label',
38-
attributes: {
39-
'title': ?title,
40-
'aria-label': ?(label ?? title),
41-
},
42-
[
43-
if (icon case final iconId?) MaterialIcon(iconId),
44-
span([.text(content)]),
45-
],
64+
attributes: attributes,
65+
children,
4666
);
4767
}
4868
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:convert' show jsonDecode;
6+
import 'dart:io';
7+
8+
import 'package:path/path.dart' as p;
9+
10+
import '../util.dart';
11+
12+
extension type DiagnosticInfo.fromJson(Map<String, Object?> info) {
13+
String get id => info['id'] as String;
14+
String get description => info['description'] as String;
15+
String? get documentation => info['documentation'] as String?;
16+
bool get hasDocumentation => info['hasDocumentation'] as bool? ?? false;
17+
bool get fromLint => info['fromLint'] as bool? ?? false;
18+
List<String> get previousNames =>
19+
(info['previousNames'] as List<Object?>).cast<String>();
20+
}
21+
22+
/// Reads and parses information about diagnostics from
23+
/// the `src/data/diagnostics.json` file.
24+
List<DiagnosticInfo> readAndLoadDiagnostics() {
25+
if (_loadedDiagnostics case final alreadyLoadedDiagnostics?) {
26+
return alreadyLoadedDiagnostics;
27+
}
28+
29+
final diagnosticsFile = File(
30+
p.join(siteSrcDirectoryPath, 'data', 'diagnostics.json'),
31+
);
32+
final rawDiagnosticInfo =
33+
jsonDecode(diagnosticsFile.readAsStringSync()) as List<Object?>;
34+
35+
final diagnostics = rawDiagnosticInfo
36+
.cast<Map<String, Object?>>()
37+
.map(DiagnosticInfo.fromJson)
38+
.toList(growable: false);
39+
40+
return _loadedDiagnostics = diagnostics;
41+
}
42+
43+
/// A cache of the loaded and parsed diagnostic info.
44+
List<DiagnosticInfo>? _loadedDiagnostics;

0 commit comments

Comments
 (0)