redscript-mc 1.2.15 → 1.2.16
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 +39 -0
- package/README.md +13 -6
- package/builtins.d.mcrs +559 -0
- package/dist/builtins/metadata.d.ts +36 -0
- package/dist/builtins/metadata.js +1022 -0
- package/dist/cli.js +16 -6
- package/dist/lowering/index.d.ts +11 -0
- package/dist/lowering/index.js +34 -0
- package/editors/vscode/builtins.d.mcrs +559 -0
- package/editors/vscode/out/extension.js +797 -80
- package/editors/vscode/src/symbols.ts +68 -0
- package/package.json +1 -1
- package/src/builtins/metadata.ts +1123 -0
- package/src/cli.ts +17 -6
- package/src/lowering/index.ts +39 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as vscode from 'vscode'
|
|
2
|
+
import * as path from 'path'
|
|
3
|
+
import * as fs from 'fs'
|
|
2
4
|
|
|
3
5
|
const DECL_RE = /\b(fn|let|const|struct|enum)\s+(\w+)/g
|
|
4
6
|
|
|
@@ -128,6 +130,57 @@ function escapeRegex(s: string): string {
|
|
|
128
130
|
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
129
131
|
}
|
|
130
132
|
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// Builtin go-to-definition support
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
/** Cache of builtin name → line number in builtins.d.mcrs */
|
|
138
|
+
let builtinLineCache: Map<string, number> | null = null
|
|
139
|
+
|
|
140
|
+
function getBuiltinDtsPath(context: vscode.ExtensionContext): string {
|
|
141
|
+
return path.join(context.extensionPath, 'builtins.d.mcrs')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function loadBuiltinLines(dtsPath: string): Map<string, number> {
|
|
145
|
+
if (builtinLineCache) return builtinLineCache
|
|
146
|
+
const cache = new Map<string, number>()
|
|
147
|
+
try {
|
|
148
|
+
const content = fs.readFileSync(dtsPath, 'utf-8')
|
|
149
|
+
const lines = content.split('\n')
|
|
150
|
+
// Find "declare fn <name>(" lines
|
|
151
|
+
for (let i = 0; i < lines.length; i++) {
|
|
152
|
+
const m = lines[i].match(/^declare fn (\w+)\(/)
|
|
153
|
+
if (m) {
|
|
154
|
+
cache.set(m[1], i)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
} catch {
|
|
158
|
+
// dts file not found — skip
|
|
159
|
+
}
|
|
160
|
+
builtinLineCache = cache
|
|
161
|
+
return cache
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Set of all builtin function names that have DTS entries */
|
|
165
|
+
const KNOWN_BUILTINS = new Set([
|
|
166
|
+
'say', 'tell', 'tellraw', 'announce', 'title', 'subtitle', 'actionbar', 'title_times',
|
|
167
|
+
'give', 'kill', 'effect', 'effect_clear', 'clear', 'kick', 'xp_add', 'xp_set',
|
|
168
|
+
'tp', 'tp_to',
|
|
169
|
+
'setblock', 'fill', 'clone', 'summon', 'particle', 'playsound',
|
|
170
|
+
'weather', 'time_set', 'time_add', 'gamerule', 'difficulty',
|
|
171
|
+
'tag_add', 'tag_remove',
|
|
172
|
+
'scoreboard_get', 'score', 'scoreboard_set', 'scoreboard_display', 'scoreboard_hide',
|
|
173
|
+
'scoreboard_add_objective', 'scoreboard_remove_objective',
|
|
174
|
+
'random', 'random_native', 'random_sequence',
|
|
175
|
+
'data_get', 'data_merge',
|
|
176
|
+
'bossbar_add', 'bossbar_set_value', 'bossbar_set_max', 'bossbar_set_color',
|
|
177
|
+
'bossbar_set_style', 'bossbar_set_visible', 'bossbar_set_players',
|
|
178
|
+
'bossbar_remove', 'bossbar_get_value',
|
|
179
|
+
'team_add', 'team_remove', 'team_join', 'team_leave', 'team_option',
|
|
180
|
+
'set_new', 'set_add', 'set_contains', 'set_remove', 'set_clear',
|
|
181
|
+
'setTimeout', 'setInterval', 'clearInterval',
|
|
182
|
+
])
|
|
183
|
+
|
|
131
184
|
export function registerSymbolProviders(context: vscode.ExtensionContext): void {
|
|
132
185
|
const selector: vscode.DocumentSelector = { language: 'redscript', scheme: 'file' }
|
|
133
186
|
|
|
@@ -141,6 +194,21 @@ export function registerSymbolProviders(context: vscode.ExtensionContext): void
|
|
|
141
194
|
if (!wordRange) return null
|
|
142
195
|
const word = doc.getText(wordRange)
|
|
143
196
|
|
|
197
|
+
// ── Go-to-definition for builtin functions ──────────────
|
|
198
|
+
// Only when used as a function call (followed by '(')
|
|
199
|
+
const line = doc.lineAt(position.line).text
|
|
200
|
+
const afterWord = line.slice(wordRange.end.character).trimStart()
|
|
201
|
+
if (afterWord.startsWith('(') && KNOWN_BUILTINS.has(word)) {
|
|
202
|
+
const dtsPath = getBuiltinDtsPath(context)
|
|
203
|
+
const lines = loadBuiltinLines(dtsPath)
|
|
204
|
+
const lineNum = lines.get(word)
|
|
205
|
+
if (lineNum !== undefined) {
|
|
206
|
+
const dtsUri = vscode.Uri.file(dtsPath)
|
|
207
|
+
const pos = new vscode.Position(lineNum, 0)
|
|
208
|
+
return new vscode.Location(dtsUri, pos)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
144
212
|
// Check if this is a struct literal field key: { fieldName: value }
|
|
145
213
|
const structType = isStructLiteralField(doc, position, word)
|
|
146
214
|
if (structType) {
|