Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.GetService<SVsShell, IVsShell>();
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.GetService<SVsRegisterPriorityCommandTarget, IVsRegisterPriorityCommandTarget>();
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.GetService<SUIHostCommandDispatcher, IOleCommandTarget>();
}
}

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

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

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.GetService<SVsRegisterPriorityCommandTarget, IVsRegisterPriorityCommandTarget>();
var cookie = _priorityCommandTargetCookie;
_priorityCommandTargetCookie = VSConstants.VSCOOKIE_NIL;
var hr = priorityCommandTargetRegistrar.UnregisterPriorityCommandTarget(cookie);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.LanguageServices.Implementation.Extensions;
using Microsoft.VisualStudio.LanguageServices.Utilities;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
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.GetService<SVsUIShellOpenDocument, IVsUIShellOpenDocument>();
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.GetService<SVsUIShellOpenDocument, IVsUIShellOpenDocument>();
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 @@ -24,9 +24,9 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.LanguageServices.Implementation.Extensions;
using Microsoft.VisualStudio.LanguageServices.Implementation.Library;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.Utilities;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Diagnostics;

namespace Microsoft.VisualStudio.LanguageServices.Utilities
{
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)
where TInterfaceType : class
where TServiceType : class
/// <inheritdoc cref="Shell.ServiceExtensions.GetService{TService, TInterface}(IServiceProvider, bool)"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we're not just using the one that comes from the Shell binaries in the first place? Will this also inherit a documentation that won't apply for whatever that bool parameter is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we're not just using the one that comes from the Shell binaries in the first place?

It uses ThreadHelper.JoinableTaskFactory. I'm not sure we initialize that property in test scenarios.

Will this also inherit a documentation that won't apply for whatever that bool parameter is?

Not really, it just ignores it.

public static TInterface GetService<TService, TInterface>(this IServiceProvider sp)
{
return (TInterfaceType)sp.GetService(typeof(TServiceType));
var service = (TInterface)sp.GetService(typeof(TService));
Debug.Assert(service != null);
return service;
}

/// <summary>
Expand Down