@rohal12/spindle-lsp 0.15.18 → 0.15.20

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/dist/bin.js CHANGED
@@ -55,7 +55,7 @@ var VERSION;
55
55
  var init_version = __esm({
56
56
  "src/version.ts"() {
57
57
  "use strict";
58
- VERSION = false ? pkg.version : "0.15.18";
58
+ VERSION = false ? pkg.version : "0.15.20";
59
59
  }
60
60
  });
61
61
 
@@ -33212,6 +33212,8 @@ var init_variable_tracker = __esm({
33212
33212
  usagesByUri = /* @__PURE__ */ new Map();
33213
33213
  /** Per-URI list of transient variable usages. */
33214
33214
  transientUsagesByUri = /* @__PURE__ */ new Map();
33215
+ /** Executable assignments can replace a declaration's default shape anywhere in the story. */
33216
+ rootWritesByUri = /* @__PURE__ */ new Map();
33215
33217
  /**
33216
33218
  * Parse the StoryVariables passage content for declarations.
33217
33219
  * Each line like `$name = value` becomes a declaration.
@@ -33244,7 +33246,17 @@ var init_variable_tracker = __esm({
33244
33246
  this.removeDocument(uri);
33245
33247
  const usages = [];
33246
33248
  const transientUsages = [];
33249
+ const rootWrites = /* @__PURE__ */ new Set();
33247
33250
  for (const passage of markup.passages) {
33251
+ for (const piece of passage.pieces) {
33252
+ if (piece.kind !== "code") continue;
33253
+ try {
33254
+ for (const ref2 of parseCode(piece.code, piece.goal).refs) {
33255
+ if (ref2.write && (ref2.sigil === "$" || ref2.sigil === "%")) rootWrites.add(ref2.sigil + ref2.name);
33256
+ }
33257
+ } catch {
33258
+ }
33259
+ }
33248
33260
  for (const ref2 of collectVariableReferences2(passage)) {
33249
33261
  const usage = {
33250
33262
  uri,
@@ -33257,11 +33269,13 @@ var init_variable_tracker = __esm({
33257
33269
  }
33258
33270
  if (usages.length > 0) this.usagesByUri.set(uri, usages);
33259
33271
  if (transientUsages.length > 0) this.transientUsagesByUri.set(uri, transientUsages);
33272
+ if (rootWrites.size > 0) this.rootWritesByUri.set(uri, rootWrites);
33260
33273
  }
33261
33274
  /** Forget the usages recorded for a document, e.g. after it was deleted. */
33262
33275
  removeDocument(uri) {
33263
33276
  this.usagesByUri.delete(uri);
33264
33277
  this.transientUsagesByUri.delete(uri);
33278
+ this.rootWritesByUri.delete(uri);
33265
33279
  }
33266
33280
  /** Get all declared variables. */
33267
33281
  getDeclared() {
@@ -33315,11 +33329,12 @@ var init_variable_tracker = __esm({
33315
33329
  }
33316
33330
  /**
33317
33331
  * Get `$var.member` / `%var.member` accesses in a document where `var` is
33318
- * declared with an array literal default and `member` is not a property
33319
- * that JavaScript arrays have (so the access always yields undefined).
33332
+ * declared with an array literal default, with no known root assignment,
33333
+ * and `member` is not a property that JavaScript arrays have.
33320
33334
  */
33321
33335
  getArrayMemberAccesses(uri) {
33322
33336
  const results = [];
33337
+ const rootWrites = new Set([...this.rootWritesByUri.values()].flatMap((writes) => [...writes]));
33323
33338
  const sources = [
33324
33339
  ["$", this.usagesByUri.get(uri), this.variables.declared],
33325
33340
  ["%", this.transientUsagesByUri.get(uri), this.transients.declared]
@@ -33329,6 +33344,7 @@ var init_variable_tracker = __esm({
33329
33344
  const member = u.fullName.split(".")[1];
33330
33345
  if (member === void 0) continue;
33331
33346
  if (declared.get(u.baseName)?.type !== "array") continue;
33347
+ if (rootWrites.has(sigil + u.baseName)) continue;
33332
33348
  if (ARRAY_MEMBERS.has(member) || /^(0|[1-9]\d*)$/.test(member) && Number(member) < 4294967295) continue;
33333
33349
  results.push({ sigil, name: u.baseName, member, range: u.range });
33334
33350
  }
@@ -35166,15 +35182,17 @@ function parentDiagnostics(passage, token, ancestors, workspace) {
35166
35182
  return [makeDiag(range2, DiagnosticCode.InvalidChildren, `Invalid: {${token.name}} can only be inside {${parentList}}`)];
35167
35183
  }
35168
35184
  function childDiagnostics(passage, node, token, workspace) {
35169
- const constraints = workspace.getEffectiveMacro(token.name)?.children;
35185
+ const macro = workspace.getEffectiveMacro(token.name);
35186
+ const constraints = macro?.children;
35170
35187
  if (!constraints || constraints.length === 0 || !node.body?.close) return [];
35171
35188
  const direct = [...node.body.children];
35172
35189
  for (const branch of node.body.branches) direct.push({ token: branch.tag, start: branch.tag.start, end: branch.tag.end }, ...branch.children);
35190
+ const consumesOptions = macro?.source === "builtin" && ["listbox", "cycle"].includes(token.name.toLowerCase());
35173
35191
  const counts = /* @__PURE__ */ Object.create(null);
35174
35192
  for (const child of direct) {
35175
35193
  if (child.token.type !== "macro" || child.token.isClose) continue;
35176
35194
  const key = child.token.name.toLowerCase();
35177
- if (workspace.getEffectiveMacro(key)) counts[key] = (counts[key] ?? 0) + 1;
35195
+ if (consumesOptions && key === "option" || workspace.getEffectiveMacro(key)) counts[key] = (counts[key] ?? 0) + 1;
35178
35196
  }
35179
35197
  const diagnostics = [];
35180
35198
  const range2 = passage.range(token.start, token.end);
@@ -37967,7 +37985,7 @@ async function formatLf2(text3, options) {
37967
37985
  if (passage.body === "") continue;
37968
37986
  const role = parsePassageHeader(passage.header, passage.startLine);
37969
37987
  const kind = classifyPassage(passage.header);
37970
- const body = kind === "normal" && role && !isMarkupPassage(role) ? passage.body : await formatPassage(passage.body, {
37988
+ const body = role && (!isRuntimePassage({ name: role.name }) || kind === "normal" && !isMarkupPassage(role)) ? passage.body : await formatPassage(passage.body, {
37971
37989
  kind,
37972
37990
  prettier: prettier2?.prettier,
37973
37991
  prettierOptions: prettier2?.options,