Skip to content

LSP reports Unknown timer unit for valid scalar timer units #643

Open

Description

@peter-popescu

Problem

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

  1. Create a .cook file containing the example above.
  2. Open it in an editor configured to run cook lsp.
  3. Observe the Unknown timer unit diagnostic.
  4. 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.

Activity

  1. drawmeanelephant commented on Oct 10, 2026

    @drawmeanelephant
    Contributor

    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.

  2. added
    bug
    area: parser
    upstream
    on Oct 10, 2026
  3. LeMyst commented on Oct 11, 2026

    @LeMyst
    Collaborator

    Some history this thread is missing, because it decides which fix can land:

    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:

    1. cooklang-language-server diagnostics.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.
    2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: parserbugupstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions