Skip to content

Commit

Permalink
fix: re-set global usings on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavisau committed Feb 5, 2023
1 parent 10ccc7c commit 6095abc
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -98,6 +98,11 @@ IEnumerable<ICompilationFixer> 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(
Expand All @@ -108,7 +113,6 @@ IEnumerable<ICompilationFixer> fixers
.WithPreprocessorSymbols(_options.PreprocessorSymbols.ToArray()),
path: "",
Encoding.Default));

}

private ImmutableDictionary<SourceGeneratorReference, ResolveSourceGeneratorsResponse> ResolveSourceGenerators()
Expand Down Expand Up @@ -360,15 +364,19 @@ private T WithCompilation<T>(Func<CSharpCompilation, (CSharpCompilation, T)> 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)
Expand Down

0 comments on commit 6095abc

Please sign in to comment.