cluaupp 1.5.2 → 2.0.0-beta.1
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/CHANGELOG.md +3 -0
- package/README.md +27 -40
- package/api/generated/bench-latest.json +43 -21
- package/api/generated/lsp-index.json +1 -1
- package/api/manifests/roblox-target.manifest.json +5 -5
- package/api/normalized/roblox-target.profile.json +8729 -267
- package/api/roblox/luau-builtins.d.luau +185 -0
- package/api/roblox/surface.json +1 -0
- package/api/roblox-api.lock.json +11 -2
- package/bin/cluaupp.js +38 -0
- package/editors/vscode/syntaxes/clpp.tmLanguage.json +211 -0
- package/examples/README.md +9 -9
- package/examples/game/cluaupp.config.json +2 -2
- package/examples/game/default.project.json +4 -15
- package/examples/game/out/ReplicatedStorage/Shared/GameInfo.luau +8 -0
- package/examples/game/out/ReplicatedStorage/Shared/GameInfo.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Leaderstats.server.luau +26 -0
- package/examples/game/out/ServerScriptService/Leaderstats.server.luau.map.json +13 -0
- package/examples/game/out/ServerScriptService/Main.server.luau +15 -0
- package/examples/game/out/ServerScriptService/Main.server.luau.map.json +13 -0
- package/examples/game/out/StarterPlayer/StarterPlayerScripts/Main.client.luau +10 -0
- package/examples/game/out/StarterPlayer/StarterPlayerScripts/Main.client.luau.map.json +13 -0
- package/examples/game/src/ReplicatedStorage/Shared/GameInfo.clp +1 -0
- package/examples/game/src/ServerScriptService/Leaderstats.server.clp +18 -0
- package/examples/game/src/ServerScriptService/Main.server.clp +9 -0
- package/examples/game/src/StarterPlayer/StarterPlayerScripts/Main.client.clp +4 -0
- package/generated/api/build-profile.js +1 -1
- package/generated/api/loader.js +2 -2
- package/generated/api/surface/build.js +328 -0
- package/generated/api/surface/luau-defs.js +595 -0
- package/generated/api/surface/model.js +8 -0
- package/generated/clpp/contract.js +6 -3
- package/generated/clpp/handshake.js +36 -0
- package/generated/clpp/modules.js +20 -9
- package/generated/clpp/runner.js +62 -31
- package/generated/compile.js +18 -1
- package/generated/compiler/ast.js +3 -0
- package/generated/compiler/checker/calls.js +999 -0
- package/generated/compiler/checker/checker.js +1215 -0
- package/generated/compiler/checker/exprs.js +791 -0
- package/generated/compiler/checker/flow.js +168 -0
- package/generated/compiler/checker/members.js +763 -0
- package/generated/compiler/checker/statements.js +792 -0
- package/generated/compiler/checker/symbols.js +90 -0
- package/generated/compiler/checker/typeops.js +348 -0
- package/generated/compiler/checker/yields.js +115 -0
- package/generated/compiler/diagnostics.js +138 -0
- package/generated/compiler/emit/emitter.js +2356 -0
- package/generated/compiler/emit/luau-types.js +137 -0
- package/generated/compiler/emit/names.js +130 -0
- package/generated/compiler/emit/runtime.js +432 -0
- package/generated/compiler/lexer.js +403 -0
- package/generated/compiler/parser.js +1881 -0
- package/generated/compiler/project.js +332 -0
- package/generated/compiler/roblox/api.js +388 -0
- package/generated/compiler/roblox/context.js +100 -0
- package/generated/compiler/source.js +59 -0
- package/generated/compiler/stdlib.js +232 -0
- package/generated/compiler/types.js +250 -0
- package/generated/target/build-cache.js +4 -4
- package/generated/target/gen-rojo-tree.js +15 -0
- package/generated/target/source-map.js +61 -8
- package/generated/target/studio-bridge.js +1 -0
- package/generated/utils/project.js +83 -25
- package/native/bin/.gitkeep +1 -0
- package/package.json +17 -6
- package/plugins/CluauppNav/Plugin.luau +28 -4
- package/rust/cluaupp/Cargo.lock +795 -0
- package/rust/cluaupp/Cargo.toml +17 -0
- package/rust/cluaupp/src/main.rs +717 -0
- package/scripts/postinstall-native.js +56 -0
- package/skills/README.md +3 -3
- package/skills/clpp-hive-flare/SKILL.md +30 -26
- package/skills/clpp-language/SKILL.md +67 -74
- package/skills/clpp-language/compiler.md +24 -36
- package/skills/clpp-style/SKILL.md +31 -44
- package/src/api/build-profile.ts +1 -1
- package/src/api/loader.ts +2 -2
- package/src/api/surface/build.ts +374 -0
- package/src/api/surface/luau-defs.ts +635 -0
- package/src/api/surface/model.ts +96 -0
- package/src/clpp/contract.ts +20 -3
- package/src/clpp/handshake.ts +25 -0
- package/src/clpp/modules.ts +17 -10
- package/src/clpp/runner.ts +52 -34
- package/src/compile.ts +20 -2
- package/src/compiler/ast.ts +336 -0
- package/src/compiler/checker/calls.ts +1025 -0
- package/src/compiler/checker/checker.ts +1352 -0
- package/src/compiler/checker/exprs.ts +805 -0
- package/src/compiler/checker/flow.ts +174 -0
- package/src/compiler/checker/members.ts +793 -0
- package/src/compiler/checker/statements.ts +802 -0
- package/src/compiler/checker/symbols.ts +219 -0
- package/src/compiler/checker/typeops.ts +355 -0
- package/src/compiler/checker/yields.ts +120 -0
- package/src/compiler/diagnostics.ts +163 -0
- package/src/compiler/emit/emitter.ts +2486 -0
- package/src/compiler/emit/luau-types.ts +143 -0
- package/src/compiler/emit/names.ts +130 -0
- package/src/compiler/emit/runtime.ts +438 -0
- package/src/compiler/lexer.ts +444 -0
- package/src/compiler/parser.ts +1943 -0
- package/src/compiler/project.ts +354 -0
- package/src/compiler/roblox/api.ts +408 -0
- package/src/compiler/roblox/context.ts +108 -0
- package/src/compiler/source.ts +67 -0
- package/src/compiler/stdlib.ts +256 -0
- package/src/compiler/types.ts +313 -0
- package/src/target/build-cache.ts +5 -8
- package/src/target/gen-rojo-tree.ts +15 -0
- package/src/target/source-map.ts +65 -27
- package/src/target/studio-bridge.ts +3 -0
- package/src/types.ts +3 -0
- package/src/utils/project.ts +79 -31
- package/templates/README.md +7 -0
- package/templates/{game → game-modern}/cluaupp.config.json +2 -2
- package/templates/{game → game-modern}/package.json +1 -2
- package/templates/game-modern/rokit.toml +2 -0
- package/templates/game-modern/src/ReplicatedStorage/Shared/GameInfo.clp +1 -0
- package/templates/game-modern/src/ServerScriptService/Handlers/Guard.server.clp +4 -0
- package/templates/game-modern/src/ServerScriptService/Main.server.clp +8 -0
- package/templates/game-modern/src/StarterPlayer/StarterPlayerScripts/Main.client.clp +4 -0
- package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau +0 -29
- package/examples/game/out/ReplicatedStorage/Shared/Constants/Datas/TemplateData.luau.map.json +0 -13
- package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau +0 -83
- package/examples/game/out/ReplicatedStorage/Shared/Net/Net.luau.map.json +0 -13
- package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau +0 -18
- package/examples/game/out/ServerScriptService/Boot/DataBoot.server.luau.map.json +0 -13
- package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau +0 -14
- package/examples/game/out/ServerScriptService/Configuration/ServerConfig.luau.map.json +0 -13
- package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau +0 -15
- package/examples/game/out/ServerScriptService/Handlers/Guard.server.luau.map.json +0 -13
- package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau +0 -50
- package/examples/game/out/ServerScriptService/Handlers/PlayerHandler.server.luau.map.json +0 -13
- package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau +0 -12
- package/examples/game/out/StarterPlayer/StarterCharacterScripts/Character/CharacterReady.client.luau.map.json +0 -13
- package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau +0 -16
- package/examples/game/out/StarterPlayer/StarterPlayerScripts/Controllers/DataController.client.luau.map.json +0 -13
- package/examples/game/src/Client/Controllers/DataController.client.clpp +0 -7
- package/examples/game/src/Client/Main.client.clpp +0 -4
- package/examples/game/src/Declarations/Net.flare +0 -5
- package/examples/game/src/Include/GameTypes.clh +0 -40
- package/examples/game/src/Modules/Core/Guard.server.clpp +0 -7
- package/examples/game/src/Modules/Core/PlayerHandler.server.clpp +0 -23
- package/examples/game/src/Server/Boot/DataBoot.server.clpp +0 -13
- package/examples/game/src/Server/Main.server.clpp +0 -4
- package/templates/game/.clangd +0 -25
- package/templates/game/.vscode/extensions.json +0 -8
- package/templates/game/.vscode/settings.json +0 -17
- package/templates/game/Packages/.gitkeep +0 -0
- package/templates/game/compile_flags.txt +0 -6
- package/templates/game/default.project.json +0 -41
- package/templates/game/include/clpp/datatypes.clh +0 -575
- package/templates/game/include/clpp/generated/enums.clh +0 -4920
- package/templates/game/include/clpp/generated/instances.clh +0 -87182
- package/templates/game/include/clpp/libs/arrayindexer.clh +0 -12
- package/templates/game/include/clpp/libs/axiom.clh +0 -154
- package/templates/game/include/clpp/libs/bloom.clh +0 -58
- package/templates/game/include/clpp/libs/coil.clh +0 -37
- package/templates/game/include/clpp/libs/crest.clh +0 -22
- package/templates/game/include/clpp/libs/echo.clh +0 -52
- package/templates/game/include/clpp/libs/ember.clh +0 -17
- package/templates/game/include/clpp/libs/flare.clh +0 -65
- package/templates/game/include/clpp/libs/gleam.clh +0 -111
- package/templates/game/include/clpp/libs/guide.clh +0 -42
- package/templates/game/include/clpp/libs/helm.clh +0 -31
- package/templates/game/include/clpp/libs/hive.clh +0 -20
- package/templates/game/include/clpp/libs/keep.clh +0 -158
- package/templates/game/include/clpp/libs/lens.clh +0 -24
- package/templates/game/include/clpp/libs/mint.clh +0 -28
- package/templates/game/include/clpp/libs/net.clh +0 -31
- package/templates/game/include/clpp/libs/occlude.clh +0 -15
- package/templates/game/include/clpp/libs/pin.clh +0 -28
- package/templates/game/include/clpp/libs/promise.clh +0 -24
- package/templates/game/include/clpp/libs/roster.clh +0 -123
- package/templates/game/include/clpp/libs/shift.clh +0 -22
- package/templates/game/include/clpp/libs/spark.clh +0 -28
- package/templates/game/include/clpp/libs/stage.clh +0 -23
- package/templates/game/include/clpp/libs/sweep.clh +0 -23
- package/templates/game/include/clpp/libs/trace.clh +0 -18
- package/templates/game/include/clpp/libs/ward.clh +0 -19
- package/templates/game/include/clpp/libs.clh +0 -31
- package/templates/game/include/clpp/roblox.clh +0 -41
- package/templates/game/rokit.toml +0 -5
- package/templates/game/src/Client/Controllers/DataController.client.clpp +0 -7
- package/templates/game/src/Client/Main.client.clpp +0 -4
- package/templates/game/src/Declarations/Net.flare +0 -5
- package/templates/game/src/Include/GameTypes.clh +0 -40
- package/templates/game/src/Modules/Core/Guard.server.clpp +0 -7
- package/templates/game/src/Modules/Core/PlayerHandler.server.clpp +0 -24
- package/templates/game/src/Server/Boot/DataBoot.server.clpp +0 -13
- package/templates/game/src/Server/Main.server.clpp +0 -4
- package/templates/game/stylua.toml +0 -9
- package/templates/game/wally.toml +0 -12
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { SourceFile, Span } from "./source.js";
|
|
2
|
+
|
|
3
|
+
export type Severity = "error" | "warning" | "info" | "hint";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Diagnostic codes, grouped by family:
|
|
7
|
+
* - CL1xxx syntax · CL2xxx names · CL3xxx types · CL4xxx control flow
|
|
8
|
+
* - RBX5xxx Roblox API · CTX6xxx server/client authority · PAR7xxx parallel Luau
|
|
9
|
+
* - PERF8xxx performance hints · MOD9xxx modules and links
|
|
10
|
+
*/
|
|
11
|
+
export interface Diagnostic {
|
|
12
|
+
code: string;
|
|
13
|
+
severity: Severity;
|
|
14
|
+
message: string;
|
|
15
|
+
file: string;
|
|
16
|
+
span: Span;
|
|
17
|
+
line: number;
|
|
18
|
+
column: number;
|
|
19
|
+
endLine: number;
|
|
20
|
+
endColumn: number;
|
|
21
|
+
/** Extra lines shown under the excerpt (hints, "did you mean"). */
|
|
22
|
+
notes?: string[];
|
|
23
|
+
/** Replacement text that fixes the problem, when there is one obvious fix. */
|
|
24
|
+
fix?: { span: Span; text: string; title: string };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class DiagnosticBag {
|
|
28
|
+
readonly items: Diagnostic[] = [];
|
|
29
|
+
private readonly seen = new Set<string>();
|
|
30
|
+
|
|
31
|
+
constructor(readonly source: SourceFile) {}
|
|
32
|
+
|
|
33
|
+
add(code: string, severity: Severity, span: Span, message: string, notes?: string[], fix?: Diagnostic["fix"]): Diagnostic {
|
|
34
|
+
const start = this.source.position(span.start);
|
|
35
|
+
const end = this.source.position(Math.max(span.start, span.end));
|
|
36
|
+
const diagnostic: Diagnostic = {
|
|
37
|
+
code,
|
|
38
|
+
severity,
|
|
39
|
+
message,
|
|
40
|
+
file: this.source.path,
|
|
41
|
+
span,
|
|
42
|
+
line: start.line,
|
|
43
|
+
column: start.column,
|
|
44
|
+
endLine: end.line,
|
|
45
|
+
endColumn: end.column,
|
|
46
|
+
};
|
|
47
|
+
if (notes && notes.length > 0) {
|
|
48
|
+
diagnostic.notes = notes;
|
|
49
|
+
}
|
|
50
|
+
if (fix) {
|
|
51
|
+
diagnostic.fix = fix;
|
|
52
|
+
}
|
|
53
|
+
const key = `${code}:${span.start}:${span.end}:${message}`;
|
|
54
|
+
if (!this.seen.has(key)) {
|
|
55
|
+
this.seen.add(key);
|
|
56
|
+
this.items.push(diagnostic);
|
|
57
|
+
}
|
|
58
|
+
return diagnostic;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
error(code: string, span: Span, message: string, notes?: string[], fix?: Diagnostic["fix"]): Diagnostic {
|
|
62
|
+
return this.add(code, "error", span, message, notes, fix);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
warning(code: string, span: Span, message: string, notes?: string[], fix?: Diagnostic["fix"]): Diagnostic {
|
|
66
|
+
return this.add(code, "warning", span, message, notes, fix);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
info(code: string, span: Span, message: string, notes?: string[]): Diagnostic {
|
|
70
|
+
return this.add(code, "info", span, message, notes);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get errorCount(): number {
|
|
74
|
+
let n = 0;
|
|
75
|
+
for (const d of this.items) {
|
|
76
|
+
if (d.severity === "error") {
|
|
77
|
+
n++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return n;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function hasErrors(diagnostics: readonly Diagnostic[]): boolean {
|
|
85
|
+
return diagnostics.some((d) => d.severity === "error");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function sortDiagnostics(diagnostics: Diagnostic[]): Diagnostic[] {
|
|
89
|
+
return diagnostics.sort((a, b) => a.file.localeCompare(b.file) || a.span.start - b.span.start || a.code.localeCompare(b.code));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** `file:line:col: error[CL3001]: message` plus a caret excerpt, like rustc/clang. */
|
|
93
|
+
export function formatDiagnostic(d: Diagnostic, source?: SourceFile, color = false): string {
|
|
94
|
+
const paint = (code: string, text: string) => (color ? `\x1b[${code}m${text}\x1b[0m` : text);
|
|
95
|
+
const label = d.severity === "error" ? paint("1;31", "error") : d.severity === "warning" ? paint("1;33", "warning") : paint("1;36", d.severity);
|
|
96
|
+
const lines = [`${d.file}:${d.line}:${d.column}: ${label}[${d.code}]: ${d.message}`];
|
|
97
|
+
if (source) {
|
|
98
|
+
const text = source.lineText(d.line).replace(/\t/g, " ");
|
|
99
|
+
const raw = source.lineText(d.line);
|
|
100
|
+
const prefix = raw.slice(0, d.column - 1).replace(/\t/g, " ");
|
|
101
|
+
const width = d.endLine === d.line ? Math.max(1, d.endColumn - d.column) : Math.max(1, raw.length - (d.column - 1));
|
|
102
|
+
const gutter = String(d.line).length;
|
|
103
|
+
lines.push(`${" ".repeat(gutter)} |`);
|
|
104
|
+
lines.push(`${d.line} | ${text}`);
|
|
105
|
+
lines.push(`${" ".repeat(gutter)} | ${" ".repeat(prefix.length)}${paint(d.severity === "error" ? "1;31" : "1;33", "^".repeat(Math.min(width, Math.max(1, text.length - prefix.length))))}`);
|
|
106
|
+
}
|
|
107
|
+
for (const note of d.notes || []) {
|
|
108
|
+
lines.push(` = ${note}`);
|
|
109
|
+
}
|
|
110
|
+
return lines.join("\n");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Damerau-free Levenshtein, capped; used for "did you mean" suggestions. */
|
|
114
|
+
export function editDistance(a: string, b: string, cap = 4): number {
|
|
115
|
+
if (Math.abs(a.length - b.length) > cap) {
|
|
116
|
+
return cap + 1;
|
|
117
|
+
}
|
|
118
|
+
const prev = new Array<number>(b.length + 1);
|
|
119
|
+
const cur = new Array<number>(b.length + 1);
|
|
120
|
+
for (let j = 0; j <= b.length; j++) {
|
|
121
|
+
prev[j] = j;
|
|
122
|
+
}
|
|
123
|
+
for (let i = 1; i <= a.length; i++) {
|
|
124
|
+
cur[0] = i;
|
|
125
|
+
let rowMin = cur[0];
|
|
126
|
+
const ca = a.charCodeAt(i - 1);
|
|
127
|
+
for (let j = 1; j <= b.length; j++) {
|
|
128
|
+
const cost = ca === b.charCodeAt(j - 1) ? 0 : 1;
|
|
129
|
+
cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + cost);
|
|
130
|
+
if (cur[j] < rowMin) {
|
|
131
|
+
rowMin = cur[j];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (rowMin > cap) {
|
|
135
|
+
return cap + 1;
|
|
136
|
+
}
|
|
137
|
+
for (let j = 0; j <= b.length; j++) {
|
|
138
|
+
prev[j] = cur[j];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return prev[b.length];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function suggest(name: string, candidates: Iterable<string>, max = 2): string | null {
|
|
145
|
+
let best: string | null = null;
|
|
146
|
+
let bestScore = Infinity;
|
|
147
|
+
const lower = name.toLowerCase();
|
|
148
|
+
for (const candidate of candidates) {
|
|
149
|
+
if (candidate === name) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (candidate.toLowerCase() === lower) {
|
|
153
|
+
return candidate;
|
|
154
|
+
}
|
|
155
|
+
const limit = Math.min(max, Math.max(1, Math.floor(name.length / 3)));
|
|
156
|
+
const score = editDistance(lower, candidate.toLowerCase(), limit);
|
|
157
|
+
if (score <= limit && score < bestScore) {
|
|
158
|
+
best = candidate;
|
|
159
|
+
bestScore = score;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return best;
|
|
163
|
+
}
|