@exercism/codemirror-lang-idris 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 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
- # Temporary Holding Version
1
+ # Idris 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-idris)
4
+
5
+ This package gives the CodeMirror 6 editor a Lezer grammar for Idris 2, with highlighting, indentation, folding and autocompletion.
6
+ Exercism uses it in the in-browser editor for the Idris track.
7
+
8
+ Keep these dependency versions as they are, so the package works with 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-idris`
19
+ - Yarn: `yarn add @exercism/codemirror-lang-idris`
20
+ - Bun: `bun add @exercism/codemirror-lang-idris`
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ import { EditorView, basicSetup } from "codemirror";
26
+ import { idris } from "@exercism/codemirror-lang-idris";
27
+
28
+ new EditorView({
29
+ extensions: [basicSetup, idris()],
30
+ parent: document.body,
31
+ });
32
+ ```
33
+
34
+ ## What it does
35
+
36
+ - It highlights keywords, modifiers such as `public export`, strings, characters, numbers, comments, documentation comments, pragmas such as `%default total`, declarations, function calls, types, constructors, record fields, holes and operators.
37
+ - It indents a new line under `=`, `=>`, `->`, `do`, `where`, `of`, `let` and `with`, and folds declarations, `where` blocks, `do` blocks, `case` expressions and `with` blocks.
38
+ - Its autocompletion offers:
39
+ - keywords, and snippets for a function with its signature, `case`, `if`, `let`, `where`, `do`, a lambda, `with`, both kinds of data type, a record, an interface, an implementation, a module header and an import.
40
+ - names from the Prelude and from the base modules that solutions import most, such as `Data.List`, `Data.Vect` and `Data.String`.
41
+ - the names declared in the file that are in scope at the cursor: top-level functions, types, constructors and interfaces, parameters, and the names bound by `where`, `let`, `case`, `with`, lambdas and `do`.
42
+ - the file's record fields after a dot, as in `person.name`.
43
+
44
+ ## How the grammar reads indentation
45
+
46
+ Idris marks its blocks with indentation, so the grammar can't be written with token rules alone.
47
+ The layout tokenizer in `src/tokens.ts` adds three invisible tokens for the grammar to use: one that opens a block, one that separates its items, and one that closes it.
48
+
49
+ - The file is a block, so a line at the left margin starts a new declaration.
50
+ - `where`, `do`, `let`, `of`, `with`, `namespace`, `mutual` and `parameters` open a block at the column of the token after them.
51
+ - A line at that column starts the next item, and a line further left closes the block.
52
+ - 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.
53
+ - A tab counts as one column, as it does in Idris.
54
+
55
+ The tokenizer also reads nested block comments, `|||` documentation, pragmas, the module part of a qualified name such as `Vect.` in `Vect.index`, and the `!` of bang notation.
56
+
57
+ ## Credits
58
+
59
+ The grammar, the layout tokenizer and the scoped completion are adapted from [CodinCod's Haskell grammar](https://codeberg.org/reeven/codemirror-lang-haskell), which is MIT licensed.
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 Idris 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`.
75
+
76
+ ## Building
77
+
78
+ Run `bun run prepare` to build the package into `dist/`.
79
+ It runs Rollup under Bun's runtime, because one of the Rollup plugins doesn't load in recent versions of Node.
80
+
81
+ ## Testing
82
+
83
+ Run `bun run test`. It builds the package and then runs the tests in `test/`.
84
+
85
+ - `test/cases/*.txt` hold the grammar tests, in [Lezer's test format](https://lezer.codemirror.net/docs/guide/#running-the-grammar).
86
+ - `test/completion.test.ts` checks what the completion offers at a given position.
87
+ - `test/editor.test.ts` checks highlighting, indentation and folding.
88
+
89
+ ## Resources
90
+
91
+ - [CodeMirror](https://codemirror.net/docs/)
92
+ - [Lezer](https://lezer.codemirror.net/docs/guide/)
93
+
94
+ ## Publishing
95
+
96
+ To publish a new version, set `version` in `package.json` and commit it.
97
+ Then push a tag made of `v` followed by that version, for example `v1.0.0`.
98
+ The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
99
+ If the tag differs from `version`, the workflow stops before it publishes.