You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LSP reports Unknown timer unit for valid scalar timer units #643
With CookCLI 0.36.0, the language server reports Unknown timer unit for valid scalar timers such as:
Boil for ~{25%minutes}.
The same recipe is accepted by cook recipe -f json, and cook doctor validate passes. In a collection of recipes, the LSP reported this for scalar minutes and seconds units, as well as the tested singular and abbreviated variants. This appears to be an LSP diagnostic mismatch rather than an invalid timer value.
Expected behavior
Timer units accepted by CookCLI's recipe parser should not be reported as unknown by the LSP.
Actual behavior
The LSP emits Unknown timer unit on the timer even though the CLI parses it.
Reproduction
Create a .cook file containing the example above.
Open it in an editor configured to run cook lsp.
Observe the Unknown timer unit diagnostic.
Run cook recipe -f json <file.cook>; the timer is parsed without that error.
Related: #214 covers cook doctor not reporting non-numeric timer values. That is a different case: this report uses a numeric value and concerns the LSP rejecting a unit.
I’d be interested in contributing a fix and would welcome guidance on the relevant code path.
Update: I retested with CookCLI 0.37.0 and still see the diagnostic. Neovim’s :LspInfo reports language-server version 0.2.4. The CookCLI v0.37.0 manifest pins cooklang-language-server 0.2.4, while the current CookCLI main manifest pins 0.3.0. I filed this against CookCLI because it’s the released cook lsp behavior I encountered. I also found the related cooklang-language-server issue #12. I’m happy to follow up in that repo if maintainers prefer.
Reproduced on current main — the cooklang-language-server 0.2.4 → 0.3.0 bump doesn't change it. cook lsp (serverInfo 0.3.0) still publishes Unknown timer unit: minutes (severity: error) for Boil for ~{25%minutes}. on a recipe that cook recipe and cook doctor validate accept.
The diagnostic isn't produced by the language server itself; diagnostics.rs forwards the cooklang parser's SourceDiags. The warning comes from cooklang's analysis (analysis/event_consumer.rs), which reports Unknown timer unit whenever quantity.unit_info(converter) returns None.
Why every valid unit reports None inside cook lsp: the language server parses with CooklangParser::new(Extensions::all(), Default::default()), i.e. Converter::default(). That default is Converter::bundled() only with the bundled_units cargo feature and Converter::empty() otherwise — and cookcli deliberately builds cooklang without bundled_units (see the comment on the cooklang dep in Cargo.toml: it keeps Converter::default() from rewriting quantities). Through feature unification the cooklang inside cook lsp has it off as well, so the LSP's converter knows no units at all and every ~{x%unit} errors.
That also means enabling bundled_units in the language server's cooklang dep is not a safe fix: inside cook lsp it would leak the feature into cookcli's own build via feature unification and reintroduce the quantity rewriting cookcli avoids. The natural fix looks to be in cooklang-language-server itself — don't forward unit diagnostics (or check them) when the parser's converter knows no units, e.g. converter.unit_count() == 0. Happy to open a PR there if that direction sounds right.
So turning the unit database back on is off the table for now. The other approach, suggested above, doesn't need it: stop reporting a timer unit as unknown when the converter has no units to check it against. With an empty converter unit_info() is always None, so Unknown timer unit fires on every timer that has a unit, while Timer unit is not time can never fire. The check is in one place in cooklang-rs (analysis/event_consumer.rs, the ADVANCED_UNITS timer block), and there are two places it could be skipped:
cooklang-language-serverdiagnostics.rs: drop that diagnostic when converter.unit_count() == 0. This is local to the LSP, but it has to recognise the diagnostic by its message text.
cooklang-rs: run the timer unit check only when self.converter.unit_count() > 0. This fixes every consumer that parses with an empty converter, and nothing changes for those using bundled units. The other ADVANCED_UNITS checks, such as Timer value is text, still run.
Either one makes ~{25%minutes} and ~{24%heures} stop erroring in the editor. Neither adds a unit database, so it shouldn't get in the way of the ecosystem-level work.
@dubadub, which do you prefer: a stop-gap like this, or keeping #643 open until the unit work lands? @peter-popescu, you offered to contribute. Once there's a direction, either change is small (a guard plus a regression test for ~{25%minutes} and ~{24%heures}).
🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.
Activity
drawmeanelephant commentedon Oct 10, 2026
Reproduced on current
main— thecooklang-language-server0.2.4 → 0.3.0 bump doesn't change it.cook lsp(serverInfo 0.3.0) still publishesUnknown timer unit: minutes(severity: error) forBoil for ~{25%minutes}.on a recipe thatcook recipeandcook doctor validateaccept.The diagnostic isn't produced by the language server itself;
diagnostics.rsforwards thecooklangparser'sSourceDiags. The warning comes fromcooklang's analysis (analysis/event_consumer.rs), which reportsUnknown timer unitwheneverquantity.unit_info(converter)returnsNone.Why every valid unit reports
Noneinsidecook lsp: the language server parses withCooklangParser::new(Extensions::all(), Default::default()), i.e.Converter::default(). That default isConverter::bundled()only with thebundled_unitscargo feature andConverter::empty()otherwise — and cookcli deliberately buildscooklangwithoutbundled_units(see the comment on thecooklangdep inCargo.toml: it keepsConverter::default()from rewriting quantities). Through feature unification thecooklanginsidecook lsphas it off as well, so the LSP's converter knows no units at all and every~{x%unit}errors.That also means enabling
bundled_unitsin the language server'scooklangdep is not a safe fix: insidecook lspit would leak the feature into cookcli's own build via feature unification and reintroduce the quantity rewriting cookcli avoids. The natural fix looks to be incooklang-language-serveritself — don't forward unit diagnostics (or check them) when the parser's converter knows no units, e.g.converter.unit_count() == 0. Happy to open a PR there if that direction sounds right.LeMyst commentedon Oct 11, 2026
Some history this thread is missing, because it decides which fix can land:
bundled_unitsfrom the language server, which is why its converter knows no units insidecook lsp.bundled_unitsback. @dubadub closed it: the bundled (English) units would make recipes written with non-English units fail in the CLI and editors (How to use translated timer ? cooklang-language-server#12 is the same report for~{24%heures}). Proper unit support is planned at the ecosystem level.So turning the unit database back on is off the table for now. The other approach, suggested above, doesn't need it: stop reporting a timer unit as unknown when the converter has no units to check it against. With an empty converter
unit_info()is alwaysNone, soUnknown timer unitfires on every timer that has a unit, whileTimer unit is not timecan never fire. The check is in one place in cooklang-rs (analysis/event_consumer.rs, theADVANCED_UNITStimer block), and there are two places it could be skipped:diagnostics.rs: drop that diagnostic whenconverter.unit_count() == 0. This is local to the LSP, but it has to recognise the diagnostic by its message text.self.converter.unit_count() > 0. This fixes every consumer that parses with an empty converter, and nothing changes for those using bundled units. The otherADVANCED_UNITSchecks, such asTimer value is text, still run.Either one makes
~{25%minutes}and~{24%heures}stop erroring in the editor. Neither adds a unit database, so it shouldn't get in the way of the ecosystem-level work.@dubadub, which do you prefer: a stop-gap like this, or keeping #643 open until the unit work lands? @peter-popescu, you offered to contribute. Once there's a direction, either change is small (a guard plus a regression test for
~{25%minutes}and~{24%heures}).🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.