diff --git a/docs/diff-tool.order.md b/docs/diff-tool.order.md index 74ed923d..d550d6e0 100644 --- a/docs/diff-tool.order.md +++ b/docs/diff-tool.order.md @@ -51,5 +51,5 @@ For example `VisualStudio,Meld` will result in VisualStudio then Meld then all o ```cs DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge); ``` -snippet source | anchor +snippet source | anchor diff --git a/src/DiffEngine.Tests/DiffToolsTest.cs b/src/DiffEngine.Tests/DiffToolsTest.cs index 7b882db0..9c98e20d 100644 --- a/src/DiffEngine.Tests/DiffToolsTest.cs +++ b/src/DiffEngine.Tests/DiffToolsTest.cs @@ -155,8 +155,15 @@ public Task TextFileConvention() var targetFile = Path.Combine(SourceDirectory, "input.target.txtConvention"); return DiffRunner.LaunchAsync(tempFile, targetFile); } - **/ + [Fact] + public Task LaunchForTextAsync() + { + var tempFile = Path.Combine(SourceDirectory, "input.temp.txtConvention"); + var targetFile = Path.Combine(SourceDirectory, "input.target.txtConvention"); + return DiffRunner.LaunchForTextAsync(tempFile, targetFile); + } + **/ //todo: re enable tests with fake diff tool. /** diff --git a/src/DiffEngine/DiffRunner.cs b/src/DiffEngine/DiffRunner.cs index b674c657..d9ed532f 100644 --- a/src/DiffEngine/DiffRunner.cs +++ b/src/DiffEngine/DiffRunner.cs @@ -64,6 +64,35 @@ public static Task LaunchAsync(string tempFile, string targetFile, targetFile, encoding); } + /// + /// Launch a diff tool for the given paths. + /// + public static Task LaunchForTextAsync(string tempFile, string targetFile, Encoding? encoding = null) + { + GuardFiles(tempFile, targetFile); + + return InnerLaunchAsync( + ([NotNullWhen(true)] out ResolvedTool? tool) => + DiffTools.TryFindForText(out tool), + tempFile, + targetFile, + encoding); + } + + /// + /// Launch a diff tool for the given paths. + /// + public static LaunchResult LaunchForText(string tempFile, string targetFile, Encoding? encoding = null) + { + GuardFiles(tempFile, targetFile); + + return InnerLaunch( + ([NotNullWhen(true)] out ResolvedTool? tool) => + DiffTools.TryFindForText(out tool), + tempFile, + targetFile, + encoding); + } public static LaunchResult Launch(ResolvedTool tool, string tempFile, string targetFile, Encoding? encoding = null) { diff --git a/src/DiffEngine/DiffTools_TryFind.cs b/src/DiffEngine/DiffTools_TryFind.cs index 326adbad..c1c4f527 100644 --- a/src/DiffEngine/DiffTools_TryFind.cs +++ b/src/DiffEngine/DiffTools_TryFind.cs @@ -20,6 +20,12 @@ public static bool TryFindByExtension( return ExtensionLookup.TryGetValue(extension, out tool); } + public static bool TryFindForText([NotNullWhen(true)] out ResolvedTool? tool) + { + tool = resolved.FirstOrDefault(_ => _.SupportsText); + return tool != null; + } + public static bool TryFindForInputFilePath( string path, [NotNullWhen(true)] out ResolvedTool? tool) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 6bf6484a..b6c38b73 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;CS0649 - 15.7.1 + 15.8.0 1.0.0 Testing, Snapshot, Diff, Compare Launches diff tools based on file extensions. Designed to be consumed by snapshot testing libraries.