Skip to content

Re-check consumer scripts when an included module changes (#165)#167

Open
bentsherman wants to merge 1 commit into
mainfrom
re-check-consumers-on-module-change
Open

Re-check consumer scripts when an included module changes (#165)#167
bentsherman wants to merge 1 commit into
mainfrom
re-check-consumers-on-module-change

Conversation

@bentsherman

Copy link
Copy Markdown
Member

Overview

Follow-up to b29edb8 for #165. That commit fixed the cold-scan false warning by type-checking included modules before their includers. This addresses the remaining incremental-invalidation half of the issue:

Editing a module does not re-check its consumers, so a stale false warning lingers in the editor until the consuming file is touched.

Root cause

Editing a module did add its direct consumer to the change set, so the consumer was re-type-checked — but only the directly-changed files are re-parsed. Consumers pulled in during analysis were re-type-checked over their old AST nodes, which still carried INFERRED_TYPE metadata from the previous run. Since getType() short-circuits on cached INFERRED_TYPE, a changed process output type was never observed (e.g. ch_produced kept resolving to the stale Channel<Record{id, data}>). Transitive consumers (A → B → C) were never re-checked at all.

Fix

Add an expandInvalidation() hook in ASTNodeCache.update() (default no-op) that runs before parsing. ScriptAstCache overrides it to walk the reverse include graph and pull every transitive consumer into the invalidation set, so consumers are re-parsed from fresh (metadata-free) AST nodes and their cross-file inferred types are recomputed. Reuses the existing parse→analyze pipeline and the localIncludeUri helper.

Testing

New test in ScriptDiagnosticsTest: with a compatible producer→consumer wiring, edit only the producer module to emit an incompatible record → the consumer call now reports the mismatch; restore the producer → the stale warning clears. Verified it fails without the fix and passes with it. Full suite green.

Known ceiling

expandInvalidation rebuilds the reverse graph each update and localIncludeUri does one Files.isDirectory stat per include — fine at debounced-update cadence; memoize if it shows up on a large workspace. Remote/plugin includes are still not tracked.

Editing a module left stale diagnostics in its consumers. The consumer was
re-type-checked, but only the directly-changed files were re-parsed, so the
consumer's nodes kept stale INFERRED_TYPE metadata and getType() short-circuited
on the cached value -- a changed process output type was never observed.
Transitive consumers were not re-checked at all.

Expand the invalidation set (before parsing) to include every cached file that
transitively includes a changed file, so consumers are re-parsed from fresh AST
nodes and their cross-file inferred types are recomputed.

Signed-off-by: Ben Sherman <bentshermann@gmail.com>
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