@exercism/codemirror-lang-gdscript 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 +22 -0
- package/README.md +104 -2
- package/dist/index.cjs +679 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +671 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2024 by Erik Schierboom <erik_schierboom@hotmail.com> and others
|
|
4
|
+
Copyright (C) 2018-2021 by Marijn Haverbeke <marijn@haverbeke.berlin> and others (the @lezer/python tokenizers and the @codemirror/lang-python indentation and completion that this package adapts)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# GDScript language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives the CodeMirror 6 editor a Lezer grammar for GDScript 2, the language of Godot 4, with highlighting, indentation, folding and autocompletion.
|
|
6
|
+
Exercism uses it in the in-browser editor for the GDScript 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-gdscript`
|
|
19
|
+
- Yarn: `yarn add @exercism/codemirror-lang-gdscript`
|
|
20
|
+
- Bun: `bun add @exercism/codemirror-lang-gdscript`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
26
|
+
import { gdscript } from "@exercism/codemirror-lang-gdscript";
|
|
27
|
+
|
|
28
|
+
new EditorView({
|
|
29
|
+
extensions: [basicSetup, gdscript()],
|
|
30
|
+
parent: document.body,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Godot indents with tabs. To match it, add `indentUnit.of("\t")` from `@codemirror/language` to the editor's extensions.
|
|
35
|
+
|
|
36
|
+
## What it does
|
|
37
|
+
|
|
38
|
+
- It reads GDScript 2: annotations, typed variables and parameters, `:=`, typed arrays and dictionaries, properties with `set` and `get`, signals, enums, inner classes, static functions, lambdas (including block lambdas inside a call), `match` with array, dictionary and binding patterns and `when` guards, `await`, node paths such as `$Sprite` and `%Unique`, and `&"name"`, `^"path"` and `r"raw"` strings.
|
|
39
|
+
- It highlights keywords, strings, numbers, comments, annotations, definitions, function and method calls, types, node paths and operators.
|
|
40
|
+
- It indents a new line after a block opens, and folds functions, classes, blocks, arrays, dictionaries and enums.
|
|
41
|
+
- Its autocompletion offers:
|
|
42
|
+
- keywords, and snippets for a function, a static function, a lambda, a `class_name` and `extends` header, an inner class, `if` with `elif` and `else`, `for`, `while`, `match`, `signal`, `enum` and a property with a setter and getter.
|
|
43
|
+
- the functions in `@GlobalScope` and `@GDScript`, such as `print`, `range` and `clamp`, the constants `PI`, `TAU`, `INF` and `NAN`, and the built-in types and common engine classes, such as `Vector2`, `Array`, `Dictionary`, `String` and `Node2D`.
|
|
44
|
+
- only types in a type annotation, such as after `var x:` or `->`.
|
|
45
|
+
- the annotations after `@`, such as `@export`, `@export_range` and `@onready`.
|
|
46
|
+
- the names declared in the file that are in scope at the cursor: functions, classes, variables, constants, signals, enums, parameters, loop variables and match bindings.
|
|
47
|
+
- the members of an enum or inner class from the file after its name and a dot, as in `State.IDLE`.
|
|
48
|
+
|
|
49
|
+
## How the grammar reads indentation
|
|
50
|
+
|
|
51
|
+
GDScript marks its blocks with indentation, as Python does.
|
|
52
|
+
The tokenizers in `src/tokens.ts` are adapted from [@lezer/python](https://github.com/lezer-parser/python).
|
|
53
|
+
They add tokens for a line break, a deeper indent and a shallower indent, and ignore line breaks inside brackets.
|
|
54
|
+
|
|
55
|
+
GDScript has two things that Python doesn't:
|
|
56
|
+
|
|
57
|
+
- A lambda can have a block for its body, even inside a call's brackets. A line break after the lambda's `:` starts the block, and a shallower line, a closing bracket or a comma ends it.
|
|
58
|
+
- A statement can end with a block, such as `var f = func():` followed by the lambda's lines, or a property with its `set` and `get` blocks. In both cases the tokenizer ends the statement at the start of the next line.
|
|
59
|
+
|
|
60
|
+
A tab counts as four columns, as in Godot's editor, so files that mix tabs and spaces still line up.
|
|
61
|
+
|
|
62
|
+
## Prerequisites
|
|
63
|
+
|
|
64
|
+
- [Bun](https://bun.sh/)
|
|
65
|
+
|
|
66
|
+
## Setup
|
|
67
|
+
|
|
68
|
+
Run `bun install` to install all dependencies.
|
|
69
|
+
|
|
70
|
+
## Developing
|
|
71
|
+
|
|
72
|
+
To help with development, run `bun run dev`.
|
|
73
|
+
This starts a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders `index.html` with some sample GDScript.
|
|
74
|
+
|
|
75
|
+
The grammar is in `src/syntax.grammar`, the external tokenizers are in `src/tokens.ts`, and the completion is in `src/complete.ts`.
|
|
76
|
+
|
|
77
|
+
## Building
|
|
78
|
+
|
|
79
|
+
Run `bun run prepare` to build the package into `dist/`.
|
|
80
|
+
It runs Rollup under Bun's runtime, because one of the Rollup plugins doesn't load in recent versions of Node.
|
|
81
|
+
|
|
82
|
+
## Testing
|
|
83
|
+
|
|
84
|
+
Run `bun run test`. It builds the package and then runs the tests in `test/`.
|
|
85
|
+
|
|
86
|
+
- `test/cases/*.txt` hold the grammar tests, in [Lezer's test format](https://lezer.codemirror.net/docs/guide/#running-the-grammar).
|
|
87
|
+
- `test/completion.test.ts` checks what the completion offers at a given position.
|
|
88
|
+
- `test/editor.test.ts` checks highlighting, indentation and folding.
|
|
89
|
+
|
|
90
|
+
## Credits
|
|
91
|
+
|
|
92
|
+
The tokenizers are adapted from [@lezer/python](https://github.com/lezer-parser/python), and the indentation and the scope walk for completion from [@codemirror/lang-python](https://github.com/codemirror/lang-python). Both are by Marijn Haverbeke and released under the MIT licence.
|
|
93
|
+
|
|
94
|
+
## Resources
|
|
95
|
+
|
|
96
|
+
- [CodeMirror](https://codemirror.net/docs/)
|
|
97
|
+
- [Lezer](https://lezer.codemirror.net/docs/guide/)
|
|
98
|
+
- [GDScript reference](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html)
|
|
99
|
+
|
|
100
|
+
## Publishing
|
|
101
|
+
|
|
102
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
103
|
+
Then push a tag made of `v` followed by that version, for example `v1.0.0`.
|
|
104
|
+
The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
|
|
105
|
+
If the tag differs from `version`, the workflow stops before it publishes.
|