public static async Task <IWpfTextView> GetWpfTextViewAsync(this Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) { IVsTextManager2 textManager = (IVsTextManager2)await serviceProvider.GetServiceAsync(typeof(SVsTextManager)); if (textManager == null) { return(null); } int result = textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out IVsTextView view); if (result != VSConstants.S_OK) { return(null); } IComponentModel componentModel = (IComponentModel)await serviceProvider.GetServiceAsync(typeof(SComponentModel)); IVsEditorAdaptersFactoryService adapterService = componentModel?.GetService <IVsEditorAdaptersFactoryService>(); if (adapterService == null) { return(null); } return(adapterService.GetWpfTextView(view)); }
public static async void Initialize(IAsyncServiceProvider provider, string name) { _provider = provider; _name = name; _output = await _provider.GetServiceAsync(typeof(SVsOutputWindow)) as IVsOutputWindow; }
private static async System.Threading.Tasks.Task <T> GetMefServiceIteratorAsync <T>(this Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) where T : class { IComponentModel componentModel = await serviceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel; return(GetMefService <T>(componentModel)); }
private static async System.Threading.Tasks.Task <T> GetMefServiceAsyncIterator <T>(this Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) where T : class { IComponentModel componentModel = await serviceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel; // We don't want to throw in the case of a missing service (don't use GetService<T>) return(componentModel?.GetExtensions <T>().SingleOrDefault()); }
public async Task LoadAsync() { Microsoft.VisualStudio.Shell.IAsyncServiceProvider asyncServiceProvider = await((Microsoft.VisualStudio.Shell.AsyncPackage)ServiceProvider).GetServiceAsync(typeof(Microsoft.VisualStudio.Shell.Interop.SAsyncServiceProvider)) as Microsoft.VisualStudio.Shell.IAsyncServiceProvider; var testService = await asyncServiceProvider.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE; var props = testService.Properties["ClaudiaIDE", "General"]; Load(props); }
public VsProjectAdapterProvider( [Import(typeof(SAsyncServiceProvider))] IAsyncServiceProvider serviceProvider, IVsProjectThreadingService threadingService) : this( threadingService, new AsyncLazy <SVsSolution>(() => serviceProvider.GetServiceAsync <SVsSolution>(), threadingService.JoinableTaskFactory)) { }
public static async Task <GraphIconCache> CreateAsync(IAsyncServiceProvider serviceProvider) { #pragma warning disable RS0030 // Do not used banned APIs var imageService = (IVsImageService2)await serviceProvider.GetServiceAsync(typeof(SVsImageService)); #pragma warning restore RS0030 // Do not used banned APIs return(new GraphIconCache(imageService)); }
public static async System.Threading.Tasks.Task <string> GetActiveDocumentFilePathAsync(Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) { var service = serviceProvider.GetServiceAsync(typeof(DTE)); EnvDTE80.DTE2 applicationObject = await Task.Run(() => service) as EnvDTE80.DTE2; await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(applicationObject.ActiveDocument.FullName); }
public static async Task <WritableSettingsStore> GetWritableSettingsStoreAsync( this Microsoft.VisualStudio.Shell.IAsyncServiceProvider asyncServiceProvider) { var vsSettingsManager = (IVsSettingsManager)await asyncServiceProvider.GetServiceAsync(typeof(SVsSettingsManager)); var shellSettingsManager = new ShellSettingsManager(vsSettingsManager); return(shellSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings)); }
public static async Task <VirtualMemoryNotificationListener> CreateAsync(VisualStudioWorkspace workspace, IThreadingContext threadingContext, IAsyncServiceProvider serviceProvider, CancellationToken cancellationToken) { await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var shell = (IVsShell?)await serviceProvider.GetServiceAsync(typeof(SVsShell)).ConfigureAwait(true); Assumes.Present(shell); return(new VirtualMemoryNotificationListener(threadingContext, shell, workspace)); }
public async ValueTask <IOptionPersister> GetOrCreatePersisterAsync(CancellationToken cancellationToken) { if (_lazyPersister is not null) { return(_lazyPersister); } var settingsManager = (ISettingsManager?)await _serviceProvider.GetServiceAsync(typeof(SVsSettingsPersistenceManager)).ConfigureAwait(true); _lazyPersister ??= new RoamingVisualStudioProfileOptionPersister(_optionService, settingsManager); return(_lazyPersister); }
public SettingsManagerWrapper(Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) { _settingsManager = new AsyncLazy <IVsSettingsManager>(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var settingsManager = await serviceProvider.GetServiceAsync <SVsSettingsManager, IVsSettingsManager>(); Assumes.Present(settingsManager); return(settingsManager); }, NuGetUIThreadHelper.JoinableTaskFactory); }
private async Task <T> GetServiceAsync() { // If the service request requires a package load, GetServiceAsync will // happily do that on a background thread. object iunknown = await _serviceProvider.GetServiceAsync(ServiceType); // We explicitly switch to the UI thread to avoid doing a QueryInterface // via blocking RPC for STA objects when we cast explicitly to the type await _threadingService.SwitchToUIThread(); return((T)iunknown); }
public static async System.Threading.Tasks.Task <T> GetMefServiceAsync <T>(this Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) where T : class { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } IComponentModel componentModel = await serviceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel; // We don't want to throw in the case of a missing service (don't use GetService<T>) return(componentModel?.GetExtensions <T>().SingleOrDefault()); }
public async ValueTask <IOptionPersister> GetOrCreatePersisterAsync(CancellationToken cancellationToken) { if (_lazyPersister is not null) { return(_lazyPersister); } await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var settingsManager = (ISettingsManager?)await _serviceProvider.GetServiceAsync(typeof(SVsSettingsPersistenceManager)).ConfigureAwait(true); _lazyPersister ??= new RoamingVisualStudioProfileOptionPersister(_threadingContext, _optionService, settingsManager); return(_lazyPersister); }
public async ValueTask <IOptionPersister> GetOrCreatePersisterAsync(CancellationToken cancellationToken) { if (_lazyPersister is not null) { return(_lazyPersister); } await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); // Not all SVsTaskList implementations implement ITaskList, but when it does we will use it var taskList = await _serviceProvider.GetServiceAsync(typeof(SVsTaskList)).ConfigureAwait(true) as ITaskList; _lazyPersister ??= new CommentTaskTokenSerializer(_optionService, taskList); return(_lazyPersister); }
private async Task SubscribeAsync(Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) { // Don't use CPS thread helper because of RPS perf regression await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _solutionBuildManager = await serviceProvider.GetServiceAsync <SVsSolutionBuildManager, IVsSolutionBuildManager3>(); Assumes.Present(_solutionBuildManager); ((IVsSolutionBuildManager5)_solutionBuildManager).AdviseUpdateSolutionEvents4(this, out _updateSolutionEventsCookie4); ErrorHandler.ThrowOnFailure( ((IVsSolutionBuildManager2)_solutionBuildManager).AdviseUpdateSolutionEvents( this, out _updateSolutionEventsCookie2)); }
public static async Task <TInterface> GetServiceAsync <TService, TInterface>( this Microsoft.VisualStudio.Shell.IAsyncServiceProvider site) where TInterface : class { var service = await site.GetServiceAsync(typeof(TService)); if (service != null) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(service as TInterface); } return(null); }
public async ValueTask <IOptionPersister> GetOrCreatePersisterAsync(CancellationToken cancellationToken) { if (_lazyPersister is not null) { return(_lazyPersister); } await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var textManager = (IVsTextManager4?)await _serviceProvider.GetServiceAsync(typeof(SVsTextManager)).ConfigureAwait(true); Assumes.Present(textManager); _lazyPersister ??= new LanguageSettingsPersister(_threadingContext, textManager, _optionService); return(_lazyPersister); }
public static async System.Threading.Tasks.Task <TextViewSelection> GetSelectionAsync(Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) { var service = serviceProvider.GetServiceAsync(typeof(SVsTextManager)); var textManager = await Task.Run(() => service) as IVsTextManager2; IVsTextView view; int result = textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out view); view.GetSelection(out int startLine, out int startColumn, out int endLine, out int endColumn);//end could be before beginning var start = new TextViewPosition(startLine, startColumn); var end = new TextViewPosition(endLine, endColumn); view.GetSelectedText(out string selectedText); TextViewSelection selection = new TextViewSelection(start, end, selectedText); return(selection); }
public VsService([Import(typeof(SAsyncServiceProvider))] IAsyncServiceProvider serviceProvider, JoinableTaskContext joinableTaskContext) { Requires.NotNull(serviceProvider, nameof(serviceProvider)); Requires.NotNull(joinableTaskContext, nameof(joinableTaskContext)); _value = new AsyncLazy <T>(async() => { // If the service request requires a package load, GetServiceAsync will // happily do that on a background thread. object iunknown = await serviceProvider.GetServiceAsync(ServiceType); // We explicitly switch to the UI thread to avoid doing a QueryInterface // via blocking RPC for STA objects when we cast explicitly to the type await joinableTaskContext.Factory.SwitchToMainThreadAsync(); return((T)iunknown); }, joinableTaskContext.Factory); }
public async Task InitializeAsync(Microsoft.VisualStudio.Shell.IAsyncServiceProvider serviceProvider) { Host = await serviceProvider.GetServiceAsync(typeof(SDTE)) as DTE; }
public ChannelOutputConsole(IAsyncServiceProvider asyncServiceProvider, Guid channelId, string outputName, JoinableTaskFactory joinableTaskFactory) { if (asyncServiceProvider == null) { throw new ArgumentNullException(nameof(asyncServiceProvider)); } _channelGuid = channelId; _channelId = _channelGuid.ToString(); _channelOutputName = outputName ?? throw new ArgumentNullException(nameof(outputName)); _joinableTaskFactory = joinableTaskFactory ?? throw new ArgumentNullException(nameof(joinableTaskFactory)); _serviceBrokerClient = new AsyncLazy <ServiceBrokerClient>(async() => { IBrokeredServiceContainer container = (IBrokeredServiceContainer)await asyncServiceProvider.GetServiceAsync(typeof(SVsBrokeredServiceContainer)); Assumes.Present(container); IServiceBroker serviceBroker = container.GetFullAccessServiceBroker(); return(new ServiceBrokerClient(serviceBroker, _joinableTaskFactory)); }, _joinableTaskFactory); }
public static async Task <TInterface> GetServiceAsync <TService, TInterface>( this Microsoft.VisualStudio.Shell.IAsyncServiceProvider site) where TInterface : class { return(await site.GetServiceAsync(typeof(TService)) as TInterface); }
public static Task <IComponentModel> GetComponentModelAsync( this Microsoft.VisualStudio.Shell.IAsyncServiceProvider site) { return(site.GetServiceAsync <SComponentModel, IComponentModel>()); }
public static Task <EnvDTE.DTE> GetDTEAsync( this Microsoft.VisualStudio.Shell.IAsyncServiceProvider site) { return(site.GetServiceAsync <SDTE, EnvDTE.DTE>()); }