@rohal12/spindle-lsp 0.15.11 → 0.15.12

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.11";
58
+ VERSION = false ? pkg.version : "0.15.12";
59
59
  }
60
60
  });
61
61
 
@@ -31356,6 +31356,15 @@ var init_passage_parser = __esm({
31356
31356
 
31357
31357
  // src/core/workspace/passage-index.ts
31358
31358
  import { createRequire as createSettingsRequire } from "node:module";
31359
+ function compareSourceUris(left, right) {
31360
+ const a = left.split("/").map(decodeURIComponent);
31361
+ const b = right.split("/").map(decodeURIComponent);
31362
+ for (let i2 = 0; i2 < Math.min(a.length, b.length); i2++) {
31363
+ const order = Buffer.compare(Buffer.from(a[i2], "utf8"), Buffer.from(b[i2], "utf8"));
31364
+ if (order !== 0) return order;
31365
+ }
31366
+ return a.length - b.length;
31367
+ }
31359
31368
  var PassageIndex;
31360
31369
  var init_passage_index = __esm({
31361
31370
  "src/core/workspace/passage-index.ts"() {
@@ -31443,6 +31452,10 @@ var init_passage_index = __esm({
31443
31452
  }
31444
31453
  return found;
31445
31454
  }
31455
+ /** The compiler replaces duplicate passages with the later source declaration. */
31456
+ getEffectivePassage(name) {
31457
+ return this.getPassages(name).sort((a, b) => compareSourceUris(a.uri, b.uri)).at(-1);
31458
+ }
31446
31459
  /** Get the passage containing a specific line in a document. */
31447
31460
  getPassageAt(uri, line) {
31448
31461
  const passages = this.byUri.get(uri);
@@ -31475,11 +31488,11 @@ var init_passage_index = __esm({
31475
31488
  }
31476
31489
  /** Get the StoryVariables passage, if any. */
31477
31490
  getStoryVariables() {
31478
- return this.getPassage("StoryVariables");
31491
+ return this.getEffectivePassage("StoryVariables");
31479
31492
  }
31480
31493
  /** Get the StoryTransients passage, if any. */
31481
31494
  getStoryTransients() {
31482
- return this.getPassage("StoryTransients");
31495
+ return this.getEffectivePassage("StoryTransients");
31483
31496
  }
31484
31497
  /** Get the StoryInit passage, if any. */
31485
31498
  getStoryInit() {
@@ -33898,7 +33911,7 @@ var init_workspace_model = __esm({
33898
33911
  this.declaredVersion = storyDataFormatVersion(this.passages.getAllPassages(), (uri) => this.documents.getText(uri));
33899
33912
  this._target = resolveSpindleTarget(this.installedVersion, this.declaredVersion);
33900
33913
  const declarations = (name) => {
33901
- const passage = this.passages.getPassage(name);
33914
+ const passage = this.passages.getEffectivePassage(name);
33902
33915
  return passage && isRuntimePassage(passage) ? this.markup.get(passage.uri)?.passages.find((p) => p.passage === passage) : void 0;
33903
33916
  };
33904
33917
  const variables = declarations("StoryVariables");
@@ -34205,6 +34218,7 @@ var init_passage_refs = __esm({
34205
34218
 
34206
34219
  // src/core/parsing/link-parser.ts
34207
34220
  function markupOfText(text3) {
34221
+ if (typeof text3 !== "string") return text3;
34208
34222
  if (lastMarkup?.text === text3) return lastMarkup;
34209
34223
  const markup = readText2(text3);
34210
34224
  lastMarkup = markup;
@@ -34228,7 +34242,7 @@ function readText2(text3) {
34228
34242
  return new DocumentMarkup(TEXT_URI, text3, passages, TEXT_CONTEXT);
34229
34243
  }
34230
34244
  function findLinkRuntimeMismatches(text3) {
34231
- if (!text3.includes("[[")) return [];
34245
+ if (!(typeof text3 === "string" ? text3 : text3.text).includes("[[")) return [];
34232
34246
  const found = [];
34233
34247
  for (const ref2 of documentPassageRefs(markupOfText(text3))) {
34234
34248
  if (ref2.form !== "bracket") continue;
@@ -34521,7 +34535,7 @@ function structureDiagnostics(passage, workspace) {
34521
34535
  if (token.type === "macro" && !token.isClose) {
34522
34536
  diagnostics.push(...parentDiagnostics(passage, token, ancestors, workspace));
34523
34537
  diagnostics.push(...childDiagnostics(passage, node, token, workspace));
34524
- diagnostics.push(...loopDiagnostics(passage, token, ancestors));
34538
+ diagnostics.push(...loopDiagnostics(passage, token, ancestors, workspace));
34525
34539
  }
34526
34540
  if (!node.body) continue;
34527
34541
  const inside = [...ancestors, {
@@ -34647,13 +34661,13 @@ function statementEnd(code, from) {
34647
34661
  }
34648
34662
  return code.length;
34649
34663
  }
34650
- function loopDiagnostics(passage, token, ancestors) {
34664
+ function loopDiagnostics(passage, token, ancestors, workspace) {
34651
34665
  const macro = token.name.toLowerCase();
34652
- if (macro !== "computed" && macro !== "set" || !token.rawArgs) return [];
34666
+ if (macro !== "computed" && macro !== "set" || !token.rawArgs || workspace.macros.getMacro(macro)?.source !== "builtin") return [];
34653
34667
  let loop;
34654
34668
  for (let i2 = ancestors.length - 1; i2 >= 0; i2--) {
34655
34669
  const ancestor = ancestors[i2];
34656
- if (ancestor.element) continue;
34670
+ if (ancestor.element || workspace.macros.getMacro(ancestor.name)?.source !== "builtin") continue;
34657
34671
  if (DEFERRED_CONTAINERS.has(ancestor.name)) return [];
34658
34672
  if (ancestor.name === "for") {
34659
34673
  loop = ancestor;
@@ -34782,14 +34796,14 @@ function describeNavigation(passage) {
34782
34796
  }
34783
34797
  function linkDiagnostics(doc) {
34784
34798
  const diagnostics = [];
34785
- for (const link of findLinkRuntimeMismatches(doc.text)) {
34799
+ for (const link of findLinkRuntimeMismatches(doc)) {
34786
34800
  diagnostics.push(makeDiag(
34787
34801
  link.range,
34788
34802
  DiagnosticCode.LinkRuntimeMismatch,
34789
34803
  `Spindle reads this link differently from how it is written: the link macro reads the label as ${JSON.stringify(link.runtime.display)} and a click ${describeNavigation(link.runtime.passage)}, not to ${JSON.stringify(link.target)}.`
34790
34804
  ));
34791
34805
  }
34792
- for (const found of findLiteralLinkInterpolations(doc.text)) {
34806
+ for (const found of findLiteralLinkInterpolations(doc)) {
34793
34807
  diagnostics.push(makeDiag(
34794
34808
  found.range,
34795
34809
  DiagnosticCode.LiteralLinkInterpolation,
@@ -79932,7 +79946,7 @@ function linkable(name) {
79932
79946
  return tokens2.length === 1 && link.type === "link" && link.target === name && !bracketLinkMismatch("label", name);
79933
79947
  }
79934
79948
  function getPassageNameCompletions(workspace) {
79935
- return workspace.passages.getAllPassages().filter((p) => linkable(p.name)).map((p) => ({
79949
+ return workspace.passages.getAllPassages().filter((p) => isRuntimePassage(p) && linkable(p.name)).map((p) => ({
79936
79950
  label: p.name,
79937
79951
  kind: 18,
79938
79952
  // CompletionItemKind.Reference
@@ -79947,6 +79961,7 @@ var init_completions = __esm({
79947
79961
  init_widgets();
79948
79962
  init_passage_refs();
79949
79963
  init_link_runtime();
79964
+ init_passage_parser();
79950
79965
  init_markup_cursor();
79951
79966
  init_markup_symbols();
79952
79967
  VARIABLE_DETAIL = { $: "story variable", "%": "transient variable", _: "temporary variable", "@": "local/parameter variable" };