@exercism/codemirror-lang-fsharp 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 +91 -2
- package/dist/index.cjs +806 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +798 -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,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# F# language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives the CodeMirror 6 editor a Lezer grammar for F#, with highlighting, indentation, folding and autocompletion.
|
|
6
|
+
Exercism uses it in the in-browser editor for the F# 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-fsharp`
|
|
19
|
+
- Yarn: `yarn add @exercism/codemirror-lang-fsharp`
|
|
20
|
+
- Bun: `bun add @exercism/codemirror-lang-fsharp`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
26
|
+
import { fsharp } from "@exercism/codemirror-lang-fsharp";
|
|
27
|
+
|
|
28
|
+
new EditorView({
|
|
29
|
+
extensions: [basicSetup, fsharp()],
|
|
30
|
+
parent: document.body,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## What it does
|
|
35
|
+
|
|
36
|
+
- It highlights keywords, strings, numbers, comments, definitions, function calls, types, union cases, record fields, attributes and operators.
|
|
37
|
+
- It indents a new line after a line that opens a block, such as a line that ends in `=`, `->`, `then`, `else`, `do` or `with`, and folds blocks, types, lists, records and block comments.
|
|
38
|
+
- Its autocompletion offers:
|
|
39
|
+
- keywords, common functions such as `printfn` and `failwith`, built-in types, and snippets for a function, `let rec`, a lambda, `match`, `if`/`then`/`else`, `for`, a record type, a discriminated union and a module.
|
|
40
|
+
- the functions of `List`, `Seq`, `Array`, `Map`, `Set`, `String`, `Option` and `Result` after the module name and a dot, as in `List.map`.
|
|
41
|
+
- the names declared in the file that are in scope at the cursor: `let` bindings, parameters, lambda parameters, the variables bound by a match rule or a `for` loop, types, union cases, exceptions and modules.
|
|
42
|
+
|
|
43
|
+
Autocompletion is switched off inside strings and comments.
|
|
44
|
+
|
|
45
|
+
## How the grammar reads indentation
|
|
46
|
+
|
|
47
|
+
F# uses the offside rule: indentation decides where a block ends.
|
|
48
|
+
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.
|
|
49
|
+
|
|
50
|
+
- The file is a block at column 0, so a line at the left margin starts a new declaration.
|
|
51
|
+
- The `=` of a `let`, `type` or `module`, the `->` of a lambda or match rule, and `then`, `else`, `do`, `try` and `finally` open a block at the column of the next token.
|
|
52
|
+
- A line at that column starts the next item, unless it starts with an operator such as `|>` or a word such as `else`, `with` or `and`. Those lines carry on the line above.
|
|
53
|
+
- A line further left closes the block. A `|` may sit to the left of the block it belongs to, as in `let f = function` followed by its rules.
|
|
54
|
+
- A block also closes in front of a closing bracket, or a keyword that can't go inside it. That is how `if a then b else c` works on one line.
|
|
55
|
+
- Inside brackets, a line at the column of the first item starts a new item, as in a list written one item per line.
|
|
56
|
+
|
|
57
|
+
The same file reads nested block comments, numbers (so that `1..10` is a range), and the angle brackets of type arguments such as `List<int>`.
|
|
58
|
+
|
|
59
|
+
## Prerequisites
|
|
60
|
+
|
|
61
|
+
- [Bun](https://bun.sh/)
|
|
62
|
+
|
|
63
|
+
## Setup
|
|
64
|
+
|
|
65
|
+
Run `bun install` to install all dependencies.
|
|
66
|
+
|
|
67
|
+
## Developing
|
|
68
|
+
|
|
69
|
+
To help with development, run `bun run dev`.
|
|
70
|
+
This starts a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders `index.html` with some sample F# code.
|
|
71
|
+
|
|
72
|
+
The grammar is in `src/syntax.grammar`, the external tokenizers are in `src/tokens.ts`, the highlighting is in `src/highlight.ts`, and the completion is in `src/complete.ts` and `src/modules.ts`.
|
|
73
|
+
|
|
74
|
+
## Building
|
|
75
|
+
|
|
76
|
+
Run `bun run prepare` to build the package into `dist/`.
|
|
77
|
+
It runs Rollup under Bun's runtime, because one of the Rollup plugins doesn't load in recent versions of Node.
|
|
78
|
+
|
|
79
|
+
## Testing
|
|
80
|
+
|
|
81
|
+
Run `bun run test`. It builds the package and then runs the tests in `test/`.
|
|
82
|
+
|
|
83
|
+
- `test/cases/*.txt` hold the grammar tests, in [Lezer's test format](https://lezer.codemirror.net/docs/guide/#running-the-grammar).
|
|
84
|
+
- `test/completion.test.ts` checks what the completion offers at a given position.
|
|
85
|
+
- `test/editor.test.ts` checks the highlighting, indentation and folding.
|
|
86
|
+
|
|
87
|
+
## Publishing
|
|
88
|
+
|
|
89
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
90
|
+
Then push a tag made of `v` followed by that version, for example `v1.0.0`.
|
|
91
|
+
The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
|
|
92
|
+
If the tag differs from `version`, the workflow stops before it publishes.
|