@@ -8,6 +8,7 @@ import 'dart:convert';
8
8
import 'package:flutter/material.dart' ;
9
9
import 'package:flutter/services.dart' show rootBundle;
10
10
11
+ import '../../shared/config_specific/logger/logger.dart' ;
11
12
import '../../shared/primitives/utils.dart' ;
12
13
import '../../shared/theme.dart' ;
13
14
import 'span_parser.dart' ;
@@ -41,7 +42,19 @@ class SyntaxHighlighter {
41
42
final grammarJson = json.decode (
42
43
await rootBundle.loadString ('assets/dart_syntax.json' ),
43
44
);
44
- _grammar = Grammar .fromJson (grammarJson);
45
+ try {
46
+ _grammar = Grammar .fromJson (grammarJson);
47
+ } catch (error) {
48
+ // Safari does not support negative-lookbehind regex which are currently
49
+ // required by the syntax highlighting. An unhandled exception here will
50
+ // prevent DevTools initializing, so just print the error and leave
51
+ // syntax highlighting disabled if this happens.
52
+ log (
53
+ 'Failed to load Dart Syntax Highlighting:\n '
54
+ '$error ' ,
55
+ LogLevel .warning,
56
+ );
57
+ }
45
58
}
46
59
}
47
60
@@ -60,11 +73,15 @@ class SyntaxHighlighter {
60
73
.sublist (lineRange.begin - 1 , lineRange.end)
61
74
.join ('\n ' );
62
75
}
76
+ final grammar = _grammar;
77
+ if (grammar == null ) {
78
+ return TextSpan (text: _processedSource);
79
+ }
63
80
return TextSpan (
64
81
children: _highlightLoopHelper (
65
82
currentScope: null ,
66
83
loopCondition: () => _currentPosition < _processedSource.length,
67
- scopes: SpanParser .parse (_grammar ! , _processedSource),
84
+ scopes: SpanParser .parse (grammar , _processedSource),
68
85
),
69
86
);
70
87
}
0 commit comments