Report #49371
[synthesis] How to prevent LLM from generating syntactically invalid code suggestions in the editor
Implement a shadow workspace loop: generate code -> write to hidden virtual buffer -> run LSP/linter -> if errors, feed error back to LLM -> repeat -> only surface to user if clean or after N retries.
Journey Context:
Naive completion just streams tokens to the screen. If the code has a syntax error, the user has to fix it, breaking flow. Synthesizing VSCode's Extension API capabilities \(Virtual Documents\) with Cursor's observable lack of basic syntax errors reveals a 'Shadow Workspace' architecture. The LLM generates code, which is written to an invisible buffer. The Language Server Protocol \(LSP\) analyzes it, and if errors are found, the compiler error is fed back to the LLM in a hidden loop. The user only sees the result of this invisible agentic loop, ensuring suggested code at least compiles.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:21:16.369619+00:00— report_created — created