@rohal12/spindle-lsp 0.15.0 → 0.15.1

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
@@ -50,6 +50,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
50
50
  ));
51
51
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
52
52
 
53
+ // src/version.ts
54
+ var VERSION;
55
+ var init_version = __esm({
56
+ "src/version.ts"() {
57
+ "use strict";
58
+ VERSION = false ? pkg.version : "0.15.1";
59
+ }
60
+ });
61
+
53
62
  // node_modules/glob/dist/esm/index.min.js
54
63
  import { fileURLToPath as Wi } from "node:url";
55
64
  import { posix as mi, win32 as re } from "node:path";
@@ -23372,10 +23381,11 @@ function parsePassageHeader(rawLine, lineNumber) {
23372
23381
  const delimiter = /[\[\]{}]/g;
23373
23382
  delimiter.lastIndex = nameStart;
23374
23383
  const first = delimiter.exec(escaped);
23375
- const nameEnd = first?.index ?? line.length;
23376
- const name = line.slice(nameStart, nameEnd).trim();
23384
+ const boundary = first?.index ?? line.length;
23385
+ const nameEnd = escaped.slice(0, boundary).trimEnd().length;
23386
+ const name = line.slice(nameStart, nameEnd).replace(/\\(.)/g, "$1").trim();
23377
23387
  if (!name) return null;
23378
- let rest = nameEnd;
23388
+ let rest = boundary;
23379
23389
  let tags = [];
23380
23390
  if (escaped[rest] === "[") {
23381
23391
  const end = escaped.indexOf("]", rest + 1);
@@ -23400,14 +23410,13 @@ function parsePassageHeader(rawLine, lineNumber) {
23400
23410
  end: { line: lineNumber, character: line.length }
23401
23411
  };
23402
23412
  const nameCharStart = nameStart;
23403
- const nameCharEnd = nameCharStart + name.length;
23413
+ const nameCharEnd = nameEnd;
23404
23414
  const nameRange = {
23405
23415
  start: { line: lineNumber, character: nameCharStart },
23406
23416
  end: { line: lineNumber, character: nameCharEnd }
23407
23417
  };
23408
23418
  return {
23409
- name: name.replace(/\\(.)/g, "$1"),
23410
- // unescape
23419
+ name,
23411
23420
  tags,
23412
23421
  meta: meta3,
23413
23422
  headerRange,
@@ -31765,6 +31774,13 @@ var init_widget_registry = __esm({
31765
31774
  getAllWidgets() {
31766
31775
  return Array.from(this.widgets.values());
31767
31776
  }
31777
+ /** The effective widget whose declared name contains the cursor. */
31778
+ definitionAt(uri, position) {
31779
+ return this.getAllWidgets().find((widget) => {
31780
+ const { start, end } = widget.nameRange;
31781
+ return widget.uri === uri && position.line === start.line && position.character >= start.character && position.character <= end.character;
31782
+ });
31783
+ }
31768
31784
  /**
31769
31785
  * Record the macros opened in a document (its tags and those in the labels
31770
31786
  * and attribute values that hold markup), replacing any previous record for
@@ -34007,6 +34023,10 @@ function structureDiagnostics(passage, workspace) {
34007
34023
  }
34008
34024
  };
34009
34025
  visit(passage.pairing.nodes, []);
34026
+ for (const piece of passage.pieces) {
34027
+ if (piece.kind !== "text") continue;
34028
+ visit(pairMarkup(piece.tokens, { isBlock: (name) => workspace.isContainer(name) }).nodes, []);
34029
+ }
34010
34030
  return diagnostics;
34011
34031
  }
34012
34032
  function parentDiagnostics(passage, token, ancestors, workspace) {
@@ -34539,7 +34559,7 @@ function formatSarif(results) {
34539
34559
  tool: {
34540
34560
  driver: {
34541
34561
  name: "spindle-lsp",
34542
- version: "0.1.0",
34562
+ version: VERSION,
34543
34563
  rules: Array.from(ruleIds).map((id) => ({
34544
34564
  id,
34545
34565
  shortDescription: { text: `Spindle diagnostic ${id}` }
@@ -34556,6 +34576,7 @@ var sarifLevelMap;
34556
34576
  var init_sarif = __esm({
34557
34577
  "src/cli/reporters/sarif.ts"() {
34558
34578
  "use strict";
34579
+ init_version();
34559
34580
  sarifLevelMap = {
34560
34581
  error: "error",
34561
34582
  warning: "warning",
@@ -34813,7 +34834,7 @@ async function loadPrettier(filePath) {
34813
34834
  if (!p) return void 0;
34814
34835
  try {
34815
34836
  const path = filePath?.startsWith("file:") ? fileURLToPath3(filePath) : filePath;
34816
- const resolved = await p.resolveConfig(path ?? resolve5(process.cwd(), "story.tw"));
34837
+ const resolved = await p.resolveConfig(path ?? resolve5(process.cwd(), "story.tw"), { useCache: false });
34817
34838
  return { prettier: p, options: { tabWidth: 2, ...resolved ?? {} } };
34818
34839
  } catch {
34819
34840
  return { prettier: p, options: { tabWidth: 2 } };
@@ -34867,8 +34888,7 @@ async function formatLf2(text3, options) {
34867
34888
  }
34868
34889
  }
34869
34890
  if (passage.header) {
34870
- const header = PASSAGE_HEADER_REGEX.test(passage.header) ? normalizePassageHeader(passage.header) : passage.header;
34871
- resultLines.push(header.replace(/\s+$/, ""));
34891
+ resultLines.push(normalizePassageHeader(passage.header));
34872
34892
  }
34873
34893
  if (passage.body === "") continue;
34874
34894
  const role = parsePassageHeader(passage.header, passage.startLine);
@@ -34889,26 +34909,14 @@ async function formatRange(text3, _range, options) {
34889
34909
  return formatDocument(text3, options);
34890
34910
  }
34891
34911
  function normalizePassageHeader(line) {
34892
- const headerMatch = line.match(/^::\s*(.*)/);
34893
- if (!headerMatch) return line;
34894
- const rest = headerMatch[1];
34895
- const unescaped = rest.replace(/\\./g, "ec");
34896
- const bracketIdx = unescaped.indexOf("[");
34897
- const braceIdx = unescaped.indexOf("{");
34898
- let name;
34899
- let suffix = "";
34900
- if (bracketIdx !== -1 && (braceIdx === -1 || bracketIdx < braceIdx)) {
34901
- name = rest.substring(0, bracketIdx).trim();
34902
- suffix = " " + rest.substring(bracketIdx).trim();
34903
- } else if (braceIdx !== -1) {
34904
- name = rest.substring(0, braceIdx).trim();
34905
- suffix = " " + rest.substring(braceIdx).trim();
34906
- } else {
34907
- name = rest.trim();
34908
- }
34909
- return `:: ${name}${suffix}`;
34910
- }
34911
- var PASSAGE_HEADER_REGEX, DEFAULT_DEDENTING2, BUILTIN_CONTAINERS, formatPlugin;
34912
+ const header = parsePassageHeader(line, 0);
34913
+ if (!header) return line;
34914
+ const { start, end } = header.nameRange;
34915
+ const name = line.slice(start.character, end.character);
34916
+ const suffix = line.slice(end.character).trim();
34917
+ return `:: ${name}${suffix ? ` ${suffix}` : ""}`;
34918
+ }
34919
+ var DEFAULT_DEDENTING2, BUILTIN_CONTAINERS, formatPlugin;
34912
34920
  var init_format = __esm({
34913
34921
  "src/plugins/format.ts"() {
34914
34922
  "use strict";
@@ -34916,7 +34924,6 @@ var init_format = __esm({
34916
34924
  init_passage_parser();
34917
34925
  init_segment();
34918
34926
  init_prettier_bridge();
34919
- PASSAGE_HEADER_REGEX = /^(::)\s*/;
34920
34927
  DEFAULT_DEDENTING2 = /* @__PURE__ */ new Set(["else", "elseif", "next", "case", "default"]);
34921
34928
  BUILTIN_CONTAINERS = new Set(builtinMacros.filter((m) => m.block).map((m) => m.name.toLowerCase()));
34922
34929
  formatPlugin = {
@@ -77681,6 +77688,30 @@ function getSignatureHelp(uri, position, workspace) {
77681
77688
  return { signatures, activeSignature, activeParameter };
77682
77689
  }
77683
77690
  }
77691
+ if (macroInfo) {
77692
+ const definitions = macroInfo.parameters === void 0 ? macroInfo.parameterDefs : void 0;
77693
+ if (!definitions?.length) return null;
77694
+ const parameters = definitions.map((parameter) => ({
77695
+ label: parameter.required ? parameter.name : `[${parameter.name}]`,
77696
+ documentation: [parameter.description, `Type: ${parameter.type}`].filter(Boolean).join("\n\n")
77697
+ }));
77698
+ const positional = definitions.every((p) => p.type === "string" || p.type === "number") && argument < parameters.length;
77699
+ const documentation = [
77700
+ macroInfo.description,
77701
+ ...!positional ? parameters.map((p) => `${p.label}
77702
+
77703
+ ${p.documentation}`) : []
77704
+ ].filter(Boolean).join("\n\n") || void 0;
77705
+ return {
77706
+ signatures: [{
77707
+ label: `{${[macroName, ...parameters.map((p) => p.label)].join(" ")}}`,
77708
+ documentation,
77709
+ parameters: positional ? parameters : []
77710
+ }],
77711
+ activeSignature: 0,
77712
+ activeParameter: positional ? argument : 0
77713
+ };
77714
+ }
77684
77715
  const widget = workspace.widgets.getWidget(macroName);
77685
77716
  if (widget && widget.params.length > 0) {
77686
77717
  const paramLabels = widget.params;
@@ -77885,6 +77916,8 @@ function findReferences(uri, position, workspace, includeDeclaration) {
77885
77916
  if (variable) {
77886
77917
  return variable.sigil === "%" ? findTransientReferences(variable.name, workspace, includeDeclaration) : findVariableReferences(variable.name, workspace, includeDeclaration);
77887
77918
  }
77919
+ const declaration = workspace.widgets.definitionAt(uri, position);
77920
+ if (declaration) return findWidgetReferences(declaration.name, workspace, includeDeclaration);
77888
77921
  const doc = workspace.markup.get(uri);
77889
77922
  const head = doc && macroHeadAt(doc, position);
77890
77923
  if (head) {
@@ -77963,6 +77996,7 @@ function findWidgetReferences(widgetName2, workspace, includeDeclaration) {
77963
77996
  if (includeDeclaration && widget) {
77964
77997
  locations.push({ uri: widget.uri, range: widget.range });
77965
77998
  }
77999
+ if (workspace.macros.getMacro(widgetName2)) return locations;
77966
78000
  const lowerName2 = widgetName2.toLowerCase();
77967
78001
  const isBlock = widget?.block ?? false;
77968
78002
  for (const docUri of workspace.documents.getUris()) {
@@ -78241,12 +78275,8 @@ function resolveSymbolAtCursor(uri, position, workspace) {
78241
78275
  if (variable) {
78242
78276
  return { kind: "variable", name: variable.name, sigil: variable.sigil, range: variable.range };
78243
78277
  }
78244
- for (const widget of workspace.widgets.getAllWidgets()) {
78245
- const { start, end } = widget.nameRange;
78246
- if (widget.uri === uri && position.line === start.line && position.character >= start.character && position.character <= end.character) {
78247
- return { kind: "widget", name: widget.name, range: widget.nameRange };
78248
- }
78249
- }
78278
+ const declaration = workspace.widgets.definitionAt(uri, position);
78279
+ if (declaration) return { kind: "widget", name: declaration.name, range: declaration.nameRange };
78250
78280
  const doc = workspace.markup.get(uri);
78251
78281
  const head = doc && macroHeadAt(doc, position);
78252
78282
  if (head) {
@@ -79606,8 +79636,8 @@ var init_server4 = __esm({
79606
79636
  });
79607
79637
 
79608
79638
  // src/bin.ts
79639
+ init_version();
79609
79640
  var args = process.argv.slice(2);
79610
- var VERSION = "0.15.0";
79611
79641
  var HELP = `spindle-lsp v${VERSION}
79612
79642
  Language Server Protocol server for Spindle story format
79613
79643