From 6095abccd6a9b985836cedf81c579115e0752545 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sun, 5 Feb 2023 10:44:55 +1000 Subject: [PATCH] fix: re-set global usings on reset --- .../IncrementalCompiler/IncrementalCompiler.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/tbc.host/Components/IncrementalCompiler/IncrementalCompiler.cs b/src/components/tbc.host/Components/IncrementalCompiler/IncrementalCompiler.cs index 515864f..0bda9b1 100644 --- a/src/components/tbc.host/Components/IncrementalCompiler/IncrementalCompiler.cs +++ b/src/components/tbc.host/Components/IncrementalCompiler/IncrementalCompiler.cs @@ -98,6 +98,11 @@ IEnumerable fixers GlobalUsingResolution = _globalUsingsResolver.ResolveGlobalUsings(new ResolveGlobalUsingsRequest(options.GlobalUsingsSources)).Result; + SetGlobalUsings(); + } + + private void SetGlobalUsings() + { if (GlobalUsingResolution.Usings.Any() && GlobalUsingResolution.UsingsSource is { } gus) CurrentCompilation = CurrentCompilation.AddSyntaxTrees( CSharpSyntaxTree.ParseText( @@ -108,7 +113,6 @@ IEnumerable fixers .WithPreprocessorSymbols(_options.PreprocessorSymbols.ToArray()), path: "", Encoding.Default)); - } private ImmutableDictionary ResolveSourceGenerators() @@ -360,15 +364,19 @@ private T WithCompilation(Func act return c.RemoveAllReferences(); }); - public void ClearTrees() => + public void ClearTrees() + { WithCompilation(c => { Logger.LogInformation("Clearing syntax trees"); - + RawTrees.Clear(); return c.RemoveAllSyntaxTrees(); }); - + + SetGlobalUsings(); + } + public void PrintTrees(bool withDetail) { if (_rootPath is null)