@exercism/codemirror-lang-unison 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2024 by Erik Schierboom <erik_schierboom@hotmail.com> and others
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
13
+ all 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
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,108 @@
1
- # Temporary Holding Version
1
+ # Unison language support for CodeMirror
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
+ ![NPM Version](https://img.shields.io/npm/v/@exercism/codemirror-lang-unison)
4
+
5
+ This package gives the [CodeMirror 6](https://codemirror.net/) editor a [Lezer](https://lezer.codemirror.net/) grammar for [Unison](https://www.unison-lang.org/), with highlighting, folding, indentation and autocompletion.
6
+ Exercism uses it in the in-browser editor for the Unison track.
7
+
8
+ ⚠️ To ensure that the package can be integrated on the Exercism website, don't change the packages' versions:
9
+
10
+ ```json
11
+ "@codemirror/language": "^6.10.1",
12
+ "@lezer/highlight": "^1.2.0",
13
+ "@lezer/lr": "^1.4.0"
14
+ ```
15
+
16
+ ## Install
17
+
18
+ - NPM: `npm install @exercism/codemirror-lang-unison`
19
+ - Yarn: `yarn add @exercism/codemirror-lang-unison`
20
+ - Bun: `bun add @exercism/codemirror-lang-unison`
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ import { EditorView, basicSetup } from "codemirror";
26
+ import { unison } from "@exercism/codemirror-lang-unison";
27
+
28
+ new EditorView({
29
+ doc: 'main = do printLine "Hello"',
30
+ extensions: [basicSetup, unison()],
31
+ parent: document.body,
32
+ });
33
+ ```
34
+
35
+ ## What it supports
36
+
37
+ The grammar reads type signatures and definitions, including namespaced names such as `List.map`, operator definitions and bindings that take a value apart, such as `(a, b) = pair`.
38
+ It reads `cases`, `match ... with` (with several patterns and guards), `if ... then ... else`, lambdas, `do`, `let`, `handle ... with`, delayed computations (`'expr`) and forcing them (`!expr`).
39
+ It also reads `use` clauses, type declarations with constructors or records, ability declarations, handler patterns such as `{ ask -> resume }`, watches (`> expr`), tests (`test> ...`), docs (`{{ ... }}`) and the `---` line that folds away the rest of a file.
40
+ In types, it reads functions, ability lists such as `{IO, Exception}`, delayed types such as `'{Random} Nat`, lists, tuples and `forall`.
41
+
42
+ Unison uses indentation to open and close blocks. The tokenizer in `src/tokens.ts` follows the indentation and tells the grammar where each block opens, where each item starts and where each block ends.
43
+
44
+ Completion offers:
45
+
46
+ - the keywords
47
+ - snippets for functions, `cases`, `match`, guards, `if`, `do`, `let`, lambdas, folds, types, records, abilities, handlers, `use` and tests
48
+ - common functions, types and constructors from base, such as `printLine`, `Optional` and `Some`
49
+ - the common members of `List`, `Text`, `Nat`, `Int`, `Optional`, `Map`, `Char` and `Set` after their name and a dot, as in `List.`
50
+ - the names declared in the file that are in scope at the cursor, such as definitions, types, constructors, ability operations, parameters, pattern variables, lambda arguments and the bindings in blocks
51
+ - a definition's short name as well as its full name. For example, `sublist.isSuperlist` is offered in full, as `isSuperlist` on its own, and as `isSuperlist` after typing `sublist.`
52
+
53
+ Completion switches off inside texts, comments and docs.
54
+
55
+ ## Credits
56
+
57
+ The layout tokenizer follows the approach of the PureScript grammar. That grammar is adapted from [codemirror-lang-haskell](https://codeberg.org/reeven/codemirror-lang-haskell) by CodinCod, which is released under the MIT licence.
58
+
59
+ ## Prerequisites
60
+
61
+ - [Bun](https://bun.sh/)
62
+
63
+ ## Structure
64
+
65
+ ```text
66
+ .
67
+ ├── src
68
+ │ ├── index.ts (the language support: highlighting, folding and indentation)
69
+ │ ├── complete.ts (the completion sources and snippets)
70
+ │ ├── syntax.grammar (the Lezer grammar)
71
+ │ ├── tokens.ts (the layout, comment, name and doc tokenizers)
72
+ │ └── syntax.grammar*.d.ts (the grammar typings)
73
+ ├── test
74
+ │ ├── cases (grammar test cases)
75
+ │ ├── grammar.test.ts (runs the grammar test cases)
76
+ │ ├── complete.test.ts (completion tests)
77
+ │ └── editor.test.ts (folding, indentation and highlighting tests)
78
+ ├── index.html (dev server file)
79
+ ├── rollup.config.js (bundling config)
80
+ ├── tsconfig.json (TypeScript config)
81
+ └── vite.config.js (Vite dev server config)
82
+ ```
83
+
84
+ ## Setup
85
+
86
+ Run `bun install` to install all dependencies.
87
+
88
+ ## Developing
89
+
90
+ Run `bun run dev` to start a [Vite](https://vite.dev/) dev server, usually at http://localhost:5173/.
91
+ It shows `index.html`, which loads some sample Unison into an editor that uses this package.
92
+ The page reloads when the grammar changes.
93
+
94
+ ## Building
95
+
96
+ Run `bun run prepare` to build the package into `dist`.
97
+ `bun install` also runs this script.
98
+
99
+ ## Testing
100
+
101
+ Run `bun run test`. It builds the package and then runs the tests, because the grammar tests use the built parser.
102
+ Each file in `test/cases` holds grammar test cases. Keep each case small and about one feature.
103
+
104
+ ## Publishing
105
+
106
+ To publish a new version, set `version` in `package.json` and commit it.
107
+ Then push a git tag named `v` followed by that version, such as `v1.0.1` for version 1.0.1.
108
+ The publish workflow builds and tests the package, then publishes it to npm.