Reload from Disk vs. Invalidate Caches: Which Cache Layer Must Be Rebuilt After External Go Code Generation?
0 reputation · 12 Sept 2022, 07:46 UTC
0 reputation · 12 Sept 2022, 07:46 UTC
After running go generate, switching git branches, or letting mock generators rewrite files externally, GoLand can continue serving stale symbol resolution and completion. The cheap path, File | Reload All from Disk, re-reads file bytes and updates the virtual file system, but it does not rebuild symbol indexes, so unresolved-reference diagnostics may persist. The expensive path, File | Invalidate Caches / Restart, discards VFS and index caches and forces a full reindex, but it costs time on large Go monorepos and discards unsaved in-memory changes. Automatic invalidation depends on file-system watchers and sync settings, which can miss atomic-rename writes or network shares, and Go module state may remain stale after an external go mod tidy.
Given that no documented, deterministic guarantee exists that an external tool's write is detected, which refresh scope should a team standardize on when correctness matters more than IDE responsiveness? Is there a middle-ground configuration of synchronization settings or module reload triggers that avoids full reindexing while ensuring generated symbols resolve? How can the limits of file-watcher events be verified on the installed GoLand build before choosing a policy?
When correctness is the priority and you must ensure that all externally generated symbols (via go generate or mock generators) are resolved, the team should standardize on File | Invalidate Caches / Restart. While expensive, this is the only operation that guarantees the disposal of stale index pointers and forces a complete rebuild of the symbol table from the current state of the disk.
To choose a policy, it is necessary to distinguish between the Virtual File System (VFS) and the Symbol Index:
Reload All from Disk updates the VFS. If the IDE knows a file exists but cannot find a function inside it, the VFS is likely current, but the index is not.To avoid full reindexing while maintaining symbol accuracy, implement this tiered escalation path:
go.mod or go.sum were changed externally (e.g., go mod tidy), click the "Sync Dependencies" notification or run the command from the Go tool window. This updates module resolution without a full cache wipe.You can verify if your current GoLand build and OS environment are missing events by performing a "blind write" test:
# 1. Open a file in GoLand
# 2. In a terminal, overwrite the file using a method that bypasses standard watchers
echo "package main" > filename.go
# 3. Observe the IDE: if the content does not update within 5-10 seconds,
# your filesystem watcher is failing to detect the event.
Diagnostic Detail Needed: Are you using a network-mounted drive (NFS/Samba) or a Docker-mounted volume? If so, filesystem events are often not propagated, making Reload All from Disk mandatory and Invalidate Caches more frequent.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.