diff --git a/GitDiffMargin.Commands/CommandHandlerTextViewCreationListener.cs b/GitDiffMargin.Commands/CommandHandlerTextViewCreationListener.cs
index a6b275d..c6bcd01 100644
--- a/GitDiffMargin.Commands/CommandHandlerTextViewCreationListener.cs
+++ b/GitDiffMargin.Commands/CommandHandlerTextViewCreationListener.cs
@@ -1,22 +1,23 @@
-namespace GitDiffMargin.Commands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Editor;
- using Microsoft.VisualStudio.Shell;
- using Microsoft.VisualStudio.Text.Editor;
- using Microsoft.VisualStudio.TextManager.Interop;
- using Microsoft.VisualStudio.Utilities;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Editor;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.TextManager.Interop;
+using Microsoft.VisualStudio.Utilities;
+namespace GitDiffMargin.Commands
+{
[Export(typeof(IVsTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Editable)]
internal class CommandHandlerTextViewCreationListener : IVsTextViewCreationListener
{
- private readonly SVsServiceProvider _serviceProvider;
private readonly IVsEditorAdaptersFactoryService _editorAdaptersFactoryService;
+ private readonly SVsServiceProvider _serviceProvider;
[ImportingConstructor]
- public CommandHandlerTextViewCreationListener(SVsServiceProvider serviceProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
+ public CommandHandlerTextViewCreationListener(SVsServiceProvider serviceProvider,
+ IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
{
_serviceProvider = serviceProvider;
_editorAdaptersFactoryService = editorAdaptersFactoryService;
@@ -30,8 +31,8 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
// The new command handling approach does not require that the command filter be enabled. The command
// implementations interact directly with the handler via its IOleCommandTarget interface.
- GitDiffMarginCommandHandler filter = new GitDiffMarginCommandHandler(textViewAdapter, _editorAdaptersFactoryService, textView);
+ var filter = new GitDiffMarginCommandHandler(textViewAdapter, _editorAdaptersFactoryService, textView);
textView.Properties.AddProperty(typeof(GitDiffMarginCommandHandler), filter);
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/CopyOldTextCommandArgs.cs b/GitDiffMargin.Commands/CopyOldTextCommandArgs.cs
index 8c22a8d..4aa5b66 100644
--- a/GitDiffMargin.Commands/CopyOldTextCommandArgs.cs
+++ b/GitDiffMargin.Commands/CopyOldTextCommandArgs.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using Microsoft.VisualStudio.Text;
- using Microsoft.VisualStudio.Text.Editor;
- using Microsoft.VisualStudio.Text.Editor.Commanding;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.Text.Editor.Commanding;
+namespace GitDiffMargin.Commands
+{
internal class CopyOldTextCommandArgs : EditorCommandArgs
{
public CopyOldTextCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
@@ -11,4 +11,4 @@ public CopyOldTextCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
{
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/CopyOldTextCommandHandler.cs b/GitDiffMargin.Commands/CopyOldTextCommandHandler.cs
index 4edc684..fb062e3 100644
--- a/GitDiffMargin.Commands/CopyOldTextCommandHandler.cs
+++ b/GitDiffMargin.Commands/CopyOldTextCommandHandler.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Commanding;
- using Microsoft.VisualStudio.Utilities;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Commanding;
+using Microsoft.VisualStudio.Utilities;
+namespace GitDiffMargin.Commands
+{
[Export(typeof(ICommandHandler))]
[ContentType("text")]
[Name(nameof(CopyOldTextCommandHandler))]
@@ -16,4 +16,4 @@ public CopyOldTextCommandHandler()
public override string DisplayName => "Copy Old Text";
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/GitDiffMargin.Commands.csproj b/GitDiffMargin.Commands/GitDiffMargin.Commands.csproj
index 387a29e..3478af2 100644
--- a/GitDiffMargin.Commands/GitDiffMargin.Commands.csproj
+++ b/GitDiffMargin.Commands/GitDiffMargin.Commands.csproj
@@ -21,6 +21,7 @@
DEBUG;TRACE
prompt
4
+ 7.3
pdbonly
diff --git a/GitDiffMargin.Commands/GitDiffMarginCommandBinding.cs b/GitDiffMargin.Commands/GitDiffMarginCommandBinding.cs
index 45b283f..99c4745 100644
--- a/GitDiffMargin.Commands/GitDiffMarginCommandBinding.cs
+++ b/GitDiffMargin.Commands/GitDiffMarginCommandBinding.cs
@@ -1,32 +1,37 @@
-namespace GitDiffMargin.Commands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Editor.Commanding;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Editor.Commanding;
+namespace GitDiffMargin.Commands
+{
internal class GitDiffMarginCommandBinding
{
#pragma warning disable CS0649 // Field 'fieldName' is never assigned to, and will always have its default value null
[Export]
- [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.PreviousChange, typeof(PreviousChangeCommandArgs))]
+ [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.PreviousChange,
+ typeof(PreviousChangeCommandArgs))]
internal CommandBindingDefinition PreviousChangeCommandBinding;
[Export]
- [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.NextChange, typeof(NextChangeCommandArgs))]
+ [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.NextChange,
+ typeof(NextChangeCommandArgs))]
internal CommandBindingDefinition NextChangeCommandBinding;
[Export]
- [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.RollbackChange, typeof(RollbackChangeCommandArgs))]
+ [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.RollbackChange,
+ typeof(RollbackChangeCommandArgs))]
internal CommandBindingDefinition RollbackChangeCommandBinding;
[Export]
- [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.CopyOldText, typeof(CopyOldTextCommandArgs))]
+ [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.CopyOldText,
+ typeof(CopyOldTextCommandArgs))]
internal CommandBindingDefinition CopyOldTextCommandBinding;
[Export]
- [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint)GitDiffMarginCommand.ShowPopup, typeof(ShowPopupCommandArgs))]
+ [CommandBinding(GitDiffMarginCommandHandler.GitDiffMarginCommandSet, (uint) GitDiffMarginCommand.ShowPopup,
+ typeof(ShowPopupCommandArgs))]
internal CommandBindingDefinition ShowPopupCommandBinding;
#pragma warning restore CS0649 // Field 'fieldName' is never assigned to, and will always have its default value null
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/GitDiffMarginCommandHandler`1.cs b/GitDiffMargin.Commands/GitDiffMarginCommandHandler`1.cs
index 7f716d1..5ed7bc4 100644
--- a/GitDiffMargin.Commands/GitDiffMarginCommandHandler`1.cs
+++ b/GitDiffMargin.Commands/GitDiffMarginCommandHandler`1.cs
@@ -1,18 +1,21 @@
-namespace GitDiffMargin.Commands
-{
- using System;
- using Microsoft.VisualStudio.OLE.Interop;
- using Microsoft.VisualStudio.Text.Editor.Commanding;
+using System;
+using Microsoft.VisualStudio.OLE.Interop;
+using Microsoft.VisualStudio.Text.Editor.Commanding;
+namespace GitDiffMargin.Commands
+{
internal abstract class GitDiffMarginCommandHandler : ShimCommandHandler
where T : EditorCommandArgs
{
protected GitDiffMarginCommandHandler(GitDiffMarginCommand commandId)
- : base(new Guid(GitDiffMarginCommandHandler.GitDiffMarginCommandSet), (uint)commandId)
+ : base(new Guid(GitDiffMarginCommandHandler.GitDiffMarginCommandSet), (uint) commandId)
{
}
protected override IOleCommandTarget GetCommandTarget(T args)
- => args.TextView.Properties.GetProperty(typeof(GitDiffMarginCommandHandler));
+ {
+ return args.TextView.Properties.GetProperty(
+ typeof(GitDiffMarginCommandHandler));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/NextChangeCommandArgs.cs b/GitDiffMargin.Commands/NextChangeCommandArgs.cs
index 664321b..071c405 100644
--- a/GitDiffMargin.Commands/NextChangeCommandArgs.cs
+++ b/GitDiffMargin.Commands/NextChangeCommandArgs.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using Microsoft.VisualStudio.Text;
- using Microsoft.VisualStudio.Text.Editor;
- using Microsoft.VisualStudio.Text.Editor.Commanding;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.Text.Editor.Commanding;
+namespace GitDiffMargin.Commands
+{
internal class NextChangeCommandArgs : EditorCommandArgs
{
public NextChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
@@ -11,4 +11,4 @@ public NextChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
{
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/NextChangeCommandHandler.cs b/GitDiffMargin.Commands/NextChangeCommandHandler.cs
index 65c6359..ba96c34 100644
--- a/GitDiffMargin.Commands/NextChangeCommandHandler.cs
+++ b/GitDiffMargin.Commands/NextChangeCommandHandler.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Commanding;
- using Microsoft.VisualStudio.Utilities;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Commanding;
+using Microsoft.VisualStudio.Utilities;
+namespace GitDiffMargin.Commands
+{
[Export(typeof(ICommandHandler))]
[ContentType("text")]
[Name(nameof(NextChangeCommandHandler))]
@@ -16,4 +16,4 @@ public NextChangeCommandHandler()
public override string DisplayName => "Next Change";
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/PreviousChangeCommandArgs.cs b/GitDiffMargin.Commands/PreviousChangeCommandArgs.cs
index 85e5b4b..49a30fa 100644
--- a/GitDiffMargin.Commands/PreviousChangeCommandArgs.cs
+++ b/GitDiffMargin.Commands/PreviousChangeCommandArgs.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using Microsoft.VisualStudio.Text;
- using Microsoft.VisualStudio.Text.Editor;
- using Microsoft.VisualStudio.Text.Editor.Commanding;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.Text.Editor.Commanding;
+namespace GitDiffMargin.Commands
+{
internal class PreviousChangeCommandArgs : EditorCommandArgs
{
public PreviousChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
@@ -11,4 +11,4 @@ public PreviousChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
{
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/PreviousChangeCommandHandler.cs b/GitDiffMargin.Commands/PreviousChangeCommandHandler.cs
index 70eca90..adfc23c 100644
--- a/GitDiffMargin.Commands/PreviousChangeCommandHandler.cs
+++ b/GitDiffMargin.Commands/PreviousChangeCommandHandler.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Commanding;
- using Microsoft.VisualStudio.Utilities;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Commanding;
+using Microsoft.VisualStudio.Utilities;
+namespace GitDiffMargin.Commands
+{
[Export(typeof(ICommandHandler))]
[ContentType("text")]
[Name(nameof(PreviousChangeCommandHandler))]
@@ -16,4 +16,4 @@ public PreviousChangeCommandHandler()
public override string DisplayName => "Previous Change";
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/Properties/AssemblyInfo.cs b/GitDiffMargin.Commands/Properties/AssemblyInfo.cs
index 599f125..5074ca6 100644
--- a/GitDiffMargin.Commands/Properties/AssemblyInfo.cs
+++ b/GitDiffMargin.Commands/Properties/AssemblyInfo.cs
@@ -1,5 +1,4 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@@ -34,4 +33,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.8.0.0")]
[assembly: AssemblyFileVersion("3.8.0.0")]
-[assembly: AssemblyInformationalVersion("3.8.0.0")]
+[assembly: AssemblyInformationalVersion("3.8.0.0")]
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/RollbackChangeCommandArgs.cs b/GitDiffMargin.Commands/RollbackChangeCommandArgs.cs
index 3b0a5b7..9648d8a 100644
--- a/GitDiffMargin.Commands/RollbackChangeCommandArgs.cs
+++ b/GitDiffMargin.Commands/RollbackChangeCommandArgs.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using Microsoft.VisualStudio.Text;
- using Microsoft.VisualStudio.Text.Editor;
- using Microsoft.VisualStudio.Text.Editor.Commanding;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.Text.Editor.Commanding;
+namespace GitDiffMargin.Commands
+{
internal class RollbackChangeCommandArgs : EditorCommandArgs
{
public RollbackChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
@@ -11,4 +11,4 @@ public RollbackChangeCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
{
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/RollbackChangeCommandHandler.cs b/GitDiffMargin.Commands/RollbackChangeCommandHandler.cs
index efdd9d0..b709739 100644
--- a/GitDiffMargin.Commands/RollbackChangeCommandHandler.cs
+++ b/GitDiffMargin.Commands/RollbackChangeCommandHandler.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Commanding;
- using Microsoft.VisualStudio.Utilities;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Commanding;
+using Microsoft.VisualStudio.Utilities;
+namespace GitDiffMargin.Commands
+{
[Export(typeof(ICommandHandler))]
[ContentType("text")]
[Name(nameof(RollbackChangeCommandHandler))]
@@ -16,4 +16,4 @@ public RollbackChangeCommandHandler()
public override string DisplayName => "Rollback Change";
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/ShimCommandHandler.cs b/GitDiffMargin.Commands/ShimCommandHandler.cs
index c9e7191..9cc7f01 100644
--- a/GitDiffMargin.Commands/ShimCommandHandler.cs
+++ b/GitDiffMargin.Commands/ShimCommandHandler.cs
@@ -1,19 +1,16 @@
-namespace GitDiffMargin.Commands
-{
- using System;
- using Microsoft.VisualStudio;
- using Microsoft.VisualStudio.Commanding;
- using Microsoft.VisualStudio.Shell;
- using IOleCommandTarget = Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget;
- using OLECMD = Microsoft.VisualStudio.OLE.Interop.OLECMD;
- using OLECMDEXECOPT = Microsoft.VisualStudio.OLE.Interop.OLECMDEXECOPT;
- using OLECMDF = Microsoft.VisualStudio.OLE.Interop.OLECMDF;
+using System;
+using Microsoft.VisualStudio;
+using Microsoft.VisualStudio.Commanding;
+using Microsoft.VisualStudio.OLE.Interop;
+using Microsoft.VisualStudio.Shell;
+namespace GitDiffMargin.Commands
+{
internal abstract class ShimCommandHandler : ICommandHandler
where T : CommandArgs
{
- private readonly Guid _commandSet;
private readonly uint _commandId;
+ private readonly Guid _commandSet;
protected ShimCommandHandler(Guid commandSet, uint commandId)
{
@@ -21,32 +18,30 @@ protected ShimCommandHandler(Guid commandSet, uint commandId)
_commandId = commandId;
}
- public abstract string DisplayName
- {
- get;
- }
+ public abstract string DisplayName { get; }
public virtual CommandState GetCommandState(T args)
{
ThreadHelper.ThrowIfNotOnUIThread();
- OLECMD[] command = { new OLECMD { cmdID = _commandId } };
+ OLECMD[] command = {new OLECMD {cmdID = _commandId}};
ErrorHandler.ThrowOnFailure(GetCommandTarget(args).QueryStatus(_commandSet, 1, command, IntPtr.Zero));
- if ((command[0].cmdf & (uint)OLECMDF.OLECMDF_SUPPORTED) == 0)
+ if ((command[0].cmdf & (uint) OLECMDF.OLECMDF_SUPPORTED) == 0)
return CommandState.Unspecified;
- else if ((command[0].cmdf & (uint)OLECMDF.OLECMDF_ENABLED) == 0)
- return CommandState.Unavailable;
- else
- return CommandState.Available;
+
+ return (command[0].cmdf & (uint) OLECMDF.OLECMDF_ENABLED) == 0
+ ? CommandState.Unavailable
+ : CommandState.Available;
}
public virtual bool ExecuteCommand(T args, CommandExecutionContext executionContext)
{
ThreadHelper.ThrowIfNotOnUIThread();
- return ErrorHandler.Succeeded(GetCommandTarget(args).Exec(_commandSet, _commandId, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero));
+ return ErrorHandler.Succeeded(GetCommandTarget(args).Exec(_commandSet, _commandId,
+ (uint) OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero));
}
protected abstract IOleCommandTarget GetCommandTarget(T args);
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/ShowDiffCommandArgs.cs b/GitDiffMargin.Commands/ShowDiffCommandArgs.cs
index 35e5e03..db259aa 100644
--- a/GitDiffMargin.Commands/ShowDiffCommandArgs.cs
+++ b/GitDiffMargin.Commands/ShowDiffCommandArgs.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using Microsoft.VisualStudio.Text;
- using Microsoft.VisualStudio.Text.Editor;
- using Microsoft.VisualStudio.Text.Editor.Commanding;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.Text.Editor.Commanding;
+namespace GitDiffMargin.Commands
+{
internal class ShowDiffCommandArgs : EditorCommandArgs
{
public ShowDiffCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
@@ -11,4 +11,4 @@ public ShowDiffCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
{
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/ShowDiffCommandHandler.cs b/GitDiffMargin.Commands/ShowDiffCommandHandler.cs
index 91071ad..b86dcd6 100644
--- a/GitDiffMargin.Commands/ShowDiffCommandHandler.cs
+++ b/GitDiffMargin.Commands/ShowDiffCommandHandler.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Commanding;
- using Microsoft.VisualStudio.Utilities;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Commanding;
+using Microsoft.VisualStudio.Utilities;
+namespace GitDiffMargin.Commands
+{
[Export(typeof(ICommandHandler))]
[ContentType("text")]
[Name(nameof(ShowDiffCommandHandler))]
@@ -16,4 +16,4 @@ public ShowDiffCommandHandler()
public override string DisplayName => "Show Diff";
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/ShowPopupCommandArgs.cs b/GitDiffMargin.Commands/ShowPopupCommandArgs.cs
index e255bd6..fa6f25d 100644
--- a/GitDiffMargin.Commands/ShowPopupCommandArgs.cs
+++ b/GitDiffMargin.Commands/ShowPopupCommandArgs.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using Microsoft.VisualStudio.Text;
- using Microsoft.VisualStudio.Text.Editor;
- using Microsoft.VisualStudio.Text.Editor.Commanding;
+using Microsoft.VisualStudio.Text;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.Text.Editor.Commanding;
+namespace GitDiffMargin.Commands
+{
internal class ShowPopupCommandArgs : EditorCommandArgs
{
public ShowPopupCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
@@ -11,4 +11,4 @@ public ShowPopupCommandArgs(ITextView textView, ITextBuffer subjectBuffer)
{
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Commands/ShowPopupCommandHandler.cs b/GitDiffMargin.Commands/ShowPopupCommandHandler.cs
index 23ca7f0..78cec45 100644
--- a/GitDiffMargin.Commands/ShowPopupCommandHandler.cs
+++ b/GitDiffMargin.Commands/ShowPopupCommandHandler.cs
@@ -1,9 +1,9 @@
-namespace GitDiffMargin.Commands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Commanding;
- using Microsoft.VisualStudio.Utilities;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Commanding;
+using Microsoft.VisualStudio.Utilities;
+namespace GitDiffMargin.Commands
+{
[Export(typeof(ICommandHandler))]
[ContentType("text")]
[Name(nameof(ShowPopupCommandHandler))]
@@ -16,4 +16,4 @@ public ShowPopupCommandHandler()
public override string DisplayName => "Show Popup";
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Extension/GitDiffMargin.Extension.csproj b/GitDiffMargin.Extension/GitDiffMargin.Extension.csproj
index 34a73f0..f555772 100644
--- a/GitDiffMargin.Extension/GitDiffMargin.Extension.csproj
+++ b/GitDiffMargin.Extension/GitDiffMargin.Extension.csproj
@@ -26,6 +26,7 @@
DEBUG;TRACE
prompt
4
+ 7.3
pdbonly
diff --git a/GitDiffMargin.Extension/Properties/AssemblyInfo.cs b/GitDiffMargin.Extension/Properties/AssemblyInfo.cs
index c9cc8d8..8264dfa 100644
--- a/GitDiffMargin.Extension/Properties/AssemblyInfo.cs
+++ b/GitDiffMargin.Extension/Properties/AssemblyInfo.cs
@@ -38,4 +38,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.8.0.0")]
[assembly: AssemblyFileVersion("3.8.0.0")]
-[assembly: AssemblyInformationalVersion("3.8.0.0")]
+[assembly: AssemblyInformationalVersion("3.8.0.0")]
\ No newline at end of file
diff --git a/GitDiffMargin.Extension/source.extension.vsixmanifest b/GitDiffMargin.Extension/source.extension.vsixmanifest
index 66e6272..a952a20 100644
--- a/GitDiffMargin.Extension/source.extension.vsixmanifest
+++ b/GitDiffMargin.Extension/source.extension.vsixmanifest
@@ -1,29 +1,38 @@
-
-
-
- Git Diff Margin
- Git Diff Margin displays live changes of the currently edited file on Visual Studio 2012+ margin and scroll bar.
- https://github.com/laurentkempe/GitDiffMargin
- License.md
- http://visualstudiogallery.msdn.microsoft.com/cf49cf30-2ca6-4ea0-b7cc-6a8e0dadc1a8
- https://github.com/laurentkempe/GitDiffMargin/releases/tag/v3.8.0
- Resources/GitDiffMargin-Thumb.png
- Resources/GitDiffMargin-Preview.png
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ Git Diff Margin
+ Git Diff Margin displays live changes of the currently edited file on Visual Studio 2012+ margin and scroll bar.
+ https://github.com/laurentkempe/GitDiffMargin
+ License.md
+ http://visualstudiogallery.msdn.microsoft.com/cf49cf30-2ca6-4ea0-b7cc-6a8e0dadc1a8
+ https://github.com/laurentkempe/GitDiffMargin/releases/tag/v3.8.0
+ Resources/GitDiffMargin-Thumb.png
+ Resources/GitDiffMargin-Preview.png
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/GitDiffMargin.LegacyCommands/GitDiffMargin.LegacyCommands.csproj b/GitDiffMargin.LegacyCommands/GitDiffMargin.LegacyCommands.csproj
index 657b4eb..7a65cd0 100644
--- a/GitDiffMargin.LegacyCommands/GitDiffMargin.LegacyCommands.csproj
+++ b/GitDiffMargin.LegacyCommands/GitDiffMargin.LegacyCommands.csproj
@@ -20,6 +20,7 @@
DEBUG;TRACE
prompt
4
+ 7.3
pdbonly
diff --git a/GitDiffMargin.LegacyCommands/LegacyCommandHandlerTextViewCreationListener.cs b/GitDiffMargin.LegacyCommands/LegacyCommandHandlerTextViewCreationListener.cs
index a425cc8..216d685 100644
--- a/GitDiffMargin.LegacyCommands/LegacyCommandHandlerTextViewCreationListener.cs
+++ b/GitDiffMargin.LegacyCommands/LegacyCommandHandlerTextViewCreationListener.cs
@@ -1,22 +1,23 @@
-namespace GitDiffMargin.LegacyCommands
-{
- using System.ComponentModel.Composition;
- using Microsoft.VisualStudio.Editor;
- using Microsoft.VisualStudio.Shell;
- using Microsoft.VisualStudio.Text.Editor;
- using Microsoft.VisualStudio.TextManager.Interop;
- using Microsoft.VisualStudio.Utilities;
+using System.ComponentModel.Composition;
+using Microsoft.VisualStudio.Editor;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Text.Editor;
+using Microsoft.VisualStudio.TextManager.Interop;
+using Microsoft.VisualStudio.Utilities;
+namespace GitDiffMargin.LegacyCommands
+{
[Export(typeof(IVsTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Editable)]
internal class LegacyCommandHandlerTextViewCreationListener : IVsTextViewCreationListener
{
- private readonly SVsServiceProvider _serviceProvider;
private readonly IVsEditorAdaptersFactoryService _editorAdaptersFactoryService;
+ private readonly SVsServiceProvider _serviceProvider;
[ImportingConstructor]
- public LegacyCommandHandlerTextViewCreationListener(SVsServiceProvider serviceProvider, IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
+ public LegacyCommandHandlerTextViewCreationListener(SVsServiceProvider serviceProvider,
+ IVsEditorAdaptersFactoryService editorAdaptersFactoryService)
{
_serviceProvider = serviceProvider;
_editorAdaptersFactoryService = editorAdaptersFactoryService;
@@ -28,9 +29,9 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
if (textView == null)
return;
- GitDiffMarginCommandHandler filter = new GitDiffMarginCommandHandler(textViewAdapter, _editorAdaptersFactoryService, textView);
+ var filter = new GitDiffMarginCommandHandler(textViewAdapter, _editorAdaptersFactoryService, textView);
filter.Enabled = true;
textView.Properties.AddProperty(typeof(GitDiffMarginCommandHandler), filter);
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.LegacyCommands/Properties/AssemblyInfo.cs b/GitDiffMargin.LegacyCommands/Properties/AssemblyInfo.cs
index 280e953..ccab4ad 100644
--- a/GitDiffMargin.LegacyCommands/Properties/AssemblyInfo.cs
+++ b/GitDiffMargin.LegacyCommands/Properties/AssemblyInfo.cs
@@ -1,5 +1,4 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@@ -34,4 +33,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.8.0.0")]
[assembly: AssemblyFileVersion("3.8.0.0")]
-[assembly: AssemblyInformationalVersion("3.8.0.0")]
+[assembly: AssemblyInformationalVersion("3.8.0.0")]
\ No newline at end of file
diff --git a/GitDiffMargin.Unit.Tests/Git/GitDiffParserTests.cs b/GitDiffMargin.Unit.Tests/Git/GitDiffParserTests.cs
index 926effc..12b2e21 100644
--- a/GitDiffMargin.Unit.Tests/Git/GitDiffParserTests.cs
+++ b/GitDiffMargin.Unit.Tests/Git/GitDiffParserTests.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using GitDiffMargin.Git;
using NUnit.Framework;
@@ -43,8 +42,8 @@ index b8a4c69..e73b080 100644
+ bool IsDependencyThroughReference { get; }
*/
- private const string FirstGitDiff =
-@"diff --git a/skye-editor/Sources/skyeEditor/Core/Model/Dependency/IModelDependency.cs b/skye-editor/Sources/skyeEditor/Core/Model/Dependency/IModelDependency.cs
+ private const string FirstGitDiff =
+ @"diff --git a/skye-editor/Sources/skyeEditor/Core/Model/Dependency/IModelDependency.cs b/skye-editor/Sources/skyeEditor/Core/Model/Dependency/IModelDependency.cs
index b8a4c69..e73b080 100644
--- a/skye-editor/Sources/skyeEditor/Core/Model/Dependency/IModelDependency.cs
+++ b/skye-editor/Sources/skyeEditor/Core/Model/Dependency/IModelDependency.cs
@@ -71,8 +70,8 @@ index b8a4c69..e73b080 100644
+ bool IsDependencyThroughReference { get; } *
";
- private const string SecondGitDiff =
-@"diff --git a/skye-editor/Sources/skyeEditor/Core/Model/Dependency/ModelDependency.cs b/skye-editor/Sources/skyeEditor/Core/Model/Dependency/ModelDependency.cs
+ private const string SecondGitDiff =
+ @"diff --git a/skye-editor/Sources/skyeEditor/Core/Model/Dependency/ModelDependency.cs b/skye-editor/Sources/skyeEditor/Core/Model/Dependency/ModelDependency.cs
index 157e930..571aa23 100644
--- a/skye-editor/Sources/skyeEditor/Core/Model/Dependency/ModelDependency.cs
+++ b/skye-editor/Sources/skyeEditor/Core/Model/Dependency/ModelDependency.cs
@@ -114,8 +113,8 @@ index 157e930..571aa23 100644
private const string EmptyGitDiff = "";
- private const string ThirdGitDiff =
-@"diff --git a/README.md b/README.md
+ private const string ThirdGitDiff =
+ @"diff --git a/README.md b/README.md
index 8bb01f5..51495f9 100644
--- a/README.md
+++ b/README.md
@@ -124,8 +123,8 @@ index 8bb01f5..51495f9 100644
+# Hubot 2
";
- private const string DiffOfADeleteOfThreeLines =
-@"diff --git a/note.txt b/note.txt
+ private const string DiffOfADeleteOfThreeLines =
+ @"diff --git a/note.txt b/note.txt
index e91ba58..e2dbef0 100644
--- a/note.txt
+++ b/note.txt
@@ -134,8 +133,8 @@ index e91ba58..e2dbef0 100644
-using Microsoft.VisualStudio.Text;
-using Microsoft.VisualStudio.Text.Editor;";
- private const string DiffFromLibGit =
-@"diff --git a/ConsoleApplication1/Class1.cs b/ConsoleApplication1/Class1.cs
+ private const string DiffFromLibGit =
+ @"diff --git a/ConsoleApplication1/Class1.cs b/ConsoleApplication1/Class1.cs
index 6f4c525..a42139b 100644
--- a/ConsoleApplication1/Class1.cs
+++ b/ConsoleApplication1/Class1.cs
@@ -156,270 +155,274 @@ index 6f4c525..a42139b 100644
";
[Test]
- public void Parse_DiffFromLibGit_Expect5HunkRangeInfos()
+ public void GetHunkNewFile_DeleteDiff_ExpectHunkNewFile()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffOfADeleteOfThreeLines, 0);
+
//Act
- var hunkRangeInfos = gitDiffParser.Parse().ToList();
+ var hunkOriginalFile =
+ gitDiffParser.GetHunkOriginalFile(gitDiffParser.GetUnifiedFormatHunkLines().First().Item1);
//Assert
- hunkRangeInfos.Count.ShouldBe(5);
+ hunkOriginalFile.ShouldBe("7,3");
}
[Test]
- public void Parse_DiffFromLibGit_ExpectFirstHunkRangeToBeDeletion()
+ public void GetHunkNewFile_WithOneHunk_ExpectHunkNewFile()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
-
+ var gitDiffParser = new GitDiffParser(FirstGitDiff, 0);
+
//Act
- var hunkRangeInfos = gitDiffParser.Parse().ToList();
+ var hunkOriginalFile =
+ gitDiffParser.GetHunkOriginalFile(gitDiffParser.GetUnifiedFormatHunkLines().First().Item1);
//Assert
- hunkRangeInfos[0].IsDeletion.ShouldBe(true);
- hunkRangeInfos[0].IsAddition.ShouldBe(false);
- hunkRangeInfos[0].IsModification.ShouldBe(false);
+ hunkOriginalFile.ShouldBe("41,0");
}
[Test]
- public void Parse_DiffFromLibGit_ExpectSecondHunkRangeToBeModification()
+ public void GetHunkOriginalFile_DeleteDiff_ExpectHunkOriginalFile()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffOfADeleteOfThreeLines, 0);
+
//Act
- var hunkRangeInfos = gitDiffParser.Parse().ToList();
+ var hunkOriginalFile =
+ gitDiffParser.GetHunkNewFile(gitDiffParser.GetUnifiedFormatHunkLines().First().Item1);
//Assert
- hunkRangeInfos[1].IsDeletion.ShouldBe(false);
- hunkRangeInfos[1].IsAddition.ShouldBe(false);
- hunkRangeInfos[1].IsModification.ShouldBe(true);
+ hunkOriginalFile.ShouldBe("6,0");
}
[Test]
- public void Parse_DiffFromLibGit_ExpectSecondHunkRangeOriginalText()
+ public void GetHunkOriginalFile_WithOneHunk_ExpectHunkOriginalFile()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
-
+ var gitDiffParser = new GitDiffParser(FirstGitDiff, 0);
+
//Act
- var hunkRangeInfos = gitDiffParser.Parse().ToList();
+ var hunkOriginalFile =
+ gitDiffParser.GetHunkNewFile(gitDiffParser.GetUnifiedFormatHunkLines().First().Item1);
//Assert
- hunkRangeInfos[1].OriginalText.ShouldBe(new List {" class Class1"});
+ hunkOriginalFile.ShouldBe("42,20");
}
[Test]
- public void Parse_DiffFromLibGit_ExpectThirdHunkRangeToBeAddition()
+ public void GetUnifiedFormatHunkLine_DeleteDiff_ExpectedHunkLine()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffOfADeleteOfThreeLines, 0);
+
//Act
- var hunkRangeInfos = gitDiffParser.Parse().ToList();
+ var unifiedFormatHunk = gitDiffParser.GetUnifiedFormatHunkLines().ToList();
//Assert
- hunkRangeInfos[2].IsDeletion.ShouldBe(false);
- hunkRangeInfos[2].IsAddition.ShouldBe(true);
- hunkRangeInfos[2].IsModification.ShouldBe(false);
+ unifiedFormatHunk[0].Item1.ShouldBe("@@ -7,3 +6,0 @@ using GitDiffMargin.Git;");
}
[Test]
- public void Parse_DiffFromLibGit_ExpectFourthHunkRangeToBeDeletion()
+ public void GetUnifiedFormatHunkLine_WithOneHunk_ExpectHunkLine()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
-
+ var gitDiffParser = new GitDiffParser(FirstGitDiff, 0);
+
//Act
- var hunkRangeInfos = gitDiffParser.Parse().ToList();
+ var unifiedFormatHunk = gitDiffParser.GetUnifiedFormatHunkLines().ToList();
//Assert
- hunkRangeInfos[3].IsDeletion.ShouldBe(true);
- hunkRangeInfos[3].IsAddition.ShouldBe(false);
- hunkRangeInfos[3].IsModification.ShouldBe(false);
+ unifiedFormatHunk[0].Item1.ShouldBe("@@ -41,0 +42,20 @@ namespace skyeEditor.Core.Model.Dependency");
}
[Test]
- public void Parse_DiffFromLibGit_ExpectFifthHunkRangeToBeAddition()
+ public void GetUnifiedFormatHunkLine_WithTwoHunk_ExpectHunkLine()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
-
+ var gitDiffParser = new GitDiffParser(SecondGitDiff, 0);
+
//Act
- var hunkRangeInfos = gitDiffParser.Parse().ToList();
+ var unifiedFormatHunk = gitDiffParser.GetUnifiedFormatHunkLines().ToList();
//Assert
- hunkRangeInfos[4].IsDeletion.ShouldBe(false);
- hunkRangeInfos[4].IsAddition.ShouldBe(true);
- hunkRangeInfos[4].IsModification.ShouldBe(false);
+ unifiedFormatHunk[0].Item1.ShouldBe("@@ -68,2 +67,0 @@ namespace skyeEditor.Core.Model.Dependency");
+ unifiedFormatHunk[1].Item1.ShouldBe("@@ -170,0 +169,27 @@ namespace skyeEditor.Core.Model.Dependency");
+ unifiedFormatHunk[2].Item1.ShouldBe("@@ -185,2 +209,0 @@ namespace skyeEditor.Core.Model.Dependency");
}
[Test]
- public void Parse_EmptyGitDiff_Expect0HunkRangeInfos()
+ public void Parse_DiffFromLibGit_Expect5HunkRangeInfos()
{
//Arrange
- var gitDiffParser = new GitDiffParser(EmptyGitDiff, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
+
//Act
var hunkRangeInfos = gitDiffParser.Parse().ToList();
//Assert
- hunkRangeInfos.Count.ShouldBe(0);
+ hunkRangeInfos.Count.ShouldBe(5);
}
[Test]
- public void Parse_WithOneHunk_ExpectHunkRanges()
+ public void Parse_DiffFromLibGit_ExpectFifthHunkRangeToBeAddition()
{
//Arrange
- var gitDiffParser = new GitDiffParser(FirstGitDiff, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
+
//Act
- var hunkRanges = gitDiffParser.Parse().ToList();
+ var hunkRangeInfos = gitDiffParser.Parse().ToList();
//Assert
- hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(40);
- hunkRanges[0].OriginalHunkRange.NumberOfLines.ShouldBe(0);
- hunkRanges[0].NewHunkRange.StartingLineNumber.ShouldBe(41);
- hunkRanges[0].NewHunkRange.NumberOfLines.ShouldBe(20);
+ hunkRangeInfos[4].IsDeletion.ShouldBe(false);
+ hunkRangeInfos[4].IsAddition.ShouldBe(true);
+ hunkRangeInfos[4].IsModification.ShouldBe(false);
}
-
+
[Test]
- public void Parse_WithOneHunkWithoutLineCount_ExpectHunkRanges()
+ public void Parse_DiffFromLibGit_ExpectFirstHunkRangeToBeDeletion()
{
//Arrange
- var gitDiffParser = new GitDiffParser(ThirdGitDiff, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
+
//Act
- var hunkRanges = gitDiffParser.Parse().ToList();
+ var hunkRangeInfos = gitDiffParser.Parse().ToList();
//Assert
- hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(0);
- hunkRanges[0].OriginalHunkRange.NumberOfLines.ShouldBe(1);
- hunkRanges[0].NewHunkRange.StartingLineNumber.ShouldBe(0);
- hunkRanges[0].NewHunkRange.NumberOfLines.ShouldBe(1);
+ hunkRangeInfos[0].IsDeletion.ShouldBe(true);
+ hunkRangeInfos[0].IsAddition.ShouldBe(false);
+ hunkRangeInfos[0].IsModification.ShouldBe(false);
}
[Test]
- public void Parse_WithThreeHunk_ExpectHunkRanges()
+ public void Parse_DiffFromLibGit_ExpectFourthHunkRangeToBeDeletion()
{
//Arrange
- var gitDiffParser = new GitDiffParser(SecondGitDiff, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
+
//Act
- var hunkRanges = gitDiffParser.Parse().ToList();
+ var hunkRangeInfos = gitDiffParser.Parse().ToList();
//Assert
- hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(67);
- hunkRanges[0].OriginalHunkRange.NumberOfLines.ShouldBe(2);
- hunkRanges[0].NewHunkRange.StartingLineNumber.ShouldBe(66);
- hunkRanges[0].NewHunkRange.NumberOfLines.ShouldBe(0);
-
- hunkRanges[1].OriginalHunkRange.StartingLineNumber.ShouldBe(169);
- hunkRanges[1].OriginalHunkRange.NumberOfLines.ShouldBe(0);
- hunkRanges[1].NewHunkRange.StartingLineNumber.ShouldBe(168);
- hunkRanges[1].NewHunkRange.NumberOfLines.ShouldBe(27);
-
- hunkRanges[2].OriginalHunkRange.StartingLineNumber.ShouldBe(184);
- hunkRanges[2].OriginalHunkRange.NumberOfLines.ShouldBe(2);
- hunkRanges[2].NewHunkRange.StartingLineNumber.ShouldBe(208);
- hunkRanges[2].NewHunkRange.NumberOfLines.ShouldBe(0);
+ hunkRangeInfos[3].IsDeletion.ShouldBe(true);
+ hunkRangeInfos[3].IsAddition.ShouldBe(false);
+ hunkRangeInfos[3].IsModification.ShouldBe(false);
}
[Test]
- public void GetUnifiedFormatHunkLine_WithOneHunk_ExpectHunkLine()
+ public void Parse_DiffFromLibGit_ExpectSecondHunkRangeOriginalText()
{
//Arrange
- var gitDiffParser = new GitDiffParser(FirstGitDiff, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
+
//Act
- var unifiedFormatHunk = gitDiffParser.GetUnifiedFormatHunkLines().ToList();
+ var hunkRangeInfos = gitDiffParser.Parse().ToList();
//Assert
- unifiedFormatHunk[0].Item1.ShouldBe("@@ -41,0 +42,20 @@ namespace skyeEditor.Core.Model.Dependency");
+ hunkRangeInfos[1].OriginalText.ShouldBe(new List {" class Class1"});
}
[Test]
- public void GetUnifiedFormatHunkLine_DeleteDiff_ExpectedHunkLine()
+ public void Parse_DiffFromLibGit_ExpectSecondHunkRangeToBeModification()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffOfADeleteOfThreeLines, 0);
+ var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
//Act
- var unifiedFormatHunk = gitDiffParser.GetUnifiedFormatHunkLines().ToList();
+ var hunkRangeInfos = gitDiffParser.Parse().ToList();
//Assert
- unifiedFormatHunk[0].Item1.ShouldBe("@@ -7,3 +6,0 @@ using GitDiffMargin.Git;");
+ hunkRangeInfos[1].IsDeletion.ShouldBe(false);
+ hunkRangeInfos[1].IsAddition.ShouldBe(false);
+ hunkRangeInfos[1].IsModification.ShouldBe(true);
}
[Test]
- public void GetUnifiedFormatHunkLine_WithTwoHunk_ExpectHunkLine()
+ public void Parse_DiffFromLibGit_ExpectThirdHunkRangeToBeAddition()
{
//Arrange
- var gitDiffParser = new GitDiffParser(SecondGitDiff, 0);
-
+ var gitDiffParser = new GitDiffParser(DiffFromLibGit, 0);
+
//Act
- List>> unifiedFormatHunk = gitDiffParser.GetUnifiedFormatHunkLines().ToList();
+ var hunkRangeInfos = gitDiffParser.Parse().ToList();
//Assert
- unifiedFormatHunk[0].Item1.ShouldBe("@@ -68,2 +67,0 @@ namespace skyeEditor.Core.Model.Dependency");
- unifiedFormatHunk[1].Item1.ShouldBe("@@ -170,0 +169,27 @@ namespace skyeEditor.Core.Model.Dependency");
- unifiedFormatHunk[2].Item1.ShouldBe("@@ -185,2 +209,0 @@ namespace skyeEditor.Core.Model.Dependency");
+ hunkRangeInfos[2].IsDeletion.ShouldBe(false);
+ hunkRangeInfos[2].IsAddition.ShouldBe(true);
+ hunkRangeInfos[2].IsModification.ShouldBe(false);
}
[Test]
- public void GetHunkOriginalFile_WithOneHunk_ExpectHunkOriginalFile()
+ public void Parse_EmptyGitDiff_Expect0HunkRangeInfos()
{
//Arrange
- var gitDiffParser = new GitDiffParser(FirstGitDiff, 0);
-
+ var gitDiffParser = new GitDiffParser(EmptyGitDiff, 0);
+
//Act
- string hunkOriginalFile = gitDiffParser.GetHunkNewFile(gitDiffParser.GetUnifiedFormatHunkLines().First().Item1);
+ var hunkRangeInfos = gitDiffParser.Parse().ToList();
//Assert
- hunkOriginalFile.ShouldBe("42,20");
+ hunkRangeInfos.Count.ShouldBe(0);
}
[Test]
- public void GetHunkNewFile_WithOneHunk_ExpectHunkNewFile()
+ public void Parse_WithOneHunk_ExpectHunkRanges()
{
//Arrange
var gitDiffParser = new GitDiffParser(FirstGitDiff, 0);
-
+
//Act
- string hunkOriginalFile = gitDiffParser.GetHunkOriginalFile(gitDiffParser.GetUnifiedFormatHunkLines().First().Item1);
+ var hunkRanges = gitDiffParser.Parse().ToList();
//Assert
- hunkOriginalFile.ShouldBe("41,0");
+ hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(40);
+ hunkRanges[0].OriginalHunkRange.NumberOfLines.ShouldBe(0);
+ hunkRanges[0].NewHunkRange.StartingLineNumber.ShouldBe(41);
+ hunkRanges[0].NewHunkRange.NumberOfLines.ShouldBe(20);
}
[Test]
- public void GetHunkOriginalFile_DeleteDiff_ExpectHunkOriginalFile()
+ public void Parse_WithOneHunkWithoutLineCount_ExpectHunkRanges()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffOfADeleteOfThreeLines, 0);
+ var gitDiffParser = new GitDiffParser(ThirdGitDiff, 0);
//Act
- var hunkOriginalFile = gitDiffParser.GetHunkNewFile(gitDiffParser.GetUnifiedFormatHunkLines().First().Item1);
+ var hunkRanges = gitDiffParser.Parse().ToList();
//Assert
- hunkOriginalFile.ShouldBe("6,0");
+ hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(0);
+ hunkRanges[0].OriginalHunkRange.NumberOfLines.ShouldBe(1);
+ hunkRanges[0].NewHunkRange.StartingLineNumber.ShouldBe(0);
+ hunkRanges[0].NewHunkRange.NumberOfLines.ShouldBe(1);
}
[Test]
- public void GetHunkNewFile_DeleteDiff_ExpectHunkNewFile()
+ public void Parse_WithThreeHunk_ExpectHunkRanges()
{
//Arrange
- var gitDiffParser = new GitDiffParser(DiffOfADeleteOfThreeLines, 0);
+ var gitDiffParser = new GitDiffParser(SecondGitDiff, 0);
//Act
- var hunkOriginalFile = gitDiffParser.GetHunkOriginalFile(gitDiffParser.GetUnifiedFormatHunkLines().First().Item1);
+ var hunkRanges = gitDiffParser.Parse().ToList();
//Assert
- hunkOriginalFile.ShouldBe("7,3");
+ hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(67);
+ hunkRanges[0].OriginalHunkRange.NumberOfLines.ShouldBe(2);
+ hunkRanges[0].NewHunkRange.StartingLineNumber.ShouldBe(66);
+ hunkRanges[0].NewHunkRange.NumberOfLines.ShouldBe(0);
+
+ hunkRanges[1].OriginalHunkRange.StartingLineNumber.ShouldBe(169);
+ hunkRanges[1].OriginalHunkRange.NumberOfLines.ShouldBe(0);
+ hunkRanges[1].NewHunkRange.StartingLineNumber.ShouldBe(168);
+ hunkRanges[1].NewHunkRange.NumberOfLines.ShouldBe(27);
+
+ hunkRanges[2].OriginalHunkRange.StartingLineNumber.ShouldBe(184);
+ hunkRanges[2].OriginalHunkRange.NumberOfLines.ShouldBe(2);
+ hunkRanges[2].NewHunkRange.StartingLineNumber.ShouldBe(208);
+ hunkRanges[2].NewHunkRange.NumberOfLines.ShouldBe(0);
}
}
// ReSharper restore InconsistentNaming
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Unit.Tests/Git/HunkRangeInfoTests.cs b/GitDiffMargin.Unit.Tests/Git/HunkRangeInfoTests.cs
index 53d9b27..47747f8 100644
--- a/GitDiffMargin.Unit.Tests/Git/HunkRangeInfoTests.cs
+++ b/GitDiffMargin.Unit.Tests/Git/HunkRangeInfoTests.cs
@@ -19,16 +19,17 @@ public HunkRangeInfoTests(int contextLines)
_contextLines = contextLines;
}
- private readonly int _contextLines = 0;
+ private readonly int _contextLines;
[Test]
public void IsAddition_AllDiffLinesWithStartsWithPlusSign_ExpectedTrue()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List { "+ ", "+ " }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines),
+ new HunkRange("+42,20", _contextLines), new List {"+ ", "+ "}.ToArray());
//Act
- bool isAddition = hunkRangeInfo.IsAddition;
+ var isAddition = hunkRangeInfo.IsAddition;
//Assert
isAddition.ShouldBe(true);
@@ -38,78 +39,91 @@ public void IsAddition_AllDiffLinesWithStartsWithPlusSign_ExpectedTrue()
public void IsAddition_NotAllDiffLinesStartsWithPlusSign_ExpectedFalse()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List { "+ ", "- " }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines),
+ new HunkRange("+42,20", _contextLines), new List {"+ ", "- "}.ToArray());
//Act
- bool isAddition = hunkRangeInfo.IsAddition;
+ var isAddition = hunkRangeInfo.IsAddition;
//Assert
isAddition.ShouldBe(false);
}
[Test]
- public void IsModification_DiffLinesStartsWithPlusSignAndWithMinus_ExpectedTrue()
+ public void IsDeletion_3DeletedLines_ExpectTrue()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List { "+ ", "- " }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-7,3", _contextLines),
+ new HunkRange("+6,0", _contextLines),
+ new List
+ {
+ "-using Microsoft.VisualStudio.Shell;", "-using Microsoft.VisualStudio.Text;",
+ "-using Microsoft.VisualStudio.Text.Editor;"
+ }.ToArray());
//Act
- bool isModification = hunkRangeInfo.IsModification;
+ var isDeletion = hunkRangeInfo.IsDeletion;
//Assert
- isModification.ShouldBe(true);
+ isDeletion.ShouldBe(true);
}
[Test]
- public void OriginalText_1NewLineAnd1OriginalLine_ExpectedOriginalText()
+ public void IsModification_DiffLinesStartsWithPlusSignAndWithMinus_ExpectedTrue()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List { "+New Text", "-Original Text" }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines),
+ new HunkRange("+42,20", _contextLines), new List {"+ ", "- "}.ToArray());
//Act
- string originalText = hunkRangeInfo.OriginalText[0];
+ var isModification = hunkRangeInfo.IsModification;
//Assert
- originalText.ShouldBe("Original Text");
+ isModification.ShouldBe(true);
}
[Test]
- public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpaces_ExpectedOriginalText()
+ public void OriginalText_1NewLineAnd1OriginalLine_ExpectedOriginalText()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines), new HunkRange("+42,20", _contextLines), new List { "+ New Text", "- Original Text" }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines),
+ new HunkRange("+42,20", _contextLines), new List {"+New Text", "-Original Text"}.ToArray());
//Act
- string originalText = hunkRangeInfo.OriginalText[0];
+ var originalText = hunkRangeInfo.OriginalText[0];
//Assert
- originalText.ShouldBe(" Original Text");
+ originalText.ShouldBe("Original Text");
}
[Test]
- public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpacesAndInvertedOrder_ExpectedOriginalText()
+ public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpaces_ExpectedOriginalText()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-18", _contextLines), new HunkRange("+18", _contextLines), new List { "- it++; // this is just a comment", "+ it--;" }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0", _contextLines),
+ new HunkRange("+42,20", _contextLines),
+ new List {"+ New Text", "- Original Text"}.ToArray());
//Act
- var originalText = hunkRangeInfo.OriginalText;
+ var originalText = hunkRangeInfo.OriginalText[0];
//Assert
- originalText[0].ShouldBe(" it++; // this is just a comment");
+ originalText.ShouldBe(" Original Text");
}
[Test]
- public void IsDeletion_3DeletedLines_ExpectTrue()
+ public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpacesAndInvertedOrder_ExpectedOriginalText()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-7,3", _contextLines), new HunkRange("+6,0", _contextLines), new List { "-using Microsoft.VisualStudio.Shell;", "-using Microsoft.VisualStudio.Text;", "-using Microsoft.VisualStudio.Text.Editor;" }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-18", _contextLines),
+ new HunkRange("+18", _contextLines),
+ new List {"- it++; // this is just a comment", "+ it--;"}.ToArray());
//Act
- var isDeletion = hunkRangeInfo.IsDeletion;
+ var originalText = hunkRangeInfo.OriginalText;
//Assert
- isDeletion.ShouldBe(true);
+ originalText[0].ShouldBe(" it++; // this is just a comment");
}
}
diff --git a/GitDiffMargin.Unit.Tests/Git/HunkRangeTests.cs b/GitDiffMargin.Unit.Tests/Git/HunkRangeTests.cs
index 74e7e89..148b6fb 100644
--- a/GitDiffMargin.Unit.Tests/Git/HunkRangeTests.cs
+++ b/GitDiffMargin.Unit.Tests/Git/HunkRangeTests.cs
@@ -9,6 +9,18 @@ namespace GitDiffMargin.Unit.Tests.Git
[TestFixture]
public class HunkRangeTests
{
+ [Test]
+ public void HunkRange_HunkNewFileWith3AsContextLines_ExpectHunkNewFile()
+ {
+ //Arrange
+ //Act
+ var hunkRange = new HunkRange(@"12,11", 3);
+
+ //Assert
+ hunkRange.StartingLineNumber.ShouldBe(14);
+ hunkRange.NumberOfLines.ShouldBe(5);
+ }
+
[Test]
public void HunkRange_HunkOriginalFile_ExpectHunkOriginalFile()
{
@@ -45,18 +57,6 @@ public void HunkRange_ValidHunk_ExpectHunkNewFile()
hunkRange.NumberOfLines.ShouldBe(20);
}
- [Test]
- public void HunkRange_HunkNewFileWith3AsContextLines_ExpectHunkNewFile()
- {
- //Arrange
- //Act
- var hunkRange = new HunkRange(@"12,11", 3);
-
- //Assert
- hunkRange.StartingLineNumber.ShouldBe(14);
- hunkRange.NumberOfLines.ShouldBe(5);
- }
-
[Test]
public void NumberOfLines_HunkWithoutLineNumber_ExpectDefaultTo1LineNumber()
{
@@ -85,4 +85,4 @@ public void StartingLineNumber_HunkWithoutLineNumber_ExpectLineNumber()
}
// ReSharper restore InconsistentNaming
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin.Unit.Tests/GitDiffMargin.Unit.Tests.csproj b/GitDiffMargin.Unit.Tests/GitDiffMargin.Unit.Tests.csproj
index 245fb0b..52c047e 100644
--- a/GitDiffMargin.Unit.Tests/GitDiffMargin.Unit.Tests.csproj
+++ b/GitDiffMargin.Unit.Tests/GitDiffMargin.Unit.Tests.csproj
@@ -24,6 +24,7 @@
prompt
4
false
+ 7.3
pdbonly
diff --git a/GitDiffMargin.Unit.Tests/Properties/AssemblyInfo.cs b/GitDiffMargin.Unit.Tests/Properties/AssemblyInfo.cs
index a1d43c5..eefc69b 100644
--- a/GitDiffMargin.Unit.Tests/Properties/AssemblyInfo.cs
+++ b/GitDiffMargin.Unit.Tests/Properties/AssemblyInfo.cs
@@ -1,5 +1,4 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@@ -33,4 +32,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
diff --git a/GitDiffMargin/Core/BackgroundParser.cs b/GitDiffMargin/Core/BackgroundParser.cs
index 6138314..2bd9f02 100644
--- a/GitDiffMargin/Core/BackgroundParser.cs
+++ b/GitDiffMargin/Core/BackgroundParser.cs
@@ -1,4 +1,4 @@
-/* The MIT License
+/* The MIT License
*
* Copyright (c) 2013 Sam Harwell, Tunnel Vision Labs, LLC
*
@@ -32,31 +32,25 @@ namespace GitDiffMargin.Core
{
public abstract class BackgroundParser : IDisposable
{
- private readonly WeakReference _textBuffer;
private readonly TaskScheduler _taskScheduler;
- private readonly ITextDocumentFactoryService _textDocumentFactoryService;
+ private readonly WeakReference _textBuffer;
private readonly Timer _timer;
-
- private TimeSpan _reparseDelay;
- private DateTimeOffset _lastEdit;
private bool _dirty;
+ private DateTimeOffset _lastEdit;
private int _parsing;
- private bool _disposed;
- public event EventHandler ParseComplete;
+ private TimeSpan _reparseDelay;
- protected BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService)
+ protected BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler,
+ ITextDocumentFactoryService textDocumentFactoryService)
{
if (textBuffer == null)
- throw new ArgumentNullException("textBuffer");
- if (taskScheduler == null)
- throw new ArgumentNullException("taskScheduler");
- if (textDocumentFactoryService == null)
- throw new ArgumentNullException("textDocumentFactoryService");
-
+ throw new ArgumentNullException(nameof(textBuffer));
_textBuffer = new WeakReference(textBuffer);
- _taskScheduler = taskScheduler;
- _textDocumentFactoryService = textDocumentFactoryService;
+
+ _taskScheduler = taskScheduler ?? throw new ArgumentNullException(nameof(taskScheduler));
+ TextDocumentFactoryService = textDocumentFactoryService ??
+ throw new ArgumentNullException(nameof(textDocumentFactoryService));
textBuffer.PostChanged += TextBufferPostChanged;
@@ -66,32 +60,17 @@ protected BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler,
_lastEdit = DateTimeOffset.MinValue;
}
- public ITextBuffer TextBuffer
- {
- get
- {
- return _textBuffer.Target;
- }
- }
+ public ITextBuffer TextBuffer => _textBuffer.Target;
- public bool Disposed
- {
- get
- {
- return _disposed;
- }
- }
+ public bool Disposed { get; private set; }
public TimeSpan ReparseDelay
{
- get
- {
- return _reparseDelay;
- }
+ get => _reparseDelay;
set
{
- TimeSpan originalDelay = _reparseDelay;
+ var originalDelay = _reparseDelay;
try
{
_reparseDelay = value;
@@ -104,27 +83,15 @@ public TimeSpan ReparseDelay
}
}
+ protected ITextDocumentFactoryService TextDocumentFactoryService { get; }
+
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
- public virtual string Name
- {
- get
- {
- return string.Empty;
- }
- }
-
- protected ITextDocumentFactoryService TextDocumentFactoryService
- {
- get
- {
- return _textDocumentFactoryService;
- }
- }
+ public event EventHandler ParseComplete;
public void RequestParse(bool forceReparse)
{
@@ -135,32 +102,30 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
- ITextBuffer textBuffer = TextBuffer;
+ var textBuffer = TextBuffer;
if (textBuffer != null)
textBuffer.PostChanged -= TextBufferPostChanged;
_timer.Dispose();
}
- _disposed = true;
+ Disposed = true;
}
protected abstract void ReParseImpl();
- protected virtual void OnParseComplete(ParseResultEventArgs e)
+ protected void OnParseComplete(DiffParseResultEventArgs e)
{
if (e == null)
- throw new ArgumentNullException("e");
+ throw new ArgumentNullException(nameof(e));
- var t = ParseComplete;
- if (t != null)
- t(this, e);
+ ParseComplete?.Invoke(this, e);
}
protected void MarkDirty(bool resetTimer)
{
- this._dirty = true;
- this._lastEdit = DateTimeOffset.Now;
+ _dirty = true;
+ _lastEdit = DateTimeOffset.Now;
if (resetTimer)
_timer.Change(_reparseDelay, _reparseDelay);
@@ -190,18 +155,18 @@ private void TryReparse(bool forceReparse)
if (DateTimeOffset.Now - _lastEdit < ReparseDelay)
return;
- if (Interlocked.CompareExchange(ref _parsing, 1, 0) == 0)
+ if (Interlocked.CompareExchange(ref _parsing, 1, 0) != 0) return;
+
+ try
{
- try
- {
- Task task = Task.Factory.StartNew(ReParse, CancellationToken.None, TaskCreationOptions.None, _taskScheduler);
- task.ContinueWith(_ => _parsing = 0);
- }
- catch
- {
- _parsing = 0;
- throw;
- }
+ var task = Task.Factory.StartNew(ReParse, CancellationToken.None, TaskCreationOptions.None,
+ _taskScheduler);
+ task.ContinueWith(_ => _parsing = 0);
+ }
+ catch
+ {
+ _parsing = 0;
+ throw;
}
}
@@ -219,4 +184,4 @@ private void ReParse()
}
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin/Core/DiffParseResultEventArgs.cs b/GitDiffMargin/Core/DiffParseResultEventArgs.cs
index 282a51d..a28aed2 100644
--- a/GitDiffMargin/Core/DiffParseResultEventArgs.cs
+++ b/GitDiffMargin/Core/DiffParseResultEventArgs.cs
@@ -1,26 +1,17 @@
-using System;
using System.Collections.Generic;
using GitDiffMargin.Git;
-using Microsoft.VisualStudio.Text;
namespace GitDiffMargin.Core
{
- public class DiffParseResultEventArgs : ParseResultEventArgs
+ public class DiffParseResultEventArgs
{
private readonly List _diff;
- public DiffParseResultEventArgs(ITextSnapshot snapshot, TimeSpan elapsedTime, List diff)
- : base(snapshot, elapsedTime)
+ public DiffParseResultEventArgs(List diff)
{
_diff = diff;
}
- public IEnumerable Diff
- {
- get
- {
- return _diff;
- }
- }
+ public IEnumerable Diff => _diff;
}
}
\ No newline at end of file
diff --git a/GitDiffMargin/Core/DiffUpdateBackgroundParser.cs b/GitDiffMargin/Core/DiffUpdateBackgroundParser.cs
index 19bcdf7..d41036c 100644
--- a/GitDiffMargin/Core/DiffUpdateBackgroundParser.cs
+++ b/GitDiffMargin/Core/DiffUpdateBackgroundParser.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Diagnostics;
+using System;
using System.IO;
using System.Linq;
using System.Threading;
@@ -12,57 +11,55 @@ namespace GitDiffMargin.Core
{
public class DiffUpdateBackgroundParser : BackgroundParser
{
- private readonly FileSystemWatcher _watcher;
private readonly IGitCommands _commands;
- private readonly ITextDocument _textDocument;
private readonly ITextBuffer _documentBuffer;
private readonly string _originalPath;
+ private readonly ITextDocument _textDocument;
+ private readonly FileSystemWatcher _watcher;
- internal DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, string originalPath, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IGitCommands commands)
+ internal DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, string originalPath,
+ TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IGitCommands commands)
: base(textBuffer, taskScheduler, textDocumentFactoryService)
{
_documentBuffer = documentBuffer;
_commands = commands;
ReparseDelay = TimeSpan.FromMilliseconds(500);
- if (TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out _textDocument))
- {
- _originalPath = originalPath;
- if (_commands.IsGitRepository(_textDocument.FilePath, _originalPath))
- {
- _textDocument.FileActionOccurred += OnFileActionOccurred;
-
- var repositoryDirectory = _commands.GetGitRepository(_textDocument.FilePath, _originalPath);
- if (repositoryDirectory != null)
- {
- _watcher = new FileSystemWatcher(repositoryDirectory);
- _watcher.Changed += HandleFileSystemChanged;
- _watcher.Created += HandleFileSystemChanged;
- _watcher.Deleted += HandleFileSystemChanged;
- _watcher.Renamed += HandleFileSystemChanged;
- _watcher.EnableRaisingEvents = true;
- }
- }
- }
+ if (!TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out _textDocument)) return;
+
+ _originalPath = originalPath;
+
+ if (!_commands.IsGitRepository(_textDocument.FilePath, _originalPath)) return;
+
+ _textDocument.FileActionOccurred += OnFileActionOccurred;
+
+ var repositoryDirectory = _commands.GetGitRepository(_textDocument.FilePath, _originalPath);
+ if (repositoryDirectory == null) return;
+
+ _watcher = new FileSystemWatcher(repositoryDirectory);
+ _watcher.Changed += HandleFileSystemChanged;
+ _watcher.Created += HandleFileSystemChanged;
+ _watcher.Deleted += HandleFileSystemChanged;
+ _watcher.Renamed += HandleFileSystemChanged;
+ _watcher.EnableRaisingEvents = true;
}
private void HandleFileSystemChanged(object sender, FileSystemEventArgs e)
{
- Action action =
- () =>
+ void HandleFileSystemChanged()
+ {
+ try
{
- try
- {
- ProcessFileSystemChange(e);
- }
- catch (Exception ex)
- {
- if (ErrorHandler.IsCriticalException(ex))
- throw;
- }
- };
-
- Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
+ ProcessFileSystemChange(e);
+ }
+ catch (Exception ex)
+ {
+ if (ErrorHandler.IsCriticalException(ex)) throw;
+ }
+ }
+
+ Task.Factory.StartNew(HandleFileSystemChanged, CancellationToken.None, TaskCreationOptions.None,
+ TaskScheduler.Default);
}
private void ProcessFileSystemChange(FileSystemEventArgs e)
@@ -78,32 +75,18 @@ private void ProcessFileSystemChange(FileSystemEventArgs e)
private void OnFileActionOccurred(object sender, TextDocumentFileActionEventArgs e)
{
- if ((e.FileActionType & FileActionTypes.ContentSavedToDisk) != 0)
- {
- MarkDirty(true);
- }
- }
-
- public override string Name
- {
- get
- {
- return "Git Diff Analyzer";
- }
+ if ((e.FileActionType & FileActionTypes.ContentSavedToDisk) != 0) MarkDirty(true);
}
protected override void ReParseImpl()
{
try
{
- var stopwatch = Stopwatch.StartNew();
-
var snapshot = TextBuffer.CurrentSnapshot;
- ITextDocument textDocument;
- if (!TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out textDocument)) return;
+ if (!TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out var textDocument)) return;
var diff = _commands.GetGitDiffFor(textDocument, _originalPath, snapshot);
- var result = new DiffParseResultEventArgs(snapshot, stopwatch.Elapsed, diff.ToList());
+ var result = new DiffParseResultEventArgs(diff.ToList());
OnParseComplete(result);
}
catch (InvalidOperationException)
@@ -117,17 +100,10 @@ protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
- if (disposing)
- {
- if (_textDocument != null)
- {
- _textDocument.FileActionOccurred -= OnFileActionOccurred;
- }
- if (_watcher != null)
- {
- _watcher.Dispose();
- }
- }
+ if (!disposing) return;
+
+ if (_textDocument != null) _textDocument.FileActionOccurred -= OnFileActionOccurred;
+ _watcher?.Dispose();
}
}
}
\ No newline at end of file
diff --git a/GitDiffMargin/Core/HunksChangedEventArgs.cs b/GitDiffMargin/Core/HunksChangedEventArgs.cs
index 56781f6..ab55096 100644
--- a/GitDiffMargin/Core/HunksChangedEventArgs.cs
+++ b/GitDiffMargin/Core/HunksChangedEventArgs.cs
@@ -6,19 +6,11 @@ namespace GitDiffMargin.Core
{
public class HunksChangedEventArgs : EventArgs
{
- private readonly IEnumerable _hunks;
-
public HunksChangedEventArgs(IEnumerable hunks)
{
- _hunks = hunks;
+ Hunks = hunks;
}
- public IEnumerable Hunks
- {
- get
- {
- return _hunks;
- }
- }
+ public IEnumerable Hunks { get; }
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin/Core/IMarginCore.cs b/GitDiffMargin/Core/IMarginCore.cs
index bb1ad71..f9b0cc0 100644
--- a/GitDiffMargin/Core/IMarginCore.cs
+++ b/GitDiffMargin/Core/IMarginCore.cs
@@ -9,10 +9,6 @@ namespace GitDiffMargin.Core
{
internal interface IMarginCore
{
- event EventHandler BrushesChanged;
-
- event EventHandler HunksChanged;
-
IWpfTextView TextView { get; }
string OriginalPath { get; }
IGitCommands GitCommands { get; }
@@ -29,6 +25,9 @@ internal interface IMarginCore
double EditorChangeLeft { get; }
double EditorChangeWidth { get; }
double ScrollChangeWidth { get; }
+ event EventHandler BrushesChanged;
+
+ event EventHandler HunksChanged;
void MoveToChange(int lineNumber);
bool RollBack(HunkRangeInfo hunkRangeInfo);
ITextDocument GetTextDocument();
diff --git a/GitDiffMargin/Core/MarginCore.cs b/GitDiffMargin/Core/MarginCore.cs
index a7c6443..133cba3 100644
--- a/GitDiffMargin/Core/MarginCore.cs
+++ b/GitDiffMargin/Core/MarginCore.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
@@ -13,36 +13,37 @@ namespace GitDiffMargin.Core
{
internal sealed class MarginCore : IMarginCore, IDisposable
{
- private readonly IWpfTextView _textView;
-
private readonly IClassificationFormatMap _classificationFormatMap;
private readonly IEditorFormatMap _editorFormatMap;
- private readonly IGitCommands _gitCommands;
private readonly DiffUpdateBackgroundParser _parser;
private Brush _additionBrush;
- private Brush _modificationBrush;
- private Brush _removedBrush;
private bool _isDisposed;
+ private Brush _modificationBrush;
+ private Brush _removedBrush;
- public MarginCore(IWpfTextView textView, string originalPath, ITextDocumentFactoryService textDocumentFactoryService, IClassificationFormatMapService classificationFormatMapService, IEditorFormatMapService editorFormatMapService, IGitCommands gitCommands)
+ public MarginCore(IWpfTextView textView, string originalPath,
+ ITextDocumentFactoryService textDocumentFactoryService,
+ IClassificationFormatMapService classificationFormatMapService,
+ IEditorFormatMapService editorFormatMapService, IGitCommands gitCommands)
{
- _textView = textView;
+ TextView = textView;
_classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(textView);
_editorFormatMap = editorFormatMapService.GetEditorFormatMap(textView);
_editorFormatMap.FormatMappingChanged += HandleFormatMappingChanged;
- _gitCommands = gitCommands;
+ GitCommands = gitCommands;
- _parser = new DiffUpdateBackgroundParser(textView.TextBuffer, textView.TextDataModel.DocumentBuffer, originalPath, TaskScheduler.Default, textDocumentFactoryService, GitCommands);
+ _parser = new DiffUpdateBackgroundParser(textView.TextBuffer, textView.TextDataModel.DocumentBuffer,
+ originalPath, TaskScheduler.Default, textDocumentFactoryService, GitCommands);
_parser.ParseComplete += HandleParseComplete;
_parser.RequestParse(false);
- _textView.Closed += (sender, e) =>
+ TextView.Closed += (sender, e) =>
{
_editorFormatMap.FormatMappingChanged -= HandleFormatMappingChanged;
_parser.ParseComplete -= HandleParseComplete;
@@ -51,143 +52,68 @@ public MarginCore(IWpfTextView textView, string originalPath, ITextDocumentFacto
UpdateBrushes();
}
- public IWpfTextView TextView
+ public void Dispose()
{
- get
- {
- return _textView;
- }
- }
+ if (_isDisposed)
+ return;
- public string OriginalPath
- {
- get;
- }
+ _isDisposed = true;
- public IGitCommands GitCommands
- {
- get
- {
- return _gitCommands;
- }
+ _parser.Dispose();
}
- public FontFamily FontFamily
- {
- get
- {
- if (_classificationFormatMap.DefaultTextProperties.TypefaceEmpty)
- return new FontFamily("Consolas");
+ public IWpfTextView TextView { get; }
- return _classificationFormatMap.DefaultTextProperties.Typeface.FontFamily;
- }
- }
+ public string OriginalPath { get; }
- public FontStretch FontStretch
- {
- get
- {
- if (_classificationFormatMap.DefaultTextProperties.TypefaceEmpty)
- return FontStretches.Normal;
+ public IGitCommands GitCommands { get; }
- return _classificationFormatMap.DefaultTextProperties.Typeface.Stretch;
- }
- }
+ public FontFamily FontFamily => _classificationFormatMap.DefaultTextProperties.TypefaceEmpty
+ ? new FontFamily("Consolas")
+ : _classificationFormatMap.DefaultTextProperties.Typeface.FontFamily;
- public FontStyle FontStyle
- {
- get
- {
- if (_classificationFormatMap.DefaultTextProperties.TypefaceEmpty)
- return FontStyles.Normal;
+ public FontStretch FontStretch => _classificationFormatMap.DefaultTextProperties.TypefaceEmpty
+ ? FontStretches.Normal
+ : _classificationFormatMap.DefaultTextProperties.Typeface.Stretch;
- return _classificationFormatMap.DefaultTextProperties.Typeface.Style;
- }
- }
+ public FontStyle FontStyle => _classificationFormatMap.DefaultTextProperties.TypefaceEmpty
+ ? FontStyles.Normal
+ : _classificationFormatMap.DefaultTextProperties.Typeface.Style;
- public FontWeight FontWeight
- {
- get
- {
- if (_classificationFormatMap.DefaultTextProperties.TypefaceEmpty)
- return FontWeights.Normal;
+ public FontWeight FontWeight => _classificationFormatMap.DefaultTextProperties.TypefaceEmpty
+ ? FontWeights.Normal
+ : _classificationFormatMap.DefaultTextProperties.Typeface.Weight;
- return _classificationFormatMap.DefaultTextProperties.Typeface.Weight;
- }
- }
+ public double FontSize => _classificationFormatMap.DefaultTextProperties.FontRenderingEmSizeEmpty
+ ? 12.0
+ : _classificationFormatMap.DefaultTextProperties.FontRenderingEmSize;
- public double FontSize
- {
- get
- {
- if (_classificationFormatMap.DefaultTextProperties.FontRenderingEmSizeEmpty)
- return 12.0;
-
- return _classificationFormatMap.DefaultTextProperties.FontRenderingEmSize;
- }
- }
-
- public Brush Background
- {
- get
- {
- if (_classificationFormatMap.DefaultTextProperties.BackgroundBrushEmpty)
- return _textView.Background;
-
- return _classificationFormatMap.DefaultTextProperties.BackgroundBrush;
- }
- }
+ public Brush Background => _classificationFormatMap.DefaultTextProperties.BackgroundBrushEmpty
+ ? TextView.Background
+ : _classificationFormatMap.DefaultTextProperties.BackgroundBrush;
public Brush Foreground
{
get
{
if (_classificationFormatMap.DefaultTextProperties.ForegroundBrushEmpty)
- return (Brush)Application.Current.Resources[VsBrushes.ToolWindowTextKey];
+ return (Brush) Application.Current.Resources[VsBrushes.ToolWindowTextKey];
return _classificationFormatMap.DefaultTextProperties.ForegroundBrush;
}
}
- public Brush AdditionBrush
- {
+ public Brush AdditionBrush => _additionBrush ?? Brushes.Transparent;
- get
- {
- return _additionBrush ?? Brushes.Transparent;
- }
- }
+ public Brush ModificationBrush => _modificationBrush ?? Brushes.Transparent;
- public Brush ModificationBrush
- {
- get
- {
- return _modificationBrush ?? Brushes.Transparent;
- }
- }
+ public Brush RemovedBrush => _removedBrush ?? Brushes.Transparent;
- public Brush RemovedBrush
- {
- get
- {
- return _removedBrush ?? Brushes.Transparent;
- }
- }
+ public double EditorChangeLeft => 2.5;
- public double EditorChangeLeft
- {
- get { return 2.5; }
- }
-
- public double EditorChangeWidth
- {
- get { return 5.0; }
- }
+ public double EditorChangeWidth => 5.0;
- public double ScrollChangeWidth
- {
- get { return 3.0; }
- }
+ public double ScrollChangeWidth => 3.0;
public event EventHandler BrushesChanged;
@@ -195,84 +121,20 @@ public double ScrollChangeWidth
public void MoveToChange(int lineNumber)
{
- var diffLine = _textView.TextSnapshot.GetLineFromLineNumber(lineNumber);
+ var diffLine = TextView.TextSnapshot.GetLineFromLineNumber(lineNumber);
- _textView.VisualElement.Focus();
- _textView.Caret.MoveTo(diffLine.Start);
- _textView.ViewScroller.EnsureSpanVisible(diffLine.ExtentIncludingLineBreak,
+ TextView.VisualElement.Focus();
+ TextView.Caret.MoveTo(diffLine.Start);
+ TextView.ViewScroller.EnsureSpanVisible(diffLine.ExtentIncludingLineBreak,
EnsureSpanVisibleOptions.AlwaysCenter);
}
- private void CheckBeginInvokeOnUi(Action action)
- {
- if (_textView.VisualElement.Dispatcher.CheckAccess())
- {
- action();
- }
- else
- {
- _textView.VisualElement.Dispatcher.BeginInvoke(action);
- }
- }
-
- private void HandleFormatMappingChanged(object sender, FormatItemsEventArgs e)
- {
- if (e.ChangedItems.Contains(DiffFormatNames.Addition)
- || e.ChangedItems.Contains(DiffFormatNames.Modification)
- || e.ChangedItems.Contains(DiffFormatNames.Removed))
- {
- UpdateBrushes();
- }
- }
-
- private void UpdateBrushes()
- {
- _additionBrush = GetBrush(_editorFormatMap.GetProperties(DiffFormatNames.Addition));
- _modificationBrush = GetBrush(_editorFormatMap.GetProperties(DiffFormatNames.Modification));
- _removedBrush = GetBrush(_editorFormatMap.GetProperties(DiffFormatNames.Removed));
- OnBrushesChanged(EventArgs.Empty);
- }
-
- private void OnBrushesChanged(EventArgs e)
- {
- var t = BrushesChanged;
- if (t != null)
- t(this, e);
- }
-
- private static Brush GetBrush(ResourceDictionary properties)
- {
- if (properties == null)
- return Brushes.Transparent;
-
- if (properties.Contains(EditorFormatDefinition.BackgroundColorId))
- {
- var color = (Color)properties[EditorFormatDefinition.BackgroundColorId];
- var brush = new SolidColorBrush(color);
- if (brush.CanFreeze)
- {
- brush.Freeze();
- }
- return brush;
- }
- if (properties.Contains(EditorFormatDefinition.BackgroundBrushId))
- {
- var brush = (Brush)properties[EditorFormatDefinition.BackgroundBrushId];
- if (brush.CanFreeze)
- {
- brush.Freeze();
- }
- return brush;
- }
-
- return Brushes.Transparent;
- }
public bool RollBack(HunkRangeInfo hunkRangeInfo)
{
if (hunkRangeInfo.SuppressRollback)
return false;
- var snapshot = _textView.TextSnapshot;
+ var snapshot = TextView.TextSnapshot;
if (snapshot != snapshot.TextBuffer.CurrentSnapshot)
return false;
@@ -288,24 +150,27 @@ public bool RollBack(HunkRangeInfo hunkRangeInfo)
else
{
var startLine = snapshot.GetLineFromLineNumber(hunkRangeInfo.NewHunkRange.StartingLineNumber);
- var endLine = snapshot.GetLineFromLineNumber(hunkRangeInfo.NewHunkRange.StartingLineNumber + hunkRangeInfo.NewHunkRange.NumberOfLines - 1);
+ var endLine = snapshot.GetLineFromLineNumber(
+ hunkRangeInfo.NewHunkRange.StartingLineNumber + hunkRangeInfo.NewHunkRange.NumberOfLines - 1);
newSpan = Span.FromBounds(startLine.Start.Position, endLine.EndIncludingLineBreak.Position);
}
if (hunkRangeInfo.IsAddition)
{
var startLine = snapshot.GetLineFromLineNumber(hunkRangeInfo.NewHunkRange.StartingLineNumber);
- var endLine = snapshot.GetLineFromLineNumber(hunkRangeInfo.NewHunkRange.StartingLineNumber + hunkRangeInfo.NewHunkRange.NumberOfLines - 1);
+ var endLine = snapshot.GetLineFromLineNumber(
+ hunkRangeInfo.NewHunkRange.StartingLineNumber + hunkRangeInfo.NewHunkRange.NumberOfLines - 1);
edit.Delete(Span.FromBounds(startLine.Start.Position, endLine.EndIncludingLineBreak.Position));
}
else
{
var lineBreak = snapshot.GetLineFromLineNumber(0).GetLineBreakText();
- if (String.IsNullOrEmpty(lineBreak))
+ if (string.IsNullOrEmpty(lineBreak))
lineBreak = Environment.NewLine;
- var originalText = String.Join(lineBreak, hunkRangeInfo.OriginalText);
- if (hunkRangeInfo.NewHunkRange.StartingLineNumber + hunkRangeInfo.NewHunkRange.NumberOfLines != snapshot.LineCount)
+ var originalText = string.Join(lineBreak, hunkRangeInfo.OriginalText);
+ if (hunkRangeInfo.NewHunkRange.StartingLineNumber + hunkRangeInfo.NewHunkRange.NumberOfLines !=
+ snapshot.LineCount)
originalText += lineBreak;
edit.Replace(newSpan, originalText);
@@ -319,8 +184,8 @@ public bool RollBack(HunkRangeInfo hunkRangeInfo)
public ITextDocument GetTextDocument()
{
- ITextDocument document;
- _textView.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document);
+ TextView.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(ITextDocument),
+ out ITextDocument document);
return document;
}
@@ -329,29 +194,67 @@ public void FocusTextView()
TextView.VisualElement.Focus();
}
- private void HandleParseComplete(object sender, ParseResultEventArgs e)
+ private void CheckBeginInvokeOnUi(Action action)
+ {
+ if (TextView.VisualElement.Dispatcher.CheckAccess())
+ action();
+ else
+ TextView.VisualElement.Dispatcher.BeginInvoke(action);
+ }
+
+ private void HandleFormatMappingChanged(object sender, FormatItemsEventArgs e)
{
- var diffResult = e as DiffParseResultEventArgs;
- if (diffResult == null) return;
+ if (e.ChangedItems.Contains(DiffFormatNames.Addition)
+ || e.ChangedItems.Contains(DiffFormatNames.Modification)
+ || e.ChangedItems.Contains(DiffFormatNames.Removed))
+ UpdateBrushes();
+ }
- CheckBeginInvokeOnUi(() => OnHunksChanged(diffResult.Diff));
+ private void UpdateBrushes()
+ {
+ _additionBrush = GetBrush(_editorFormatMap.GetProperties(DiffFormatNames.Addition));
+ _modificationBrush = GetBrush(_editorFormatMap.GetProperties(DiffFormatNames.Modification));
+ _removedBrush = GetBrush(_editorFormatMap.GetProperties(DiffFormatNames.Removed));
+ OnBrushesChanged(EventArgs.Empty);
}
- private void OnHunksChanged(IEnumerable hunkRangeInfos)
+ private void OnBrushesChanged(EventArgs e)
{
- var t = HunksChanged;
- if (t != null)
- t(this, new HunksChangedEventArgs(hunkRangeInfos));
+ BrushesChanged?.Invoke(this, e);
}
- public void Dispose()
+ private static Brush GetBrush(ResourceDictionary properties)
{
- if (_isDisposed)
- return;
+ Brush GetBrush()
+ {
+ var brush = (Brush) properties[EditorFormatDefinition.BackgroundBrushId];
+ if (brush.CanFreeze) brush.Freeze();
+ return brush;
+ }
- _isDisposed = true;
+ Brush GetSolidColorBrush()
+ {
+ var color = (Color) properties[EditorFormatDefinition.BackgroundColorId];
+ var brush = new SolidColorBrush(color);
+ if (brush.CanFreeze) brush.Freeze();
+ return brush;
+ }
- _parser.Dispose();
+ if (properties == null) return Brushes.Transparent;
+
+ if (properties.Contains(EditorFormatDefinition.BackgroundColorId)) return GetSolidColorBrush();
+
+ return properties.Contains(EditorFormatDefinition.BackgroundBrushId) ? GetBrush() : Brushes.Transparent;
+ }
+
+ private void HandleParseComplete(object sender, DiffParseResultEventArgs e)
+ {
+ if (e is DiffParseResultEventArgs diffResult) CheckBeginInvokeOnUi(() => OnHunksChanged(diffResult.Diff));
+ }
+
+ private void OnHunksChanged(IEnumerable hunkRangeInfos)
+ {
+ HunksChanged?.Invoke(this, new HunksChangedEventArgs(hunkRangeInfos));
}
}
}
\ No newline at end of file
diff --git a/GitDiffMargin/Core/ParseResultEventArgs.cs b/GitDiffMargin/Core/ParseResultEventArgs.cs
deleted file mode 100644
index f252bf1..0000000
--- a/GitDiffMargin/Core/ParseResultEventArgs.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-/* The MIT License
- *
- * Copyright (c) 2013 Sam Harwell, Tunnel Vision Labs, LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-using System;
-using Microsoft.VisualStudio.Text;
-
-namespace GitDiffMargin.Core
-{
- public class ParseResultEventArgs : EventArgs
- {
- public ParseResultEventArgs(ITextSnapshot snapshot)
- {
- Snapshot = snapshot;
- }
-
- public ParseResultEventArgs(ITextSnapshot snapshot, TimeSpan elapsedTime)
- {
- Snapshot = snapshot;
- ElapsedTime = elapsedTime;
- }
-
- public ITextSnapshot Snapshot
- {
- get;
- private set;
- }
-
- public TimeSpan? ElapsedTime
- {
- get;
- private set;
- }
- }
-}
diff --git a/GitDiffMargin/Core/WeakReference.cs b/GitDiffMargin/Core/WeakReference.cs
index 3c233fd..4b1859e 100644
--- a/GitDiffMargin/Core/WeakReference.cs
+++ b/GitDiffMargin/Core/WeakReference.cs
@@ -47,15 +47,9 @@ protected WeakReference(SerializationInfo info, StreamingContext context)
public new T Target
{
- get
- {
- return (T)base.Target;
- }
+ get => (T) base.Target;
- set
- {
- base.Target = value;
- }
+ set => base.Target = value;
}
}
-}
+}
\ No newline at end of file
diff --git a/GitDiffMargin/DiffMarginBase.cs b/GitDiffMargin/DiffMarginBase.cs
index dff0fb9..da95c77 100644
--- a/GitDiffMargin/DiffMarginBase.cs
+++ b/GitDiffMargin/DiffMarginBase.cs
@@ -11,10 +11,8 @@ internal abstract class DiffMarginBase : Canvas, IWpfTextViewMargin
{
protected readonly ITextView TextView;
private bool _isDisposed;
- protected DiffMarginViewModelBase ViewModel;
protected UserControl UserControl;
-
- protected abstract string MarginName { get; }
+ protected DiffMarginViewModelBase ViewModel;
protected DiffMarginBase(ITextView textView)
{
@@ -24,17 +22,14 @@ protected DiffMarginBase(ITextView textView)
TextView.LayoutChanged += OnLayoutChanged;
}
+ protected abstract string MarginName { get; }
+
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
- protected virtual void Dispose(bool disposing)
- {
- _isDisposed = true;
- }
-
public ITextViewMargin GetTextViewMargin(string marginName)
{
return string.Equals(marginName, MarginName, StringComparison.OrdinalIgnoreCase) ? this : null;
@@ -49,13 +44,7 @@ public double MarginSize
}
}
- public bool Enabled
- {
- get
- {
- return TextView.Options.IsSelectionMarginEnabled();
- }
- }
+ public bool Enabled => TextView.Options.IsSelectionMarginEnabled();
public FrameworkElement VisualElement
{
@@ -66,12 +55,14 @@ public FrameworkElement VisualElement
}
}
+ protected virtual void Dispose(bool disposing)
+ {
+ _isDisposed = true;
+ }
+
private void HandleOptionChanged(object sender, EditorOptionChangedEventArgs e)
{
- if (!_isDisposed && e.OptionId == GitDiffMarginTextViewOptions.DiffMarginName)
- {
- UpdateVisibility();
- }
+ if (!_isDisposed && e.OptionId == GitDiffMarginTextViewOptions.DiffMarginName) UpdateVisibility();
}
private void UpdateVisibility()
diff --git a/GitDiffMargin/DiffMarginFactoryBase.cs b/GitDiffMargin/DiffMarginFactoryBase.cs
index b409429..deb6ad7 100644
--- a/GitDiffMargin/DiffMarginFactoryBase.cs
+++ b/GitDiffMargin/DiffMarginFactoryBase.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Security;
@@ -7,48 +7,42 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Editor;
-using Path = System.IO.Path;
namespace GitDiffMargin
{
internal abstract class DiffMarginFactoryBase : IWpfTextViewMarginProvider
{
- [Import]
- internal ITextDocumentFactoryService TextDocumentFactoryService { get; private set; }
+ [Import] internal ITextDocumentFactoryService TextDocumentFactoryService { get; private set; }
- [Import]
- internal IClassificationFormatMapService ClassificationFormatMapService { get; private set; }
+ [Import] internal IClassificationFormatMapService ClassificationFormatMapService { get; private set; }
- [Import]
- internal IEditorFormatMapService EditorFormatMapService { get; private set; }
+ [Import] internal IEditorFormatMapService EditorFormatMapService { get; private set; }
- [Import]
- internal IGitCommands GitCommands { get; private set; }
+ [Import] internal IGitCommands GitCommands { get; private set; }
- public abstract IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer);
+ public abstract IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost,
+ IWpfTextViewMargin marginContainer);
protected IMarginCore TryGetMarginCore(IWpfTextViewHost textViewHost)
{
- MarginCore marginCore;
- if (textViewHost.TextView.Properties.TryGetProperty(typeof(MarginCore), out marginCore))
+ if (textViewHost.TextView.Properties.TryGetProperty(typeof(MarginCore), out MarginCore marginCore))
return marginCore;
// play nice with other source control providers
ITextView textView = textViewHost.TextView;
- ITextDataModel textDataModel = textView != null ? textView.TextDataModel : null;
- ITextBuffer documentBuffer = textDataModel != null ? textDataModel.DocumentBuffer : null;
+ var textDataModel = textView?.TextDataModel;
+ var documentBuffer = textDataModel?.DocumentBuffer;
if (documentBuffer == null)
return null;
- ITextDocument textDocument;
- if (!TextDocumentFactoryService.TryGetTextDocument(documentBuffer, out textDocument))
+ if (!TextDocumentFactoryService.TryGetTextDocument(documentBuffer, out var textDocument))
return null;
- var fullPath= GetFullPath(textDocument.FilePath);
+ var fullPath = GetFullPath(textDocument.FilePath);
if (fullPath == null)
return null;
- if (!GitCommands.TryGetOriginalPath(fullPath, out string originalPath))
+ if (!GitCommands.TryGetOriginalPath(fullPath, out var originalPath))
return null;
var repositoryPath = GitCommands.GetGitRepository(fullPath, originalPath);
@@ -56,7 +50,8 @@ protected IMarginCore TryGetMarginCore(IWpfTextViewHost textViewHost)
return null;
return textViewHost.TextView.Properties.GetOrCreateSingletonProperty(
- () => new MarginCore(textViewHost.TextView, originalPath, TextDocumentFactoryService, ClassificationFormatMapService, EditorFormatMapService, GitCommands));
+ () => new MarginCore(textViewHost.TextView, originalPath, TextDocumentFactoryService,
+ ClassificationFormatMapService, EditorFormatMapService, GitCommands));
}
private static string GetFullPath(string filename)
diff --git a/GitDiffMargin/EditorDiffMargin.cs b/GitDiffMargin/EditorDiffMargin.cs
index 641383e..f69a393 100644
--- a/GitDiffMargin/EditorDiffMargin.cs
+++ b/GitDiffMargin/EditorDiffMargin.cs
@@ -1,4 +1,4 @@
-#region using
+#region using
using GitDiffMargin.Core;
using GitDiffMargin.Git;
@@ -18,11 +18,6 @@ internal sealed class EditorDiffMargin : DiffMarginBase
public const string MarginNameConst = "EditorDiffMargin";
- protected override string MarginName
- {
- get { return MarginNameConst; }
- }
-
internal EditorDiffMargin(IWpfTextView textView, IMarginCore marginCore)
: base(textView)
{
@@ -31,16 +26,14 @@ internal EditorDiffMargin(IWpfTextView textView, IMarginCore marginCore)
UserControl = new EditorDiffMarginControl {DataContext = ViewModel, Width = MarginWidth};
}
+ protected override string MarginName => MarginNameConst;
+
private void UpdateDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hunkRangeInfo)
{
if (TextView.IsClosed)
return;
- bool? visible;
- if (diffViewModel.IsDeletion)
- visible = UpdateDeletedDiffDimensions(diffViewModel, hunkRangeInfo);
- else
- visible = UpdateNormalDiffDimensions(diffViewModel, hunkRangeInfo);
+ var visible = diffViewModel.IsDeletion ? UpdateDeletedDiffDimensions(diffViewModel, hunkRangeInfo) : UpdateNormalDiffDimensions(diffViewModel, hunkRangeInfo);
if (visible.HasValue)
diffViewModel.IsVisible = visible.Value;
@@ -48,11 +41,7 @@ private void UpdateDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hun
private bool? UpdateNormalDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hunkRangeInfo)
{
- if (hunkRangeInfo.NewHunkRange.NumberOfLines <= 0)
- {
- // if visible, it would have been as a deletion
- return false;
- }
+ if (hunkRangeInfo.NewHunkRange.NumberOfLines <= 0) return false;
var snapshot = TextView.TextBuffer.CurrentSnapshot;
@@ -62,9 +51,7 @@ private void UpdateDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hun
|| startLineNumber >= snapshot.LineCount
|| endLineNumber < 0
|| endLineNumber >= snapshot.LineCount)
- {
return false;
- }
var startLine = snapshot.GetLineFromLineNumber(startLineNumber);
var endLine = snapshot.GetLineFromLineNumber(endLineNumber);
@@ -82,17 +69,9 @@ private void UpdateDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hun
if (startLineView == null || endLineView == null)
return false;
- if (TextView.TextViewLines.LastVisibleLine.EndIncludingLineBreak < startLineView.Start)
- {
- // starts after the last visible line
- return false;
- }
+ if (TextView.TextViewLines.LastVisibleLine.EndIncludingLineBreak < startLineView.Start) return false;
- if (TextView.TextViewLines.FirstVisibleLine.Start > endLineView.EndIncludingLineBreak)
- {
- // ends before the first visible line
- return false;
- }
+ if (TextView.TextViewLines.FirstVisibleLine.Start > endLineView.EndIncludingLineBreak) return false;
double startTop;
switch (startLineView.VisibilityState)
@@ -139,11 +118,7 @@ private void UpdateDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hun
private bool? UpdateDeletedDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hunkRangeInfo)
{
- if (hunkRangeInfo.NewHunkRange.NumberOfLines != 0)
- {
- // unexpected number of lines for a deletion hunk
- return false;
- }
+ if (hunkRangeInfo.NewHunkRange.NumberOfLines != 0) return false;
var snapshot = TextView.TextBuffer.CurrentSnapshot;
@@ -163,17 +138,9 @@ private void UpdateDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hun
if (followingLineView == null)
return false;
- if (TextView.TextViewLines.LastVisibleLine.EndIncludingLineBreak < followingLineView.Start)
- {
- // starts after the last visible line
- return false;
- }
+ if (TextView.TextViewLines.LastVisibleLine.EndIncludingLineBreak < followingLineView.Start) return false;
- if (TextView.TextViewLines.FirstVisibleLine.Start > followingLineView.EndIncludingLineBreak)
- {
- // ends before the first visible line
- return false;
- }
+ if (TextView.TextViewLines.FirstVisibleLine.Start > followingLineView.EndIncludingLineBreak) return false;
double followingTop;
switch (followingLineView.VisibilityState)
@@ -194,9 +161,9 @@ private void UpdateDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hun
return false;
}
- double center = followingTop;
- double height = TextView.LineHeight;
- diffViewModel.Top = center - (height / 2.0);
+ var center = followingTop;
+ var height = TextView.LineHeight;
+ diffViewModel.Top = center - height / 2.0;
diffViewModel.Height = TextView.LineHeight;
return true;
}
diff --git a/GitDiffMargin/EditorDiffMarginFactory.cs b/GitDiffMargin/EditorDiffMarginFactory.cs
index 9b5d180..7ac630c 100644
--- a/GitDiffMargin/EditorDiffMarginFactory.cs
+++ b/GitDiffMargin/EditorDiffMarginFactory.cs
@@ -1,4 +1,4 @@
-#region using
+#region using
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Editor;
@@ -8,7 +8,7 @@
namespace GitDiffMargin
{
- [Export(typeof (IWpfTextViewMarginProvider))]
+ [Export(typeof(IWpfTextViewMarginProvider))]
[Name(EditorDiffMargin.MarginNameConst)]
[Order(After = PredefinedMarginNames.Spacer, Before = PredefinedMarginNames.Outlining)]
[MarginContainer(PredefinedMarginNames.LeftSelection)]
@@ -16,13 +16,12 @@ namespace GitDiffMargin
[TextViewRole(PredefinedTextViewRoles.Editable)]
internal sealed class EditorDiffMarginFactory : DiffMarginFactoryBase
{
- public override IWpfTextViewMargin CreateMargin(IWpfTextViewHost textViewHost, IWpfTextViewMargin containerMargin)
+ public override IWpfTextViewMargin CreateMargin(IWpfTextViewHost textViewHost,
+ IWpfTextViewMargin containerMargin)
{
var marginCore = TryGetMarginCore(textViewHost);
- if (marginCore == null)
- return null;
- return new EditorDiffMargin(textViewHost.TextView, marginCore);
+ return marginCore == null ? null : new EditorDiffMargin(textViewHost.TextView, marginCore);
}
}
}
\ No newline at end of file
diff --git a/GitDiffMargin/Git/GitCommands.cs b/GitDiffMargin/Git/GitCommands.cs
index 06a0101..68cf5ec 100644
--- a/GitDiffMargin/Git/GitCommands.cs
+++ b/GitDiffMargin/Git/GitCommands.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
@@ -7,22 +7,15 @@
using LibGit2Sharp;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text;
-using __VSDIFFSERVICEOPTIONS = Microsoft.VisualStudio.Shell.Interop.__VSDIFFSERVICEOPTIONS;
-using __VSENUMPROJFLAGS = Microsoft.VisualStudio.Shell.Interop.__VSENUMPROJFLAGS;
-using IEnumHierarchies = Microsoft.VisualStudio.Shell.Interop.IEnumHierarchies;
-using IVsDifferenceService = Microsoft.VisualStudio.Shell.Interop.IVsDifferenceService;
-using IVsHierarchy = Microsoft.VisualStudio.Shell.Interop.IVsHierarchy;
-using IVsProject = Microsoft.VisualStudio.Shell.Interop.IVsProject;
-using IVsSolution = Microsoft.VisualStudio.Shell.Interop.IVsSolution;
-using SVsDifferenceService = Microsoft.VisualStudio.Shell.Interop.SVsDifferenceService;
-using SVsSolution = Microsoft.VisualStudio.Shell.Interop.SVsSolution;
namespace GitDiffMargin.Git
{
[Export(typeof(IGitCommands))]
public class GitCommands : IGitCommands
{
+ private const int ContextLines = 0;
private readonly SVsServiceProvider _serviceProvider;
[ImportingConstructor]
@@ -31,9 +24,8 @@ public GitCommands(SVsServiceProvider serviceProvider)
_serviceProvider = serviceProvider;
}
- private const int ContextLines = 0;
-
- public IEnumerable GetGitDiffFor(ITextDocument textDocument, string originalPath, ITextSnapshot snapshot)
+ public IEnumerable GetGitDiffFor(ITextDocument textDocument, string originalPath,
+ ITextSnapshot snapshot)
{
var filename = textDocument.FilePath;
var repositoryPath = GetGitRepository(Path.GetFullPath(filename), ref originalPath);
@@ -47,27 +39,14 @@ public IEnumerable GetGitDiffFor(ITextDocument textDocument, stri
yield break;
var retrieveStatus = repo.RetrieveStatus(originalPath);
- if (retrieveStatus == FileStatus.Nonexistent)
- {
- // this occurs if a file within the repository itself (not the working copy) is opened.
- yield break;
- }
+ if (retrieveStatus == FileStatus.Nonexistent) yield break;
- if ((retrieveStatus & FileStatus.Ignored) != 0)
- {
- // pointless to show diffs for ignored files
- yield break;
- }
+ if ((retrieveStatus & FileStatus.Ignored) != 0) yield break;
if (retrieveStatus == FileStatus.Unaltered
&& !textDocument.IsDirty
&& Path.GetFullPath(filename) == originalPath)
- {
- // Truly unaltered. The `IsDirty` check isn't valid for cases where the textDocument is a view of a
- // temporary copy of the file, since the temporary copy could have been made using unsaved changes
- // and still appear "not dirty".
yield break;
- }
var content = GetCompleteContent(textDocument, snapshot);
if (content == null) yield break;
@@ -83,7 +62,8 @@ public IEnumerable GetGitDiffFor(ITextDocument textDocument, stri
bool suppressRollback;
Blob blob;
- if ((retrieveStatus & FileStatus.NewInWorkdir) != 0 || (retrieveStatus & FileStatus.NewInIndex) != 0)
+ if ((retrieveStatus & FileStatus.NewInWorkdir) != 0 ||
+ (retrieveStatus & FileStatus.NewInIndex) != 0)
{
suppressRollback = true;
@@ -97,18 +77,19 @@ public IEnumerable GetGitDiffFor(ITextDocument textDocument, stri
{
suppressRollback = false;
- Commit from = repo.Head.Tip;
- TreeEntry fromEntry = from[relativeFilepath];
+ var from = repo.Head.Tip;
+ var fromEntry = from[relativeFilepath];
if (fromEntry == null)
{
// try again using case-insensitive comparison
- Tree tree = from.Tree;
- foreach (string segment in relativeFilepath.Split(Path.DirectorySeparatorChar))
+ var tree = from.Tree;
+ foreach (var segment in relativeFilepath.Split(Path.DirectorySeparatorChar))
{
if (tree == null)
yield break;
- fromEntry = tree.FirstOrDefault(i => string.Equals(segment, i.Name, StringComparison.OrdinalIgnoreCase));
+ fromEntry = tree.FirstOrDefault(i =>
+ string.Equals(segment, i.Name, StringComparison.OrdinalIgnoreCase));
if (fromEntry == null)
yield break;
@@ -121,35 +102,17 @@ public IEnumerable GetGitDiffFor(ITextDocument textDocument, stri
yield break;
}
- var treeChanges = repo.Diff.Compare(blob, newBlob, new CompareOptions { ContextLines = ContextLines, InterhunkLines = 0 });
+ var treeChanges = repo.Diff.Compare(blob, newBlob,
+ new CompareOptions {ContextLines = ContextLines, InterhunkLines = 0});
var gitDiffParser = new GitDiffParser(treeChanges.Patch, ContextLines, suppressRollback);
var hunkRangeInfos = gitDiffParser.Parse();
- foreach (var hunkRangeInfo in hunkRangeInfos)
- {
- yield return hunkRangeInfo;
- }
+ foreach (var hunkRangeInfo in hunkRangeInfos) yield return hunkRangeInfo;
}
}
}
- private static byte[] GetCompleteContent(ITextDocument textDocument, ITextSnapshot snapshot)
- {
- var currentText = snapshot.GetText();
-
- var content = textDocument.Encoding.GetBytes(currentText);
-
- var preamble = textDocument.Encoding.GetPreamble();
- if (preamble.Length == 0) return content;
-
- var completeContent = new byte[preamble.Length + content.Length];
- Buffer.BlockCopy(preamble, 0, completeContent, 0, preamble.Length);
- Buffer.BlockCopy(content, 0, completeContent, preamble.Length, content.Length);
-
- return completeContent;
- }
-
public void StartExternalDiff(ITextDocument textDocument, string originalPath)
{
if (textDocument == null || string.IsNullOrEmpty(textDocument.FilePath)) return;
@@ -161,13 +124,13 @@ public void StartExternalDiff(ITextDocument textDocument, string originalPath)
using (var repo = new Repository(repositoryPath))
{
- string workingDirectory = repo.Info.WorkingDirectory;
- string relativePath = originalPath;
+ var workingDirectory = repo.Info.WorkingDirectory;
+ var relativePath = originalPath;
if (relativePath.StartsWith(workingDirectory, StringComparison.OrdinalIgnoreCase))
relativePath = relativePath.Substring(workingDirectory.Length);
// the name of the object in the database
- string objectName = Path.GetFileName(filename);
+ var objectName = Path.GetFileName(filename);
Blob oldBlob = null;
var indexEntry = repo.Index[relativePath];
@@ -179,17 +142,19 @@ public void StartExternalDiff(ITextDocument textDocument, string originalPath)
var tempFileName = Path.GetTempFileName();
if (oldBlob != null)
- File.WriteAllText(tempFileName, oldBlob.GetContentText(new FilteringOptions(relativePath)), GetEncoding(filename));
+ File.WriteAllText(tempFileName, oldBlob.GetContentText(new FilteringOptions(relativePath)),
+ GetEncoding(filename));
- IVsDifferenceService differenceService = _serviceProvider.GetService(typeof(SVsDifferenceService)) as IVsDifferenceService;
- string leftFileMoniker = tempFileName;
+ var differenceService =
+ _serviceProvider.GetService(typeof(SVsDifferenceService)) as IVsDifferenceService;
+ var leftFileMoniker = tempFileName;
// The difference service will automatically load the text from the file open in the editor, even if
// it has changed. Don't use the original path here.
- string rightFileMoniker = filename;
+ var rightFileMoniker = filename;
- string actualFilename = objectName;
- string tempPrefix = Path.GetRandomFileName().Substring(0, 5);
- string caption = string.Format("{0}_{1} vs. {1}", tempPrefix, actualFilename);
+ var actualFilename = objectName;
+ var tempPrefix = Path.GetRandomFileName().Substring(0, 5);
+ var caption = string.Format("{0}_{1} vs. {1}", tempPrefix, actualFilename);
string tooltip = null;
@@ -197,14 +162,12 @@ public void StartExternalDiff(ITextDocument textDocument, string originalPath)
if (indexEntry != null)
{
// determine if the file has been staged
- string revision;
var stagedMask = FileStatus.NewInIndex | FileStatus.ModifiedInIndex;
- if ((repo.RetrieveStatus(relativePath) & stagedMask) != 0)
- revision = "index";
- else
- revision = repo.Head.Tip.Sha.Substring(0, 7);
+ var revision = (repo.RetrieveStatus(relativePath) & stagedMask) != 0
+ ? "index"
+ : repo.Head.Tip.Sha.Substring(0, 7);
- leftLabel = string.Format("{0}@{1}", objectName, revision);
+ leftLabel = $"{objectName}@{revision}";
}
else if (oldBlob != null)
{
@@ -214,41 +177,40 @@ public void StartExternalDiff(ITextDocument textDocument, string originalPath)
else
{
// we just compared to head
- leftLabel = string.Format("{0}@{1}", objectName, repo.Head.Tip.Sha.Substring(0, 7));
+ leftLabel = $"{objectName}@{repo.Head.Tip.Sha.Substring(0, 7)}";
}
- string rightLabel = originalPath;
+ var rightLabel = originalPath;
string inlineLabel = null;
string roles = null;
- __VSDIFFSERVICEOPTIONS grfDiffOptions = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;
- differenceService.OpenComparisonWindow2(leftFileMoniker, rightFileMoniker, caption, tooltip, leftLabel, rightLabel, inlineLabel, roles, (uint)grfDiffOptions);
+ var grfDiffOptions = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;
+ differenceService.OpenComparisonWindow2(leftFileMoniker, rightFileMoniker, caption, tooltip, leftLabel,
+ rightLabel, inlineLabel, roles, (uint) grfDiffOptions);
// Since the file is marked as temporary, we can delete it now
File.Delete(tempFileName);
}
}
- ///
+ ///
public bool TryGetOriginalPath(string path, out string originalPath)
{
originalPath = null;
- if (GetGitRepository(path, ref originalPath) == null)
- {
- originalPath = path;
- return false;
- }
+ if (GetGitRepository(path, ref originalPath) != null) return true;
+
+ originalPath = path;
+ return false;
- return true;
}
- ///
+ ///
public bool IsGitRepository(string path, string originalPath)
{
return GetGitRepository(path, originalPath) != null;
}
- ///
+ ///
public string GetGitRepository(string path, string originalPath)
{
if (originalPath == null)
@@ -257,6 +219,40 @@ public string GetGitRepository(string path, string originalPath)
return GetGitRepository(path, ref originalPath);
}
+ ///
+ public string GetGitWorkingCopy(string path, string originalPath)
+ {
+ if (originalPath == null)
+ throw new ArgumentNullException(nameof(originalPath));
+
+ var repositoryPath = GetGitRepository(path, originalPath);
+ if (repositoryPath == null)
+ return null;
+
+ using (var repository = new Repository(repositoryPath))
+ {
+ var workingDirectory = repository.Info.WorkingDirectory;
+
+ return workingDirectory == null ? null : Path.GetFullPath(workingDirectory);
+ }
+ }
+
+ private static byte[] GetCompleteContent(ITextDocument textDocument, ITextSnapshot snapshot)
+ {
+ var currentText = snapshot.GetText();
+
+ var content = textDocument.Encoding.GetBytes(currentText);
+
+ var preamble = textDocument.Encoding.GetPreamble();
+ if (preamble.Length == 0) return content;
+
+ var completeContent = new byte[preamble.Length + content.Length];
+ Buffer.BlockCopy(preamble, 0, completeContent, 0, preamble.Length);
+ Buffer.BlockCopy(content, 0, completeContent, preamble.Length, content.Length);
+
+ return completeContent;
+ }
+
private string GetGitRepository(string path, ref string originalPath)
{
if (originalPath == null)
@@ -280,51 +276,20 @@ private string GetGitRepository(string path, ref string originalPath)
return Repository.Discover(Path.GetFullPath(originalPath));
}
- ///
- public string GetGitWorkingCopy(string path, string originalPath)
- {
- if (originalPath == null)
- throw new ArgumentNullException(nameof(originalPath));
-
- var repositoryPath = GetGitRepository(path, originalPath);
- if (repositoryPath == null)
- return null;
-
- using (Repository repository = new Repository(repositoryPath))
- {
- string workingDirectory = repository.Info.WorkingDirectory;
- if (workingDirectory == null)
- return null;
-
- return Path.GetFullPath(workingDirectory);
- }
- }
-
- static Encoding GetEncoding(string file)
+ private static Encoding GetEncoding(string file)
{
- if (File.Exists(file))
- {
- var encoding = Encoding.UTF8;
- if (HasPreamble(file, encoding))
- {
- return encoding;
- }
- }
-
- return Encoding.Default;
+ return File.Exists(file)
+ ? (HasPreamble(file, Encoding.UTF8) ? Encoding.UTF8 : Encoding.Default)
+ : Encoding.Default;
}
- static bool HasPreamble(string file, Encoding encoding)
+ private static bool HasPreamble(string file, Encoding encoding)
{
using (var stream = File.OpenRead(file))
{
foreach (var b in encoding.GetPreamble())
- {
if (b != stream.ReadByte())
- {
return false;
- }
- }
}
return true;
@@ -335,35 +300,31 @@ private string AdjustPath(string fullPath)
// Right now the only adjustment is for CPS-based project systems which open their project files in a
// temporary location. There are several of these, such as .csproj, .vbproj, .shproj, and .fsproj, and more
// could appear in the future.
- if (!fullPath.EndsWith("proj", StringComparison.Ordinal))
- {
- return fullPath;
- }
+ if (!fullPath.EndsWith("proj", StringComparison.Ordinal)) return fullPath;
// CPS will open the file in %TEMP%\{random name}\{ProjectFileName}
- string directoryName = Path.GetDirectoryName(fullPath);
+ var directoryName = Path.GetDirectoryName(fullPath);
if (string.IsNullOrEmpty(directoryName))
return fullPath;
directoryName = Path.GetDirectoryName(directoryName);
- if (!Path.GetTempPath().Equals(directoryName + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
+ if (!Path.GetTempPath().Equals(directoryName + Path.DirectorySeparatorChar,
+ StringComparison.OrdinalIgnoreCase))
return fullPath;
- IVsSolution solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
- if (solution == null)
+ if (!(_serviceProvider.GetService(typeof(SVsSolution)) is IVsSolution solution))
return fullPath;
- if (!ErrorHandler.Succeeded(solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, Guid.Empty, out IEnumHierarchies ppenum))
+ if (!ErrorHandler.Succeeded(solution.GetProjectEnum((uint) __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION,
+ Guid.Empty, out var ppenum))
|| ppenum == null)
- {
return fullPath;
- }
- List projectFiles = new List();
- IVsHierarchy[] hierarchies = new IVsHierarchy[1];
+ var projectFiles = new List();
+ var hierarchies = new IVsHierarchy[1];
while (true)
{
- int hr = ppenum.Next((uint)hierarchies.Length, hierarchies, out uint fetched);
+ var hr = ppenum.Next((uint) hierarchies.Length, hierarchies, out var fetched);
if (!ErrorHandler.Succeeded(hr))
return fullPath;
@@ -372,7 +333,8 @@ private string AdjustPath(string fullPath)
if (!(hierarchies[0] is IVsProject project))
continue;
- if (!ErrorHandler.Succeeded(project.GetMkDocument((uint)VSConstants.VSITEMID.Root, out string projectFilePath)))
+ if (!ErrorHandler.Succeeded(project.GetMkDocument((uint) VSConstants.VSITEMID.Root,
+ out var projectFilePath)))
continue;
if (!Path.GetFileName(projectFilePath).Equals(Path.GetFileName(fullPath), StringComparison.Ordinal))
@@ -381,34 +343,28 @@ private string AdjustPath(string fullPath)
projectFiles.Add(projectFilePath);
}
- if (hr != VSConstants.S_OK)
- {
- // No more projects
- break;
- }
+ if (hr != VSConstants.S_OK) break;
}
switch (projectFiles.Count)
{
- case 0:
- // No matching project file found in solution
- return fullPath;
+ case 0:
+ // No matching project file found in solution
+ return fullPath;
- case 1:
- // Exactly one matching project file found in solution
- return projectFiles[0];
+ case 1:
+ // Exactly one matching project file found in solution
+ return projectFiles[0];
- default:
- // Multiple project files found in solution; try to find one with a matching file size
- long desiredSize = new FileInfo(fullPath).Length;
- foreach (var projectFilePath in projectFiles)
- {
- if (File.Exists(projectFilePath) && new FileInfo(projectFilePath).Length == desiredSize)
- return projectFilePath;
- }
+ default:
+ // Multiple project files found in solution; try to find one with a matching file size
+ var desiredSize = new FileInfo(fullPath).Length;
+ foreach (var projectFilePath in projectFiles)
+ if (File.Exists(projectFilePath) && new FileInfo(projectFilePath).Length == desiredSize)
+ return projectFilePath;
- // No results found
- return fullPath;
+ // No results found
+ return fullPath;
}
}
}
diff --git a/GitDiffMargin/Git/GitDiffParser.cs b/GitDiffMargin/Git/GitDiffParser.cs
index 382468a..26f7493 100644
--- a/GitDiffMargin/Git/GitDiffParser.cs
+++ b/GitDiffMargin/Git/GitDiffParser.cs
@@ -6,16 +6,11 @@ namespace GitDiffMargin.Git
{
public class GitDiffParser
{
- private readonly string _gitDiff;
private readonly int _contextLines;
+ private readonly string _gitDiff;
private readonly bool _suppressRollback;
- public GitDiffParser(string gitDiff, int contextLines)
- : this(gitDiff, contextLines, false)
- {
- }
-
- public GitDiffParser(string gitDiff, int contextLines, bool suppressRollback)
+ public GitDiffParser(string gitDiff, int contextLines, bool suppressRollback = false)
{
_gitDiff = gitDiff;
_contextLines = contextLines;
@@ -24,9 +19,10 @@ public GitDiffParser(string gitDiff, int contextLines, bool suppressRollback)
public IEnumerable Parse()
{
- return from hunkLine in GetUnifiedFormatHunkLines()
- where !string.IsNullOrEmpty(hunkLine.Item1)
- select new HunkRangeInfo(new HunkRange(GetHunkOriginalFile(hunkLine.Item1), _contextLines), new HunkRange(GetHunkNewFile(hunkLine.Item1), _contextLines), hunkLine.Item2, _suppressRollback);
+ return from hunkLine in GetUnifiedFormatHunkLines()
+ where !string.IsNullOrEmpty(hunkLine.Item1)
+ select new HunkRangeInfo(new HunkRange(GetHunkOriginalFile(hunkLine.Item1), _contextLines),
+ new HunkRange(GetHunkNewFile(hunkLine.Item1), _contextLines), hunkLine.Item2, _suppressRollback);
}
public IEnumerable>> GetUnifiedFormatHunkLines()
@@ -38,9 +34,10 @@ public IEnumerable>> GetUnifiedFormatHunkLines
var splitHunks = SplitHunks(withoutHeader).ToList();
- return splitHunks.Any() ?
- splitHunks.Select(splitHunk => new Tuple>(splitHunk[0], splitHunk.Skip(1).TakeWhile((s, i) => i < splitHunk.Count))) :
- Enumerable.Empty>>();
+ return splitHunks.Any()
+ ? splitHunks.Select(splitHunk => new Tuple>(splitHunk[0],
+ splitHunk.Skip(1).TakeWhile((s, i) => i < splitHunk.Count)))
+ : Enumerable.Empty>>();
}
private static IEnumerable> SplitHunks(List lines)
@@ -51,7 +48,6 @@ private static IEnumerable> SplitHunks(List lines)
var hunks = new List();
foreach (var line in lines)
- {
if (line.StartsWith("@@"))
{
if (firstHunk)
@@ -70,7 +66,6 @@ private static IEnumerable> SplitHunks(List lines)
{
hunks.Add(line);
}
- }
yield return new List(hunks);
}
@@ -82,7 +77,8 @@ public string GetHunkOriginalFile(string hunkLine)
public string GetHunkNewFile(string hunkLine)
{
- return hunkLine.Split(new[] { "@@ -", " +" }, StringSplitOptions.RemoveEmptyEntries).ToArray()[1].Split(' ')[0];
+ return hunkLine.Split(new[] {"@@ -", " +"}, StringSplitOptions.RemoveEmptyEntries).ToArray()[1]
+ .Split(' ')[0];
}
}
}
\ No newline at end of file
diff --git a/GitDiffMargin/Git/HunkRange.cs b/GitDiffMargin/Git/HunkRange.cs
index f9a7b86..c8c6a81 100644
--- a/GitDiffMargin/Git/HunkRange.cs
+++ b/GitDiffMargin/Git/HunkRange.cs
@@ -7,18 +7,17 @@ public HunkRange(string hunkRange, int contextLines)
if (hunkRange.Contains(","))
{
var hunkParts = hunkRange.Split(',');
- StartingLineNumber = int.Parse(hunkParts[0]) -1 + contextLines;
- NumberOfLines = int.Parse(hunkParts[1]) - (2 * contextLines);
+ StartingLineNumber = int.Parse(hunkParts[0]) - 1 + contextLines;
+ NumberOfLines = int.Parse(hunkParts[1]) - 2 * contextLines;
}
else
{
StartingLineNumber = int.Parse(hunkRange) - 1 + contextLines;
NumberOfLines = 1;
}
-
}
- public int StartingLineNumber { get; private set; }
- public int NumberOfLines { get; private set; }
+ public int StartingLineNumber { get; }
+ public int NumberOfLines { get; }
}
}
\ No newline at end of file
diff --git a/GitDiffMargin/Git/HunkRangeInfo.cs b/GitDiffMargin/Git/HunkRangeInfo.cs
index c3f96c0..3362fc8 100644
--- a/GitDiffMargin/Git/HunkRangeInfo.cs
+++ b/GitDiffMargin/Git/HunkRangeInfo.cs
@@ -9,37 +9,32 @@ namespace GitDiffMargin.Git
{
public class HunkRangeInfo
{
- private List DiffLines { get; set; }
-
- public HunkRangeInfo(HunkRange originaleHunkRange, HunkRange newHunkRange, IEnumerable diffLines)
- : this(originaleHunkRange, newHunkRange, diffLines, false)
- {
- }
-
- public HunkRangeInfo(HunkRange originaleHunkRange, HunkRange newHunkRange, IEnumerable diffLines, bool suppressRollback)
+ public HunkRangeInfo(HunkRange originaleHunkRange, HunkRange newHunkRange, IEnumerable diffLines,
+ bool suppressRollback = false)
{
OriginalHunkRange = originaleHunkRange;
NewHunkRange = newHunkRange;
DiffLines = diffLines.ToList();
SuppressRollback = suppressRollback;
-
+
IsAddition = DiffLines.All(s => s.StartsWith("+") || s.StartsWith("\\") || string.IsNullOrWhiteSpace(s));
IsDeletion = DiffLines.All(s => s.StartsWith("-") || s.StartsWith("\\") || string.IsNullOrWhiteSpace(s));
IsModification = !IsAddition && !IsDeletion;
if (IsDeletion || IsModification)
- {
- OriginalText = DiffLines.Where(s => s.StartsWith("-")).Select(s => s.Remove(0, 1).TrimEnd('\n').TrimEnd('\r')).ToList();
- }
+ OriginalText = DiffLines.Where(s => s.StartsWith("-"))
+ .Select(s => s.Remove(0, 1).TrimEnd('\n').TrimEnd('\r')).ToList();
}
- public HunkRange OriginalHunkRange { get; private set; }
- public HunkRange NewHunkRange { get; private set; }
- public List OriginalText { get; private set; }
- public bool SuppressRollback { get; private set; }
+ private List DiffLines { get; }
+
+ public HunkRange OriginalHunkRange { get; }
+ public HunkRange NewHunkRange { get; }
+ public List OriginalText { get; }
+ public bool SuppressRollback { get; }
- public bool IsAddition { get; private set; }
- public bool IsModification { get; private set; }
- public bool IsDeletion { get; private set; }
+ public bool IsAddition { get; }
+ public bool IsModification { get; }
+ public bool IsDeletion { get; }
}
}
\ No newline at end of file
diff --git a/GitDiffMargin/Git/IGitCommands.cs b/GitDiffMargin/Git/IGitCommands.cs
index f7d681d..7c9494a 100644
--- a/GitDiffMargin/Git/IGitCommands.cs
+++ b/GitDiffMargin/Git/IGitCommands.cs
@@ -9,62 +9,75 @@ namespace GitDiffMargin.Git
{
internal interface IGitCommands
{
- IEnumerable GetGitDiffFor(ITextDocument textDocument, string originalPath, ITextSnapshot snapshot);
+ IEnumerable GetGitDiffFor(ITextDocument textDocument, string originalPath,
+ ITextSnapshot snapshot);
void StartExternalDiff(ITextDocument textDocument, string originalPath);
///
- /// Attempts to gets the original file path for the specified path.
+ /// Attempts to gets the original file path for the specified path.
///
///
- /// In some (detectable) cases, documents are opened through a temporary copy of the file rather than
- /// opening the original file directly. To preserve Git diff functionality in these cases, the original path is
- /// detected and used for diff operations.
+ ///
+ /// In some (detectable) cases, documents are opened through a temporary copy of the file rather than
+ /// opening the original file directly. To preserve Git diff functionality in these cases, the original path is
+ /// detected and used for diff operations.
+ ///
///
/// The path of a document opened in the editor.
- /// The original path of the document in a source-controlled working copy; otherwise,
- /// this is just set to .
- /// if the resulting was located (even if it
- /// matches ; otherwise, .
+ ///
+ /// The original path of the document in a source-controlled working copy; otherwise,
+ /// this is just set to .
+ ///
+ ///
+ /// if the resulting was located (even if it
+ /// matches ; otherwise, .
+ ///
bool TryGetOriginalPath(string path, out string originalPath);
///
- /// Determines if a file or directory is located within a Git repository.
+ /// Determines if a file or directory is located within a Git repository.
///
/// The path to the file or directory.
/// The original path of the file in a source-controlled working copy.
///
- /// if is a valid path of a file or directory located within a
- /// Git repository; otherwise, .
+ /// if is a valid path of a file or directory located within a
+ /// Git repository; otherwise, .
///
bool IsGitRepository(string path, string originalPath);
///
- /// Gets the absolute path to the folder containing the Git repository database for a specified path.
+ /// Gets the absolute path to the folder containing the Git repository database for a specified path.
///
/// The path to the file or directory within the repository.
/// The original path of the file in a source-controlled working copy.
///
- /// The absolute path to folder containing the repository database for .
- /// -or-
- /// if is not a path to a file or directory within a Git
- /// repository.
+ /// The absolute path to folder containing the repository database for .
+ /// -or-
+ ///
+ /// if is not a path to a file or directory within a Git
+ /// repository.
+ ///
///
string GetGitRepository(string path, string originalPath);
///
- /// Gets the root of the working copy of the Git repository containing .
+ /// Gets the root of the working copy of the Git repository containing .
///
/// The path to the file or directory.
/// The original path of the file in a source-controlled working copy.
///
- /// The absolute path to the root of the working copy of the Git repository containing
- /// .
- /// -or-
- /// if the Git repository is bare.
- /// -or-
- /// if is not a path to a file or directory within the
- /// working copy of a Git repository.
+ ///
+ /// The absolute path to the root of the working copy of the Git repository containing
+ /// .
+ ///
+ /// -or-
+ /// if the Git repository is bare.
+ /// -or-
+ ///
+ /// if is not a path to a file or directory within the
+ /// working copy of a Git repository.
+ ///
///
string GetGitWorkingCopy(string path, string originalPath);
}
diff --git a/GitDiffMargin/GitDiffMargin.csproj b/GitDiffMargin/GitDiffMargin.csproj
index 691b25a..18ddc88 100644
--- a/GitDiffMargin/GitDiffMargin.csproj
+++ b/GitDiffMargin/GitDiffMargin.csproj
@@ -31,6 +31,7 @@
prompt
4
false
+ 7.3
pdbonly
@@ -58,10 +59,8 @@
-
-