@rohal12/spindle-lsp 0.15.42 → 0.15.44

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.42";
58
+ VERSION = false ? pkg.version : "0.15.44";
59
59
  }
60
60
  });
61
61
 
@@ -3546,7 +3546,7 @@ var require_identity = __commonJS({
3546
3546
  var SCALAR = /* @__PURE__ */ Symbol.for("yaml.scalar");
3547
3547
  var SEQ = /* @__PURE__ */ Symbol.for("yaml.seq");
3548
3548
  var NODE_TYPE = /* @__PURE__ */ Symbol.for("yaml.node.type");
3549
- var isAlias = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === ALIAS;
3549
+ var isAlias2 = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === ALIAS;
3550
3550
  var isDocument = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === DOC;
3551
3551
  var isMap2 = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === MAP;
3552
3552
  var isPair = (node2) => !!node2 && typeof node2 === "object" && node2[NODE_TYPE] === PAIR;
@@ -3581,7 +3581,7 @@ var require_identity = __commonJS({
3581
3581
  exports.SCALAR = SCALAR;
3582
3582
  exports.SEQ = SEQ;
3583
3583
  exports.hasAnchor = hasAnchor;
3584
- exports.isAlias = isAlias;
3584
+ exports.isAlias = isAlias2;
3585
3585
  exports.isCollection = isCollection;
3586
3586
  exports.isDocument = isDocument;
3587
3587
  exports.isMap = isMap2;
@@ -36348,12 +36348,13 @@ function childDiagnostics(passage, node2, token, workspace) {
36348
36348
  if (!constraints || constraints.length === 0 || !node2.body?.close) return [];
36349
36349
  const direct = [...node2.body.children];
36350
36350
  for (const branch of node2.body.branches) direct.push({ token: branch.tag, start: branch.tag.start, end: branch.tag.end }, ...branch.children);
36351
+ const branchTags = new Set(node2.body.branches.map((branch) => branch.tag));
36351
36352
  const consumesOptions = macro?.source === "builtin" && ["listbox", "cycle"].includes(token.name.toLowerCase());
36352
36353
  const counts = /* @__PURE__ */ Object.create(null);
36353
36354
  for (const child of direct) {
36354
36355
  if (child.token.type !== "macro" || child.token.isClose) continue;
36355
36356
  const key = child.token.name.toLowerCase();
36356
- if (consumesOptions && key === "option" || workspace.getEffectiveMacro(key)) counts[key] = (counts[key] ?? 0) + 1;
36357
+ if (branchTags.has(child.token) || consumesOptions && key === "option" || workspace.getEffectiveMacro(key)) counts[key] = (counts[key] ?? 0) + 1;
36357
36358
  }
36358
36359
  const diagnostics = [];
36359
36360
  const range2 = passage.range(token.start, token.end);
@@ -88740,6 +88741,13 @@ function passageMacroHeads(passage) {
88740
88741
  function documentMacroHeads(doc) {
88741
88742
  return doc.passages.flatMap((passage) => passage.isMarkup ? [...passageMacroHeads(passage)] : []);
88742
88743
  }
88744
+ function* workspaceMacroHeads(workspace) {
88745
+ for (const uri of workspace.documents.getUris()) {
88746
+ const doc = workspace.markup.get(uri);
88747
+ if (!doc) continue;
88748
+ for (const head of documentMacroHeads(doc)) yield { uri, head };
88749
+ }
88750
+ }
88743
88751
  function macroHeadAt(doc, position) {
88744
88752
  const passage = doc.passageAt(position);
88745
88753
  if (!passage?.isMarkup) return void 0;
@@ -89248,13 +89256,9 @@ function computeRename(uri, position, newName, workspace) {
89248
89256
  if (workspace.passages.getPassage(newName)) {
89249
89257
  throw new RenameError(`Cannot rename to ${JSON.stringify(newName)}: a passage with that name already exists.`).at(uri, symbol2.range);
89250
89258
  }
89251
- for (const documentUri of workspace.documents.getUris()) {
89252
- const doc = workspace.markup.get(documentUri);
89253
- if (!doc) continue;
89254
- for (const head of documentMacroHeads(doc)) {
89255
- if (!head.closing && workspace.getEffectiveMacro(head.name) && workspace.macros.hasUnsafeConfiguredPassages(head.name)) {
89256
- throw new RenameError(`Cannot rename: {${head.name}} has configured passage parameters whose positions are ambiguous, repeated or conflict with its runtime signature.`).at(documentUri, head.range);
89257
- }
89259
+ for (const { uri: documentUri, head } of workspaceMacroHeads(workspace)) {
89260
+ if (!head.closing && workspace.getEffectiveMacro(head.name) && workspace.macros.hasUnsafeConfiguredPassages(head.name)) {
89261
+ throw new RenameError(`Cannot rename: {${head.name}} has configured passage parameters whose positions are ambiguous, repeated or conflict with its runtime signature.`).at(documentUri, head.range);
89258
89262
  }
89259
89263
  }
89260
89264
  const refEdits = [];
@@ -89632,6 +89636,18 @@ function computeCodeLenses(uri, workspace) {
89632
89636
  }
89633
89637
  const variableCounts = variableLines.size > 0 ? workspace.variables.getUsageCounts() : /* @__PURE__ */ new Map();
89634
89638
  const widgetLines = new Map(workspace.widgets.getAllWidgets().filter((w) => w.uri === uri).map((w) => [w.range.start.line, w.name]));
89639
+ const widgetCounts = /* @__PURE__ */ new Map();
89640
+ for (const name of widgetLines.values()) {
89641
+ if (!workspace.getEffectiveMacro(name)) widgetCounts.set(name.toLowerCase(), 0);
89642
+ }
89643
+ if (widgetCounts.size > 0) {
89644
+ for (const { head } of workspaceMacroHeads(workspace)) {
89645
+ if (!head.invocation || head.closing) continue;
89646
+ const name = head.name.toLowerCase();
89647
+ const count = widgetCounts.get(name);
89648
+ if (count !== void 0) widgetCounts.set(name, count + 1);
89649
+ }
89650
+ }
89635
89651
  for (let lineNum = 0; lineNum < lines.length; lineNum++) {
89636
89652
  const line = lines[lineNum];
89637
89653
  const header = parsePassageHeader(line, lineNum);
@@ -89644,7 +89660,7 @@ function computeCodeLenses(uri, workspace) {
89644
89660
  }
89645
89661
  const widgetName2 = widgetLines.get(lineNum);
89646
89662
  if (widgetName2 !== void 0) {
89647
- const usageCount = findWidgetReferences(widgetName2, workspace, false, false).length;
89663
+ const usageCount = widgetCounts.get(widgetName2.toLowerCase()) ?? 0;
89648
89664
  addLens(lineNum, `${usageCount} usage${usageCount !== 1 ? "s" : ""}`);
89649
89665
  }
89650
89666
  const varName = variableLines.get(lineNum);
@@ -89667,6 +89683,7 @@ var init_code_lens = __esm({
89667
89683
  "use strict";
89668
89684
  init_text();
89669
89685
  init_passage_parser();
89686
+ init_macro_heads();
89670
89687
  init_references();
89671
89688
  codeLensPlugin = {
89672
89689
  id: "code-lens",
@@ -90025,7 +90042,11 @@ function addMacroToYamlConfig(text3, macroName) {
90025
90042
  if (doc.contents !== null && !(0, import_yaml3.isMap)(doc.contents)) return null;
90026
90043
  const path2 = macrosPath(doc.toJS());
90027
90044
  const parent = path2.length > 1 ? doc.getIn(path2.slice(0, -1), true) : doc.contents;
90028
- const macros = doc.getIn(path2, true);
90045
+ let macros = doc.getIn(path2, true);
90046
+ if ((0, import_yaml3.isAlias)(macros)) {
90047
+ macros = doc.createNode(macros.toJS(doc));
90048
+ doc.setIn(path2, macros);
90049
+ }
90029
90050
  if ((0, import_yaml3.isMap)(macros) && definesMacro(macros.toJS(doc), macroName)) return null;
90030
90051
  if ((0, import_yaml3.isMap)(parent) && (0, import_yaml3.isMap)(macros) && !macros.flow && macros.items.length > 0 && macros.range) {
90031
90052
  const macrosKey = parent.items.find((p) => (0, import_yaml3.isScalar)(p.key) && p.key.value === "macros")?.key;