Skip to content

Preserve wrapped lexer invalidation in DynamicLexer - #2142

Open
FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix-dynamic-lexer-invalidation-20261016
Open

FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix-dynamic-lexer-invalidation-20261016

Conversation

@FanWu-ai

Copy link
Copy Markdown

DynamicLexer uses only the wrapped object's identity as its cache key. A nested DynamicLexer or a custom lexer with changing invalidation_hash can therefore keep displaying stale syntax highlighting while the document text is unchanged.

Include both the wrapped lexer's identity and its invalidation hash. Keeping identity also preserves invalidation when two different lexer instances expose the same revision hash. Five new cases exercise public BufferControl rendering, nested wrappers, default-lexer transitions, changing revisions, cache reuse, and equal-revision identity changes.

Validation on Linux / CPython 3.12.14:

  • Pristine complete suite: 156 passed; final complete suite: 161 passed.
  • Three added cases fail against the original implementation.
  • Ruff lint/format, typos, strict mypy for win32/linux/darwin, all 12 pinned hooks, wheel/sdist builds, and git diff --check pass.
  • Independent automated review reran the full suite and gates. Packaged implementation bytes match the tested source.

The mypy platform targets are static checks; other interpreter/native OS matrix combinations were not run locally.

Prepared and tested with OpenAI Codex assistance. No human review is claimed.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 15, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant