feat(language-server): complete frontmatter keys and recipe names, fix deprecated keys #272

Merged
abiwab merged 3 commits from feat/lsp-frontmatter-names-completion into dev/1.6 2026-11-26 13:55:17 +01:00
Owner

PR 2b of the DX plan (phase 1A), on top of the frontmatter key registry (#268). In packages/language-server, for every LSP client:

  • Frontmatter key completion: the canonical keys not written yet, with their description and value kind in the editor's language (frontmatter.keys / frontmatter.values of @gram-lang/i18n, no new string). A key written in its deprecated form counts as present; a deprecated key is never offered. Read from the live text before the !state.ast guard, so it works before the closing ---. Nothing else is completed in the frontmatter (no ingredient on @, no name on #).
  • Name completion: after # the cookware, ^ the temperatures, ~ every named timer, ~_ the passive timers (tracks) the recipe already names. Explicit textEdit from right after the sigil (_ kept, multi-word names), braces for ~ and ^. Nothing on a ## heading, inside braces, after // or mid-word. Trigger characters #, ^, ~.
  • Hover on a frontmatter key: what it means, its value kind, and its replacement for a deprecated key.
  • DEPRECATED_FRONTMATTER_KEY: anchored on the key's name (found from data.key in the text, the AST keeps no position), struck through (DiagnosticTag.Deprecated), with an isPreferred Quick Fix that renames the key, or removes the line when the key read is already another one (the replacement, or an earlier alias: yield before yields), so the value shown never changes. Nothing of this when data.specifier is set (a key of an imported module stays on its @use line).
  • A text scanner of the frontmatter (utils/frontmatter-text.ts) shared by all four: it tolerates # …, indented lines, an unclosed block, a BOM and CRLF.

Kitchen / modules: warningInfo: Record<WarningCode, { severity, deprecated? }>, with warningSeverity derived from it (no API change), and warningInfoOf(code) in @gram-lang/modules. The strikethrough comes from this flag, never from a code written in the LSP. deprecated-warning-codes.test.ts checks both ways that the flag matches the active entries of deprecations.yaml. No compiled output changes.

Docs (en + fr): Completion, Hover and Code Actions rows of reference/tooling/language-server.mdx, warningInfo in reference/api/warnings.mdx (plus DEPRECATED_FRONTMATTER_KEY among the codes with data, missed by #268), language server README. Changeset minor on language-server, kitchen, modules.

Checks: build, typecheck, lint, bun test (4065 pass, incl. generic-client.test.ts after the server build and capabilities.test.ts), conformance, deprecations:check, playground chunk 1059.1 KB (unchanged by this PR).

Fuzz (bun run fuzz --iterations 50000): 8 runs, 6 clean. One failure's seed was lost; the other (seed 2725035355, index 964) is format-preserves-meaning on a mutated frontmatter, and reproduces identically on origin/main (d8f1a67f) and origin/dev/1.6 (2af231a4): not from this PR. Cause: a : followed only by blanks after a cookware or an ingredient (#pan: at the end of a line) is read as an empty alias, so stripping the trailing blank (rule 10) changes the parse. To be fixed separately on main.

PR 2b of the DX plan (phase 1A), on top of the frontmatter key registry (#268). In `packages/language-server`, for every LSP client: - **Frontmatter key completion**: the canonical keys not written yet, with their description and value kind in the editor's language (`frontmatter.keys` / `frontmatter.values` of `@gram-lang/i18n`, no new string). A key written in its deprecated form counts as present; a deprecated key is never offered. Read from the live text before the `!state.ast` guard, so it works before the closing `---`. Nothing else is completed in the frontmatter (no ingredient on `@`, no name on `#`). - **Name completion**: after `#` the cookware, `^` the temperatures, `~` every named timer, `~_` the passive timers (tracks) the recipe already names. Explicit `textEdit` from right after the sigil (`_` kept, multi-word names), braces for `~` and `^`. Nothing on a `##` heading, inside braces, after `//` or mid-word. Trigger characters `#`, `^`, `~`. - **Hover** on a frontmatter key: what it means, its value kind, and its replacement for a deprecated key. - **`DEPRECATED_FRONTMATTER_KEY`**: anchored on the key's name (found from `data.key` in the text, the AST keeps no position), struck through (`DiagnosticTag.Deprecated`), with an `isPreferred` Quick Fix that renames the key, or removes the line when the key read is already another one (the replacement, or an earlier alias: `yield` before `yields`), so the value shown never changes. Nothing of this when `data.specifier` is set (a key of an imported module stays on its `@use` line). - A text scanner of the frontmatter (`utils/frontmatter-text.ts`) shared by all four: it tolerates `# …`, indented lines, an unclosed block, a BOM and CRLF. **Kitchen / modules**: `warningInfo: Record<WarningCode, { severity, deprecated? }>`, with `warningSeverity` derived from it (no API change), and `warningInfoOf(code)` in `@gram-lang/modules`. The strikethrough comes from this flag, never from a code written in the LSP. `deprecated-warning-codes.test.ts` checks both ways that the flag matches the active entries of `deprecations.yaml`. No compiled output changes. Docs (en + fr): Completion, Hover and Code Actions rows of `reference/tooling/language-server.mdx`, `warningInfo` in `reference/api/warnings.mdx` (plus `DEPRECATED_FRONTMATTER_KEY` among the codes with `data`, missed by #268), language server README. Changeset `minor` on `language-server`, `kitchen`, `modules`. Checks: build, typecheck, lint, `bun test` (4065 pass, incl. `generic-client.test.ts` after the server build and `capabilities.test.ts`), conformance, `deprecations:check`, playground chunk 1059.1 KB (unchanged by this PR). Fuzz (`bun run fuzz --iterations 50000`): 8 runs, 6 clean. One failure's seed was lost; the other (seed 2725035355, index 964) is `format-preserves-meaning` on a mutated frontmatter, and reproduces identically on `origin/main` (`d8f1a67f`) and `origin/dev/1.6` (`2af231a4`): not from this PR. Cause: a `:` followed only by blanks after a cookware or an ingredient (`#pan: ` at the end of a line) is read as an empty alias, so stripping the trailing blank (rule 10) changes the parse. To be fixed separately on `main`.
abiwab merged commit 999fddf2bd into dev/1.6 2026-11-26 13:55:17 +01:00
abiwab deleted branch feat/lsp-frontmatter-names-completion 2026-11-26 13:55:18 +01:00
Sign in to join this conversation.
No description provided.