@nokout/big-dill-core 0.0.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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +202 -0
  3. package/dist/completion/complete.d.ts +40 -0
  4. package/dist/completion/complete.d.ts.map +1 -0
  5. package/dist/completion/complete.js +134 -0
  6. package/dist/completion/complete.js.map +1 -0
  7. package/dist/format/tables.d.ts +7 -0
  8. package/dist/format/tables.d.ts.map +1 -0
  9. package/dist/format/tables.js +87 -0
  10. package/dist/format/tables.js.map +1 -0
  11. package/dist/gherkin/parser.d.ts +28 -0
  12. package/dist/gherkin/parser.d.ts.map +1 -0
  13. package/dist/gherkin/parser.js +44 -0
  14. package/dist/gherkin/parser.js.map +1 -0
  15. package/dist/index.d.ts +25 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +92 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/ipc/server.d.ts +13 -0
  20. package/dist/ipc/server.d.ts.map +1 -0
  21. package/dist/ipc/server.js +106 -0
  22. package/dist/ipc/server.js.map +1 -0
  23. package/dist/lint/rules.d.ts +46 -0
  24. package/dist/lint/rules.d.ts.map +1 -0
  25. package/dist/lint/rules.js +387 -0
  26. package/dist/lint/rules.js.map +1 -0
  27. package/dist/protocol/types.d.ts +97 -0
  28. package/dist/protocol/types.d.ts.map +1 -0
  29. package/dist/protocol/types.js +5 -0
  30. package/dist/protocol/types.js.map +1 -0
  31. package/dist/pytest/runner.d.ts +29 -0
  32. package/dist/pytest/runner.d.ts.map +1 -0
  33. package/dist/pytest/runner.js +225 -0
  34. package/dist/pytest/runner.js.map +1 -0
  35. package/dist/results/outcomes.d.ts +36 -0
  36. package/dist/results/outcomes.d.ts.map +1 -0
  37. package/dist/results/outcomes.js +69 -0
  38. package/dist/results/outcomes.js.map +1 -0
  39. package/dist/steps/browser.d.ts +42 -0
  40. package/dist/steps/browser.d.ts.map +1 -0
  41. package/dist/steps/browser.js +110 -0
  42. package/dist/steps/browser.js.map +1 -0
  43. package/dist/steps/documentation.d.ts +10 -0
  44. package/dist/steps/documentation.d.ts.map +1 -0
  45. package/dist/steps/documentation.js +39 -0
  46. package/dist/steps/documentation.js.map +1 -0
  47. package/dist/steps/references.d.ts +10 -0
  48. package/dist/steps/references.d.ts.map +1 -0
  49. package/dist/steps/references.js +34 -0
  50. package/dist/steps/references.js.map +1 -0
  51. package/dist/steps/stepCache.d.ts +50 -0
  52. package/dist/steps/stepCache.d.ts.map +1 -0
  53. package/dist/steps/stepCache.js +149 -0
  54. package/dist/steps/stepCache.js.map +1 -0
  55. package/dist/steps/stubs.d.ts +10 -0
  56. package/dist/steps/stubs.d.ts.map +1 -0
  57. package/dist/steps/stubs.js +46 -0
  58. package/dist/steps/stubs.js.map +1 -0
  59. package/dist/steps/unimplemented.d.ts +10 -0
  60. package/dist/steps/unimplemented.d.ts.map +1 -0
  61. package/dist/steps/unimplemented.js +26 -0
  62. package/dist/steps/unimplemented.js.map +1 -0
  63. package/dist/symbols/outline.d.ts +13 -0
  64. package/dist/symbols/outline.d.ts.map +1 -0
  65. package/dist/symbols/outline.js +38 -0
  66. package/dist/symbols/outline.js.map +1 -0
  67. package/dist/tokens/semanticTokens.d.ts +13 -0
  68. package/dist/tokens/semanticTokens.d.ts.map +1 -0
  69. package/dist/tokens/semanticTokens.js +77 -0
  70. package/dist/tokens/semanticTokens.js.map +1 -0
  71. package/dist/tree/builder.d.ts +40 -0
  72. package/dist/tree/builder.d.ts.map +1 -0
  73. package/dist/tree/builder.js +178 -0
  74. package/dist/tree/builder.js.map +1 -0
  75. package/package.json +58 -0
  76. package/src/completion/complete.ts +165 -0
  77. package/src/format/tables.ts +108 -0
  78. package/src/gherkin/parser.ts +69 -0
  79. package/src/index.ts +136 -0
  80. package/src/ipc/server.ts +84 -0
  81. package/src/lint/rules.ts +425 -0
  82. package/src/protocol/types.ts +114 -0
  83. package/src/pytest/runner.ts +249 -0
  84. package/src/results/outcomes.ts +102 -0
  85. package/src/steps/browser.ts +105 -0
  86. package/src/steps/documentation.ts +43 -0
  87. package/src/steps/references.ts +33 -0
  88. package/src/steps/stepCache.ts +168 -0
  89. package/src/steps/stubs.ts +48 -0
  90. package/src/steps/unimplemented.ts +31 -0
  91. package/src/symbols/outline.ts +52 -0
  92. package/src/tokens/semanticTokens.ts +98 -0
  93. package/src/tree/builder.ts +187 -0
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ // Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
3
+ // Licensed under the MIT License.
4
+ //
5
+ // Computes the shape of the test tree from a discovery payload.
6
+ //
7
+ // Returns plain nodes. Turning them into whatever the host uses to display a
8
+ // tree — TestItems, for a VS Code host — is the host's job.
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.buildTestTree = buildTestTree;
44
+ const path = __importStar(require("path"));
45
+ function toSentenceCase(s) {
46
+ const spaced = s.replace(/_/g, ' ');
47
+ return spaced.charAt(0).toUpperCase() + spaced.slice(1);
48
+ }
49
+ function isTestItem(node) {
50
+ return node.type_ === 'test';
51
+ }
52
+ function collectLeaves(node) {
53
+ if (isTestItem(node))
54
+ return [node];
55
+ const results = [];
56
+ for (const child of node.children) {
57
+ results.push(...collectLeaves(child));
58
+ }
59
+ return results;
60
+ }
61
+ /** pytest reports line numbers 1-based, and as a string in some payloads. */
62
+ function toRange(lineno) {
63
+ const n = typeof lineno === 'string' ? parseInt(lineno, 10) : lineno;
64
+ if (n === undefined || !Number.isFinite(n) || n <= 0)
65
+ return undefined;
66
+ return { start: { line: n - 1, character: 0 }, end: { line: n, character: 0 } };
67
+ }
68
+ function findChild(children, id) {
69
+ return children.find((c) => c.id === id);
70
+ }
71
+ /**
72
+ * Ensure a folder chain exists, returning the children array of the deepest one.
73
+ * An empty `parts` yields the roots, which is how a .feature file sitting at the
74
+ * workspace root is handled.
75
+ */
76
+ function ensureFolderPath(roots, parts) {
77
+ let children = roots;
78
+ for (const part of parts) {
79
+ let existing = findChild(children, part);
80
+ if (!existing) {
81
+ existing = {
82
+ id: part,
83
+ label: `${toSentenceCase(part)} 🗂`,
84
+ // Note: only the segment, not the accumulated path. A nested folder
85
+ // therefore claims <cwd>/<segment> rather than its true location.
86
+ // Preserved deliberately — changing it is a separate fix.
87
+ uri: { path: part },
88
+ canResolveChildren: true,
89
+ tags: [],
90
+ children: [],
91
+ };
92
+ children.push(existing);
93
+ }
94
+ children = existing.children;
95
+ }
96
+ return children;
97
+ }
98
+ /**
99
+ * Build the tree.
100
+ *
101
+ * BDD items — those carrying `feature_path` — are organised under a hierarchy
102
+ * mirroring the .feature file layout. Anything else falls back to a flat
103
+ * file-based hierarchy.
104
+ */
105
+ function buildTestTree(rootNode) {
106
+ const roots = [];
107
+ const idToRunId = new Map();
108
+ const leaves = collectLeaves(rootNode);
109
+ const bddLeaves = leaves.filter((l) => l.feature_path !== undefined);
110
+ const plainLeaves = leaves.filter((l) => l.feature_path === undefined);
111
+ for (const leaf of bddLeaves) {
112
+ const featurePath = leaf.feature_path;
113
+ const scenarioName = leaf.scenario_name ?? leaf.name;
114
+ const parsed = path.parse(featurePath);
115
+ const dirParts = parsed.dir ? parsed.dir.split('/') : [];
116
+ const folderChildren = ensureFolderPath(roots, dirParts);
117
+ let featureFile = findChild(folderChildren, featurePath);
118
+ if (!featureFile) {
119
+ const featureTags = leaf.feature_tags ?? [];
120
+ featureFile = {
121
+ id: featurePath,
122
+ label: `${leaf.feature_name ?? toSentenceCase(parsed.name)} 🗒`,
123
+ uri: { path: featurePath },
124
+ canResolveChildren: true,
125
+ tags: [...featureTags],
126
+ ...(featureTags.length
127
+ ? { description: featureTags.map((t) => `@${t}`).join(' ') }
128
+ : {}),
129
+ children: [],
130
+ };
131
+ folderChildren.push(featureFile);
132
+ }
133
+ const scenarioTags = leaf.scenario_tags ?? [];
134
+ const id = `${featurePath}::${scenarioName}`;
135
+ const range = toRange(leaf.lineno);
136
+ featureFile.children.push({
137
+ id,
138
+ label: scenarioName,
139
+ uri: { path: featurePath },
140
+ canResolveChildren: false,
141
+ tags: [...(leaf.feature_tags ?? []), ...scenarioTags],
142
+ ...(scenarioTags.length
143
+ ? { description: scenarioTags.map((t) => `@${t}`).join(' ') }
144
+ : {}),
145
+ ...(range ? { range } : {}),
146
+ children: [],
147
+ });
148
+ idToRunId.set(id, leaf.runID);
149
+ }
150
+ for (const leaf of plainLeaves) {
151
+ const filePath = leaf.path;
152
+ let fileNode = roots.find((n) => n.uri.absolute && n.uri.path === filePath);
153
+ if (!fileNode) {
154
+ fileNode = {
155
+ id: filePath,
156
+ label: path.basename(filePath),
157
+ uri: { path: filePath, absolute: true },
158
+ canResolveChildren: true,
159
+ tags: [],
160
+ children: [],
161
+ };
162
+ roots.push(fileNode);
163
+ }
164
+ const range = toRange(leaf.lineno);
165
+ fileNode.children.push({
166
+ id: leaf.id_,
167
+ label: leaf.name,
168
+ uri: { path: filePath, absolute: true },
169
+ canResolveChildren: false,
170
+ tags: [],
171
+ ...(range ? { range } : {}),
172
+ children: [],
173
+ });
174
+ idToRunId.set(leaf.id_, leaf.runID);
175
+ }
176
+ return { roots, idToRunId };
177
+ }
178
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/tree/builder.ts"],"names":[],"mappings":";AAAA,yDAAyD;AACzD,kCAAkC;AAClC,EAAE;AACF,gEAAgE;AAChE,EAAE;AACF,6EAA6E;AAC7E,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiG5D,sCAmFC;AAlLD,2CAA6B;AA+B7B,SAAS,cAAc,CAAC,CAAS;IAC7B,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,UAAU,CAAC,IAA6C;IAC7D,OAAO,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC;AACjC,CAAC;AAED,SAAS,aAAa,CAAC,IAA6C;IAChE,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,OAAO,GAAyB,EAAE,CAAC;IACzC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,OAAO,CAA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,CAAC;QAEH,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@nokout/big-dill-core",
3
+ "version": "0.0.1",
4
+ "description": "Headless engine for pytest-bdd tooling: Gherkin parsing, structural linting, formatting, step indexing, and the pytest discovery/execution protocol. No editor dependency.",
5
+ "license": "MIT",
6
+ "author": "Nigel O'Keefe",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/nokout/big-dill",
10
+ "directory": "core"
11
+ },
12
+ "homepage": "https://github.com/nokout/big-dill/blob/main/core/README.md",
13
+ "bugs": {
14
+ "url": "https://github.com/nokout/big-dill/issues"
15
+ },
16
+ "keywords": [
17
+ "pytest",
18
+ "pytest-bdd",
19
+ "bdd",
20
+ "gherkin",
21
+ "cucumber",
22
+ "lint"
23
+ ],
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "files": [
27
+ "dist",
28
+ "!dist/.tsbuildinfo",
29
+ "src",
30
+ "!src/__tests__/**",
31
+ "LICENSE",
32
+ "README.md"
33
+ ],
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "compile": "tsc -p tsconfig.json",
42
+ "watch": "tsc -watch -p tsconfig.json",
43
+ "typecheck": "tsc --noEmit -p tsconfig.json",
44
+ "test": "jest",
45
+ "test:coverage": "jest --coverage",
46
+ "prepublishOnly": "npm run compile"
47
+ },
48
+ "dependencies": {
49
+ "@cucumber/gherkin": "^39.1.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/jest": "^30.0.0",
53
+ "@types/node": "^20.19.43",
54
+ "jest": "^30.4.2",
55
+ "ts-jest": "^29.4.12",
56
+ "typescript": "^5.3.0"
57
+ }
58
+ }
@@ -0,0 +1,165 @@
1
+ // Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
2
+ // Licensed under the MIT License.
3
+ //
4
+ // Completion for step lines in a .feature file.
5
+ //
6
+ // Two levels, tried in order:
7
+ // 1. parameter values — the cursor sits inside a value position of a known step
8
+ // 2. step patterns — the text so far is a prefix of one or more known steps
9
+ //
10
+ // Results are plain entries. `insertText` may carry LSP snippet syntax when
11
+ // `snippet` is set; that format is a protocol convention rather than a
12
+ // particular editor's, so hosts can pass it straight through.
13
+
14
+ import type { StepCache } from '../steps/stepCache';
15
+ import type { StepParameter } from '../protocol/types';
16
+
17
+ const KEYWORD_RE = /^\s*(Given|When|Then|And|But|\*)\s+/i;
18
+ const PARAM_RE = /\{(\w+)(?::[^}]{1,200})?\}/g;
19
+
20
+ export type CompletionKind = 'step' | 'value';
21
+
22
+ export interface CompletionEntry {
23
+ label: string;
24
+ kind: CompletionKind;
25
+ /** LSP snippet syntax when `snippet` is true, literal text otherwise. */
26
+ insertText: string;
27
+ snippet: boolean;
28
+ detail?: string;
29
+ sortText?: string;
30
+ }
31
+
32
+ export type KeywordAndText = { keyword: string; text: string };
33
+
34
+ /** Extract the Gherkin keyword and the step text from a raw line, or null. */
35
+ export function extractStepText(line: string): KeywordAndText | null {
36
+ const m = KEYWORD_RE.exec(line);
37
+ if (!m) return null;
38
+ return { keyword: m[1].toLowerCase(), text: line.slice(m[0].length) };
39
+ }
40
+
41
+ /** Strip type annotations from parameter placeholders: {name:Type} → {name}. */
42
+ function normalizePattern(pattern: string): string {
43
+ return pattern.replace(PARAM_RE, (_match, name) => `{${name}}`);
44
+ }
45
+
46
+ /** Escape for a snippet choice list, where , | \ $ } are special. */
47
+ function escapeChoice(v: string): string {
48
+ return v.replace(/[\\|,$}]/g, '\\$&');
49
+ }
50
+
51
+ /**
52
+ * Convert a step pattern to snippet syntax.
53
+ *
54
+ * Parameters with suggested values become choice tab stops (${1|NSW,VIC|}) so a
55
+ * host can offer the values inline; the rest become plain placeholders
56
+ * (${1:name}).
57
+ */
58
+ function patternToSnippet(pattern: string, parameters: StepParameter[]): string {
59
+ let i = 0;
60
+ let paramIdx = 0;
61
+ return pattern.replace(PARAM_RE, (_match, name) => {
62
+ const param = parameters[paramIdx++];
63
+ const values = param?.suggested_values ?? [];
64
+ if (values.length > 0) {
65
+ return `\${${++i}|${values.map(escapeChoice).join(',')}|}`;
66
+ }
67
+ return `\${${++i}:${name}}`;
68
+ });
69
+ }
70
+
71
+ /**
72
+ * Prefix-match regex for a step pattern: literals escaped, {param} placeholders
73
+ * widened to `.*`, and no end anchor, so partially-typed steps still match.
74
+ */
75
+ function buildPrefixRegex(pattern: string): RegExp {
76
+ const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
77
+ const withWildcards = escaped.replace(/\\\{[^}]{0,200}\\\}/g, '.*');
78
+ return new RegExp(`^${withWildcards}`, 'i');
79
+ }
80
+
81
+ /**
82
+ * Step patterns matching *partialText*, most-used first.
83
+ *
84
+ * Matches when the normalised pattern starts with the partial text, or when the
85
+ * partial text matches the pattern with placeholders treated as wildcards — the
86
+ * latter covers a user who has already typed values into parameter positions.
87
+ */
88
+ export function completeStepPatterns(
89
+ partialText: string,
90
+ keyword: string,
91
+ cache: StepCache,
92
+ ): CompletionEntry[] {
93
+ const lower = partialText.toLowerCase();
94
+ const matched = cache
95
+ .getForKeyword(keyword)
96
+ .filter((s) =>
97
+ normalizePattern(s.pattern).toLowerCase().startsWith(lower) ||
98
+ buildPrefixRegex(s.pattern).test(partialText));
99
+
100
+ matched.sort((a, b) => (b.usage_count ?? 0) - (a.usage_count ?? 0));
101
+
102
+ return matched.map((s, index) => {
103
+ const snippet = patternToSnippet(s.pattern, s.parameters ?? []);
104
+ const isSnippet = snippet !== s.pattern;
105
+ return {
106
+ label: normalizePattern(s.pattern),
107
+ kind: 'step' as const,
108
+ insertText: isSnippet ? snippet : s.pattern,
109
+ snippet: isSnippet,
110
+ detail: `${s.keyword} step`,
111
+ // Pre-ranked, so hosts that sort alphabetically preserve usage order.
112
+ sortText: String(index).padStart(6, '0'),
113
+ };
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Suggested values for the parameter the cursor sits in, if any.
119
+ *
120
+ * Three attempts, because the cursor is often mid-value where the line does not
121
+ * yet match a pattern: the text as-is, then trimmed, then with a dummy character
122
+ * appended so the pattern can match around the cursor.
123
+ */
124
+ export function completeParameterValues(
125
+ lineText: string,
126
+ column: number,
127
+ cache: StepCache,
128
+ ): CompletionEntry[] {
129
+ let pos = cache.paramPositionAt(lineText, column);
130
+
131
+ if (!pos) {
132
+ const textUpToCursor = lineText.slice(0, column);
133
+ pos = cache.paramPositionAt(textUpToCursor.trimEnd(), column);
134
+ if (!pos) {
135
+ pos = cache.paramPositionAt(`${textUpToCursor}X`, column);
136
+ }
137
+ }
138
+
139
+ if (!pos) return [];
140
+ return pos.parameter.suggested_values.map((v) => ({
141
+ label: v,
142
+ kind: 'value' as const,
143
+ insertText: v,
144
+ snippet: false,
145
+ }));
146
+ }
147
+
148
+ /**
149
+ * Complete at a cursor position on a raw line.
150
+ *
151
+ * Parameter values win when available; step patterns are the fallback.
152
+ */
153
+ export function completeAt(line: string, column: number, cache: StepCache): CompletionEntry[] {
154
+ const stepText = extractStepText(line);
155
+ if (!stepText) return [];
156
+
157
+ // indexOf('') is 0 for any string, so an empty step text would wrongly anchor
158
+ // at the start of the line. Nothing typed yet means the step starts here.
159
+ const stepTextStart = stepText.text ? line.indexOf(stepText.text) : column;
160
+
161
+ const values = completeParameterValues(stepText.text, column - stepTextStart, cache);
162
+ if (values.length > 0) return values;
163
+
164
+ return completeStepPatterns(line.slice(stepTextStart, column), stepText.keyword, cache);
165
+ }
@@ -0,0 +1,108 @@
1
+ // Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
2
+ // Licensed under the MIT License.
3
+ //
4
+ // Computes table-alignment edits for a Gherkin document.
5
+ //
6
+ // Returns plain line replacements; turning them into editor edits is the host's
7
+ // job. Datatables are left-aligned throughout; Examples tables right-align
8
+ // columns whose body cells are all numeric, with headers always left-aligned.
9
+
10
+ import type { GherkinDocument, TableRow } from '@cucumber/messages';
11
+
12
+ export interface TextEditEntry {
13
+ startLine: number; // 0-indexed
14
+ newText: string;
15
+ }
16
+
17
+ function isNumeric(v: string): boolean {
18
+ return /^-?\d+(\.\d+)?$/.test(v.trim());
19
+ }
20
+
21
+ function indent(lineText: string): string {
22
+ return lineText.match(/^(\s*)/)?.[1] ?? '';
23
+ }
24
+
25
+ function formatRows(
26
+ rows: readonly TableRow[],
27
+ lines: string[],
28
+ rightAlignNumericCols: boolean,
29
+ headerRows: readonly TableRow[] = [],
30
+ ): TextEditEntry[] {
31
+ if (rows.length === 0) return [];
32
+
33
+ const colCount = rows[0].cells.length;
34
+ const widths = Array<number>(colCount).fill(0);
35
+ const allNumeric = Array<boolean>(colCount).fill(true);
36
+
37
+ const allRows = [...headerRows, ...rows];
38
+
39
+ for (const row of allRows) {
40
+ row.cells.forEach((cell, i) => {
41
+ widths[i] = Math.max(widths[i], cell.value.length);
42
+ });
43
+ }
44
+
45
+ // Determine which columns are purely numeric (checking body rows only; headers are text labels)
46
+ // A column is numeric only if all body values are numeric (empty cells are skipped)
47
+ // We do NOT count header rows in allNumeric — the header is always left-aligned regardless
48
+ // But we DO disqualify a column from right-alignment if the header value is numeric too
49
+ // (since column names like "n" are non-numeric text, only pure-numeric body cols are right-aligned)
50
+ for (const row of rows) {
51
+ row.cells.forEach((cell, i) => {
52
+ if (cell.value !== '' && !isNumeric(cell.value)) allNumeric[i] = false;
53
+ });
54
+ }
55
+ // Also check header cells — if the header is non-empty, it's always non-numeric text
56
+ // so columns with text headers can still be right-aligned if body is all numeric
57
+ // (the header itself is left-aligned via the isHeader flag below)
58
+
59
+ const edits: TextEditEntry[] = [];
60
+
61
+ const formatRow = (row: TableRow, isHeader: boolean): void => {
62
+ const lineIndex = row.location.line - 1;
63
+ const original = lines[lineIndex] ?? '';
64
+ const pad = indent(original);
65
+ const cells = row.cells.map((cell, i) => {
66
+ // Header cells of numeric columns are left-aligned
67
+ if (rightAlignNumericCols && allNumeric[i] && !isHeader) {
68
+ return cell.value.padStart(widths[i]);
69
+ }
70
+ return cell.value.padEnd(widths[i]);
71
+ });
72
+ const newText = `${pad}| ${cells.join(' | ')} |`;
73
+ if (newText !== original) {
74
+ edits.push({ startLine: lineIndex, newText });
75
+ }
76
+ };
77
+
78
+ for (const row of headerRows) {
79
+ formatRow(row, true);
80
+ }
81
+ for (const row of rows) {
82
+ formatRow(row, false);
83
+ }
84
+
85
+ return edits;
86
+ }
87
+
88
+ export function formatTables(doc: GherkinDocument, lines: string[]): TextEditEntry[] {
89
+ const edits: TextEditEntry[] = [];
90
+
91
+ for (const child of doc.feature?.children ?? []) {
92
+ const scenario = child.scenario;
93
+ if (!scenario) continue;
94
+
95
+ for (const step of scenario.steps) {
96
+ if (step.dataTable) {
97
+ edits.push(...formatRows(step.dataTable.rows, lines, false));
98
+ }
99
+ }
100
+
101
+ for (const examples of scenario.examples) {
102
+ const headerRows = examples.tableHeader ? [examples.tableHeader] : [];
103
+ edits.push(...formatRows(examples.tableBody, lines, true, headerRows));
104
+ }
105
+ }
106
+
107
+ return edits;
108
+ }
@@ -0,0 +1,69 @@
1
+ // Copyright (c) 2026 Nigel O'Keefe. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { generateMessages } from '@cucumber/gherkin';
5
+ import { SourceMediaType } from '@cucumber/messages';
6
+ import type { GherkinDocument } from '@cucumber/messages';
7
+
8
+ export interface ParseResult {
9
+ doc: GherkinDocument | null;
10
+ errors: string[];
11
+ }
12
+
13
+ /**
14
+ * The minimum a host must supply to be cacheable: a stable identity, a version
15
+ * that changes when the text changes, and the text itself.
16
+ *
17
+ * VS Code's TextDocument satisfies this structurally, which is why the cache
18
+ * previously took `Pick<vscode.TextDocument, …>` — the coupling was never real.
19
+ */
20
+ export interface CacheableDocument {
21
+ readonly uri: { readonly fsPath: string };
22
+ readonly version: number;
23
+ getText(): string;
24
+ }
25
+
26
+ let _counter = 0;
27
+ const newId = (): string => String(_counter++);
28
+
29
+ export function parseSource(source: string): ParseResult {
30
+ const errors: string[] = [];
31
+ let doc: GherkinDocument | null = null;
32
+
33
+ const envelopes = generateMessages(
34
+ source,
35
+ 'anonymous.feature',
36
+ SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN,
37
+ { newId, includeSource: false, includeGherkinDocument: true, includePickles: false },
38
+ );
39
+
40
+ for (const envelope of envelopes) {
41
+ if (envelope.gherkinDocument) {
42
+ doc = envelope.gherkinDocument;
43
+ }
44
+ if (envelope.parseError) {
45
+ errors.push(envelope.parseError.message ?? 'Parse error');
46
+ }
47
+ }
48
+
49
+ return { doc, errors };
50
+ }
51
+
52
+ export class GherkinParseCache {
53
+ private cache = new Map<string, { version: number; result: ParseResult }>();
54
+
55
+ parse(document: CacheableDocument): ParseResult {
56
+ const key = document.uri.fsPath;
57
+ const cached = this.cache.get(key);
58
+ if (cached?.version === document.version) {
59
+ return cached.result;
60
+ }
61
+ const result = parseSource(document.getText());
62
+ this.cache.set(key, { version: document.version, result });
63
+ return result;
64
+ }
65
+
66
+ invalidate(uri: { fsPath: string }): void {
67
+ this.cache.delete(uri.fsPath);
68
+ }
69
+ }