@exercism/codemirror-lang-dart 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,29 @@
1
+ ## 1.0.1
2
+
3
+ The README is restructured. This release is the first published from GitHub Actions, with npm provenance.
4
+
5
+ ## 1.0.0
6
+
7
+ This is Exercism's first release of the package, published as
8
+ `@exercism/codemirror-lang-dart`. It adds completion of the names in scope,
9
+ snippets, and the common members of the core types after a dot.
10
+
11
+ ## 0.1.1 (2026-08-06)
12
+
13
+ The repository link, which npm renders as a link and a browser cannot follow
14
+ with `git+` in front of it.
15
+
16
+ ## 0.1.0 (2026-08-02)
17
+
18
+ ### First release
19
+
20
+ Dart language support: a Lezer grammar covering Dart 3, plus highlighting,
21
+ folding, indentation and completion.
22
+
23
+ CodeMirror has never shipped Dart, and what stands in for it is the C-family
24
+ stream mode ported from CodeMirror 5, which colours a keyword list and builds
25
+ no tree. No Lezer grammar for Dart existed on npm before this one.
26
+
27
+ The grammar was developed against 4 465 files from the Flutter framework and
28
+ its tools, the Dart SDK's own libraries and front end, Riverpod, bloc, Dio and
29
+ `dart-lang/core`, of which 98.66% parse with no error node.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodinCod
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,141 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-dart
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This package implements Dart language support for the
4
+ [CodeMirror](https://codemirror.net/) code editor, using a
5
+ [Lezer](https://lezer.codemirror.net/) grammar written for this package.
6
+ Exercism uses it in the Dart editor on [exercism.org](https://exercism.org).
7
+
8
+ CodeMirror 6 has never shipped Dart, and no Lezer grammar for it existed before
9
+ this one. What gets used instead is the C-family stream mode ported from
10
+ CodeMirror 5, which colours a list of keywords and builds no tree, so nothing
11
+ above it can fold a class, indent a `switch` or ask what the word under the
12
+ cursor is. It also predates most of the language: string interpolation,
13
+ cascades, null safety, records and patterns all come out as plain text or as
14
+ something else entirely.
15
+
16
+ This code is released under an [MIT license](LICENSE).
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install @exercism/codemirror-lang-dart
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```javascript
27
+ import {EditorView, basicSetup} from "codemirror"
28
+ import {dart} from "@exercism/codemirror-lang-dart"
29
+
30
+ const view = new EditorView({
31
+ parent: document.body,
32
+ doc: `class Greeter {
33
+ const Greeter(this.name);
34
+
35
+ final String name;
36
+
37
+ String greet() => 'Hello, $name!';
38
+ }
39
+ `,
40
+ extensions: [basicSetup, dart()]
41
+ })
42
+ ```
43
+
44
+ ## Completion
45
+
46
+ - Completion offers the names declared in the file that are in scope at the
47
+ cursor. That covers classes, mixins, enums and their values, extensions,
48
+ typedefs, functions, methods, getters and setters, fields, top-level and
49
+ local variables, parameters, type parameters, import prefixes, and the
50
+ variables bound by `for`, `catch` and patterns. Completion offers a local
51
+ variable after its declaration.
52
+ - Completion offers snippets for `main`, functions, classes, mixins, enums,
53
+ extensions, typedefs, getters, `if`, `if case`, the `for` loops, `while`,
54
+ `do`, both kinds of `switch`, `try`, `throw` and `import`.
55
+ - After a dot, completion offers the common members of the core types, and
56
+ nothing else. Completion is switched off inside strings and comments, except
57
+ inside a `${}` interpolation.
58
+
59
+ ## Coverage
60
+
61
+ Dart 3. Classes, mixins, enums with constructors and members, extensions and
62
+ extension types, sealed and base hierarchies, typedefs both ways, generics with
63
+ bounds, sound null safety, records and their types, patterns everywhere Dart 3
64
+ puts them, switch expressions and switch statements, `if`-case, cascades and
65
+ null-aware cascades, collection `if`, `for` and spreads, async and both kinds
66
+ of generator, initializing and super formals, metadata, and every one of the
67
+ eight ways Dart writes a string.
68
+
69
+ The parts Dart added most recently are here too: digit separators, null-aware
70
+ elements, dot shorthands, primary constructors and the `new` that names a
71
+ constructor rather than calling one.
72
+
73
+ Measured against 4 465 Dart files from six open source projects (the Flutter
74
+ framework and its tools, the Dart SDK's own libraries and front end, Riverpod,
75
+ bloc, Dio and `dart-lang/core`), which is 58 MiB of code, of which 98.66% parse
76
+ with no error node.
77
+
78
+ ## What the grammar cannot say
79
+
80
+ Three things about Dart are settled in `src/tokens.ts` rather than in the
81
+ grammar, because no context free rule can decide them.
82
+
83
+ **A `?` makes a type nullable or opens a conditional.** `e as String?` and
84
+ `e is String ? a : b` disagree about one character, and the disagreement cannot
85
+ be settled where it stands. Lezer settles a shift against a reduce by
86
+ precedence rather than by trying both, because the two readings do not cover
87
+ the same span and so are not the kind of ambiguity a conflict marker can hold
88
+ open; whichever way the precedence goes, half the language breaks. The
89
+ tokenizer answers it instead, by looking further along the line than the parser
90
+ does: a colon outside every bracket means a conditional, and a semicolon, a
91
+ comma, an assignment or a bracket nobody opened means a type. An angle bracket
92
+ behind the cursor that nothing closed is what tells the `?` of
93
+ `c ? JS<Ref?>(a) : d` from the one that opens the conditional around it.
94
+
95
+ **A string is eight different languages.** The quote may be single or double,
96
+ the delimiter one character or three, and an `r` in front turns every escape
97
+ back into an ordinary character. Which of the eight is being read decides what
98
+ ends the string and whether `$` opens a hole holding an expression, and none of
99
+ it can be read off the character at the cursor. It is not remembered in the
100
+ tokenizer either, because the parser may fork and anything remembered would be
101
+ remembered for both halves; it is asked of the parser instead, since each
102
+ flavour's content token can only be shifted inside its own kind of string. That
103
+ is also what makes `'a ${b("c")} d'` work: inside the hole no content token can
104
+ be shifted at all, so the quote there opens a string of its own.
105
+
106
+ **Block comments nest, and a raw string opens with a letter.** `/* /* */ */` is
107
+ one comment in Dart and two in most other languages, which is a thing a regular
108
+ token cannot say: it has to count. And `r'a'` begins with something every other
109
+ tokenizer is happy to call an identifier, so it has to be claimed before the
110
+ grammar's own tokenizer is asked.
111
+
112
+ Two decisions about the tree are worth saying out loud.
113
+
114
+ **Casing decides what is a type.** `Foo bar` is a declaration and `foo.bar` is
115
+ a member access, and after one identifier no amount of lookahead separates
116
+ them, so the parser follows the convention every Dart codebase keeps: a word
117
+ starting with a capital is read as a type first and an ordinary name second,
118
+ and a word starting with a lower case letter the other way round. Both readings
119
+ stay alive and the one that fits wins. Dart writes a private name with a
120
+ leading underscore and generated code writes one with a dollar, so the letter
121
+ that decides is the first one that is a letter: `_MyWidgetState` and
122
+ `_$FooImpl` are types.
123
+
124
+ **A cascade is a member access.** `a..b()..c = 1` binds looser than anything
125
+ else in the real language, but a highlighter has no use for the difference, and
126
+ reading `..` at the precedence of `.` costs no level, no conflict and no
127
+ lookahead. The tree says `(a..b)()` where Dart says `a..(b())`; every token in
128
+ it is still coloured by what it is.
129
+
130
+ ## Building and testing
131
+
132
+ ```bash
133
+ npm install # installs the dependencies and builds dist/
134
+ npm run build # regenerates the parser and rebuilds dist/
135
+ npm test # builds, then runs the tests
136
+ ```
137
+
138
+ ## Contributing
139
+
140
+ Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
141
+ Be sure to read the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).