public sealed class ScriptWorkspaceA project's editor scripts, compiled again and again without starting over.
Remarks
Doc 36 § P5's incremental compilation. Compile reads, parses and metadata-loads everything on every save; a project with a dozen scripts does not notice and one with hundreds does. What is kept between builds is the two expensive things and nothing else: the parsed syntax tree of every file whose text has not changed, and the MetadataReference set — a few hundred assemblies whose metadata Roslyn reads and caches per reference object, so handing it the same objects again is what makes the second build cheap.
⚠ Staleness is decided by the text and not by a timestamp, deliberately. A last-write time plus a length is the classic file cache and the classic file-cache bug: two saves inside one filesystem tick that leave the file the same length are indistinguishable, and the symptom is an editor running the code somebody deleted. Reading the file is what the old path did anyway; what this skips is the parse, which is the part that costs.
⚠ The reference set is rebuilt when the default context's assembly count changes. ScriptCompiler's own remarks say a script can break when the editor loads a panel it had not loaded before; that stays true, and a set held for ever would have made it worse by freezing the answer at whatever was loaded when the project opened.
⚠ The cost is the source text of every script, held for the life of the project. That is the price of comparing text rather than a stamp, and it is small against the thing beside it: a SyntaxTree is several times its own source, and the reference set dwarfs both. A project large enough for this to matter is one where the parse it avoids matters far more.
⚠ Not thread-safe, and it does not need to be. A rebuild is raised by the asset watcher's pump on the frame thread, which is the only caller — see ScriptsModule.
Fields and properties (1)
public int CachedHow many files this workspace is holding parsed trees for.
Methods (1)
public ScriptBuild Compile(string projectRoot, string output)Compiles the project's editor scripts, reusing whatever has not changed.
Used by (3)
- EditorScriptsVixen.Editor.Scripts
- ScriptCompilerVixen.Editor.Scripts
- ScriptWorkspaceTestsVixen.Editor.Scripts.Tests