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

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,25 @@
1
+ ## 1.0.0
2
+
3
+ This is Exercism's first release of the package, published as
4
+ `@exercism/codemirror-lang-dart`. It adds completion of the names in scope,
5
+ snippets, and the common members of the core types after a dot.
6
+
7
+ ## 0.1.1 (2026-08-06)
8
+
9
+ The repository link, which npm renders as a link and a browser cannot follow
10
+ with `git+` in front of it.
11
+
12
+ ## 0.1.0 (2026-08-02)
13
+
14
+ ### First release
15
+
16
+ Dart language support: a Lezer grammar covering Dart 3, plus highlighting,
17
+ folding, indentation and completion.
18
+
19
+ CodeMirror has never shipped Dart, and what stands in for it is the C-family
20
+ stream mode ported from CodeMirror 5, which colours a keyword list and builds
21
+ no tree. No Lezer grammar for Dart existed on npm before this one.
22
+
23
+ The grammar was developed against 4 465 files from the Flutter framework and
24
+ its tools, the Dart SDK's own libraries and front end, Riverpod, bloc, Dio and
25
+ `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,146 @@
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 is Exercism's fork of
4
+ [@codincod/codemirror-lang-dart](https://codeberg.org/reeven/codemirror-lang-dart),
5
+ written by CodinCod. Exercism uses it in the Dart editor on
6
+ [exercism.org](https://exercism.org). Our changes are on the `main` branch.
7
+
8
+ The fork changes the completion. The grammar is upstream's.
9
+
10
+ - Completion offers the names declared in the file that are in scope at the
11
+ cursor. That covers classes, mixins, enums and their values, extensions,
12
+ typedefs, functions, methods, getters and setters, fields, top-level and
13
+ local variables, parameters, type parameters, import prefixes, and the
14
+ variables bound by `for`, `catch` and patterns. Completion offers a local
15
+ variable after its declaration.
16
+ - Completion offers snippets for `main`, functions, classes, mixins, enums,
17
+ extensions, typedefs, getters, `if`, `if case`, the `for` loops, `while`,
18
+ `do`, both kinds of `switch`, `try`, `throw` and `import`.
19
+ - After a dot, completion offers the common members of the core types, and
20
+ nothing else. Completion is switched off inside strings and comments, except
21
+ inside a `${}` interpolation.
22
+
23
+ The rest of this README is upstream's.
24
+
25
+ This package implements Dart language support for the
26
+ [CodeMirror](https://codemirror.net/) code editor, using a
27
+ [Lezer](https://lezer.codemirror.net/) grammar written for this package.
28
+
29
+ CodeMirror 6 has never shipped Dart, and no Lezer grammar for it existed before
30
+ this one. What gets used instead is the C-family stream mode ported from
31
+ CodeMirror 5, which colours a list of keywords and builds no tree, so nothing
32
+ above it can fold a class, indent a `switch` or ask what the word under the
33
+ cursor is. It also predates most of the language: string interpolation,
34
+ cascades, null safety, records and patterns all come out as plain text or as
35
+ something else entirely.
36
+
37
+ Written in part for [CodinCod](https://codincod.com/), a competitive coding
38
+ platform, where it colours the editor people solve puzzles in.
39
+
40
+ This code is released under an
41
+ [MIT license](https://codeberg.org/reeven/codemirror-lang-dart/src/branch/master/LICENSE).
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ npm install @exercism/codemirror-lang-dart
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ ```javascript
52
+ import {EditorView, basicSetup} from "codemirror"
53
+ import {dart} from "@exercism/codemirror-lang-dart"
54
+
55
+ const view = new EditorView({
56
+ parent: document.body,
57
+ doc: `class Greeter {
58
+ const Greeter(this.name);
59
+
60
+ final String name;
61
+
62
+ String greet() => 'Hello, $name!';
63
+ }
64
+ `,
65
+ extensions: [basicSetup, dart()]
66
+ })
67
+ ```
68
+
69
+ ## Coverage
70
+
71
+ Dart 3. Classes, mixins, enums with constructors and members, extensions and
72
+ extension types, sealed and base hierarchies, typedefs both ways, generics with
73
+ bounds, sound null safety, records and their types, patterns everywhere Dart 3
74
+ puts them, switch expressions and switch statements, `if`-case, cascades and
75
+ null-aware cascades, collection `if`, `for` and spreads, async and both kinds
76
+ of generator, initializing and super formals, metadata, and every one of the
77
+ eight ways Dart writes a string.
78
+
79
+ The parts Dart added most recently are here too: digit separators, null-aware
80
+ elements, dot shorthands, primary constructors and the `new` that names a
81
+ constructor rather than calling one.
82
+
83
+ Measured against 4 465 Dart files from six open source projects (the Flutter
84
+ framework and its tools, the Dart SDK's own libraries and front end, Riverpod,
85
+ bloc, Dio and `dart-lang/core`), which is 58 MiB of code, of which 98.66% parse
86
+ with no error node.
87
+
88
+ ## What the grammar cannot say
89
+
90
+ Three things about Dart are settled in `src/tokens.ts` rather than in the
91
+ grammar, because no context free rule can decide them.
92
+
93
+ **A `?` makes a type nullable or opens a conditional.** `e as String?` and
94
+ `e is String ? a : b` disagree about one character, and the disagreement cannot
95
+ be settled where it stands. Lezer settles a shift against a reduce by
96
+ precedence rather than by trying both, because the two readings do not cover
97
+ the same span and so are not the kind of ambiguity a conflict marker can hold
98
+ open; whichever way the precedence goes, half the language breaks. The
99
+ tokenizer answers it instead, by looking further along the line than the parser
100
+ does: a colon outside every bracket means a conditional, and a semicolon, a
101
+ comma, an assignment or a bracket nobody opened means a type. An angle bracket
102
+ behind the cursor that nothing closed is what tells the `?` of
103
+ `c ? JS<Ref?>(a) : d` from the one that opens the conditional around it.
104
+
105
+ **A string is eight different languages.** The quote may be single or double,
106
+ the delimiter one character or three, and an `r` in front turns every escape
107
+ back into an ordinary character. Which of the eight is being read decides what
108
+ ends the string and whether `$` opens a hole holding an expression, and none of
109
+ it can be read off the character at the cursor. It is not remembered in the
110
+ tokenizer either, because the parser may fork and anything remembered would be
111
+ remembered for both halves; it is asked of the parser instead, since each
112
+ flavour's content token can only be shifted inside its own kind of string. That
113
+ is also what makes `'a ${b("c")} d'` work: inside the hole no content token can
114
+ be shifted at all, so the quote there opens a string of its own.
115
+
116
+ **Block comments nest, and a raw string opens with a letter.** `/* /* */ */` is
117
+ one comment in Dart and two in most other languages, which is a thing a regular
118
+ token cannot say: it has to count. And `r'a'` begins with something every other
119
+ tokenizer is happy to call an identifier, so it has to be claimed before the
120
+ grammar's own tokenizer is asked.
121
+
122
+ Two decisions about the tree are worth saying out loud.
123
+
124
+ **Casing decides what is a type.** `Foo bar` is a declaration and `foo.bar` is
125
+ a member access, and after one identifier no amount of lookahead separates
126
+ them, so the parser follows the convention every Dart codebase keeps: a word
127
+ starting with a capital is read as a type first and an ordinary name second,
128
+ and a word starting with a lower case letter the other way round. Both readings
129
+ stay alive and the one that fits wins. Dart writes a private name with a
130
+ leading underscore and generated code writes one with a dollar, so the letter
131
+ that decides is the first one that is a letter: `_MyWidgetState` and
132
+ `_$FooImpl` are types.
133
+
134
+ **A cascade is a member access.** `a..b()..c = 1` binds looser than anything
135
+ else in the real language, but a highlighter has no use for the difference, and
136
+ reading `..` at the precedence of `.` costs no level, no conflict and no
137
+ lookahead. The tree says `(a..b)()` where Dart says `a..(b())`; every token in
138
+ it is still coloured by what it is.
139
+
140
+ ## Building and testing
141
+
142
+ ```bash
143
+ npm install # installs the dependencies and builds dist/
144
+ npm run build # regenerates the parser and rebuilds dist/
145
+ npm test # builds, then runs the tests
146
+ ```