Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 6b38d26

Browse files
committed
Changed to use IGitHubServiceProvider
1 parent 237e40f commit 6b38d26

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/GitHub.App/Services/NavigationService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
using Microsoft.VisualStudio.Shell;
55
using Microsoft.VisualStudio.Shell.Interop;
66
using Microsoft.VisualStudio.TextManager.Interop;
7-
using IServiceProvider = System.IServiceProvider;
87
using GitHub.Models;
98

109
namespace GitHub.Services
1110
{
1211
[Export(typeof(INavigationService))]
1312
public class NavigationService : INavigationService
1413
{
15-
readonly IServiceProvider serviceProvider;
14+
readonly IGitHubServiceProvider serviceProvider;
1615

1716
// If the target line doesn't have a unique match, search this number of lines above looking for a match.
1817
public const int MatchLinesAboveTarget = 4;
1918

2019
[ImportingConstructor]
21-
public NavigationService([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
20+
public NavigationService(IGitHubServiceProvider serviceProvider)
2221
{
2322
this.serviceProvider = serviceProvider;
2423
}
@@ -51,7 +50,7 @@ public IVsTextView NavigateToEquivalentPosition(IVsTextView sourceView, string t
5150

5251
public IVsTextView FindActiveView()
5352
{
54-
var textManager = (IVsTextManager2)serviceProvider.GetService(typeof(SVsTextManager));
53+
var textManager = serviceProvider.GetService<SVsTextManager, IVsTextManager2>();
5554
IVsTextView view;
5655
var hresult = textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out view);
5756
return hresult == VSConstants.S_OK ? view : null;

test/UnitTests/GitHub.App/Services/NavigationServiceTests.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using GitHub.Services;
43
using NUnit.Framework;
54
using NSubstitute;
@@ -18,8 +17,7 @@ public class TheFindNearestMatchingLineMethod
1817
public void FindNearestMatchingLine(IList<string> fromLines, IList<string> toLines, int line,
1918
int expectNearestLine, int expectMatchingLines)
2019
{
21-
var sp = Substitute.For<IServiceProvider>();
22-
var target = new NavigationService(sp);
20+
var target = CreateNavigationService();
2321

2422
int matchedLines;
2523
var nearestLine = target.FindNearestMatchingLine(fromLines, toLines, line, out matchedLines);
@@ -39,12 +37,17 @@ public class TheFindMatchingLineMethod
3937
public void FindNearestMatchingLine(IList<string> fromLines, IList<string> toLines, int line,
4038
int matchingLine)
4139
{
42-
var sp = Substitute.For<IServiceProvider>();
43-
var target = new NavigationService(sp);
40+
var target = CreateNavigationService();
4441

4542
var nearestLine = target.FindMatchingLine(fromLines, toLines, line);
4643

4744
Assert.That(nearestLine, Is.EqualTo(matchingLine));
4845
}
4946
}
47+
48+
static NavigationService CreateNavigationService()
49+
{
50+
var sp = Substitute.For<IGitHubServiceProvider>();
51+
return new NavigationService(sp);
52+
}
5053
}

0 commit comments

Comments
 (0)