Skip to content

Commit

Permalink
Rename GetService to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jul 16, 2020
1 parent 0535a47 commit 2e14de4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void InitializeCore()
return;
}

var vsShell = _serviceProvider.GetService<IVsShell, SVsShell>();
var vsShell = _serviceProvider.GetServiceTheWrongWay<IVsShell, SVsShell>();
var hr = vsShell.IsPackageInstalled(ReSharperPackageGuid, out var extensionEnabled);
if (ErrorHandler.Failed(hr))
{
Expand All @@ -127,7 +127,7 @@ private void InitializeCore()
if (_resharperExtensionInstalledAndEnabled)
{
// We need to monitor for suspend/resume commands, so create and install the command target and the modal callback.
var priorityCommandTargetRegistrar = _serviceProvider.GetService<IVsRegisterPriorityCommandTarget, SVsRegisterPriorityCommandTarget>();
var priorityCommandTargetRegistrar = _serviceProvider.GetServiceTheWrongWay<IVsRegisterPriorityCommandTarget, SVsRegisterPriorityCommandTarget>();
hr = priorityCommandTargetRegistrar.RegisterPriorityCommandTarget(
dwReserved: 0 /* from docs must be 0 */,
pCmdTrgt: this,
Expand Down Expand Up @@ -335,7 +335,7 @@ async Task EnsureOleCommandTargetAsync()

await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

_oleCommandTarget = _serviceProvider.GetService<IOleCommandTarget, SUIHostCommandDispatcher>();
_oleCommandTarget = _serviceProvider.GetServiceTheWrongWay<IOleCommandTarget, SUIHostCommandDispatcher>();
}
}

Expand All @@ -345,7 +345,7 @@ private void RestoreVsKeybindings()

if (_uiShell == null)
{
_uiShell = _serviceProvider.GetService<IVsUIShell, SVsUIShell>();
_uiShell = _serviceProvider.GetServiceTheWrongWay<IVsUIShell, SVsUIShell>();
}

ErrorHandler.ThrowOnFailure(_uiShell.PostExecCommand(
Expand Down Expand Up @@ -432,7 +432,7 @@ private async Task ShutdownAsync()

if (_priorityCommandTargetCookie != VSConstants.VSCOOKIE_NIL)
{
var priorityCommandTargetRegistrar = _serviceProvider.GetService<IVsRegisterPriorityCommandTarget, SVsRegisterPriorityCommandTarget>();
var priorityCommandTargetRegistrar = _serviceProvider.GetServiceTheWrongWay<IVsRegisterPriorityCommandTarget, SVsRegisterPriorityCommandTarget>();
var cookie = _priorityCommandTargetCookie;
_priorityCommandTargetCookie = VSConstants.VSCOOKIE_NIL;
var hr = priorityCommandTargetRegistrar.UnregisterPriorityCommandTarget(cookie);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ private bool TryGetFrame(CodeAnalysis.TextDocument document, [NotNullWhen(return
// document using its ItemId. Thus, we must use OpenDocumentViaProject, which only
// depends on the file path.

var openDocumentService = ServiceProvider.GlobalProvider.GetService<IVsUIShellOpenDocument, SVsUIShellOpenDocument>();
var openDocumentService = ServiceProvider.GlobalProvider.GetServiceTheWrongWay<IVsUIShellOpenDocument, SVsUIShellOpenDocument>();
return ErrorHandler.Succeeded(openDocumentService.OpenDocumentViaProject(
document.FilePath,
VSConstants.LOGVIEWID.TextView_guid,
Expand Down Expand Up @@ -1072,7 +1072,7 @@ public void CloseDocumentCore(DocumentId documentId)
var filePath = this.GetFilePath(documentId);
if (filePath != null)
{
var openDocumentService = ServiceProvider.GlobalProvider.GetService<IVsUIShellOpenDocument, SVsUIShellOpenDocument>();
var openDocumentService = ServiceProvider.GlobalProvider.GetServiceTheWrongWay<IVsUIShellOpenDocument, SVsUIShellOpenDocument>();
if (ErrorHandler.Succeeded(openDocumentService.IsDocumentOpen(null, 0, filePath, Guid.Empty, 0, out var uiHierarchy, null, out var frame, out var isOpen)))
{
// TODO: do we need save argument for CloseDocument?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;

namespace Microsoft.VisualStudio.LanguageServices.Utilities
{
Expand All @@ -11,7 +12,7 @@ internal static class IServiceProviderExtensions
/// <summary>
/// Returns the specified interface from the service. This is useful when the service and interface differ
/// </summary>
public static TInterfaceType GetService<TInterfaceType, TServiceType>(this IServiceProvider sp)
public static TInterfaceType GetServiceTheWrongWay<TInterfaceType, TServiceType>(this IServiceProvider sp)
where TInterfaceType : class
where TServiceType : class
{
Expand All @@ -22,6 +23,6 @@ public static TInterfaceType GetService<TInterfaceType, TServiceType>(this IServ
/// Returns the specified service type from the service.
/// </summary>
public static TServiceType GetService<TServiceType>(this IServiceProvider sp) where TServiceType : class
=> sp.GetService<TServiceType, TServiceType>();
=> sp.GetServiceTheWrongWay<TServiceType, TServiceType>();
}
}

0 comments on commit 2e14de4

Please sign in to comment.