@rohal12/spindle-lsp 0.15.14 → 0.15.15

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.14";
58
+ VERSION = false ? pkg.version : "0.15.15";
59
59
  }
60
60
  });
61
61
 
@@ -33390,6 +33390,20 @@ var init_markup_index = __esm({
33390
33390
  }
33391
33391
  });
33392
33392
 
33393
+ // src/core/workspace/story-data.ts
33394
+ import { createRequire as createCompilerRequire2 } from "node:module";
33395
+ function readStoryData(content2) {
33396
+ const { StoryBuilder } = createCompilerRequire2(import.meta.url)("@rohal12/twee-ts");
33397
+ const builder = new StoryBuilder();
33398
+ builder.add({ name: "StoryData", tags: [], text: content2 }, []);
33399
+ return builder.build().twine2;
33400
+ }
33401
+ var init_story_data = __esm({
33402
+ "src/core/workspace/story-data.ts"() {
33403
+ "use strict";
33404
+ }
33405
+ });
33406
+
33393
33407
  // src/core/workspace/spindle-version.ts
33394
33408
  import { existsSync as existsSync3, readFileSync as readFileSync5 } from "node:fs";
33395
33409
  import { dirname as dirname2, join as join3, resolve as resolve4 } from "node:path";
@@ -33500,31 +33514,14 @@ function isSpindleFormatName(name) {
33500
33514
  return name.trim().toLowerCase() === "spindle";
33501
33515
  }
33502
33516
  function readStoryDataFormat(content2) {
33503
- let data2;
33504
- try {
33505
- data2 = JSON.parse(content2);
33506
- } catch {
33507
- return void 0;
33508
- }
33509
- if (typeof data2 !== "object" || data2 === null || Array.isArray(data2)) return void 0;
33510
- const format = data2.format;
33511
- if (typeof format !== "string") return void 0;
33512
- return format.trim() || void 0;
33517
+ return readStoryData(content2).format.trim() || void 0;
33513
33518
  }
33514
33519
  function readStoryDataFormatVersion(content2) {
33515
- let data2;
33516
- try {
33517
- data2 = JSON.parse(content2);
33518
- } catch {
33520
+ const metadata2 = readStoryData(content2);
33521
+ if (metadata2.format.trim() && !isSpindleFormatName(metadata2.format)) {
33519
33522
  return void 0;
33520
33523
  }
33521
- if (typeof data2 !== "object" || data2 === null || Array.isArray(data2)) return void 0;
33522
- const record2 = data2;
33523
- if (typeof record2.format === "string" && record2.format.trim() && !isSpindleFormatName(record2.format)) {
33524
- return void 0;
33525
- }
33526
- const version2 = record2["format-version"];
33527
- return typeof version2 === "string" && version2.trim() ? version2.trim() : void 0;
33524
+ return metadata2.formatVersion.trim() || void 0;
33528
33525
  }
33529
33526
  function resolveStoryFormat(declared) {
33530
33527
  let foreign;
@@ -33619,6 +33616,7 @@ var init_story_format = __esm({
33619
33616
  "use strict";
33620
33617
  init_document_store();
33621
33618
  init_passage_index();
33619
+ init_story_data();
33622
33620
  init_macro_sources();
33623
33621
  init_spindle_version();
33624
33622
  UNDECLARED_STORY_FORMAT = { name: void 0, isSpindle: true };
@@ -81083,9 +81081,9 @@ function preserveEntryPassage(oldName, newName, workspace, addEdit) {
81083
81081
  } catch {
81084
81082
  throw new RenameError("Cannot preserve the entry passage: StoryData must contain a valid JSON object.").at(declaration.uri, declaration.nameRange);
81085
81083
  }
81086
- const start = typeof data2.start === "string" && data2.start ? data2.start : "Start";
81084
+ const start = readStoryData(passage.content).start || "Start";
81087
81085
  if (start !== oldName) continue;
81088
- if (Object.hasOwn(data2, "start") && typeof data2.start !== "string") {
81086
+ if (Object.entries(data2).some(([key, value]) => isEntryField(key) && typeof value !== "string")) {
81089
81087
  throw new RenameError("Cannot preserve the entry passage: StoryData.start must be a string.").at(declaration.uri, declaration.nameRange);
81090
81088
  }
81091
81089
  let depth = 0;
@@ -81100,7 +81098,7 @@ function preserveEntryPassage(oldName, newName, workspace, addEdit) {
81100
81098
  literal(text3, index) {
81101
81099
  if (depth !== 1 || !text3.startsWith('"')) return;
81102
81100
  const isKey = /^\s*:/.test(passage.content.slice(index + text3.length));
81103
- if (isKey) startValue = JSON.parse(text3) === "start";
81101
+ if (isKey) startValue = isEntryField(JSON.parse(text3));
81104
81102
  else if (startValue) {
81105
81103
  addEdit(declaration.uri, passage.range(index, index + text3.length), JSON.stringify(newName));
81106
81104
  replaced = true;
@@ -81120,6 +81118,9 @@ function preserveEntryPassage(oldName, newName, workspace, addEdit) {
81120
81118
  addEdit(declaration.uri, { start: end, end }, `${eol}${eol}:: StoryData${eol}${JSON.stringify({ start: newName })}${eol}`);
81121
81119
  }
81122
81120
  }
81121
+ function isEntryField(key) {
81122
+ return readStoryData(JSON.stringify({ [key]: "Start" })).start === "Start";
81123
+ }
81123
81124
  function passageHeaderProblem(name) {
81124
81125
  if (name.trim() === "") return "a passage name cannot be empty";
81125
81126
  if (/[\r\n]/.test(name)) return "a passage header is a single line, so the name cannot contain a line break";
@@ -81237,6 +81238,7 @@ var init_rename = __esm({
81237
81238
  "src/plugins/rename.ts"() {
81238
81239
  "use strict";
81239
81240
  import_vscode_languageserver2 = __toESM(require_api3(), 1);
81241
+ init_story_data();
81240
81242
  init_tooling();
81241
81243
  init_source_view();
81242
81244
  init_text();