redscript-mc 3.0.1 → 3.0.2
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/.github/workflows/ci.yml +1 -0
- package/README.md +119 -313
- package/README.zh.md +118 -314
- package/ROADMAP.md +5 -5
- package/dist/data/impl_test/function/counter/get.mcfunction +5 -0
- package/dist/data/impl_test/function/counter/inc.mcfunction +7 -0
- package/dist/data/impl_test/function/counter/new.mcfunction +4 -0
- package/dist/data/impl_test/function/load.mcfunction +1 -0
- package/dist/data/impl_test/function/test_impl.mcfunction +10 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/playground/function/load.mcfunction +1 -0
- package/dist/data/playground/function/start.mcfunction +4 -0
- package/dist/data/playground/function/start__say_macro_t1.mcfunction +1 -0
- package/dist/data/playground/function/stop.mcfunction +5 -0
- package/dist/data/playground/function/stop__say_macro_t0.mcfunction +1 -0
- package/dist/data/stdlib_queue8_test/function/__queue_append_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/__queue_peek_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/__queue_size_raw_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/load.mcfunction +1 -0
- package/dist/data/stdlib_queue8_test/function/queue_clear.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_empty__merge_1.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_empty__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_peek__merge_1.mcfunction +13 -0
- package/dist/data/stdlib_queue8_test/function/queue_peek__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_pop__merge_1.mcfunction +15 -0
- package/dist/data/stdlib_queue8_test/function/queue_pop__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_push__const_11.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_push__const_22.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_size.mcfunction +13 -0
- package/dist/data/stdlib_queue8_test/function/test_queue_push_and_size.mcfunction +13 -0
- package/dist/data/test/function/load.mcfunction +1 -0
- package/dist/data/test/function/say_at.mcfunction +6 -0
- package/dist/data/test/function/test.mcfunction +4 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/package.json +1 -1
- package/dist/src/__tests__/formatter-extra.test.d.ts +7 -0
- package/dist/src/__tests__/formatter-extra.test.js +123 -0
- package/dist/src/__tests__/global-vars.test.d.ts +13 -0
- package/dist/src/__tests__/global-vars.test.js +156 -0
- package/dist/src/__tests__/lint/new-rules.test.d.ts +9 -0
- package/dist/src/__tests__/lint/new-rules.test.js +402 -0
- package/dist/src/__tests__/lsp-rename.test.d.ts +8 -0
- package/dist/src/__tests__/lsp-rename.test.js +157 -0
- package/dist/src/__tests__/mc-integration/say-fstring.test.d.ts +11 -0
- package/dist/src/__tests__/mc-integration/say-fstring.test.js +220 -0
- package/dist/src/__tests__/mc-integration/stdlib-coverage-2.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-3.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-4.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-5.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-6.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-7.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-8.test.js +1 -1
- package/dist/src/__tests__/mc-syntax.test.js +4 -1
- package/dist/src/__tests__/monomorphize-coverage.test.d.ts +9 -0
- package/dist/src/__tests__/monomorphize-coverage.test.js +204 -0
- package/dist/src/__tests__/optimizer-cse.test.d.ts +7 -0
- package/dist/src/__tests__/optimizer-cse.test.js +226 -0
- package/dist/src/__tests__/parser.test.js +4 -13
- package/dist/src/__tests__/repl-server-extra.test.js +6 -7
- package/dist/src/__tests__/repl-server.test.js +5 -7
- package/dist/src/__tests__/stdlib/queue.test.js +6 -6
- package/dist/src/cli.js +0 -0
- package/dist/src/lexer/index.js +2 -1
- package/dist/src/lint/index.d.ts +12 -5
- package/dist/src/lint/index.js +730 -5
- package/dist/src/lsp/main.js +0 -0
- package/dist/src/mc-test/client.d.ts +21 -0
- package/dist/src/mc-test/client.js +34 -0
- package/dist/src/mir/lower.js +108 -6
- package/dist/src/optimizer/interprocedural.js +37 -2
- package/dist/src/parser/decl-parser.d.ts +19 -0
- package/dist/src/parser/decl-parser.js +323 -0
- package/dist/src/parser/expr-parser.d.ts +46 -0
- package/dist/src/parser/expr-parser.js +759 -0
- package/dist/src/parser/index.d.ts +8 -129
- package/dist/src/parser/index.js +13 -2262
- package/dist/src/parser/stmt-parser.d.ts +28 -0
- package/dist/src/parser/stmt-parser.js +577 -0
- package/dist/src/parser/type-parser.d.ts +20 -0
- package/dist/src/parser/type-parser.js +257 -0
- package/dist/src/parser/utils.d.ts +34 -0
- package/dist/src/parser/utils.js +141 -0
- package/docs/dev/README-mc-integration-tests.md +141 -0
- package/docs/lint-rules.md +162 -0
- package/docs/stdlib/bigint.md +2 -0
- package/editors/vscode/README.md +63 -41
- package/editors/vscode/out/extension.js +1881 -1776
- package/editors/vscode/out/lsp-server.js +4257 -3651
- package/editors/vscode/package-lock.json +3 -3
- package/editors/vscode/package.json +1 -1
- package/examples/loops-demo.mcrs +87 -0
- package/package.json +1 -1
- package/redscript-docs/docs/en/stdlib/advanced.md +629 -0
- package/redscript-docs/docs/en/stdlib/bigint.md +316 -0
- package/redscript-docs/docs/en/stdlib/bits.md +292 -0
- package/redscript-docs/docs/en/stdlib/bossbar.md +177 -0
- package/redscript-docs/docs/en/stdlib/calculus.md +289 -0
- package/redscript-docs/docs/en/stdlib/color.md +353 -0
- package/redscript-docs/docs/en/stdlib/combat.md +88 -0
- package/redscript-docs/docs/en/stdlib/cooldown.md +82 -0
- package/redscript-docs/docs/en/stdlib/dialog.md +155 -0
- package/redscript-docs/docs/en/stdlib/easing.md +558 -0
- package/redscript-docs/docs/en/stdlib/ecs.md +475 -0
- package/redscript-docs/docs/en/stdlib/effects.md +324 -0
- package/redscript-docs/docs/en/stdlib/events.md +3 -0
- package/redscript-docs/docs/en/stdlib/expr.md +45 -0
- package/redscript-docs/docs/en/stdlib/fft.md +141 -0
- package/redscript-docs/docs/en/stdlib/geometry.md +430 -0
- package/redscript-docs/docs/en/stdlib/graph.md +259 -0
- package/redscript-docs/docs/en/stdlib/heap.md +185 -0
- package/redscript-docs/docs/en/stdlib/interactions.md +179 -0
- package/redscript-docs/docs/en/stdlib/inventory.md +97 -0
- package/redscript-docs/docs/en/stdlib/linalg.md +557 -0
- package/redscript-docs/docs/en/stdlib/list.md +559 -0
- package/redscript-docs/docs/en/stdlib/map.md +140 -0
- package/redscript-docs/docs/en/stdlib/math.md +193 -0
- package/redscript-docs/docs/en/stdlib/math_hp.md +149 -0
- package/redscript-docs/docs/en/stdlib/matrix.md +403 -0
- package/redscript-docs/docs/en/stdlib/mobs.md +965 -0
- package/redscript-docs/docs/en/stdlib/noise.md +244 -0
- package/redscript-docs/docs/en/stdlib/ode.md +253 -0
- package/redscript-docs/docs/en/stdlib/parabola.md +342 -0
- package/redscript-docs/docs/en/stdlib/particles.md +311 -0
- package/redscript-docs/docs/en/stdlib/pathfind.md +255 -0
- package/redscript-docs/docs/en/stdlib/physics.md +493 -0
- package/redscript-docs/docs/en/stdlib/player.md +78 -0
- package/redscript-docs/docs/en/stdlib/quaternion.md +673 -0
- package/redscript-docs/docs/en/stdlib/queue.md +134 -0
- package/redscript-docs/docs/en/stdlib/random.md +223 -0
- package/redscript-docs/docs/en/stdlib/result.md +143 -0
- package/redscript-docs/docs/en/stdlib/scheduler.md +183 -0
- package/redscript-docs/docs/en/stdlib/set_int.md +190 -0
- package/redscript-docs/docs/en/stdlib/sets.md +101 -0
- package/redscript-docs/docs/en/stdlib/signal.md +400 -0
- package/redscript-docs/docs/en/stdlib/sort.md +104 -0
- package/redscript-docs/docs/en/stdlib/spawn.md +147 -0
- package/redscript-docs/docs/en/stdlib/state.md +142 -0
- package/redscript-docs/docs/en/stdlib/strings.md +154 -0
- package/redscript-docs/docs/en/stdlib/tags.md +3451 -0
- package/redscript-docs/docs/en/stdlib/teams.md +153 -0
- package/redscript-docs/docs/en/stdlib/timer.md +246 -0
- package/redscript-docs/docs/en/stdlib/vec.md +158 -0
- package/redscript-docs/docs/en/stdlib/world.md +298 -0
- package/redscript-docs/docs/zh/stdlib/advanced.md +615 -0
- package/redscript-docs/docs/zh/stdlib/bigint.md +316 -0
- package/redscript-docs/docs/zh/stdlib/bits.md +292 -0
- package/redscript-docs/docs/zh/stdlib/bossbar.md +170 -0
- package/redscript-docs/docs/zh/stdlib/calculus.md +287 -0
- package/redscript-docs/docs/zh/stdlib/color.md +353 -0
- package/redscript-docs/docs/zh/stdlib/combat.md +88 -0
- package/redscript-docs/docs/zh/stdlib/cooldown.md +84 -0
- package/redscript-docs/docs/zh/stdlib/dialog.md +152 -0
- package/redscript-docs/docs/zh/stdlib/easing.md +558 -0
- package/redscript-docs/docs/zh/stdlib/ecs.md +472 -0
- package/redscript-docs/docs/zh/stdlib/effects.md +324 -0
- package/redscript-docs/docs/zh/stdlib/events.md +3 -0
- package/redscript-docs/docs/zh/stdlib/expr.md +37 -0
- package/redscript-docs/docs/zh/stdlib/fft.md +128 -0
- package/redscript-docs/docs/zh/stdlib/geometry.md +430 -0
- package/redscript-docs/docs/zh/stdlib/graph.md +259 -0
- package/redscript-docs/docs/zh/stdlib/heap.md +185 -0
- package/redscript-docs/docs/zh/stdlib/interactions.md +160 -0
- package/redscript-docs/docs/zh/stdlib/inventory.md +94 -0
- package/redscript-docs/docs/zh/stdlib/linalg.md +543 -0
- package/redscript-docs/docs/zh/stdlib/list.md +561 -0
- package/redscript-docs/docs/zh/stdlib/map.md +132 -0
- package/redscript-docs/docs/zh/stdlib/math.md +193 -0
- package/redscript-docs/docs/zh/stdlib/math_hp.md +143 -0
- package/redscript-docs/docs/zh/stdlib/matrix.md +396 -0
- package/redscript-docs/docs/zh/stdlib/mobs.md +965 -0
- package/redscript-docs/docs/zh/stdlib/noise.md +244 -0
- package/redscript-docs/docs/zh/stdlib/ode.md +243 -0
- package/redscript-docs/docs/zh/stdlib/parabola.md +337 -0
- package/redscript-docs/docs/zh/stdlib/particles.md +307 -0
- package/redscript-docs/docs/zh/stdlib/pathfind.md +255 -0
- package/redscript-docs/docs/zh/stdlib/physics.md +493 -0
- package/redscript-docs/docs/zh/stdlib/player.md +78 -0
- package/redscript-docs/docs/zh/stdlib/quaternion.md +669 -0
- package/redscript-docs/docs/zh/stdlib/queue.md +124 -0
- package/redscript-docs/docs/zh/stdlib/random.md +222 -0
- package/redscript-docs/docs/zh/stdlib/result.md +147 -0
- package/redscript-docs/docs/zh/stdlib/scheduler.md +173 -0
- package/redscript-docs/docs/zh/stdlib/set_int.md +180 -0
- package/redscript-docs/docs/zh/stdlib/sets.md +107 -0
- package/redscript-docs/docs/zh/stdlib/signal.md +373 -0
- package/redscript-docs/docs/zh/stdlib/sort.md +104 -0
- package/redscript-docs/docs/zh/stdlib/spawn.md +142 -0
- package/redscript-docs/docs/zh/stdlib/state.md +134 -0
- package/redscript-docs/docs/zh/stdlib/strings.md +107 -0
- package/redscript-docs/docs/zh/stdlib/tags.md +3451 -0
- package/redscript-docs/docs/zh/stdlib/teams.md +150 -0
- package/redscript-docs/docs/zh/stdlib/timer.md +254 -0
- package/redscript-docs/docs/zh/stdlib/vec.md +158 -0
- package/redscript-docs/docs/zh/stdlib/world.md +289 -0
- package/src/__tests__/formatter-extra.test.ts +139 -0
- package/src/__tests__/global-vars.test.ts +171 -0
- package/src/__tests__/lint/new-rules.test.ts +437 -0
- package/src/__tests__/lsp-rename.test.ts +171 -0
- package/src/__tests__/mc-integration/say-fstring.test.ts +211 -0
- package/src/__tests__/mc-integration/stdlib-coverage-2.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-3.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-4.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-5.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-6.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-7.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-8.test.ts +1 -1
- package/src/__tests__/mc-syntax.test.ts +3 -0
- package/src/__tests__/monomorphize-coverage.test.ts +220 -0
- package/src/__tests__/optimizer-cse.test.ts +250 -0
- package/src/__tests__/parser.test.ts +4 -13
- package/src/__tests__/repl-server-extra.test.ts +6 -6
- package/src/__tests__/repl-server.test.ts +5 -6
- package/src/__tests__/stdlib/queue.test.ts +6 -6
- package/src/lexer/index.ts +2 -1
- package/src/lint/index.ts +713 -5
- package/src/mc-test/client.ts +40 -0
- package/src/mir/lower.ts +111 -2
- package/src/optimizer/interprocedural.ts +40 -2
- package/src/parser/decl-parser.ts +349 -0
- package/src/parser/expr-parser.ts +838 -0
- package/src/parser/index.ts +17 -2558
- package/src/parser/stmt-parser.ts +585 -0
- package/src/parser/type-parser.ts +276 -0
- package/src/parser/utils.ts +173 -0
- package/src/stdlib/queue.mcrs +19 -6
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# RedScript Lint Rules
|
|
2
|
+
|
|
3
|
+
The lint engine runs after HIR lowering and reports warnings before code generation.
|
|
4
|
+
|
|
5
|
+
## Existing Rules
|
|
6
|
+
|
|
7
|
+
### `unused-variable`
|
|
8
|
+
Warns when a `let` binding is declared but never read.
|
|
9
|
+
|
|
10
|
+
```redscript
|
|
11
|
+
fn foo(): void {
|
|
12
|
+
let x: int = 5; // warning: "x" is declared but never used
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### `unused-import`
|
|
17
|
+
Warns when an imported symbol is never called in the module.
|
|
18
|
+
|
|
19
|
+
```redscript
|
|
20
|
+
import mylib::helper; // warning: "helper" is never used
|
|
21
|
+
|
|
22
|
+
fn main(): void {
|
|
23
|
+
say("hello");
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### `magic-number`
|
|
28
|
+
Warns when a literal number with absolute value greater than 1 is used directly outside a `const` declaration.
|
|
29
|
+
|
|
30
|
+
```redscript
|
|
31
|
+
fn foo(): void {
|
|
32
|
+
let x: int = 1000; // warning: avoid magic number 1000
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const MAX: int = 1000; // OK — const declarations are exempt
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### `dead-branch`
|
|
39
|
+
Warns when an `if` condition is a compile-time constant (always true or always false).
|
|
40
|
+
|
|
41
|
+
```redscript
|
|
42
|
+
fn foo(): void {
|
|
43
|
+
if 1 == 2 { // warning: condition is always false
|
|
44
|
+
say("never");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### `function-too-long`
|
|
50
|
+
Warns when a function body exceeds the line limit (default: 50 lines). Configurable via `LintOptions.maxFunctionLines`.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## New Rules
|
|
55
|
+
|
|
56
|
+
### `no-dead-assignment`
|
|
57
|
+
Warns when a variable is assigned a value that is immediately overwritten before being read. The initial write is "dead" — it has no effect on program behavior.
|
|
58
|
+
|
|
59
|
+
```redscript
|
|
60
|
+
fn foo(): void {
|
|
61
|
+
let x: int = 0; // warning: assignment to "x" is never read before being overwritten
|
|
62
|
+
x = 42;
|
|
63
|
+
say("done");
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
No warning when each assigned value is read:
|
|
68
|
+
|
|
69
|
+
```redscript
|
|
70
|
+
fn foo(): int {
|
|
71
|
+
let x: int = 5;
|
|
72
|
+
let y: int = x; // reads x — clears pending write
|
|
73
|
+
x = 10;
|
|
74
|
+
return x + y; // reads x again
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `prefer-match-exhaustive`
|
|
79
|
+
Warns when a `match` expression uses Option patterns (`Some`/`None`) but is missing one of the arms and has no wildcard `_` catch-all.
|
|
80
|
+
|
|
81
|
+
```redscript
|
|
82
|
+
fn foo(x: Option<int>): void {
|
|
83
|
+
match x {
|
|
84
|
+
Some(v) => { say("got value"); }
|
|
85
|
+
// warning: match on Option is missing a None arm
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
No warning when both arms are present, or when a wildcard covers the rest:
|
|
91
|
+
|
|
92
|
+
```redscript
|
|
93
|
+
fn foo(x: Option<int>): void {
|
|
94
|
+
match x {
|
|
95
|
+
Some(v) => { say("got value"); }
|
|
96
|
+
None => { say("nothing"); }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### `no-empty-catch`
|
|
102
|
+
Warns about silent failure patterns — specifically:
|
|
103
|
+
- An `if let Some` with an empty `else {}` block (silently ignores the None case)
|
|
104
|
+
- A `match` arm with an empty body
|
|
105
|
+
|
|
106
|
+
```redscript
|
|
107
|
+
fn foo(x: Option<int>): void {
|
|
108
|
+
if let Some(v) = x {
|
|
109
|
+
say("ok");
|
|
110
|
+
} else {} // warning: None case is silently ignored
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn bar(x: Option<int>): void {
|
|
114
|
+
match x {
|
|
115
|
+
Some(v) => { say("ok"); }
|
|
116
|
+
None => {} // warning: empty match arm body
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### `naming-convention`
|
|
122
|
+
Enforces naming conventions:
|
|
123
|
+
- Variables (let bindings, foreach bindings, if-let / while-let bindings) must use **camelCase**
|
|
124
|
+
- Struct and enum type names must use **PascalCase**
|
|
125
|
+
|
|
126
|
+
A leading underscore is allowed (e.g. `_unused` is valid camelCase).
|
|
127
|
+
|
|
128
|
+
```redscript
|
|
129
|
+
fn foo(): void {
|
|
130
|
+
let my_var: int = 5; // warning: "my_var" should use camelCase — use myVar
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
struct myPoint { x: int, y: int } // warning: "myPoint" should use PascalCase — use MyPoint
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
No warning for:
|
|
137
|
+
|
|
138
|
+
```redscript
|
|
139
|
+
fn foo(): void {
|
|
140
|
+
let myVar: int = 5;
|
|
141
|
+
let _ignored: int = 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
struct MyPoint { x: int, y: int }
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `no-magic-numbers`
|
|
148
|
+
Similar to `magic-number` but checks against a configurable allow-list (default: `[0, 1]`) instead of a threshold. Numbers outside the allow-list that appear in expressions outside `const` declarations are flagged.
|
|
149
|
+
|
|
150
|
+
```redscript
|
|
151
|
+
fn foo(): void {
|
|
152
|
+
let x: int = 42; // warning: Magic number 42 — extract to a named const
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const ANSWER: int = 42; // OK — const declarations are exempt
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Configurable via `LintOptions.allowedNumbers`:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
lintString(source, file, ns, { allowedNumbers: [0, 1, 42, 100] })
|
|
162
|
+
```
|
package/docs/stdlib/bigint.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Import: `import bigint;`
|
|
4
4
|
|
|
5
|
+
> **Attribution:** Parts of this module's multi-precision arithmetic approach were inspired by [kaer-3058/large_number](https://github.com/kaer-3058/large_number).
|
|
6
|
+
|
|
5
7
|
Arbitrary-precision integers represented as base-10000 (万進制) `int` arrays in NBT storage. Arrays are big-endian (index 0 = most significant chunk). Provides 3-chunk (96-bit) helpers and arbitrary-length operations for addition, subtraction, multiplication, division, comparison, and utility functions. Full bigint×bigint multiplication and squaring included.
|
|
6
8
|
|
|
7
9
|
## Functions
|
package/editors/vscode/README.md
CHANGED
|
@@ -1,47 +1,67 @@
|
|
|
1
1
|
# RedScript VSCode Extension
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Version 1.3.80 | [RedScript 3.0](https://github.com/bkmashiro/redscript)
|
|
4
|
+
|
|
5
|
+
Full language support for [RedScript](https://github.com/bkmashiro/redscript) — a compiler targeting Minecraft Java Edition datapacks.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
### Syntax Highlighting
|
|
10
|
+
|
|
11
|
+
- **RedScript** (`.mcrs`, `.rs` files)
|
|
12
|
+
- Keywords, types, decorators, operators
|
|
13
|
+
- Entity selectors: `@a`, `@e[type=zombie, distance=..5]`
|
|
10
14
|
- Range literals: `..5`, `1..`, `1..10`
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
- Format strings: `f"Hello {name}!"`
|
|
16
|
+
- All 50 stdlib modules
|
|
17
|
+
|
|
18
|
+
- **mcfunction** (`.mcfunction` files)
|
|
19
|
+
- Full command syntax highlighting
|
|
20
|
+
- Entity selectors, NBT, coordinates
|
|
21
|
+
|
|
22
|
+
### Language Server (LSP)
|
|
23
|
+
|
|
24
|
+
- **Diagnostics** — Real-time error checking
|
|
25
|
+
- **Hover** — Type info and `///` doc comments
|
|
26
|
+
- **Go to Definition** — Jump to function/struct declarations
|
|
27
|
+
- **Auto-complete** — Functions, types, stdlib modules
|
|
28
|
+
- **Lint warnings** — 5 built-in lint rules
|
|
29
|
+
|
|
30
|
+
### Code Snippets
|
|
31
|
+
|
|
32
|
+
| Trigger | Result |
|
|
33
|
+
|---------|--------|
|
|
34
|
+
| `fn` | Function declaration |
|
|
35
|
+
| `tickfn` | `@tick` function |
|
|
36
|
+
| `struct` | Struct declaration |
|
|
37
|
+
| `match` | Match expression |
|
|
38
|
+
| `foreach` | Entity foreach loop |
|
|
39
|
+
| `result` | Result<T> handling |
|
|
29
40
|
|
|
30
41
|
## Install
|
|
31
42
|
|
|
32
|
-
###
|
|
43
|
+
### VS Code Marketplace
|
|
44
|
+
|
|
45
|
+
Search for "RedScript" in the Extensions panel, or:
|
|
46
|
+
```
|
|
47
|
+
ext install bkmashiro.redscript-vscode
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Manual (VSIX)
|
|
33
51
|
|
|
34
52
|
```bash
|
|
35
53
|
cd editors/vscode
|
|
36
54
|
npm install -g @vscode/vsce
|
|
37
55
|
vsce package
|
|
38
|
-
code --install-extension redscript-vscode-
|
|
56
|
+
code --install-extension redscript-vscode-1.3.80.vsix
|
|
39
57
|
```
|
|
40
58
|
|
|
41
|
-
|
|
59
|
+
## File Extensions
|
|
42
60
|
|
|
43
|
-
|
|
61
|
+
- `.mcrs` — Recommended (no conflict with Rust)
|
|
62
|
+
- `.rs` — Supported, but may conflict with Rust extension
|
|
44
63
|
|
|
64
|
+
To force `.rs` as RedScript:
|
|
45
65
|
```json
|
|
46
66
|
// settings.json
|
|
47
67
|
{
|
|
@@ -51,28 +71,30 @@ RedScript uses `.rs` files, same as Rust. If you have the Rust extension install
|
|
|
51
71
|
}
|
|
52
72
|
```
|
|
53
73
|
|
|
54
|
-
Or use `.mcrs` extension (we may switch to this in future).
|
|
55
|
-
|
|
56
74
|
## Usage
|
|
57
75
|
|
|
58
|
-
|
|
76
|
+
```redscript
|
|
77
|
+
import math;
|
|
78
|
+
import player;
|
|
59
79
|
|
|
60
|
-
```
|
|
61
80
|
@tick(rate=20)
|
|
62
|
-
fn
|
|
63
|
-
foreach (
|
|
64
|
-
|
|
81
|
+
fn gravity_check() {
|
|
82
|
+
foreach (p in @a[tag=flying]) {
|
|
83
|
+
let y = player::get_y(p);
|
|
84
|
+
if y > 100 {
|
|
85
|
+
effect::give(p, "slow_falling", 5);
|
|
86
|
+
}
|
|
65
87
|
}
|
|
66
88
|
}
|
|
67
|
-
|
|
68
|
-
@on_trigger("claim_reward")
|
|
69
|
-
fn handle_claim() {
|
|
70
|
-
give(@s, "minecraft:diamond", 1);
|
|
71
|
-
}
|
|
72
89
|
```
|
|
73
90
|
|
|
74
|
-
Compile
|
|
75
|
-
|
|
91
|
+
Compile:
|
|
76
92
|
```bash
|
|
77
|
-
redscript
|
|
93
|
+
redscript build src/ -o dist/mypack/
|
|
78
94
|
```
|
|
95
|
+
|
|
96
|
+
## Links
|
|
97
|
+
|
|
98
|
+
- [RedScript Documentation](https://redscript-docs.pages.dev)
|
|
99
|
+
- [Online Playground](https://redscript.pages.dev)
|
|
100
|
+
- [GitHub](https://github.com/bkmashiro/redscript)
|