@exercism/codemirror-lang-groovy 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,45 @@
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-groovy`. It adds completion of keywords, common
9
+ classes, Groovy JDK methods, snippets and the names in scope, and parses a few
10
+ more forms, such as `(a, b) = [b, a]` and `f()(x)`.
11
+
12
+ ### New features
13
+
14
+ `groovy()` now has completion. `groovyCompletion` offers keywords, snippets,
15
+ common classes and global functions. After a `.`, `?.` or `*.` it offers only
16
+ the methods called on a value, and after `@` the common annotations.
17
+
18
+ `localCompletionSource` offers the names declared in the file, only where each
19
+ one is in scope. It also completes `$name` and `${...}` inside a string.
20
+
21
+ Snippets for methods, classes, enums, traits, `if`, loops, `switch`, `try`
22
+ and closures are exported as `snippets`.
23
+
24
+ ### Bug fixes
25
+
26
+ `(a, b) = [b, a]` assigns to existing variables without `def`.
27
+
28
+ `f()(x)` and `list[0](x)` call the value returned by a call or an index.
29
+
30
+ `?.@` and `*.@` combine direct field access with safe navigation and spread.
31
+
32
+ ## 0.1.2 (2026-11-07)
33
+
34
+ ### Documentation
35
+
36
+ The README gives the WebJar coordinates, `org.webjars.npm:codemirror-lang-groovy`,
37
+ for Java and Grails applications, and describes how releases are made.
38
+
39
+ ## 0.1.1 (2026-11-07)
40
+
41
+ ### New features
42
+
43
+ First release: a Lezer grammar for Groovy, derived from `@lezer/java`, with
44
+ CodeMirror 6 language support (highlighting, indentation, folding, comment
45
+ tokens and bracket closing).
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2026 by Scott Murphy Heiberg
4
+
5
+ The grammar is derived from @lezer/java:
6
+ Copyright (C) 2020 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,199 @@
1
- # Temporary Holding Version
1
+ # codemirror-lang-groovy
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
+ ## Exercism's fork
4
+
5
+ This is Exercism's fork of [codemirror-lang-groovy](https://github.com/codeconsole/codemirror-lang-groovy), by Scott Murphy Heiberg.
6
+ Exercism uses it in the Groovy editor on [exercism.org](https://exercism.org).
7
+ It is published on npm as `@exercism/codemirror-lang-groovy`.
8
+ Our changes are on the `exercism` branch, and the `main` branch follows upstream.
9
+ Below this section, the README is upstream's.
10
+
11
+ The fork parses `(a, b) = [b, a]`, `f()(x)`, `list[0](x)`, `?.@` and `*.@`, and adds completion.
12
+ `groovy()` registers two completion sources, and the package exports both, along with `snippets`:
13
+
14
+ - `groovyCompletion` offers keywords, snippets, common classes and global
15
+ functions such as `println`. After a `.`, `?.` or `*.` it offers only the
16
+ methods called on a value, such as `collect` and `inject`. After `@` it
17
+ offers common annotations such as `CompileStatic`.
18
+ - `localCompletionSource` offers the names declared in the file. A parameter
19
+ is offered inside its method or closure, a local below the place that
20
+ declares it, a class member anywhere in its class, and a top level
21
+ declaration anywhere in the file. A closure with no parameters offers `it`.
22
+
23
+ Neither source offers anything inside a comment or where you declare a new name.
24
+ Inside a string, `localCompletionSource` completes `$name` and code in
25
+ `${...}`.
26
+
27
+ The completion adds a dependency on `@codemirror/autocomplete`.
28
+ If you load CodeMirror through an import map, map `@exercism/codemirror-lang-groovy` to `dist/index.js`.
29
+
30
+ ### Install
31
+
32
+ ```sh
33
+ npm install @exercism/codemirror-lang-groovy
34
+ ```
35
+
36
+ ### Building and testing
37
+
38
+ Run `npm install`, which also builds `dist/`, then `npm test`.
39
+ Upstream's Development section below lists the other scripts.
40
+ `.github/workflows/test.yml` runs the tests on Node 24 for every push to `exercism` and every pull request.
41
+
42
+ ### Releasing
43
+
44
+ 1. Update `version` in `package.json` and add a `CHANGELOG.md` entry, then commit.
45
+ 2. Tag the commit with that version and push the tag: `git tag v1.0.0 && git push origin v1.0.0`.
46
+
47
+ Pushing the tag starts `.github/workflows/publish.yml`.
48
+ The workflow checks that the tag matches `package.json`, builds the package and runs the tests.
49
+ It then publishes the package to npm as `@exercism/codemirror-lang-groovy`, using the `exercism` organisation's `NPM_TOKEN` secret.
50
+
51
+ ### Contributing
52
+
53
+ Contributions to this fork follow the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).
54
+ Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
55
+
56
+ ---
57
+
58
+ Groovy language support for [CodeMirror 6](https://codemirror.net/), built on a
59
+ [Lezer](https://lezer.codemirror.net/) grammar.
60
+
61
+ It replaces the stream-based Groovy mode in `@codemirror/legacy-modes` with a
62
+ real parser. The editor gets a syntax tree, which brings:
63
+
64
+ - highlighting that knows a method call from a variable, a declaration from a
65
+ use, and a map key from a property;
66
+ - syntax-aware indentation and code folding;
67
+ - a tree that other extensions (autocompletion, linting, structural
68
+ navigation) can build on.
69
+
70
+ ## Usage
71
+
72
+ ```js
73
+ import {EditorView, basicSetup} from "codemirror"
74
+ import {groovy} from "@exercism/codemirror-lang-groovy"
75
+
76
+ new EditorView({
77
+ doc: 'println "Hello, Groovy"',
78
+ extensions: [basicSetup, groovy()],
79
+ parent: document.body
80
+ })
81
+ ```
82
+
83
+ The package exports:
84
+
85
+ - `groovy()`: the `LanguageSupport` to add to an editor;
86
+ - `groovyLanguage`: the `LRLanguage`, for use with other language tooling;
87
+ - `parser`: the Lezer parser on its own, which works without CodeMirror.
88
+
89
+ It depends only on `@codemirror/language`, `@lezer/lr`, `@lezer/highlight` and
90
+ `@lezer/common`. When loading CodeMirror through an import map, map
91
+ `codemirror-lang-groovy` to `dist/index.js` alongside those modules.
92
+
93
+ Java and Grails applications can take it from Maven Central as a WebJar,
94
+ `org.webjars.npm:codemirror-lang-groovy`, which serves the bundle at
95
+ `/webjars/codemirror-lang-groovy/<version>/dist/index.js`:
96
+
97
+ ```groovy
98
+ runtimeOnly "org.webjars.npm:codemirror-lang-groovy:0.1.1"
99
+ ```
100
+
101
+ ## What it parses
102
+
103
+ The grammar starts from `@lezer/java` and adds the parts of Groovy that Java
104
+ lacks:
105
+
106
+ - statements that end at a line break, with Groovy's rules for when the next
107
+ line continues an expression;
108
+ - command calls without parentheses (`println x`, `name nullable: false`)
109
+ and command chains (`id 'groovy' version '4.0' apply false`);
110
+ - closures, including parameters, `it`, `{ -> }` and closures passed after a
111
+ call's arguments;
112
+ - GStrings with `$name.path` and `${...}` interpolation, triple-quoted, slashy
113
+ (`/re/`) and dollar-slashy (`$/.../$`) strings;
114
+ - list and map literals, named arguments and the spread operators;
115
+ - `def`, untyped and default-valued parameters, methods named by strings
116
+ (`def "adds two numbers"()`), traits, records and Groovy 4 switch
117
+ expressions;
118
+ - the operators `?.`, `*.`, `.@`, `.&`, `?:`, `?=`, `**`, `<=>`, `===`,
119
+ `=~`, `==~`, `in`, `!in`, `as`, `!instanceof` and the range operators.
120
+
121
+ Against real code it parses without errors 99.1% of the 8,272 Groovy files in
122
+ `apache/grails-core`, 99.4% of 2,754 files from other Grails projects, and
123
+ 562 of 563 Gradle build scripts.
124
+
125
+ ## How it handles Groovy's line-sensitive syntax
126
+
127
+ Lezer grammars are context-free, and several parts of Groovy are not. Three
128
+ small tokenizers in `src/tokens.js` cover them, each following the rule
129
+ Groovy's own parser applies (see `GroovyParser.g4` and
130
+ `SemanticPredicates.java` in `apache/groovy`):
131
+
132
+ - **Statement ends.** A zero-width semicolon is inserted at a line break
133
+ unless the next line starts with a token that continues the expression:
134
+ member access (`.`, `?.`), most binary operators, `?`, `:`, assignment, or
135
+ a closure after a call. As in Groovy, a line starting with `+`, `-`, `(` or
136
+ `[` starts a new statement, and a line ending in a comma continues.
137
+ - **Command calls.** `a b` is a command call when the name (or the last
138
+ segment of a dotted name) starts with a lowercase letter and is not
139
+ followed by `name =`; otherwise it is a declaration, as in `String name`.
140
+ - **Blocks and closures.** Where a statement can start, `{` opens a block,
141
+ unless a parameter list and `->` follow it.
142
+
143
+ ## Known gaps
144
+
145
+ Rare forms that still produce error nodes:
146
+
147
+ - a command chain that continues after a call with parentheses or a closure,
148
+ as in `foo(a) bar` or `promise.then { } then { }`;
149
+ - `def` combined with a type (`def String name`) and `def final x`;
150
+ - a command call that starts a continuation line (`.insertMany docs, opts`).
151
+
152
+ ## Development
153
+
154
+ ```sh
155
+ npm install # also builds dist/
156
+ npm run build # regenerate the parser and bundle
157
+ npm test # grammar, highlighting, language and incremental-parsing tests
158
+ npm run corpus -- <dir> [--gradle] [--show 20]
159
+ # parse every .groovy file under <dir> and list failures
160
+ node scripts/parse.js 'println "hi"'
161
+ # print the syntax tree for a snippet
162
+ ```
163
+
164
+ `demo/index.html` shows the grammar next to the legacy mode. Build, then
165
+ serve the repository root (for example `python3 -m http.server`) and open
166
+ `/demo/`.
167
+
168
+ `.github/workflows/test.yml` runs the tests on Node 22 and 24 for every push
169
+ to `main` and every pull request.
170
+
171
+ Test cases live in `test/*.txt` in Lezer's test format.
172
+ `node scripts/fill-tests.js test/<file>.txt` fills in the expected trees from
173
+ the current parser; review every changed tree before committing it.
174
+
175
+ ## Releasing
176
+
177
+ 1. Update `version` in `package.json` and add a `CHANGELOG.md` entry, then
178
+ commit.
179
+ 2. Tag the commit with that version and push the tag:
180
+ `git tag v0.2.0 && git push origin v0.2.0`.
181
+ 3. Approve the staged version on npmjs.com, or with
182
+ `npm stage approve <stage-id>`. npm asks for your second factor.
183
+
184
+ `.github/workflows/release.yml` checks that the tag matches `package.json`,
185
+ runs the tests and stages the version on npm. Nothing is installable until
186
+ you approve it. Once you do, the workflow has webjars.org deploy the WebJar
187
+ to Maven Central, where it can take an hour to appear. The workflow waits up
188
+ to five hours for the approval; after that, re-run its `webjar` job.
189
+
190
+ Publishing uses npm's trusted publishing, so no npm token is stored in the
191
+ repository. The package's trusted publisher on npmjs.com is GitHub Actions,
192
+ user `codeconsole`, repository `codemirror-lang-groovy`, workflow
193
+ `release.yml`, allowed to stage releases only.
194
+
195
+ ## License
196
+
197
+ MIT. The grammar is derived from
198
+ [`@lezer/java`](https://github.com/lezer-parser/java) by Marijn Haverbeke and
199
+ others, also MIT licensed.