monaco-editor-gdscript 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.md +8 -0
- package/README.md +103 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +279 -0
- package/dist/index.mjs +250 -0
- package/package.json +48 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2026 Mike Rötgers
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# monaco-editor-gdscript
|
|
2
|
+
|
|
3
|
+
GDScript (Godot 4.x) syntax highlighting for the [Monaco Editor](https://microsoft.github.io/monaco-editor/).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/monaco-editor-gdscript)
|
|
6
|
+
[](https://github.com/MikeRoetgers/monaco-editor-gdscript/blob/main/LICENSE.md)
|
|
7
|
+
|
|
8
|
+
## Why? VSCode has gdscript syntax highlighting.
|
|
9
|
+
|
|
10
|
+
VScode uses the Monaco Editor internally but utilizes TextMate grammars to provide syntax highlighting whereas the standalone Monaco Editor uses the Monarch tokenizer system.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install monaco-editor-gdscript
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This package requires `monaco-editor` as a peer dependency (`>=0.30.0`). If you do not already have it installed:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install monaco-editor
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Side-effect import
|
|
27
|
+
|
|
28
|
+
The simplest way to register GDScript is a bare import. When the module loads, it detects the global `monaco` object and registers the language automatically.
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import 'monaco-editor-gdscript';
|
|
32
|
+
|
|
33
|
+
const editor = monaco.editor.create(document.getElementById('container'), {
|
|
34
|
+
value: 'func _ready():\n\tprint("Hello, Godot!")',
|
|
35
|
+
language: 'gdscript',
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
> **Note:** Auto-registration relies on a global `monaco` object, which is typically only available when using Monaco's AMD loader or a CDN build. Modern bundlers (webpack, Vite, esbuild) do **not** create a global `monaco`, so the side-effect import will silently do nothing. If you use a bundler, use the explicit `register()` pattern below instead.
|
|
40
|
+
|
|
41
|
+
### Explicit registration
|
|
42
|
+
|
|
43
|
+
If you need more control over when registration happens, or if `monaco` is not available as a global, use the named `register` export and pass your Monaco instance directly.
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import { register } from 'monaco-editor-gdscript';
|
|
47
|
+
import * as monaco from 'monaco-editor';
|
|
48
|
+
|
|
49
|
+
register(monaco);
|
|
50
|
+
|
|
51
|
+
const editor = monaco.editor.create(document.getElementById('container'), {
|
|
52
|
+
value: 'func _ready():\n\tprint("Hello, Godot!")',
|
|
53
|
+
language: 'gdscript',
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Advanced usage
|
|
58
|
+
|
|
59
|
+
The underlying Monarch language definition and language configuration objects are also exported for consumers who want to customize or extend them. This is useful if you need to register GDScript under a different language ID, or if you want to extend the tokenizer rules before registering.
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import { language, conf } from 'monaco-editor-gdscript';
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## What's included
|
|
66
|
+
|
|
67
|
+
- **Syntax highlighting** via Monaco's Monarch tokenizer covering all GDScript 4.x syntax
|
|
68
|
+
- **Language configuration**: bracket matching, auto-closing pairs, comment toggling (`#`), indentation rules, and folding
|
|
69
|
+
|
|
70
|
+
### Highlighted elements
|
|
71
|
+
|
|
72
|
+
- **Keywords** -- `func`, `var`, `class`, `if`, `for`, `match`, `signal`, `enum`, `await`, etc.
|
|
73
|
+
- **Built-in types** -- `Vector2`, `String`, `Array`, `Dictionary`, `PackedByteArray`, etc.
|
|
74
|
+
- **Annotations** -- `@export`, `@onready`, `@tool`, etc.
|
|
75
|
+
- **Built-in constants** -- `true`, `false`, `null`, `PI`, `TAU`, `INF`, `NAN`
|
|
76
|
+
- **Built-in functions** -- `preload`, `print`, `len`, `range`, `clamp`, `lerp`, etc.
|
|
77
|
+
- **Strings** -- single-quoted, double-quoted, triple-quoted multiline, and StringName literals (`&"..."`)
|
|
78
|
+
- **Comments** (`#`) and **doc comments** (`##`)
|
|
79
|
+
- **Numbers** -- integers, floats, hex (`0xFF`), binary (`0b1010`), with underscore separators
|
|
80
|
+
- **Node paths** (`$Node/Path`) and **unique nodes** (`%UniqueNode`)
|
|
81
|
+
- **`self` / `super`** -- highlighted as language variables
|
|
82
|
+
- **Operators** -- `->`, `:=`, and all standard operators
|
|
83
|
+
|
|
84
|
+
## What's NOT included
|
|
85
|
+
|
|
86
|
+
- Autocomplete / IntelliSense
|
|
87
|
+
- Go-to-definition / hover info
|
|
88
|
+
- Error checking / diagnostics
|
|
89
|
+
- GDShader support
|
|
90
|
+
- Godot scene file (`.tscn`) support
|
|
91
|
+
|
|
92
|
+
The scope of this package is intentionally limited to syntax highlighting and basic editor configuration. It does not provide language-server features or support for file formats other than `.gd`.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
[MIT](LICENSE.md)
|
|
97
|
+
|
|
98
|
+
## References
|
|
99
|
+
|
|
100
|
+
- [Monaco Editor](https://microsoft.github.io/monaco-editor/)
|
|
101
|
+
- [Monaco Monarch documentation](https://microsoft.github.io/monaco-editor/monarch.html)
|
|
102
|
+
- [GDScript reference (Godot 4.x)](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html)
|
|
103
|
+
- [Godot Engine](https://godotengine.org/)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as monaco_editor from 'monaco-editor';
|
|
2
|
+
import { languages } from 'monaco-editor';
|
|
3
|
+
|
|
4
|
+
declare const language: languages.IMonarchLanguage;
|
|
5
|
+
|
|
6
|
+
declare const conf: languages.LanguageConfiguration;
|
|
7
|
+
|
|
8
|
+
declare function register(monacoInstance: {
|
|
9
|
+
languages: typeof monaco_editor.languages;
|
|
10
|
+
}): void;
|
|
11
|
+
|
|
12
|
+
export { conf, language, register };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as monaco_editor from 'monaco-editor';
|
|
2
|
+
import { languages } from 'monaco-editor';
|
|
3
|
+
|
|
4
|
+
declare const language: languages.IMonarchLanguage;
|
|
5
|
+
|
|
6
|
+
declare const conf: languages.LanguageConfiguration;
|
|
7
|
+
|
|
8
|
+
declare function register(monacoInstance: {
|
|
9
|
+
languages: typeof monaco_editor.languages;
|
|
10
|
+
}): void;
|
|
11
|
+
|
|
12
|
+
export { conf, language, register };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
conf: () => conf,
|
|
24
|
+
language: () => language,
|
|
25
|
+
register: () => register
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/gdscript.ts
|
|
30
|
+
var language = {
|
|
31
|
+
defaultToken: "",
|
|
32
|
+
tokenPostfix: ".gdscript",
|
|
33
|
+
keywords: [
|
|
34
|
+
"if",
|
|
35
|
+
"elif",
|
|
36
|
+
"else",
|
|
37
|
+
"for",
|
|
38
|
+
"while",
|
|
39
|
+
"match",
|
|
40
|
+
"when",
|
|
41
|
+
"break",
|
|
42
|
+
"continue",
|
|
43
|
+
"pass",
|
|
44
|
+
"return",
|
|
45
|
+
"func",
|
|
46
|
+
"class",
|
|
47
|
+
"class_name",
|
|
48
|
+
"extends",
|
|
49
|
+
"is",
|
|
50
|
+
"var",
|
|
51
|
+
"const",
|
|
52
|
+
"enum",
|
|
53
|
+
"signal",
|
|
54
|
+
"static",
|
|
55
|
+
"await",
|
|
56
|
+
"yield",
|
|
57
|
+
"and",
|
|
58
|
+
"or",
|
|
59
|
+
"not",
|
|
60
|
+
"in",
|
|
61
|
+
"as",
|
|
62
|
+
"void",
|
|
63
|
+
"breakpoint"
|
|
64
|
+
],
|
|
65
|
+
builtinTypes: [
|
|
66
|
+
"bool",
|
|
67
|
+
"int",
|
|
68
|
+
"float",
|
|
69
|
+
"String",
|
|
70
|
+
"StringName",
|
|
71
|
+
"NodePath",
|
|
72
|
+
"Vector2",
|
|
73
|
+
"Vector2i",
|
|
74
|
+
"Vector3",
|
|
75
|
+
"Vector3i",
|
|
76
|
+
"Vector4",
|
|
77
|
+
"Vector4i",
|
|
78
|
+
"Color",
|
|
79
|
+
"Rect2",
|
|
80
|
+
"Rect2i",
|
|
81
|
+
"Transform2D",
|
|
82
|
+
"Transform3D",
|
|
83
|
+
"Basis",
|
|
84
|
+
"Quaternion",
|
|
85
|
+
"Projection",
|
|
86
|
+
"AABB",
|
|
87
|
+
"Plane",
|
|
88
|
+
"RID",
|
|
89
|
+
"Array",
|
|
90
|
+
"Dictionary",
|
|
91
|
+
"Callable",
|
|
92
|
+
"Signal",
|
|
93
|
+
"PackedByteArray",
|
|
94
|
+
"PackedInt32Array",
|
|
95
|
+
"PackedInt64Array",
|
|
96
|
+
"PackedFloat32Array",
|
|
97
|
+
"PackedFloat64Array",
|
|
98
|
+
"PackedStringArray",
|
|
99
|
+
"PackedVector2Array",
|
|
100
|
+
"PackedVector3Array",
|
|
101
|
+
"PackedVector4Array",
|
|
102
|
+
"PackedColorArray"
|
|
103
|
+
],
|
|
104
|
+
builtinConstants: [
|
|
105
|
+
"true",
|
|
106
|
+
"false",
|
|
107
|
+
"null"
|
|
108
|
+
],
|
|
109
|
+
numericConstants: [
|
|
110
|
+
"PI",
|
|
111
|
+
"TAU",
|
|
112
|
+
"INF",
|
|
113
|
+
"NAN"
|
|
114
|
+
],
|
|
115
|
+
builtinFunctions: [
|
|
116
|
+
"preload",
|
|
117
|
+
"load",
|
|
118
|
+
"print",
|
|
119
|
+
"print_rich",
|
|
120
|
+
"print_verbose",
|
|
121
|
+
"prints",
|
|
122
|
+
"printt",
|
|
123
|
+
"printerr",
|
|
124
|
+
"push_error",
|
|
125
|
+
"push_warning",
|
|
126
|
+
"str",
|
|
127
|
+
"len",
|
|
128
|
+
"range",
|
|
129
|
+
"type_of",
|
|
130
|
+
"typeof",
|
|
131
|
+
"is_instance_of",
|
|
132
|
+
"is_instance_valid",
|
|
133
|
+
"abs",
|
|
134
|
+
"sign",
|
|
135
|
+
"ceil",
|
|
136
|
+
"floor",
|
|
137
|
+
"round",
|
|
138
|
+
"clamp",
|
|
139
|
+
"lerp",
|
|
140
|
+
"min",
|
|
141
|
+
"max",
|
|
142
|
+
"pow",
|
|
143
|
+
"sqrt",
|
|
144
|
+
"log",
|
|
145
|
+
"exp",
|
|
146
|
+
"sin",
|
|
147
|
+
"cos",
|
|
148
|
+
"tan",
|
|
149
|
+
"asin",
|
|
150
|
+
"acos",
|
|
151
|
+
"atan",
|
|
152
|
+
"atan2",
|
|
153
|
+
"deg_to_rad",
|
|
154
|
+
"rad_to_deg",
|
|
155
|
+
"randf",
|
|
156
|
+
"randi",
|
|
157
|
+
"randfn",
|
|
158
|
+
"randf_range",
|
|
159
|
+
"randi_range",
|
|
160
|
+
"seed",
|
|
161
|
+
"randomize",
|
|
162
|
+
"get_node",
|
|
163
|
+
"get_node_or_null",
|
|
164
|
+
"has_node",
|
|
165
|
+
"instance_from_id",
|
|
166
|
+
"is_same",
|
|
167
|
+
"weakref"
|
|
168
|
+
],
|
|
169
|
+
selfSuper: [
|
|
170
|
+
"self",
|
|
171
|
+
"super"
|
|
172
|
+
],
|
|
173
|
+
tokenizer: {
|
|
174
|
+
root: [
|
|
175
|
+
// 1. Doc comments (## ...) — must be before regular comments
|
|
176
|
+
[/##.*$/, "comment.doc"],
|
|
177
|
+
// 2. Regular comments (# ...)
|
|
178
|
+
[/#.*$/, "comment"],
|
|
179
|
+
// 3. Annotations (@export, @onready, etc.)
|
|
180
|
+
[/@[a-zA-Z_]\w*/, "annotation"],
|
|
181
|
+
// 4. StringName literals (&"...") — MUST come before regular strings
|
|
182
|
+
[/&"([^"\\]|\\.)*"/, "string.special"],
|
|
183
|
+
// 5. Triple-quoted strings (multiline) — must be before single-line strings
|
|
184
|
+
[/"""/, "string", "@tripleDoubleString"],
|
|
185
|
+
[/'''/, "string", "@tripleSingleString"],
|
|
186
|
+
// 6. Regular strings
|
|
187
|
+
[/"([^"\\]|\\.)*"/, "string"],
|
|
188
|
+
[/'([^'\\]|\\.)*'/, "string"],
|
|
189
|
+
// 7. NodePath shorthand ($"Node/Path" and $Node/Path)
|
|
190
|
+
[/\$"([^"\\]|\\.)*"/, "variable.other"],
|
|
191
|
+
[/\$[\w/]+/, "variable.other"],
|
|
192
|
+
// 8. Unique node shorthand (%NodeName)
|
|
193
|
+
[/%\w+/, "variable.other"],
|
|
194
|
+
// 9. Numbers (hex, binary, float, integer)
|
|
195
|
+
[/0x[0-9a-fA-F_]+/, "number.hex"],
|
|
196
|
+
[/0b[01_]+/, "number.binary"],
|
|
197
|
+
[/\d[\d_]*\.[\d_]*([eE][\-+]?\d[\d_]*)?/, "number.float"],
|
|
198
|
+
[/\d[\d_]*([eE][\-+]?\d[\d_]*)?/, "number"],
|
|
199
|
+
// 10. Identifiers — case-switch against keyword lists
|
|
200
|
+
[/[a-zA-Z_]\w*/, {
|
|
201
|
+
cases: {
|
|
202
|
+
"@keywords": "keyword",
|
|
203
|
+
"@builtinTypes": "type",
|
|
204
|
+
"@builtinConstants": "constant.language",
|
|
205
|
+
"@numericConstants": "constant.numeric",
|
|
206
|
+
"@builtinFunctions": "support.function",
|
|
207
|
+
"@selfSuper": "variable.language",
|
|
208
|
+
"@default": "identifier"
|
|
209
|
+
}
|
|
210
|
+
}],
|
|
211
|
+
// 11. Operators
|
|
212
|
+
[/->/, "keyword.operator"],
|
|
213
|
+
[/:=/, "keyword.operator"],
|
|
214
|
+
[/[=!<>]=?|[+\-*\/%&|^~]/, "operator"],
|
|
215
|
+
// 12. Brackets
|
|
216
|
+
[/[{}()\[\]]/, "@brackets"],
|
|
217
|
+
// 13. Delimiters
|
|
218
|
+
[/[;,.:?]/, "delimiter"]
|
|
219
|
+
],
|
|
220
|
+
// States for multiline strings
|
|
221
|
+
tripleDoubleString: [
|
|
222
|
+
[/"""/, "string", "@pop"],
|
|
223
|
+
[/./, "string"]
|
|
224
|
+
],
|
|
225
|
+
tripleSingleString: [
|
|
226
|
+
[/'''/, "string", "@pop"],
|
|
227
|
+
[/./, "string"]
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// src/configuration.ts
|
|
233
|
+
var conf = {
|
|
234
|
+
comments: {
|
|
235
|
+
lineComment: "#"
|
|
236
|
+
},
|
|
237
|
+
brackets: [
|
|
238
|
+
["(", ")"],
|
|
239
|
+
["[", "]"],
|
|
240
|
+
["{", "}"]
|
|
241
|
+
],
|
|
242
|
+
autoClosingPairs: [
|
|
243
|
+
{ open: "(", close: ")" },
|
|
244
|
+
{ open: "[", close: "]" },
|
|
245
|
+
{ open: "{", close: "}" },
|
|
246
|
+
{ open: '"', close: '"', notIn: ["string"] },
|
|
247
|
+
{ open: "'", close: "'", notIn: ["string"] }
|
|
248
|
+
],
|
|
249
|
+
surroundingPairs: [
|
|
250
|
+
{ open: "(", close: ")" },
|
|
251
|
+
{ open: "[", close: "]" },
|
|
252
|
+
{ open: "{", close: "}" },
|
|
253
|
+
{ open: '"', close: '"' },
|
|
254
|
+
{ open: "'", close: "'" }
|
|
255
|
+
],
|
|
256
|
+
indentationRules: {
|
|
257
|
+
increaseIndentPattern: /^\s*(func|class|if|elif|else|for|while|match|when)\b.*:\s*(#.*)?$/,
|
|
258
|
+
decreaseIndentPattern: /^\s*(elif|else|when)\b/
|
|
259
|
+
},
|
|
260
|
+
folding: {
|
|
261
|
+
offSide: true
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/index.ts
|
|
266
|
+
function register(monacoInstance) {
|
|
267
|
+
monacoInstance.languages.register({ id: "gdscript", extensions: [".gd"] });
|
|
268
|
+
monacoInstance.languages.setMonarchTokensProvider("gdscript", language);
|
|
269
|
+
monacoInstance.languages.setLanguageConfiguration("gdscript", conf);
|
|
270
|
+
}
|
|
271
|
+
if (typeof monaco !== "undefined" && monaco && typeof monaco.languages !== "undefined") {
|
|
272
|
+
register(monaco);
|
|
273
|
+
}
|
|
274
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
275
|
+
0 && (module.exports = {
|
|
276
|
+
conf,
|
|
277
|
+
language,
|
|
278
|
+
register
|
|
279
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// src/gdscript.ts
|
|
2
|
+
var language = {
|
|
3
|
+
defaultToken: "",
|
|
4
|
+
tokenPostfix: ".gdscript",
|
|
5
|
+
keywords: [
|
|
6
|
+
"if",
|
|
7
|
+
"elif",
|
|
8
|
+
"else",
|
|
9
|
+
"for",
|
|
10
|
+
"while",
|
|
11
|
+
"match",
|
|
12
|
+
"when",
|
|
13
|
+
"break",
|
|
14
|
+
"continue",
|
|
15
|
+
"pass",
|
|
16
|
+
"return",
|
|
17
|
+
"func",
|
|
18
|
+
"class",
|
|
19
|
+
"class_name",
|
|
20
|
+
"extends",
|
|
21
|
+
"is",
|
|
22
|
+
"var",
|
|
23
|
+
"const",
|
|
24
|
+
"enum",
|
|
25
|
+
"signal",
|
|
26
|
+
"static",
|
|
27
|
+
"await",
|
|
28
|
+
"yield",
|
|
29
|
+
"and",
|
|
30
|
+
"or",
|
|
31
|
+
"not",
|
|
32
|
+
"in",
|
|
33
|
+
"as",
|
|
34
|
+
"void",
|
|
35
|
+
"breakpoint"
|
|
36
|
+
],
|
|
37
|
+
builtinTypes: [
|
|
38
|
+
"bool",
|
|
39
|
+
"int",
|
|
40
|
+
"float",
|
|
41
|
+
"String",
|
|
42
|
+
"StringName",
|
|
43
|
+
"NodePath",
|
|
44
|
+
"Vector2",
|
|
45
|
+
"Vector2i",
|
|
46
|
+
"Vector3",
|
|
47
|
+
"Vector3i",
|
|
48
|
+
"Vector4",
|
|
49
|
+
"Vector4i",
|
|
50
|
+
"Color",
|
|
51
|
+
"Rect2",
|
|
52
|
+
"Rect2i",
|
|
53
|
+
"Transform2D",
|
|
54
|
+
"Transform3D",
|
|
55
|
+
"Basis",
|
|
56
|
+
"Quaternion",
|
|
57
|
+
"Projection",
|
|
58
|
+
"AABB",
|
|
59
|
+
"Plane",
|
|
60
|
+
"RID",
|
|
61
|
+
"Array",
|
|
62
|
+
"Dictionary",
|
|
63
|
+
"Callable",
|
|
64
|
+
"Signal",
|
|
65
|
+
"PackedByteArray",
|
|
66
|
+
"PackedInt32Array",
|
|
67
|
+
"PackedInt64Array",
|
|
68
|
+
"PackedFloat32Array",
|
|
69
|
+
"PackedFloat64Array",
|
|
70
|
+
"PackedStringArray",
|
|
71
|
+
"PackedVector2Array",
|
|
72
|
+
"PackedVector3Array",
|
|
73
|
+
"PackedVector4Array",
|
|
74
|
+
"PackedColorArray"
|
|
75
|
+
],
|
|
76
|
+
builtinConstants: [
|
|
77
|
+
"true",
|
|
78
|
+
"false",
|
|
79
|
+
"null"
|
|
80
|
+
],
|
|
81
|
+
numericConstants: [
|
|
82
|
+
"PI",
|
|
83
|
+
"TAU",
|
|
84
|
+
"INF",
|
|
85
|
+
"NAN"
|
|
86
|
+
],
|
|
87
|
+
builtinFunctions: [
|
|
88
|
+
"preload",
|
|
89
|
+
"load",
|
|
90
|
+
"print",
|
|
91
|
+
"print_rich",
|
|
92
|
+
"print_verbose",
|
|
93
|
+
"prints",
|
|
94
|
+
"printt",
|
|
95
|
+
"printerr",
|
|
96
|
+
"push_error",
|
|
97
|
+
"push_warning",
|
|
98
|
+
"str",
|
|
99
|
+
"len",
|
|
100
|
+
"range",
|
|
101
|
+
"type_of",
|
|
102
|
+
"typeof",
|
|
103
|
+
"is_instance_of",
|
|
104
|
+
"is_instance_valid",
|
|
105
|
+
"abs",
|
|
106
|
+
"sign",
|
|
107
|
+
"ceil",
|
|
108
|
+
"floor",
|
|
109
|
+
"round",
|
|
110
|
+
"clamp",
|
|
111
|
+
"lerp",
|
|
112
|
+
"min",
|
|
113
|
+
"max",
|
|
114
|
+
"pow",
|
|
115
|
+
"sqrt",
|
|
116
|
+
"log",
|
|
117
|
+
"exp",
|
|
118
|
+
"sin",
|
|
119
|
+
"cos",
|
|
120
|
+
"tan",
|
|
121
|
+
"asin",
|
|
122
|
+
"acos",
|
|
123
|
+
"atan",
|
|
124
|
+
"atan2",
|
|
125
|
+
"deg_to_rad",
|
|
126
|
+
"rad_to_deg",
|
|
127
|
+
"randf",
|
|
128
|
+
"randi",
|
|
129
|
+
"randfn",
|
|
130
|
+
"randf_range",
|
|
131
|
+
"randi_range",
|
|
132
|
+
"seed",
|
|
133
|
+
"randomize",
|
|
134
|
+
"get_node",
|
|
135
|
+
"get_node_or_null",
|
|
136
|
+
"has_node",
|
|
137
|
+
"instance_from_id",
|
|
138
|
+
"is_same",
|
|
139
|
+
"weakref"
|
|
140
|
+
],
|
|
141
|
+
selfSuper: [
|
|
142
|
+
"self",
|
|
143
|
+
"super"
|
|
144
|
+
],
|
|
145
|
+
tokenizer: {
|
|
146
|
+
root: [
|
|
147
|
+
// 1. Doc comments (## ...) — must be before regular comments
|
|
148
|
+
[/##.*$/, "comment.doc"],
|
|
149
|
+
// 2. Regular comments (# ...)
|
|
150
|
+
[/#.*$/, "comment"],
|
|
151
|
+
// 3. Annotations (@export, @onready, etc.)
|
|
152
|
+
[/@[a-zA-Z_]\w*/, "annotation"],
|
|
153
|
+
// 4. StringName literals (&"...") — MUST come before regular strings
|
|
154
|
+
[/&"([^"\\]|\\.)*"/, "string.special"],
|
|
155
|
+
// 5. Triple-quoted strings (multiline) — must be before single-line strings
|
|
156
|
+
[/"""/, "string", "@tripleDoubleString"],
|
|
157
|
+
[/'''/, "string", "@tripleSingleString"],
|
|
158
|
+
// 6. Regular strings
|
|
159
|
+
[/"([^"\\]|\\.)*"/, "string"],
|
|
160
|
+
[/'([^'\\]|\\.)*'/, "string"],
|
|
161
|
+
// 7. NodePath shorthand ($"Node/Path" and $Node/Path)
|
|
162
|
+
[/\$"([^"\\]|\\.)*"/, "variable.other"],
|
|
163
|
+
[/\$[\w/]+/, "variable.other"],
|
|
164
|
+
// 8. Unique node shorthand (%NodeName)
|
|
165
|
+
[/%\w+/, "variable.other"],
|
|
166
|
+
// 9. Numbers (hex, binary, float, integer)
|
|
167
|
+
[/0x[0-9a-fA-F_]+/, "number.hex"],
|
|
168
|
+
[/0b[01_]+/, "number.binary"],
|
|
169
|
+
[/\d[\d_]*\.[\d_]*([eE][\-+]?\d[\d_]*)?/, "number.float"],
|
|
170
|
+
[/\d[\d_]*([eE][\-+]?\d[\d_]*)?/, "number"],
|
|
171
|
+
// 10. Identifiers — case-switch against keyword lists
|
|
172
|
+
[/[a-zA-Z_]\w*/, {
|
|
173
|
+
cases: {
|
|
174
|
+
"@keywords": "keyword",
|
|
175
|
+
"@builtinTypes": "type",
|
|
176
|
+
"@builtinConstants": "constant.language",
|
|
177
|
+
"@numericConstants": "constant.numeric",
|
|
178
|
+
"@builtinFunctions": "support.function",
|
|
179
|
+
"@selfSuper": "variable.language",
|
|
180
|
+
"@default": "identifier"
|
|
181
|
+
}
|
|
182
|
+
}],
|
|
183
|
+
// 11. Operators
|
|
184
|
+
[/->/, "keyword.operator"],
|
|
185
|
+
[/:=/, "keyword.operator"],
|
|
186
|
+
[/[=!<>]=?|[+\-*\/%&|^~]/, "operator"],
|
|
187
|
+
// 12. Brackets
|
|
188
|
+
[/[{}()\[\]]/, "@brackets"],
|
|
189
|
+
// 13. Delimiters
|
|
190
|
+
[/[;,.:?]/, "delimiter"]
|
|
191
|
+
],
|
|
192
|
+
// States for multiline strings
|
|
193
|
+
tripleDoubleString: [
|
|
194
|
+
[/"""/, "string", "@pop"],
|
|
195
|
+
[/./, "string"]
|
|
196
|
+
],
|
|
197
|
+
tripleSingleString: [
|
|
198
|
+
[/'''/, "string", "@pop"],
|
|
199
|
+
[/./, "string"]
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/configuration.ts
|
|
205
|
+
var conf = {
|
|
206
|
+
comments: {
|
|
207
|
+
lineComment: "#"
|
|
208
|
+
},
|
|
209
|
+
brackets: [
|
|
210
|
+
["(", ")"],
|
|
211
|
+
["[", "]"],
|
|
212
|
+
["{", "}"]
|
|
213
|
+
],
|
|
214
|
+
autoClosingPairs: [
|
|
215
|
+
{ open: "(", close: ")" },
|
|
216
|
+
{ open: "[", close: "]" },
|
|
217
|
+
{ open: "{", close: "}" },
|
|
218
|
+
{ open: '"', close: '"', notIn: ["string"] },
|
|
219
|
+
{ open: "'", close: "'", notIn: ["string"] }
|
|
220
|
+
],
|
|
221
|
+
surroundingPairs: [
|
|
222
|
+
{ open: "(", close: ")" },
|
|
223
|
+
{ open: "[", close: "]" },
|
|
224
|
+
{ open: "{", close: "}" },
|
|
225
|
+
{ open: '"', close: '"' },
|
|
226
|
+
{ open: "'", close: "'" }
|
|
227
|
+
],
|
|
228
|
+
indentationRules: {
|
|
229
|
+
increaseIndentPattern: /^\s*(func|class|if|elif|else|for|while|match|when)\b.*:\s*(#.*)?$/,
|
|
230
|
+
decreaseIndentPattern: /^\s*(elif|else|when)\b/
|
|
231
|
+
},
|
|
232
|
+
folding: {
|
|
233
|
+
offSide: true
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/index.ts
|
|
238
|
+
function register(monacoInstance) {
|
|
239
|
+
monacoInstance.languages.register({ id: "gdscript", extensions: [".gd"] });
|
|
240
|
+
monacoInstance.languages.setMonarchTokensProvider("gdscript", language);
|
|
241
|
+
monacoInstance.languages.setLanguageConfiguration("gdscript", conf);
|
|
242
|
+
}
|
|
243
|
+
if (typeof monaco !== "undefined" && monaco && typeof monaco.languages !== "undefined") {
|
|
244
|
+
register(monaco);
|
|
245
|
+
}
|
|
246
|
+
export {
|
|
247
|
+
conf,
|
|
248
|
+
language,
|
|
249
|
+
register
|
|
250
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "monaco-editor-gdscript",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "GDScript (Godot 4.x) language support for Monaco Editor",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"monaco-editor": ">=0.30.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jsdom": "^27.0.0",
|
|
28
|
+
"jsdom": "^28.0.0",
|
|
29
|
+
"monaco-editor": "^0.52.0",
|
|
30
|
+
"tsup": "^8.0.0",
|
|
31
|
+
"typescript": "^5.0.0",
|
|
32
|
+
"vitest": "^2.0.0"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"monaco",
|
|
36
|
+
"monaco-editor",
|
|
37
|
+
"gdscript",
|
|
38
|
+
"godot",
|
|
39
|
+
"syntax-highlighting",
|
|
40
|
+
"monarch",
|
|
41
|
+
"language"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/MikeRoetgers/monaco-editor-gdscript"
|
|
47
|
+
}
|
|
48
|
+
}
|