gdharness 1.1.15 → 1.1.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/build/cli.js CHANGED
@@ -8571,20 +8571,57 @@ function withAddonClassesCounted(rebuilt, listed) {
8571
8571
  return counted;
8572
8572
  }
8573
8573
  function missingMemberIn(message) {
8574
- const found = /The (method|property) "([^"(]+)(?:\(\))?" is not present on the inferred type "([^"]+)"/.exec(message);
8575
- if (found === null) {
8574
+ const inferred = /The (method|property) "([^"(]+)(?:\(\))?" is not present on the inferred type "([^"]+)"/.exec(message);
8575
+ if (inferred !== null) {
8576
+ return {
8577
+ kind: inferred[1] === "property" ? "property" : "method",
8578
+ member: inferred[2] ?? "",
8579
+ type: inferred[3] ?? ""
8580
+ };
8581
+ }
8582
+ const called = /Static function "([A-Za-z_]\w*)\(\)" not found in base "([A-Za-z_]\w*)"/.exec(message);
8583
+ if (called !== null) {
8584
+ return { kind: "static method", member: called[1] ?? "", type: called[2] ?? "" };
8585
+ }
8586
+ const inBase = /Cannot find member "([A-Za-z_]\w*)" in base "([A-Za-z_]\w*)((?:\.[A-Za-z_]\w*)*)"/.exec(message);
8587
+ if (inBase === null) {
8576
8588
  return null;
8577
8589
  }
8578
- return {
8579
- kind: found[1] === "property" ? "property" : "method",
8580
- member: found[2] ?? "",
8581
- type: found[3] ?? ""
8582
- };
8590
+ const member = inBase[1] ?? "";
8591
+ const type = inBase[2] ?? "";
8592
+ const within = (inBase[3] ?? "").split(".").filter((part) => part !== "");
8593
+ const enumName = within.at(-1);
8594
+ return enumName === undefined ? { kind: "member", member, type } : { kind: "enum member", member, type, enum: enumName };
8583
8595
  }
8584
8596
  function declaresMember(source, missing) {
8585
8597
  const name = missing.member.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8586
- const declaration = missing.kind === "method" ? new RegExp(String.raw`^\s*(?:static\s+)?func\s+${name}\s*\(`, "m") : new RegExp(String.raw`^\s*(?:static\s+)?(?:@export\s+)?(?:var|const)\s+${name}\b`, "m");
8587
- return declaration.test(source);
8598
+ if (missing.kind === "method") {
8599
+ return new RegExp(String.raw`^\s*(?:static\s+)?func\s+${name}\s*\(`, "m").test(source);
8600
+ }
8601
+ if (missing.kind === "static method") {
8602
+ return new RegExp(String.raw`^\s*static\s+func\s+${name}\s*\(`, "m").test(source);
8603
+ }
8604
+ if (missing.kind === "enum member") {
8605
+ return enumValues(source, missing.enum ?? "").includes(missing.member);
8606
+ }
8607
+ const kinds = missing.kind === "property" ? "var|const|enum|class|signal|func" : "var|const|enum|class|signal";
8608
+ return new RegExp(String.raw`^\s*(?:static\s+)?(?:@\w+(?:\([^)]*\))?\s+)*(?:${kinds})\s+${name}\b`, "m").test(source) || enumValues(source, null).includes(missing.member);
8609
+ }
8610
+ function enumValues(source, named) {
8611
+ const opening = named === null ? /^\s*enum\s*\{([^}]*)\}/gm : new RegExp(String.raw`^\s*enum\s+${named.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\s*\{([^}]*)\}`, "gm");
8612
+ const values = [];
8613
+ for (const [, body] of source.matchAll(opening)) {
8614
+ const uncommented = (body ?? "").split(`
8615
+ `).map((line) => line.replace(/#.*$/, "")).join(`
8616
+ `);
8617
+ for (const part of uncommented.split(",")) {
8618
+ const value = /^\s*([A-Za-z_]\w*)/.exec(part)?.[1];
8619
+ if (value !== undefined) {
8620
+ values.push(value);
8621
+ }
8622
+ }
8623
+ }
8624
+ return values;
8588
8625
  }
8589
8626
  function unknownTypeIn(message) {
8590
8627
  const found = /(?:Could not find (?:base class|type)|Cannot find class|Identifier) "?([A-Za-z_][A-Za-z0-9_]*)"?(?: not declared| in the current scope|\b)/.exec(message);
@@ -8615,7 +8652,7 @@ function classesNamedIn(source, known) {
8615
8652
  }
8616
8653
  function contradictedDiagnostics(messages, classes, sourceOf) {
8617
8654
  const read = new Map;
8618
- const found = [];
8655
+ const found = new Map;
8619
8656
  for (const message of messages) {
8620
8657
  const missing = missingMemberIn(message);
8621
8658
  const declaredIn = missing === null ? undefined : classes.get(missing.type);
@@ -8626,20 +8663,48 @@ function contradictedDiagnostics(messages, classes, sourceOf) {
8626
8663
  read.set(declaredIn, sourceOf(declaredIn));
8627
8664
  }
8628
8665
  const source = read.get(declaredIn) ?? null;
8629
- if (source !== null && declaresMember(source, missing)) {
8630
- found.push({ ...missing, declaredIn });
8666
+ const key = [missing.type, missing.enum ?? "", missing.member].join(".");
8667
+ const already = found.get(key);
8668
+ if (source !== null && declaresMember(source, missing) && already?.kind !== "static method") {
8669
+ found.set(key, { ...missing, declaredIn });
8631
8670
  }
8632
8671
  }
8633
- return found;
8672
+ return [...found.values()];
8634
8673
  }
8635
8674
  function staleAnalysisNote(contradicted, dependsOn) {
8636
8675
  if (contradicted.length === 0) {
8637
8676
  return "";
8638
8677
  }
8639
8678
  const types = new Set(contradicted.map((one) => one.type));
8640
- const declaring = [...new Set(contradicted.map((one) => one.declaredIn))].sort();
8679
+ const onInstances = contradicted.filter((one) => one.kind === "method" || one.kind === "property");
8680
+ const onTheClass = contradicted.filter((one) => one.kind === "member" || one.kind === "static method" || one.kind === "enum member");
8681
+ return [
8682
+ `The editor is reporting against an older copy of ${types.size === 1 ? "a type" : "some types"} ` + "named under contradictedByTheFile. Each member listed is declared in the file the class cache " + "points at, so those diagnostics are wrong however the code is written.",
8683
+ instanceRemedy(onInstances, dependsOn, onTheClass.length > 0),
8684
+ classRemedy(onTheClass)
8685
+ ].filter((part) => part !== "").join(" ");
8686
+ }
8687
+ function written(one) {
8688
+ return [one.type, ...one.enum === undefined ? [] : [one.enum], one.member].join(".");
8689
+ }
8690
+ function declaringScripts(entries) {
8691
+ return [...new Set(entries.map((one) => one.declaredIn))].sort();
8692
+ }
8693
+ function instanceRemedy(entries, dependsOn, besideOthers) {
8694
+ if (entries.length === 0) {
8695
+ return "";
8696
+ }
8697
+ const declaring = declaringScripts(entries);
8641
8698
  const lever = dependsOn.length === 0 ? ", and the named types depend on no other global class, so that lever is not available here. " + "That is the common case rather than the awkward one: an edit near a type that depends on " + "something refreshes it before the fault is noticed, which is why a type with no " + "dependencies is where this turns up" : `, so changing ${[...dependsOn].sort().join(" or ")} and then rescanning is worth a try`;
8642
- return `The editor is reporting against an older copy of ${types.size === 1 ? "a type" : "some types"} ` + "named under contradictedByTheFile. Each member listed is declared in the file the class cache " + "points at, so those diagnostics are wrong however the code is written. Run editor_rescan first: " + "it costs about half a second, and it has cleared this in every reproduction measured since the " + "scan timing was fixed: both in one project, the scan returning in 243ms and 275ms, and one in " + "another where the same call also rebuilt the copy. " + "The fault behind it is that a script the editor has loaded keeps the copy it built, and nothing " + `rebuilds that copy when the file changes; ${declaring.length === 1 ? `editor_rescan with reloadScript set to ${declaring[0]} recompiles that copy` : `reloadScript takes one script, so a call each for ${declaring.join(" and ")} recompiles those copies`} from the file into the same ` + "object and answers with the members it has afterwards under reloadedMethods. Read that and the " + "next diagnostics as two readings, because they are of two things: measured in one window on " + "one editor, the analyser resolved a call to a newly added method while the built copy of that " + "same script did not have it. So the reload is worth doing and is not what clears these; the " + "scan is. The other lever measured is that a held type is refreshed when something it " + `depends on changes rather than when it changes itself${lever}. editor_launch restart has always ` + "worked and costs a window. project_import refresh_classes does not, and answers added: [] while " + "this is happening.";
8699
+ return `${besideOthers ? `For ${entries.map(written).join(", ")}, run` : "Run"} editor_rescan first: ` + "it costs about half a second, and it has cleared this in every reproduction measured since the " + "scan timing was fixed: both in one project, the scan returning in 243ms and 275ms, and one in " + "another where the same call also rebuilt the copy. " + "The fault behind it is that a script the editor has loaded keeps the copy it built, and nothing " + `rebuilds that copy when the file changes; ${declaring.length === 1 ? `editor_rescan with reloadScript set to ${declaring[0]} recompiles that copy` : `reloadScript takes one script, so a call each for ${declaring.join(" and ")} recompiles those copies`} from the file into the same ` + "object and answers with the members it has afterwards under reloadedMethods. Read that and the " + "next diagnostics as two readings, because they are of two things: measured in one window on " + "one editor, the analyser resolved a call to a newly added method while the built copy of that " + "same script did not have it. So the reload is worth doing and is not what clears these; the " + "scan is. The other lever measured is that a held type is refreshed when something it " + `depends on changes rather than when it changes itself${lever}. editor_launch restart has always ` + "worked and costs a window. project_import refresh_classes does not, and answers added: [] while " + "this is happening.";
8700
+ }
8701
+ function classRemedy(entries) {
8702
+ if (entries.length === 0) {
8703
+ return "";
8704
+ }
8705
+ const declaring = declaringScripts(entries);
8706
+ const reload = declaring.length === 1 ? `editor_rescan with reloadScript set to ${declaring[0]}` : `editor_rescan with reloadScript, a call each for ${declaring.join(" and ")} since it takes one script,`;
8707
+ return `For ${entries.map(written).join(", ")}, run ${reload} first. In the one project that has ` + "reproduced a stale enum member, twice, the reload cleared it at once both times, and the one " + "plain editor_rescan tried left the diagnostic standing.";
8643
8708
  }
8644
8709
  function uncachedClassNote(types) {
8645
8710
  if (types.length === 0) {
@@ -17055,7 +17120,7 @@ var init_tool_definitions = __esm(() => {
17055
17120
  },
17056
17121
  {
17057
17122
  name: "script_diagnostics",
17058
- description: "Errors and warnings for a script from the editor's language server, and whether the script is clean. Needs the editor running. Diagnostics are checked against the project's own files, and the two that the files disprove are named rather than passed on: a member the class cache's file declares comes back under contradictedByTheFile, and a class this project declares that the diagnostic could not resolve comes back under typesTheEditorHasNotLoaded, with inTheClassCache saying whether a launched game would resolve it. staleAnalysis then says what to do, and for both states it is editor_rescan first: it asks the editor already running, starts nothing, and has cleared each in every reproduction measured. The one exception is named when it applies: an editor whose last scan wrote the class cache shorter than the file holds a list behind the files and writes it on every scan, so on that editor the rescan loads nothing and staleAnalysis says editor_launch restart instead. What follows differs: for a stale analysed type, editor_rescan with reloadScript recompiles the held copy and editor_launch restart is the last resort that costs a window; for a class missing from the cache, project_import refresh_classes rewrites the cache from disk at the cost of a short headless engine, which matters beside a running bench.",
17123
+ description: "Errors and warnings for a script from the editor's language server, and whether the script is clean. Needs the editor running. Diagnostics are checked against the project's own files, and the two that the files disprove are named rather than passed on: a member the class cache's file declares, a method, property, constant, static function or enum member, comes back under contradictedByTheFile, and a class this project declares that the diagnostic could not resolve comes back under typesTheEditorHasNotLoaded, with inTheClassCache saying whether a launched game would resolve it. staleAnalysis then says what to do, and for both states it is editor_rescan first: it asks the editor already running, starts nothing, and has cleared each in every reproduction measured. Two exceptions are named when they apply. For an enum member, constant or static function of a global class the reload comes first: in the one project that has reproduced a stale enum member, editor_rescan with reloadScript on the declaring script cleared it and a plain rescan did not. And an editor whose last scan wrote the class cache shorter than the file holds a list behind the files and writes it on every scan, so on that editor the rescan loads nothing and staleAnalysis says editor_launch restart instead. What follows differs: for a stale analysed type, editor_rescan with reloadScript recompiles the held copy and editor_launch restart is the last resort that costs a window; for a class missing from the cache, project_import refresh_classes rewrites the cache from disk at the cost of a short headless engine, which matters beside a running bench.",
17059
17124
  parameters: {
17060
17125
  projectPath: PROJECT_PATH,
17061
17126
  scriptPath: SCRIPT_PATH
@@ -17276,7 +17341,7 @@ var init_tool_definitions = __esm(() => {
17276
17341
  },
17277
17342
  reloadScript: {
17278
17343
  type: "string",
17279
- description: "A script to recompile in the editor after the scan, for the half a scan does not reach: a script the editor has loaded keeps the copy it built, that copy is refreshed when one of its dependencies changes rather than when it changes itself, and a scan leaves it alone. Measured here, a built copy comes back without a method added to it while script_diagnostics on the same script reads clean in the same window, so the copy the editor built and whatever the analyser resolves types against are not known to be one thing: reload for the copy, and read the diagnostics as a separate answer rather than as this one confirmed. This recompiles into the same object, so the holders that kept the stale copy alive see the new one. The methods it has afterwards come back under reloadedMethods, because a reload that compiled nothing and answered OK is the failure worth catching."
17344
+ description: "A script to recompile in the editor after the scan, for the half a scan does not reach: a script the editor has loaded keeps the copy it built, that copy is refreshed when one of its dependencies changes rather than when it changes itself, and a scan leaves it alone. Measured here, a built copy comes back without a method added to it while script_diagnostics on the same script reads clean in the same window, so the copy the editor built and whatever the analyser resolves types against are not known to be one thing: reload for the copy, and read the diagnostics as a separate answer rather than as this one confirmed. This recompiles into the same object, so the holders that kept the stale copy alive see the new one. The methods it has afterwards come back under reloadedMethods, because a reload that compiled nothing and answered OK is the failure worth catching, and what it held before under heldBeforeReload. Its constants come back the same way, under heldConstantsBeforeReload and reloadedConstants, with each enum value as Kind.SHORT: an enum member is held as a constant and never shows among the methods."
17280
17345
  }
17281
17346
  },
17282
17347
  requires: ["projectPath"]
@@ -17537,7 +17602,7 @@ var init_tool_definitions = __esm(() => {
17537
17602
  pressed: {
17538
17603
  type: "boolean",
17539
17604
  ops: ["action", "key", "mouse_click"],
17540
- description: "action, key: leave it out and the press is a whole one, down and up a frame apart. true holds it down, false lets go of one being held. mouse_click is one raw event, so it is down unless you say false; a wheel button down is a whole step, since a wheel is never held."
17605
+ description: "action, key, mouse_click: leave it out and the press is a whole one, down and up a frame apart. true holds it down, false lets go of one being held. A wheel button held down is still a whole step, since a wheel is never held."
17541
17606
  },
17542
17607
  strength: {
17543
17608
  type: "number",
@@ -17621,7 +17686,7 @@ var init_tool_definitions = __esm(() => {
17621
17686
  requires: ["text"]
17622
17687
  },
17623
17688
  mouse_click: {
17624
- summary: "one mouse button event at a position, carrying the buttons held once it has happened. A drag is a press held with pressed true, motions, and a release with pressed false. A wheel button is a whole step, press and release together as a mouse sends one, and the answer says released: a lone wheel press holds the viewport on the control that took it, so every click after it lands there",
17689
+ summary: "click a mouse button at a position, pressed and released a frame apart, each event carrying the buttons held once it has happened; the answer says whole. A drag is a press held with pressed true, motions, and a release with pressed false. A wheel button is always a whole step, press and release together as a mouse sends one: a lone wheel press holds the viewport on the control that took it, so every click after it lands there",
17625
17690
  requires: ["x", "y"]
17626
17691
  },
17627
17692
  mouse_motion: {
@@ -42958,8 +43023,16 @@ class GodotServer {
42958
43023
  try {
42959
43024
  const answer = asParams(await this.godotBridge.invokeTool("reload_script", { ...args, scriptPath: reloading }));
42960
43025
  const methods = readArray(answer, "methods");
42961
- const before = readArray(answer, "heldBefore");
42962
- reloaded = methods ? { methods: methods.map(String), ...before ? { heldBefore: before.map(String) } : {} } : { problem: `the editor would not say what ${reloading} has after reloading it` };
43026
+ const listed = (field) => {
43027
+ const found = readArray(answer, field);
43028
+ return found ? { [field]: found.map(String) } : {};
43029
+ };
43030
+ reloaded = methods ? {
43031
+ methods: methods.map(String),
43032
+ ...listed("heldBefore"),
43033
+ ...listed("constants"),
43034
+ ...listed("heldConstantsBefore")
43035
+ } : { problem: `the editor would not say what ${reloading} has after reloading it` };
42963
43036
  } catch (error) {
42964
43037
  reloaded = { problem: `${reloading} could not be reloaded: ${errorMessage(error)}` };
42965
43038
  }
@@ -42994,6 +43067,8 @@ class GodotServer {
42994
43067
  waitedForEditorScanMs: waitedForEditorMs > 0 ? waitedForEditorMs : undefined,
42995
43068
  heldBeforeReload: reloaded.heldBefore,
42996
43069
  reloadedMethods: reloaded.methods,
43070
+ heldConstantsBeforeReload: reloaded.heldConstantsBefore,
43071
+ reloadedConstants: reloaded.constants,
42997
43072
  reloadProblem: reloaded.problem,
42998
43073
  unseenByEditor: unseen.length > 0 ? unseen : undefined,
42999
43074
  broughtIn: broughtIn.length > 0 ? broughtIn : undefined,
@@ -64,6 +64,7 @@ func reload_script(args: Dictionary) -> Dictionary:
64
64
  # than the one that mends it. Without it a caller cannot tell a copy that was already current
65
65
  # from one this call repaired, and those are different facts about their editor.
66
66
  var held: Array[String] = _method_names(script)
67
+ var held_constants: Array[String] = _constant_names(script)
67
68
 
68
69
  # The source is read off disk and put back before reloading, which is the whole of the fix and
69
70
  # is not obvious. `reload` recompiles from the object's own `source_code`, not from the file, so
@@ -80,7 +81,14 @@ func reload_script(args: Dictionary) -> Dictionary:
80
81
  if failed != OK:
81
82
  return {"ok": false, "error": "Reloading " + path + " answered error " + str(failed)}
82
83
 
83
- return {"ok": true, "script": path, "heldBefore": held, "methods": _method_names(script)}
84
+ return {
85
+ "ok": true,
86
+ "script": path,
87
+ "heldBefore": held,
88
+ "methods": _method_names(script),
89
+ "heldConstantsBefore": held_constants,
90
+ "constants": _constant_names(script),
91
+ }
84
92
 
85
93
 
86
94
  func _method_names(script: GDScript) -> Array[String]:
@@ -91,6 +99,24 @@ func _method_names(script: GDScript) -> Array[String]:
91
99
  return names
92
100
 
93
101
 
102
+ ## The script's own constants, and the keys of each one that is a Dictionary as `Kind.SHORT`, which
103
+ ## is how the copy holds a named enum: a stale enum member is denied as a member of the enum rather
104
+ ## than of the class. A constant Dictionary that is not an enum is listed the same way, since the
105
+ ## map does not tell the two apart.
106
+ func _constant_names(script: GDScript) -> Array[String]:
107
+ var names: Array[String] = []
108
+ var constants: Dictionary = script.get_script_constant_map()
109
+ for named: Variant in constants:
110
+ var value: Variant = constants[named]
111
+ names.append(str(named))
112
+ if value is Dictionary:
113
+ var values: Dictionary = value
114
+ for member: Variant in values:
115
+ names.append("%s.%s" % [named, member])
116
+ names.sort()
117
+ return names
118
+
119
+
94
120
  func global_classes(_args: Dictionary) -> Dictionary:
95
121
  if not _editor_plugin:
96
122
  return {"ok": false, "error": "Editor plugin unavailable"}
@@ -353,6 +353,14 @@ func _read_point(params: Dictionary, x_key: String, y_key: String, pair_key: Str
353
353
  return "%s must be Vector2 or [x, y]" % pair_key
354
354
 
355
355
 
356
+ ## Clicks a mouse button at a position, and lets go of it again unless asked to hold it.
357
+ ##
358
+ ## The whole click by default, for the reason [method inject_action] is the whole press, and
359
+ ## because much of a UI acts on the release: a rich label opens its link then, so a click on one
360
+ ## answered input_injected and opened nothing, while the same op on the wheel was already whole.
361
+ ##
362
+ ## `pressed` is how a caller asks for one half, the way a drag is made: true holds the button down,
363
+ ## false lets go of one being held.
356
364
  func inject_mouse_click(params: Dictionary) -> Dictionary:
357
365
  var point: Variant = _read_point(params, "x", "y", "position")
358
366
  if point is String:
@@ -361,32 +369,37 @@ func inject_mouse_click(params: Dictionary) -> Dictionary:
361
369
  var button: int = _resolve_mouse_button(params.get("button", MOUSE_BUTTON_LEFT))
362
370
  if button < 0:
363
371
  return _no_such_button(params.get("button"))
364
- var pressed: bool = Read.as_bool(params.get("pressed", true), true)
372
+ var held: bool = Read.as_bool(params.get("pressed", true), true)
365
373
  var double: bool = Read.as_bool(params.get("doubleClick", false))
366
-
367
- # A button pressed somewhere puts the pointer there: the motion after a held press measures
368
- # its drag from the press, which is where a real pointer would be.
369
- var _moved: Vector2 = _arrive(position)
370
- Input.parse_input_event(_button(position, button, pressed, double))
371
374
  # A wheel step is a press and a release together, as a mouse sends one: there is no holding a
372
375
  # wheel. A lone wheel press left the viewport's mouse focus on the control that took it, with
373
376
  # the wheel's bit in the focus mask, and every click after it landed on that control rather
374
377
  # than under the pointer, landing true and doing nothing, until a release was sent by hand.
375
- var notch: bool = pressed and _mask_of(button) == 0
378
+ var notch: bool = held and _mask_of(button) == 0
379
+ var whole: bool = notch or not params.has("pressed")
380
+
381
+ # A button pressed somewhere puts the pointer there: the motion after a held press measures
382
+ # its drag from the press, which is where a real pointer would be.
383
+ var _moved: Vector2 = _arrive(position)
384
+ Input.parse_input_event(_button(position, button, whole or held, double))
376
385
  if notch:
377
386
  Input.parse_input_event(_button(position, button, false, false))
387
+ elif whole:
388
+ # A frame between the halves, as inject_action has, so a control that acts on the press and
389
+ # one that acts on the release each get a frame to do it in.
390
+ await _host.get_tree().process_frame
391
+ Input.parse_input_event(_button(position, button, false, false))
392
+ await _host.get_tree().process_frame
378
393
 
379
- var answer: Dictionary = {
394
+ return {
380
395
  "type": "input_injected",
381
396
  "input_type": "mouse_click",
382
397
  "position": [position.x, position.y],
383
398
  "button": button,
384
- "pressed": pressed,
399
+ "pressed": held and not whole,
400
+ "whole": whole,
385
401
  "double": double
386
402
  }
387
- if notch:
388
- answer["released"] = true
389
- return answer
390
403
 
391
404
 
392
405
  ## Moves the pointer to a position, with the movement the event carries taken from where the
package/build/index.js CHANGED
@@ -26141,20 +26141,57 @@ function withAddonClassesCounted(rebuilt, listed) {
26141
26141
  return counted;
26142
26142
  }
26143
26143
  function missingMemberIn(message) {
26144
- const found = /The (method|property) "([^"(]+)(?:\(\))?" is not present on the inferred type "([^"]+)"/.exec(message);
26145
- if (found === null) {
26144
+ const inferred = /The (method|property) "([^"(]+)(?:\(\))?" is not present on the inferred type "([^"]+)"/.exec(message);
26145
+ if (inferred !== null) {
26146
+ return {
26147
+ kind: inferred[1] === "property" ? "property" : "method",
26148
+ member: inferred[2] ?? "",
26149
+ type: inferred[3] ?? ""
26150
+ };
26151
+ }
26152
+ const called = /Static function "([A-Za-z_]\w*)\(\)" not found in base "([A-Za-z_]\w*)"/.exec(message);
26153
+ if (called !== null) {
26154
+ return { kind: "static method", member: called[1] ?? "", type: called[2] ?? "" };
26155
+ }
26156
+ const inBase = /Cannot find member "([A-Za-z_]\w*)" in base "([A-Za-z_]\w*)((?:\.[A-Za-z_]\w*)*)"/.exec(message);
26157
+ if (inBase === null) {
26146
26158
  return null;
26147
26159
  }
26148
- return {
26149
- kind: found[1] === "property" ? "property" : "method",
26150
- member: found[2] ?? "",
26151
- type: found[3] ?? ""
26152
- };
26160
+ const member = inBase[1] ?? "";
26161
+ const type = inBase[2] ?? "";
26162
+ const within = (inBase[3] ?? "").split(".").filter((part) => part !== "");
26163
+ const enumName = within.at(-1);
26164
+ return enumName === undefined ? { kind: "member", member, type } : { kind: "enum member", member, type, enum: enumName };
26153
26165
  }
26154
26166
  function declaresMember(source, missing) {
26155
26167
  const name = missing.member.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
26156
- const declaration = missing.kind === "method" ? new RegExp(String.raw`^\s*(?:static\s+)?func\s+${name}\s*\(`, "m") : new RegExp(String.raw`^\s*(?:static\s+)?(?:@export\s+)?(?:var|const)\s+${name}\b`, "m");
26157
- return declaration.test(source);
26168
+ if (missing.kind === "method") {
26169
+ return new RegExp(String.raw`^\s*(?:static\s+)?func\s+${name}\s*\(`, "m").test(source);
26170
+ }
26171
+ if (missing.kind === "static method") {
26172
+ return new RegExp(String.raw`^\s*static\s+func\s+${name}\s*\(`, "m").test(source);
26173
+ }
26174
+ if (missing.kind === "enum member") {
26175
+ return enumValues(source, missing.enum ?? "").includes(missing.member);
26176
+ }
26177
+ const kinds = missing.kind === "property" ? "var|const|enum|class|signal|func" : "var|const|enum|class|signal";
26178
+ return new RegExp(String.raw`^\s*(?:static\s+)?(?:@\w+(?:\([^)]*\))?\s+)*(?:${kinds})\s+${name}\b`, "m").test(source) || enumValues(source, null).includes(missing.member);
26179
+ }
26180
+ function enumValues(source, named) {
26181
+ const opening = named === null ? /^\s*enum\s*\{([^}]*)\}/gm : new RegExp(String.raw`^\s*enum\s+${named.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\s*\{([^}]*)\}`, "gm");
26182
+ const values = [];
26183
+ for (const [, body] of source.matchAll(opening)) {
26184
+ const uncommented = (body ?? "").split(`
26185
+ `).map((line) => line.replace(/#.*$/, "")).join(`
26186
+ `);
26187
+ for (const part of uncommented.split(",")) {
26188
+ const value = /^\s*([A-Za-z_]\w*)/.exec(part)?.[1];
26189
+ if (value !== undefined) {
26190
+ values.push(value);
26191
+ }
26192
+ }
26193
+ }
26194
+ return values;
26158
26195
  }
26159
26196
  function unknownTypeIn(message) {
26160
26197
  const found = /(?:Could not find (?:base class|type)|Cannot find class|Identifier) "?([A-Za-z_][A-Za-z0-9_]*)"?(?: not declared| in the current scope|\b)/.exec(message);
@@ -26185,7 +26222,7 @@ function classesNamedIn(source, known) {
26185
26222
  }
26186
26223
  function contradictedDiagnostics(messages, classes, sourceOf) {
26187
26224
  const read = new Map;
26188
- const found = [];
26225
+ const found = new Map;
26189
26226
  for (const message of messages) {
26190
26227
  const missing = missingMemberIn(message);
26191
26228
  const declaredIn = missing === null ? undefined : classes.get(missing.type);
@@ -26196,20 +26233,48 @@ function contradictedDiagnostics(messages, classes, sourceOf) {
26196
26233
  read.set(declaredIn, sourceOf(declaredIn));
26197
26234
  }
26198
26235
  const source = read.get(declaredIn) ?? null;
26199
- if (source !== null && declaresMember(source, missing)) {
26200
- found.push({ ...missing, declaredIn });
26236
+ const key = [missing.type, missing.enum ?? "", missing.member].join(".");
26237
+ const already = found.get(key);
26238
+ if (source !== null && declaresMember(source, missing) && already?.kind !== "static method") {
26239
+ found.set(key, { ...missing, declaredIn });
26201
26240
  }
26202
26241
  }
26203
- return found;
26242
+ return [...found.values()];
26204
26243
  }
26205
26244
  function staleAnalysisNote(contradicted, dependsOn) {
26206
26245
  if (contradicted.length === 0) {
26207
26246
  return "";
26208
26247
  }
26209
26248
  const types = new Set(contradicted.map((one) => one.type));
26210
- const declaring = [...new Set(contradicted.map((one) => one.declaredIn))].sort();
26249
+ const onInstances = contradicted.filter((one) => one.kind === "method" || one.kind === "property");
26250
+ const onTheClass = contradicted.filter((one) => one.kind === "member" || one.kind === "static method" || one.kind === "enum member");
26251
+ return [
26252
+ `The editor is reporting against an older copy of ${types.size === 1 ? "a type" : "some types"} ` + "named under contradictedByTheFile. Each member listed is declared in the file the class cache " + "points at, so those diagnostics are wrong however the code is written.",
26253
+ instanceRemedy(onInstances, dependsOn, onTheClass.length > 0),
26254
+ classRemedy(onTheClass)
26255
+ ].filter((part) => part !== "").join(" ");
26256
+ }
26257
+ function written(one) {
26258
+ return [one.type, ...one.enum === undefined ? [] : [one.enum], one.member].join(".");
26259
+ }
26260
+ function declaringScripts(entries) {
26261
+ return [...new Set(entries.map((one) => one.declaredIn))].sort();
26262
+ }
26263
+ function instanceRemedy(entries, dependsOn, besideOthers) {
26264
+ if (entries.length === 0) {
26265
+ return "";
26266
+ }
26267
+ const declaring = declaringScripts(entries);
26211
26268
  const lever = dependsOn.length === 0 ? ", and the named types depend on no other global class, so that lever is not available here. " + "That is the common case rather than the awkward one: an edit near a type that depends on " + "something refreshes it before the fault is noticed, which is why a type with no " + "dependencies is where this turns up" : `, so changing ${[...dependsOn].sort().join(" or ")} and then rescanning is worth a try`;
26212
- return `The editor is reporting against an older copy of ${types.size === 1 ? "a type" : "some types"} ` + "named under contradictedByTheFile. Each member listed is declared in the file the class cache " + "points at, so those diagnostics are wrong however the code is written. Run editor_rescan first: " + "it costs about half a second, and it has cleared this in every reproduction measured since the " + "scan timing was fixed: both in one project, the scan returning in 243ms and 275ms, and one in " + "another where the same call also rebuilt the copy. " + "The fault behind it is that a script the editor has loaded keeps the copy it built, and nothing " + `rebuilds that copy when the file changes; ${declaring.length === 1 ? `editor_rescan with reloadScript set to ${declaring[0]} recompiles that copy` : `reloadScript takes one script, so a call each for ${declaring.join(" and ")} recompiles those copies`} from the file into the same ` + "object and answers with the members it has afterwards under reloadedMethods. Read that and the " + "next diagnostics as two readings, because they are of two things: measured in one window on " + "one editor, the analyser resolved a call to a newly added method while the built copy of that " + "same script did not have it. So the reload is worth doing and is not what clears these; the " + "scan is. The other lever measured is that a held type is refreshed when something it " + `depends on changes rather than when it changes itself${lever}. editor_launch restart has always ` + "worked and costs a window. project_import refresh_classes does not, and answers added: [] while " + "this is happening.";
26269
+ return `${besideOthers ? `For ${entries.map(written).join(", ")}, run` : "Run"} editor_rescan first: ` + "it costs about half a second, and it has cleared this in every reproduction measured since the " + "scan timing was fixed: both in one project, the scan returning in 243ms and 275ms, and one in " + "another where the same call also rebuilt the copy. " + "The fault behind it is that a script the editor has loaded keeps the copy it built, and nothing " + `rebuilds that copy when the file changes; ${declaring.length === 1 ? `editor_rescan with reloadScript set to ${declaring[0]} recompiles that copy` : `reloadScript takes one script, so a call each for ${declaring.join(" and ")} recompiles those copies`} from the file into the same ` + "object and answers with the members it has afterwards under reloadedMethods. Read that and the " + "next diagnostics as two readings, because they are of two things: measured in one window on " + "one editor, the analyser resolved a call to a newly added method while the built copy of that " + "same script did not have it. So the reload is worth doing and is not what clears these; the " + "scan is. The other lever measured is that a held type is refreshed when something it " + `depends on changes rather than when it changes itself${lever}. editor_launch restart has always ` + "worked and costs a window. project_import refresh_classes does not, and answers added: [] while " + "this is happening.";
26270
+ }
26271
+ function classRemedy(entries) {
26272
+ if (entries.length === 0) {
26273
+ return "";
26274
+ }
26275
+ const declaring = declaringScripts(entries);
26276
+ const reload = declaring.length === 1 ? `editor_rescan with reloadScript set to ${declaring[0]}` : `editor_rescan with reloadScript, a call each for ${declaring.join(" and ")} since it takes one script,`;
26277
+ return `For ${entries.map(written).join(", ")}, run ${reload} first. In the one project that has ` + "reproduced a stale enum member, twice, the reload cleared it at once both times, and the one " + "plain editor_rescan tried left the diagnostic standing.";
26213
26278
  }
26214
26279
  function uncachedClassNote(types) {
26215
26280
  if (types.length === 0) {
@@ -30712,7 +30777,7 @@ var TOOL_SPECS = [
30712
30777
  },
30713
30778
  {
30714
30779
  name: "script_diagnostics",
30715
- description: "Errors and warnings for a script from the editor's language server, and whether the script is clean. Needs the editor running. Diagnostics are checked against the project's own files, and the two that the files disprove are named rather than passed on: a member the class cache's file declares comes back under contradictedByTheFile, and a class this project declares that the diagnostic could not resolve comes back under typesTheEditorHasNotLoaded, with inTheClassCache saying whether a launched game would resolve it. staleAnalysis then says what to do, and for both states it is editor_rescan first: it asks the editor already running, starts nothing, and has cleared each in every reproduction measured. The one exception is named when it applies: an editor whose last scan wrote the class cache shorter than the file holds a list behind the files and writes it on every scan, so on that editor the rescan loads nothing and staleAnalysis says editor_launch restart instead. What follows differs: for a stale analysed type, editor_rescan with reloadScript recompiles the held copy and editor_launch restart is the last resort that costs a window; for a class missing from the cache, project_import refresh_classes rewrites the cache from disk at the cost of a short headless engine, which matters beside a running bench.",
30780
+ description: "Errors and warnings for a script from the editor's language server, and whether the script is clean. Needs the editor running. Diagnostics are checked against the project's own files, and the two that the files disprove are named rather than passed on: a member the class cache's file declares, a method, property, constant, static function or enum member, comes back under contradictedByTheFile, and a class this project declares that the diagnostic could not resolve comes back under typesTheEditorHasNotLoaded, with inTheClassCache saying whether a launched game would resolve it. staleAnalysis then says what to do, and for both states it is editor_rescan first: it asks the editor already running, starts nothing, and has cleared each in every reproduction measured. Two exceptions are named when they apply. For an enum member, constant or static function of a global class the reload comes first: in the one project that has reproduced a stale enum member, editor_rescan with reloadScript on the declaring script cleared it and a plain rescan did not. And an editor whose last scan wrote the class cache shorter than the file holds a list behind the files and writes it on every scan, so on that editor the rescan loads nothing and staleAnalysis says editor_launch restart instead. What follows differs: for a stale analysed type, editor_rescan with reloadScript recompiles the held copy and editor_launch restart is the last resort that costs a window; for a class missing from the cache, project_import refresh_classes rewrites the cache from disk at the cost of a short headless engine, which matters beside a running bench.",
30716
30781
  parameters: {
30717
30782
  projectPath: PROJECT_PATH,
30718
30783
  scriptPath: SCRIPT_PATH
@@ -30933,7 +30998,7 @@ var TOOL_SPECS = [
30933
30998
  },
30934
30999
  reloadScript: {
30935
31000
  type: "string",
30936
- description: "A script to recompile in the editor after the scan, for the half a scan does not reach: a script the editor has loaded keeps the copy it built, that copy is refreshed when one of its dependencies changes rather than when it changes itself, and a scan leaves it alone. Measured here, a built copy comes back without a method added to it while script_diagnostics on the same script reads clean in the same window, so the copy the editor built and whatever the analyser resolves types against are not known to be one thing: reload for the copy, and read the diagnostics as a separate answer rather than as this one confirmed. This recompiles into the same object, so the holders that kept the stale copy alive see the new one. The methods it has afterwards come back under reloadedMethods, because a reload that compiled nothing and answered OK is the failure worth catching."
31001
+ description: "A script to recompile in the editor after the scan, for the half a scan does not reach: a script the editor has loaded keeps the copy it built, that copy is refreshed when one of its dependencies changes rather than when it changes itself, and a scan leaves it alone. Measured here, a built copy comes back without a method added to it while script_diagnostics on the same script reads clean in the same window, so the copy the editor built and whatever the analyser resolves types against are not known to be one thing: reload for the copy, and read the diagnostics as a separate answer rather than as this one confirmed. This recompiles into the same object, so the holders that kept the stale copy alive see the new one. The methods it has afterwards come back under reloadedMethods, because a reload that compiled nothing and answered OK is the failure worth catching, and what it held before under heldBeforeReload. Its constants come back the same way, under heldConstantsBeforeReload and reloadedConstants, with each enum value as Kind.SHORT: an enum member is held as a constant and never shows among the methods."
30937
31002
  }
30938
31003
  },
30939
31004
  requires: ["projectPath"]
@@ -31194,7 +31259,7 @@ var TOOL_SPECS = [
31194
31259
  pressed: {
31195
31260
  type: "boolean",
31196
31261
  ops: ["action", "key", "mouse_click"],
31197
- description: "action, key: leave it out and the press is a whole one, down and up a frame apart. true holds it down, false lets go of one being held. mouse_click is one raw event, so it is down unless you say false; a wheel button down is a whole step, since a wheel is never held."
31262
+ description: "action, key, mouse_click: leave it out and the press is a whole one, down and up a frame apart. true holds it down, false lets go of one being held. A wheel button held down is still a whole step, since a wheel is never held."
31198
31263
  },
31199
31264
  strength: {
31200
31265
  type: "number",
@@ -31278,7 +31343,7 @@ var TOOL_SPECS = [
31278
31343
  requires: ["text"]
31279
31344
  },
31280
31345
  mouse_click: {
31281
- summary: "one mouse button event at a position, carrying the buttons held once it has happened. A drag is a press held with pressed true, motions, and a release with pressed false. A wheel button is a whole step, press and release together as a mouse sends one, and the answer says released: a lone wheel press holds the viewport on the control that took it, so every click after it lands there",
31346
+ summary: "click a mouse button at a position, pressed and released a frame apart, each event carrying the buttons held once it has happened; the answer says whole. A drag is a press held with pressed true, motions, and a release with pressed false. A wheel button is always a whole step, press and release together as a mouse sends one: a lone wheel press holds the viewport on the control that took it, so every click after it lands there",
31282
31347
  requires: ["x", "y"]
31283
31348
  },
31284
31349
  mouse_motion: {
@@ -35418,8 +35483,16 @@ class GodotServer {
35418
35483
  try {
35419
35484
  const answer = asParams(await this.godotBridge.invokeTool("reload_script", { ...args, scriptPath: reloading }));
35420
35485
  const methods = readArray(answer, "methods");
35421
- const before = readArray(answer, "heldBefore");
35422
- reloaded = methods ? { methods: methods.map(String), ...before ? { heldBefore: before.map(String) } : {} } : { problem: `the editor would not say what ${reloading} has after reloading it` };
35486
+ const listed = (field) => {
35487
+ const found = readArray(answer, field);
35488
+ return found ? { [field]: found.map(String) } : {};
35489
+ };
35490
+ reloaded = methods ? {
35491
+ methods: methods.map(String),
35492
+ ...listed("heldBefore"),
35493
+ ...listed("constants"),
35494
+ ...listed("heldConstantsBefore")
35495
+ } : { problem: `the editor would not say what ${reloading} has after reloading it` };
35423
35496
  } catch (error) {
35424
35497
  reloaded = { problem: `${reloading} could not be reloaded: ${errorMessage(error)}` };
35425
35498
  }
@@ -35454,6 +35527,8 @@ class GodotServer {
35454
35527
  waitedForEditorScanMs: waitedForEditorMs > 0 ? waitedForEditorMs : undefined,
35455
35528
  heldBeforeReload: reloaded.heldBefore,
35456
35529
  reloadedMethods: reloaded.methods,
35530
+ heldConstantsBeforeReload: reloaded.heldConstantsBefore,
35531
+ reloadedConstants: reloaded.constants,
35457
35532
  reloadProblem: reloaded.problem,
35458
35533
  unseenByEditor: unseen.length > 0 ? unseen : undefined,
35459
35534
  broughtIn: broughtIn.length > 0 ? broughtIn : undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdharness",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "mcpName": "io.github.Aureliolo/gdharness",
5
5
  "description": "A harness for driving a Godot 4 project from an agent: editor addons, a runtime bridge into the running game, an MCP server in front of them, and a CLI that installs and diagnoses the Godot side.",
6
6
  "type": "module",