Skip to content

1.4 Implement the context service and when-clause evaluator #5

Description

@goofmint

Part of Phase 1 — Core skeleton (tasks.md Task 1.4).

Summary

Implement tecode.context (flat context map) and the when-clause parser/evaluator used by keybindings and command visibility.

Details

  • Context service: set(key, value) / get(key) over a flat Map<string, unknown> with a change event.
  • Recursive-descent parser for the MVP grammar (design.md §6.4):
    expr := or
    or := and ("||" and)*
    and := unary ("&&" unary)*
    unary := "!" unary | primary
    primary:= key | key "==" value | "(" expr ")"
    
  • Clauses parse once into a cached AST at registration; evaluation runs per lookup.
  • Unknown context keys evaluate to undefined (falsy). Malformed clauses fail at parse time with a clear error (binding is skipped and reported, not crashing).

Completion requirements

  • Table-driven tests cover: bare keys, == string comparison (editorLangId == 'ts'), !, &&/|| precedence, parentheses, unknown keys falsy, malformed input
  • AST caching verified (parse called once per clause)
  • Context change event fires on set with changed key
  • bun test and lint pass

References

  • requirements.md: Req 4.5, 4.6
  • design.md: §6.4

Dependencies

Blocked by: 1.2 (#3). Parallelizable with 1.3, 1.5–1.10.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions