@exercism/codemirror-lang-elm 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/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/index.cjs +839 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +829 -0
- package/package.json +51 -4
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,99 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Elm language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives the CodeMirror 6 editor a Lezer grammar for Elm 0.19, with highlighting, indentation, folding and autocompletion.
|
|
6
|
+
Exercism uses it in the in-browser editor for the Elm track.
|
|
7
|
+
|
|
8
|
+
⚠️ Keep the versions of these dependencies as they are, so that the package works on the Exercism website:
|
|
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-elm`
|
|
19
|
+
- Yarn: `yarn add @exercism/codemirror-lang-elm`
|
|
20
|
+
- Bun: `bun add @exercism/codemirror-lang-elm`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
26
|
+
import { elm } from "@exercism/codemirror-lang-elm";
|
|
27
|
+
|
|
28
|
+
new EditorView({
|
|
29
|
+
extensions: [basicSetup, elm()],
|
|
30
|
+
parent: document.body,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
elm-format indents by four spaces. To match it, add `indentUnit.of(" ")` from `@codemirror/language` to the editor's extensions.
|
|
35
|
+
|
|
36
|
+
## What it does
|
|
37
|
+
|
|
38
|
+
- It highlights keywords, strings, numbers, comments, declarations, function calls, types, constructors, record fields and operators.
|
|
39
|
+
- It indents a new line under `=`, `->`, `let`, `of`, `then` and `else`, and folds declarations, `let` blocks, `case` expressions, records and lists.
|
|
40
|
+
- Its autocompletion offers:
|
|
41
|
+
- keywords, and snippets for a function with its annotation, `case`, `if`, `let`, a lambda, a custom type, a record type alias, a module header and an import.
|
|
42
|
+
- the names imported into every Elm module by default, such as `List`, `Maybe`, `Just` and `modBy`.
|
|
43
|
+
- a module's functions, types and constructors after its name and a dot, such as `List.map` or `Dict.insert`. This works for elm/core, elm/regex, elm/parser, elm/time, elm/random and elm/json, and for an alias set by `import Dict as D`.
|
|
44
|
+
- the names exposed by an import, such as `insert` after `import Dict exposing (insert)`.
|
|
45
|
+
- the names declared in the file that are in scope at the cursor: top-level functions, types and constructors, parameters, and the names bound by `let`, `case` and lambdas.
|
|
46
|
+
- record field names after a dot, as in `model.count` or `.count`.
|
|
47
|
+
|
|
48
|
+
## How the grammar reads indentation
|
|
49
|
+
|
|
50
|
+
Elm marks its blocks with indentation, so the grammar can't be written with token rules alone.
|
|
51
|
+
The layout tokenizer in `src/tokens.ts` adds three invisible tokens for the grammar to use. One opens a block, one separates its items, and one closes it.
|
|
52
|
+
|
|
53
|
+
- The file is a block at column 0, so a line at the left margin starts a new declaration.
|
|
54
|
+
- A `let` or an `of` opens a block at the column of the token after it.
|
|
55
|
+
- A line at that column starts the next item, and a line further left closes the block.
|
|
56
|
+
- A block also closes in front of a token that can't go inside it. That is how `let x = 1 in x` works on one line.
|
|
57
|
+
|
|
58
|
+
The same file reads nested block comments, the module part of a qualified name such as `List.` in `List.map`, and the dot in `model.count`.
|
|
59
|
+
A dot written straight after a name reads a field, and a dot with a space in front of it starts an accessor function such as `.count`.
|
|
60
|
+
|
|
61
|
+
## Prerequisites
|
|
62
|
+
|
|
63
|
+
- [Bun](https://bun.sh/)
|
|
64
|
+
|
|
65
|
+
## Setup
|
|
66
|
+
|
|
67
|
+
Run `bun install` to install all dependencies.
|
|
68
|
+
|
|
69
|
+
## Developing
|
|
70
|
+
|
|
71
|
+
To help with development, run `bun run dev`.
|
|
72
|
+
This starts a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders `index.html` with some sample Elm code.
|
|
73
|
+
|
|
74
|
+
The grammar is in `src/syntax.grammar`, the external tokenizers are in `src/tokens.ts`, and the completion is in `src/complete.ts` and `src/modules.ts`.
|
|
75
|
+
|
|
76
|
+
## Testing
|
|
77
|
+
|
|
78
|
+
Run `bun run test`. It builds the package and then runs the tests in `test/`.
|
|
79
|
+
|
|
80
|
+
- `test/cases/*.txt` hold the grammar tests, in [Lezer's test format](https://lezer.codemirror.net/docs/guide/#running-the-grammar).
|
|
81
|
+
- `test/completion.test.ts` checks what the completion offers at a given position.
|
|
82
|
+
- `test/editor.test.ts` checks highlighting, indentation and folding.
|
|
83
|
+
|
|
84
|
+
## Building
|
|
85
|
+
|
|
86
|
+
Run `bun run prepare` to build the package into `dist/`.
|
|
87
|
+
`bun install` runs the same command, so a fresh install also builds the package.
|
|
88
|
+
|
|
89
|
+
## Publishing
|
|
90
|
+
|
|
91
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
92
|
+
Then push a tag made of `v` followed by that version, for example `v1.0.0`.
|
|
93
|
+
The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
|
|
94
|
+
If the tag differs from `version`, the workflow stops before it publishes.
|
|
95
|
+
|
|
96
|
+
## Resources
|
|
97
|
+
|
|
98
|
+
- [CodeMirror](https://codemirror.net/docs/)
|
|
99
|
+
- [Lezer](https://lezer.codemirror.net/docs/guide/)
|