refactor: move gram-tokens to @gram-lang/modules/lint and ingredient resolution to the analyzer #280

Merged
abiwab merged 2 commits from refactor/move-lint-primitives into dev/1.6 2026-11-26 18:09:46 +01:00
Owner

PR 5a of the DX plan: moves only, no new feature, no visible behavior change (hence no changeset; the unknown-ingredient verdict was already aligned by #278).

Analyzer owns the unknown-ingredient verdict and its spelling suggestion:

  • isKnownIngredient(name, db) = getIngredientData(...) !== null, on the cached index.
  • findClosestIngredients(name, db, maxDistance = 2): string[]: every entry name at the minimal distance, in database order (the LSP takes [0], same result as before; 5b will set isPreferred only when there is a single suggestion).
  • Levenshtein moves next to it, internal (not re-exported).
  • The language server keeps no copy: ingredient-loader.ts is down to loadIngredientDB and allIngredientCompletionLabels.

Modules gets the @gram-lang/modules/lint subpath (@experimental), not re-exported from the main entry, so the playground bundles nothing more:

  • packages/cli/src/core/gram-tokens.ts moves to packages/modules/src/lint/gram-tokens.ts.
  • WrittenIngredient gains start / end (UTF-16 offsets, from the @ to the quantity's } or the end of a bare name), for the loc of LOST_INGREDIENT in 5b.
  • lostFrom(compiled: Pick<CompilationResult, "registry">, written): WrittenIngredient[] is now pure; the importer keeps !ok → [] and the "name (line N)" format, so gram import output is unchanged.
  • exports map (. and ./lint) and a second tsup entry; resolves from packages/cli under node 22 and bun.
  • The scanner's pure tests move to packages/modules/tests/lint/gram-tokens.test.ts; the importer's stay in the CLI.

Checks: 4183 pass / 1 skip / 0 fail (+15 new tests, all 38 moved test names present), typecheck, biome, conformance 148/148 and 24/24 with no golden change, deprecations:check, audit 127, playground chunk 1060.6 KB (forced build, unchanged), fuzz 50k ×2 (one pre-existing parser violation, also on main, handled separately).

PR 5a of the DX plan: moves only, no new feature, no visible behavior change (hence no changeset; the unknown-ingredient verdict was already aligned by #278). **Analyzer** owns the unknown-ingredient verdict and its spelling suggestion: - `isKnownIngredient(name, db)` = `getIngredientData(...) !== null`, on the cached index. - `findClosestIngredients(name, db, maxDistance = 2): string[]`: every entry name at the minimal distance, in database order (the LSP takes `[0]`, same result as before; 5b will set `isPreferred` only when there is a single suggestion). - Levenshtein moves next to it, internal (not re-exported). - The language server keeps no copy: `ingredient-loader.ts` is down to `loadIngredientDB` and `allIngredientCompletionLabels`. **Modules** gets the `@gram-lang/modules/lint` subpath (`@experimental`), not re-exported from the main entry, so the playground bundles nothing more: - `packages/cli/src/core/gram-tokens.ts` moves to `packages/modules/src/lint/gram-tokens.ts`. - `WrittenIngredient` gains `start` / `end` (UTF-16 offsets, from the `@` to the quantity's `}` or the end of a bare name), for the `loc` of `LOST_INGREDIENT` in 5b. - `lostFrom(compiled: Pick<CompilationResult, "registry">, written): WrittenIngredient[]` is now pure; the importer keeps `!ok → []` and the `"name (line N)"` format, so `gram import` output is unchanged. - `exports` map (`.` and `./lint`) and a second tsup entry; resolves from `packages/cli` under node 22 and bun. - The scanner's pure tests move to `packages/modules/tests/lint/gram-tokens.test.ts`; the importer's stay in the CLI. **Checks**: 4183 pass / 1 skip / 0 fail (+15 new tests, all 38 moved test names present), typecheck, biome, conformance 148/148 and 24/24 with no golden change, `deprecations:check`, audit 127, playground chunk 1060.6 KB (forced build, unchanged), fuzz 50k ×2 (one pre-existing parser violation, also on `main`, handled separately).
abiwab merged commit a20488c1f0 into dev/1.6 2026-11-26 18:09:46 +01:00
abiwab deleted branch refactor/move-lint-primitives 2026-11-26 18:09:46 +01:00
Sign in to join this conversation.
No description provided.