Skip to content

Commit

Permalink
Add Vim support (#41)
Browse files Browse the repository at this point in the history
* Create Vim.cs

* add vim support
  • Loading branch information
SimonCropp authored Jul 11, 2020
1 parent b561564 commit 17f802e
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 26 deletions.
7 changes: 4 additions & 3 deletions docs/diff-tool.custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ var resolvedTool = DiffTools.AddTool(
isMdi: false,
supportsText: true,
requiresTarget: true,
shellExecute: false,
arguments: (tempFile, targetFile) => $"\"{tempFile}\" \"{targetFile}\"",
exePath: diffToolPath,
binaryExtensions: new[] {"jpg"})!;
```
<sup><a href='/src/Tests/DiffToolsTest.cs#L23-L33' title='File snippet `addtool` was extracted from'>snippet source</a> | <a href='#snippet-addtool' title='Navigate to start of snippet `addtool`'>anchor</a></sup>
<sup><a href='/src/Tests/DiffToolsTest.cs#L24-L35' title='File snippet `addtool` was extracted from'>snippet source</a> | <a href='#snippet-addtool' title='Navigate to start of snippet `addtool`'>anchor</a></sup>
<!-- endsnippet -->

Add a tool based on existing resolved tool:
Expand All @@ -35,7 +36,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(
name: "MyCustomDiffTool",
arguments: (temp, target) => $"\"custom args {temp}\" \"{target}\"");
```
<sup><a href='/src/Tests/DiffToolsTest.cs#L62-L67' title='File snippet `addtoolbasedon` was extracted from'>snippet source</a> | <a href='#snippet-addtoolbasedon' title='Navigate to start of snippet `addtoolbasedon`'>anchor</a></sup>
<sup><a href='/src/Tests/DiffToolsTest.cs#L65-L70' title='File snippet `addtoolbasedon` was extracted from'>snippet source</a> | <a href='#snippet-addtoolbasedon' title='Navigate to start of snippet `addtoolbasedon`'>anchor</a></sup>
<!-- endsnippet -->


Expand Down Expand Up @@ -63,7 +64,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(

DiffRunner.Launch(resolvedTool!, "PathToTempFile", "PathToTargetFile");
```
<sup><a href='/src/Tests/DiffToolsTest.cs#L76-L83' title='File snippet `addtoolandlaunch` was extracted from'>snippet source</a> | <a href='#snippet-addtoolandlaunch' title='Navigate to start of snippet `addtoolandlaunch`'>anchor</a></sup>
<sup><a href='/src/Tests/DiffToolsTest.cs#L79-L86' title='File snippet `addtoolandlaunch` was extracted from'>snippet source</a> | <a href='#snippet-addtoolandlaunch' title='Navigate to start of snippet `addtoolandlaunch`'>anchor</a></sup>
<!-- endsnippet -->


Expand Down
27 changes: 26 additions & 1 deletion docs/diff-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This value can be changed:
```cs
DiffRunner.MaxInstancesToLaunch(10);
```
<sup><a href='/src/Tests/DiffToolsTest.cs#L12-L16' title='File snippet `maxinstancestolaunch` was extracted from'>snippet source</a> | <a href='#snippet-maxinstancestolaunch' title='Navigate to start of snippet `maxinstancestolaunch`'>anchor</a></sup>
<sup><a href='/src/Tests/DiffToolsTest.cs#L13-L17' title='File snippet `maxinstancestolaunch` was extracted from'>snippet source</a> | <a href='#snippet-maxinstancestolaunch' title='Navigate to start of snippet `maxinstancestolaunch`'>anchor</a></sup>
<!-- endsnippet -->


Expand Down Expand Up @@ -524,6 +524,31 @@ ReSharper | Options | Tools | Unit Testing | Test Runner
* `%ProgramW6432%\TortoiseSVN\bin\TortoiseMerge.exe`
* `%ProgramFiles(x86)%\TortoiseSVN\bin\TortoiseMerge.exe`

## [Vim](https://www.vim.org/)

* Is MDI: False
* Supports auto-refresh: True
* Supports text files: True

### Notes:


* [Options](http://vimdoc.sourceforge.net/htmldoc/options.html)
* [Vim help files](https://vimhelp.org/)
* [autoread](http://vimdoc.sourceforge.net/htmldoc/options.html#'autoread')
* [nobackup](http://vimdoc.sourceforge.net/htmldoc/options.html#'backup')
* [noswapfile](http://vimdoc.sourceforge.net/htmldoc/options.html#'swapfile')

### Windows settings:


* Example arguments: `-d "tempFile" "targetFile" -c "setl autoread | setl nobackup | set noswapfile"`
* Scanned paths:

* `%ProgramFiles%\Vim\*\vim.exe`
* `%ProgramW6432%\Vim\*\vim.exe`
* `%ProgramFiles(x86)%\Vim\*\vim.exe`

## [VisualStudio](https://docs.microsoft.com/en-us/visualstudio/ide/reference/diff)

* Is MDI: True
Expand Down
5 changes: 3 additions & 2 deletions docs/diff-tool.order.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ To change this file edit the source file and then run MarkdownSnippets.
* [Diffinity](/docs/diff-tool.md#diffinity)
* [VisualStudioCode](/docs/diff-tool.md#visualstudiocode)
* [VisualStudio](/docs/diff-tool.md#visualstudio)
* [Rider](/docs/diff-tool.md#rider) <!-- end include: defaultOrder. path: /src/Tests/defaultOrder.include.md -->
* [Rider](/docs/diff-tool.md#rider)
* [Vim](/docs/diff-tool.md#vim) <!-- end include: defaultOrder. path: /src/Tests/defaultOrder.include.md -->


## Custom order
Expand All @@ -50,5 +51,5 @@ For example `VisualStudio,Meld` will result in VisualStudio then Meld then all o
```cs
DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge);
```
<sup><a href='/src/Tests/DiffToolsTest.cs#L113-L115' title='File snippet `useorder` was extracted from'>snippet source</a> | <a href='#snippet-useorder' title='Navigate to start of snippet `useorder`'>anchor</a></sup>
<sup><a href='/src/Tests/DiffToolsTest.cs#L116-L118' title='File snippet `useorder` was extracted from'>snippet source</a> | <a href='#snippet-useorder' title='Navigate to start of snippet `useorder`'>anchor</a></sup>
<!-- endsnippet -->
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Support is available via [Tidelift](https://tidelift.com/subscription/pkg/nuget-
* [TortoiseGitMerge](/docs/diff-tool.md#tortoisegitmerge)
* [TortoiseIDiff](/docs/diff-tool.md#tortoiseidiff)
* [TortoiseMerge](/docs/diff-tool.md#tortoisemerge)
* [Vim](/docs/diff-tool.md#vim)
* [VisualStudio](/docs/diff-tool.md#visualstudio)
* [VisualStudioCode](/docs/diff-tool.md#visualstudiocode)
* [WinMerge](/docs/diff-tool.md#winmerge) <!-- end include: diffToolList. path: /src/Tests/diffToolList.include.md -->
Expand Down
5 changes: 4 additions & 1 deletion src/DiffEngine/Definition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Definition
public OsSettings? Osx { get; }
public string[] BinaryExtensions { get; }
public string? Notes { get; }
public bool ShellExecute { get; }
public bool SupportsText { get; }
public bool RequiresTarget { get; }

Expand All @@ -27,14 +28,16 @@ public Definition(
OsSettings? windows = null,
OsSettings? linux = null,
OsSettings? osx = null,
string? notes = null)
string? notes = null,
bool shellExecute = false)
{
Tool = name;
Url = url;
AutoRefresh = autoRefresh;
IsMdi = isMdi;
BinaryExtensions = binaryExtensions;
Notes = notes;
ShellExecute = shellExecute;
SupportsText = supportsText;
RequiresTarget = requiresTarget;
Windows = windows;
Expand Down
3 changes: 2 additions & 1 deletion src/DiffEngine/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ internal static List<Definition> Tools()
Implementation.Diffinity(),
Implementation.VsCode(),
Implementation.VisualStudio(),
Implementation.Rider()
Implementation.Rider(),
Implementation.Vim()
};
}
}
6 changes: 5 additions & 1 deletion src/DiffEngine/DiffRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ static LaunchResult InnerLaunch(ResolvedTool tool, string tempFile, string targe
var arguments = tool.Arguments(tempFile, targetFile);
try
{
Process.Start(tool.ExePath, arguments);
var startInfo = new ProcessStartInfo(tool.ExePath, arguments)
{
UseShellExecute = tool.ShellExecute
};
Process.Start(startInfo);
return LaunchResult.StartedNewInstance;
}
catch (Exception exception)
Expand Down
3 changes: 2 additions & 1 deletion src/DiffEngine/DiffTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum DiffTool
Diffinity,
VisualStudio,
VisualStudioCode,
Rider
Rider,
Vim
}
}
78 changes: 66 additions & 12 deletions src/DiffEngine/DiffTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,27 @@ public static class DiffTools

public static IEnumerable<ResolvedTool> Resolved { get => resolved; }

public static ResolvedTool? AddTool(
string name,
public static ResolvedTool? AddTool(string name,
bool autoRefresh,
bool isMdi,
bool supportsText,
bool requiresTarget,
bool shellExecute,
BuildArguments arguments,
string exePath,
IEnumerable<string> binaryExtensions)
{
return AddInner(name, null, autoRefresh, isMdi, supportsText, requiresTarget, binaryExtensions, exePath, arguments);
return AddInner(
name,
null,
autoRefresh,
isMdi,
supportsText,
requiresTarget,
binaryExtensions,
exePath,
arguments,
shellExecute);
}

public static ResolvedTool? AddToolBasedOn(
Expand All @@ -35,7 +45,8 @@ public static class DiffTools
bool? requiresTarget = null,
BuildArguments? arguments = null,
string? exePath = null,
IEnumerable<string>? binaryExtensions = null)
IEnumerable<string>? binaryExtensions = null,
bool? shellExecute = null)
{
var existing = resolved.SingleOrDefault(x => x.Tool == basedOn);
if (existing == null)
Expand All @@ -49,10 +60,10 @@ public static class DiffTools
isMdi ?? existing.IsMdi,
supportsText ?? existing.SupportsText,
requiresTarget ?? existing.RequiresTarget,
shellExecute ?? existing.ShellExecute,
arguments ?? existing.Arguments,
exePath ?? existing.ExePath,
binaryExtensions ?? existing.BinaryExtensions
);
binaryExtensions ?? existing.BinaryExtensions);
}

public static ResolvedTool? AddTool(
Expand All @@ -61,12 +72,23 @@ public static class DiffTools
bool isMdi,
bool supportsText,
bool requiresTarget,
bool useShellExecute,
IEnumerable<string> binaryExtensions,
OsSettings? windows = null,
OsSettings? linux = null,
OsSettings? osx = null)
{
return AddTool(name, null, autoRefresh, isMdi, supportsText, requiresTarget, binaryExtensions, windows, linux, osx);
return AddTool(
name,
null,
autoRefresh,
isMdi, supportsText,
requiresTarget,
binaryExtensions,
windows,
linux,
osx,
useShellExecute);
}

static ResolvedTool? AddTool(
Expand All @@ -79,7 +101,8 @@ public static class DiffTools
IEnumerable<string> binaryExtensions,
OsSettings? windows,
OsSettings? linux,
OsSettings? osx)
OsSettings? osx,
bool useShellExecute)
{
if (windows == null &&
linux == null &&
Expand All @@ -92,7 +115,17 @@ public static class DiffTools
return null;
}

return AddInner(name, diffTool, autoRefresh, isMdi, supportsText, requiresTarget, binaryExtensions, exePath, arguments);
return AddInner(
name,
diffTool,
autoRefresh,
isMdi,
supportsText,
requiresTarget,
binaryExtensions,
exePath,
arguments,
useShellExecute);
}

static ResolvedTool? AddInner(
Expand All @@ -104,7 +137,8 @@ public static class DiffTools
bool requiresTarget,
IEnumerable<string> binaries,
string exePath,
BuildArguments arguments)
BuildArguments arguments,
bool useShellExecute)
{
Guard.AgainstNullOrEmpty(name, nameof(name));
Guard.AgainstNull(binaries, nameof(binaries));
Expand All @@ -119,7 +153,16 @@ public static class DiffTools
return null;
}

var resolvedTool = new ResolvedTool(name, diffTool, resolvedExePath, arguments, isMdi, autoRefresh, binaries.ToList(), requiresTarget, supportsText);
var resolvedTool = new ResolvedTool(
name,
diffTool,
resolvedExePath,
arguments, isMdi,
autoRefresh,
binaries.ToList(),
requiresTarget,
supportsText,
useShellExecute);

AddResolvedToolAtStart(resolvedTool);

Expand Down Expand Up @@ -158,7 +201,18 @@ static void InitTools(bool resultFoundInEnvVar, IEnumerable<DiffTool> tools)

foreach (var tool in ToolsOrder.Sort(resultFoundInEnvVar, tools).Reverse())
{
AddTool(tool.Tool.ToString(), tool.Tool, tool.AutoRefresh, tool.IsMdi, tool.SupportsText, tool.RequiresTarget, tool.BinaryExtensions, tool.Windows, tool.Linux, tool.Osx);
AddTool(
tool.Tool.ToString(),
tool.Tool,
tool.AutoRefresh,
tool.IsMdi,
tool.SupportsText,
tool.RequiresTarget,
tool.BinaryExtensions,
tool.Windows,
tool.Linux,
tool.Osx,
tool.ShellExecute);
}

custom.Reverse();
Expand Down
30 changes: 30 additions & 0 deletions src/DiffEngine/Implementation/Vim.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using DiffEngine;

static partial class Implementation
{
public static Definition Vim()
{
string Arguments(string temp, string target)
{
return $"-d \"{temp}\" \"{target}\" -c \"setl autoread | setl nobackup | set noswapfile\"";
}

return new Definition(
name: DiffTool.Vim,
url: "https://www.vim.org/",
autoRefresh: true,
isMdi: false,
supportsText: true,
shellExecute: true,
requiresTarget: true,
binaryExtensions: Array.Empty<string>(),
windows: new OsSettings(Arguments, @"%ProgramFiles%\Vim\*\vim.exe"),
notes: @"
* [Options](http://vimdoc.sourceforge.net/htmldoc/options.html)
* [Vim help files](https://vimhelp.org/)
* [autoread](http://vimdoc.sourceforge.net/htmldoc/options.html#'autoread')
* [nobackup](http://vimdoc.sourceforge.net/htmldoc/options.html#'backup')
* [noswapfile](http://vimdoc.sourceforge.net/htmldoc/options.html#'swapfile')");
}
}
9 changes: 7 additions & 2 deletions src/DiffEngine/ResolvedTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ResolvedTool
public IReadOnlyList<string> BinaryExtensions { get; }
public bool RequiresTarget { get; }
public bool SupportsText { get; }
public bool ShellExecute { get; }

public string BuildCommand(string tempFile, string targetFile)
{
Expand All @@ -30,7 +31,8 @@ internal ResolvedTool(
bool autoRefresh,
IReadOnlyList<string> binaryExtensions,
bool requiresTarget,
bool supportsText)
bool supportsText,
bool shellExecute)
{
Name = name;
Tool = tool;
Expand All @@ -41,6 +43,7 @@ internal ResolvedTool(
BinaryExtensions = binaryExtensions;
RequiresTarget = requiresTarget;
SupportsText = supportsText;
ShellExecute = shellExecute;
}

public ResolvedTool(
Expand All @@ -51,7 +54,8 @@ public ResolvedTool(
bool autoRefresh,
string[] binaryExtensions,
bool requiresTarget,
bool supportsText)
bool supportsText,
bool shellExecute)
{
Guard.FileExists(exePath, nameof(exePath));
Guard.AgainstNullOrEmpty(name, nameof(name));
Expand All @@ -65,6 +69,7 @@ public ResolvedTool(
BinaryExtensions = binaryExtensions;
RequiresTarget = requiresTarget;
SupportsText = supportsText;
ShellExecute = shellExecute;
}
}
}
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649</NoWarn>
<Version>3.6.0</Version>
<Version>4.0.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Json, Testing, Verify, Snapshot, Approvals</PackageTags>
<Description>Enables simple verification of complex models and documents.</Description>
Expand Down
Loading

0 comments on commit 17f802e

Please sign in to comment.