prettier-plugin-wolfram 0.7.14 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-wolfram",
3
- "version": "0.7.14",
3
+ "version": "0.7.15",
4
4
  "description": "Prettier plugin for Wolfram Language using tree-sitter",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,6 +10,7 @@ import {
10
10
  withMarkedTrailingCommentDocs,
11
11
  } from "../docComments.js";
12
12
  import { normalizeWolframOptions } from "../../options.js";
13
+ import { buildDispatchSets } from "../specialForms.js";
13
14
  const { group, indent, softline, line, hardline } = builders;
14
15
 
15
16
  const BRACKET_KINDS = new Set(["Token`OpenSquare", "Token`CloseSquare"]);
@@ -40,6 +41,24 @@ function hasCommentBoundary(leftEntry, rightEntry) {
40
41
  return isComment(leftEntry?.node) || isComment(rightEntry?.node);
41
42
  }
42
43
 
44
+ function callHeadName(node) {
45
+ return node.head?.type === "LeafNode" && node.head.kind === "Symbol"
46
+ ? node.head.value
47
+ : null;
48
+ }
49
+
50
+ function shouldBreakCommentedSpecialCall(node, options, entries) {
51
+ if (!entries.some((entry) => isComment(entry.node))) return false;
52
+ const name = callHeadName(node);
53
+ if (!name) return false;
54
+ const sets = buildDispatchSets(options);
55
+ return (
56
+ sets.conditionFirst.has(name) ||
57
+ sets.blockStructure.has(name) ||
58
+ sets.caseStructure.has(name)
59
+ );
60
+ }
61
+
43
62
  function commentBoundary(leftEntry, rightEntry, options, fallback = line) {
44
63
  if (!leftEntry || !rightEntry) return fallback;
45
64
  return commentBoundarySeparator(
@@ -321,5 +340,8 @@ export function printCall(path, options, print, node) {
321
340
  );
322
341
  const contents = [head, "[", indent([softline, ...docs]), softline, "]"];
323
342
 
324
- return grouped(contents, alignmentGroupId);
343
+ const shouldBreak = shouldBreakCommentedSpecialCall(node, options, entries);
344
+ return alignmentGroupId
345
+ ? group(contents, { id: alignmentGroupId, shouldBreak })
346
+ : group(contents, { shouldBreak });
325
347
  }
@@ -95,6 +95,10 @@ function isCommaToken(node) {
95
95
  return node?.type === "LeafNode" && node.kind === "Token`Comma";
96
96
  }
97
97
 
98
+ function isCommentNode(node) {
99
+ return node?.type === "LeafNode" && node.kind === "Token`Comment";
100
+ }
101
+
98
102
  function isStringJoinOperatorToken(node) {
99
103
  return node?.type === "LeafNode" && node.kind === "Token`LessGreater";
100
104
  }
@@ -459,7 +463,7 @@ function semanticGroupEntries(callNode, groupNode) {
459
463
  ) {
460
464
  const commaWrapperIdx = groupNode.children.indexOf(semanticChildren[0]);
461
465
  return semanticChildren[0].children.reduce((entries, child, idx) => {
462
- if (isTrivia(child)) return entries;
466
+ if (isTrivia(child) || isCommentNode(child)) return entries;
463
467
  if (child.type === "LeafNode" && child.kind === "Token`Comma")
464
468
  return entries;
465
469
  entries.push({
@@ -477,7 +481,7 @@ function semanticGroupEntries(callNode, groupNode) {
477
481
  }
478
482
 
479
483
  return (groupNode.children ?? []).reduce((entries, child, idx) => {
480
- if (isTrivia(child)) return entries;
484
+ if (isTrivia(child) || isCommentNode(child)) return entries;
481
485
  if (
482
486
  child.type === "LeafNode" &&
483
487
  (child.kind === "Token`OpenCurly" ||