From 3209017166f73fc8d25349316fe90aaf4c964f13 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 23 Feb 2023 14:37:52 +1000 Subject: [PATCH] feat: allow load context to specify directory with optional recursion directory/x.cs - this file directory/* - all .cs files in this directory only directory/** - all .cs files in this directory and subdirectories --- .../FileEnvironment/FileEnvironment.cs | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/components/tbc.host/Components/FileEnvironment/FileEnvironment.cs b/src/components/tbc.host/Components/FileEnvironment/FileEnvironment.cs index 1c7c53d..9f274d2 100644 --- a/src/components/tbc.host/Components/FileEnvironment/FileEnvironment.cs +++ b/src/components/tbc.host/Components/FileEnvironment/FileEnvironment.cs @@ -111,9 +111,39 @@ private async Task TryLoadLoadContext() if (ctx is null) return; - foreach (var file in ctx.WatchedFiles - .Where(x => !String.IsNullOrWhiteSpace(x) && FileSystem.File.Exists(x)) - .Select(x => new ChangedFile { Path = x, Contents = FileSystem.File.ReadAllText(x) })) + var filesToStage = new List(); + foreach (var file in ctx.WatchedFiles) + { + // todo: work out how an empty ends up in here during save + // (maybe from the warmup emit?) + if (string.IsNullOrWhiteSpace(file)) + continue; + + if (file.EndsWith("*")) // add matching files + { + var searchOption = file.EndsWith("**") + ? SearchOption.AllDirectories + : SearchOption.TopDirectoryOnly; + + var path = file[0..^(searchOption is SearchOption.AllDirectories ? 2 : 1)]; + foreach (var f in FileSystem.Directory.GetFiles(path, "*.cs", searchOption)) + filesToStage.Add(new FileInfo(f).FullName); + } + else // just add this file + { + if (FileSystem.File.Exists(file)) + filesToStage.Add(new FileInfo(file).FullName); + } + } + + var fs = filesToStage.Select(x => new ChangedFile + { + Path = x, + Contents = FileSystem.File.ReadAllText(x), + Silent = true, + }); + + foreach (var file in fs) IncrementalCompiler.StageFile(file, silent: true); await SetPrimaryTypeHint(ctx.PrimaryTypeHint);