private async Task StartUndoAsync(CancellationToken token = default) { DTE dte = await _dte.GetValueAsync(token); if (dte.UndoContext.IsOpen) { _shouldClose = false; } dte.UndoContext.Open(_renameOperationName, false); }
public async Task InitializeAsync() { await _threadHandling.Value.SwitchToUIThread(); // Initialize our cache file string appDataFolder = await _shellUtilitiesHelper.Value.GetLocalAppDataFolderAsync(_vsShellService); if (appDataFolder != null) { _versionDataCacheFile = new RemoteCacheFile(Path.Combine(appDataFolder, VersionDataFilename), VersionCompatibilityDownloadFwlink, TimeSpan.FromHours(CacheFileValidHours), _fileSystem.Value, _httpClient); } _ourVSVersion = await _shellUtilitiesHelper.Value.GetVSVersionAsync(_vsAppIdService); _vsSolution = await _vsSolutionService.GetValueAsync(); Verify.HResult(_vsSolution.AdviseSolutionEvents(this, out _solutionCookie)); // Check to see if a solution is already open. If so we set _solutionOpened to true so that subsequent projects added to // this solution are processed. if (ErrorHandler.Succeeded(_vsSolution.GetProperty((int)__VSPROPID4.VSPROPID_IsSolutionFullyLoaded, out object isFullyLoaded)) && isFullyLoaded is bool isFullyLoadedBool && isFullyLoadedBool) { _solutionOpened = true; } }
/// <summary> /// Launches the Visual Studio debugger. /// </summary> protected async Task DoLaunchAsync(IVsDebuggerLaunchCompletionCallback cb, params IDebugLaunchSettings[] launchSettings) { if (launchSettings.Length == 0) { cb.OnComplete(0, 0, null); return; } VsDebugTargetInfo4[] launchSettingsNative = launchSettings.Select(GetDebuggerStruct4).ToArray(); try { // The debugger needs to be called on the UI thread await ThreadingService.SwitchToUIThread(); IVsDebuggerLaunchAsync shellDebugger = await _vsDebuggerService.GetValueAsync(); shellDebugger.LaunchDebugTargetsAsync((uint)launchSettingsNative.Length, launchSettingsNative, cb); } finally { // Free up the memory allocated to the (mostly) managed debugger structure. foreach (VsDebugTargetInfo4 nativeStruct in launchSettingsNative) { FreeVsDebugTargetInfoStruct(nativeStruct); } } }
internal Task OnProjectChangedAsync(IProjectVersionedValue <IProjectSubscriptionUpdate>?_ = null) { return(_projectTasksService.LoadedProjectAsync(async() => { bool isDebuggable = await IsDebuggableAsync(); IVsStartupProjectsListService?startupProjectsListService = await _startupProjectsListService.GetValueAsync(); if (startupProjectsListService == null) { return; } if (isDebuggable) { // If we're already registered, the service no-ops startupProjectsListService.AddProject(ref _projectGuid); } else { // If we're already unregistered, the service no-ops startupProjectsListService.RemoveProject(ref _projectGuid); } })); }
// This method is overridden in test code protected virtual async Task <bool> IsPreviewSDKInUseAsync() { if (await _shellUtilitiesHelper.Value.IsVSFromPreviewChannelAsync()) { return(true); } if (_settingsManagerService == null) { return(false); } ISettingsManager settings = await _settingsManagerService.GetValueAsync(); return(settings.GetValueOrDefault <bool>(UsePreviewSdkSettingKey)); }
/// <summary> /// Launches the Visual Studio debugger. /// </summary> protected async Task <IReadOnlyList <VsDebugTargetProcessInfo> > DoLaunchAsync(params IDebugLaunchSettings[] launchSettings) { VsDebugTargetInfo4[] launchSettingsNative = launchSettings.Select(GetDebuggerStruct4).ToArray(); if (launchSettingsNative.Length == 0) { return(Array.Empty <VsDebugTargetProcessInfo>()); } try { // The debugger needs to be called on the UI thread await ThreadingService.SwitchToUIThread(); IVsDebugger4 shellDebugger = await _vsDebuggerService.GetValueAsync(); var launchResults = new VsDebugTargetProcessInfo[launchSettingsNative.Length]; shellDebugger.LaunchDebugTargets4((uint)launchSettingsNative.Length, launchSettingsNative, launchResults); return(launchResults); } finally { // Free up the memory allocated to the (mostly) managed debugger structure. foreach (VsDebugTargetInfo4 nativeStruct in launchSettingsNative) { FreeVsDebugTargetInfoStruct(nativeStruct); } } }
// This method is overridden in test code protected virtual async Task<bool> IsPreviewSDKInUseAsync() { if (await IsPrereleaseAsync()) { return true; } if (_settingsManagerService == null) { return false; } ISettingsManager settings = await _settingsManagerService.GetValueAsync(); return settings.GetValueOrDefault<bool>(UsePreviewSdkSettingKey); }
public async Task <Version?> GetVSVersionAsync(IVsService <IVsAppId> vsAppIdService) { await _threadingService.SwitchToUIThread(); IVsAppId?vsAppId = await vsAppIdService.GetValueAsync(); Assumes.Present(vsAppId); if (ErrorHandler.Succeeded(vsAppId.GetProperty((int)VSAPropID.VSAPROPID_ProductSemanticVersion, out object oVersion)) && oVersion is string semVersion) { // This is a semantic version string. We only care about the non-semantic version part int index = semVersion.IndexOfAny(Delimiter.PlusAndMinus); if (index != -1) { semVersion = semVersion.Substring(0, index); } if (Version.TryParse(semVersion, out Version vsVersion)) { return(vsVersion); } } return(null); }
private async Task <Project?> TryGetProjectFromPathAsync(string projectPath) { DTE?dte = await _dte.GetValueAsync(); Assumes.NotNull(dte); foreach (Project project in dte.Solution.Projects) { string?fullName = null; try { fullName = project.FullName; } catch (Exception) { // DTE COM calls can fail for any number of valid reasions. continue; } if (StringComparers.Paths.Equals(fullName, projectPath)) { return(project); } } return(null); }
// This method is overridden in test code protected virtual async Task <bool> IsPreviewSDKInUseAsync() { if (await IsPrereleaseAsync()) { return(true); } if (_settingsManagerService == null) { return(false); } ISettingsManager?settings = await _settingsManagerService.GetValueAsync(); Assumes.Present(settings); return(settings.GetValueOrDefault <bool>(UsePreviewSdkSettingKey)); }
private async Task ProcessDesignTimeInputs(IProjectVersionedValue <DesignTimeInputs> input) { DesignTimeInputs designTimeInputs = input.Value; IVsAsyncFileChangeEx?vsAsyncFileChangeEx = await _fileChangeService.GetValueAsync(); Assumes.Present(vsAsyncFileChangeEx); // we don't care about the difference between types of inputs, so we just construct one hashset for fast comparisons later var allFiles = new HashSet <string>(StringComparers.Paths); allFiles.AddRange(designTimeInputs.Inputs); allFiles.AddRange(designTimeInputs.SharedInputs); // Remove any files we're watching that we don't care about any more var removedFiles = new List <string>(); foreach ((string file, uint cookie) in _fileWatcherCookies) { if (!allFiles.Contains(file)) { await vsAsyncFileChangeEx.UnadviseFileChangeAsync(cookie); removedFiles.Add(file); } } foreach (string file in removedFiles) { _fileWatcherCookies.Remove(file); } // Now watch and output files that are new foreach (string file in allFiles) { if (!_fileWatcherCookies.ContainsKey(file)) { // We don't care about delete and add here, as they come through data flow, plus they are really bouncy - every file change is a Time, Del and Add event) uint cookie = await vsAsyncFileChangeEx.AdviseFileChangeAsync(file, _VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Size, sink : this); _fileWatcherCookies.Add(file, cookie); } } }
private async Task RegisterFileWatcherAsync(string projectLockJsonFilePath) { // Note file change service is free-threaded if (projectLockJsonFilePath != null) { _previousContentsHash = GetFileHashOrNull(projectLockJsonFilePath); _taskDelayScheduler = new TaskDelayScheduler( s_notifyDelay, _projectServices.ThreadingService, CreateLinkedCancellationToken()); IVsFileChangeEx fileChangeService = await _fileChangeService.GetValueAsync(); int hr = fileChangeService.AdviseFileChange(projectLockJsonFilePath, (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Add | _VSFILECHANGEFLAGS.VSFILECHG_Del), this, out _filechangeCookie); ErrorHandler.ThrowOnFailure(hr); } _fileBeingWatched = projectLockJsonFilePath; }
protected virtual async Task <bool> IsPreviewSDKInUseAsync() { if (await IsPrereleaseAsync()) { return(true); } ISettingsManager settings = await _settingsManagerService?.GetValueAsync(); return(settings.GetValueOrDefault <bool>(s_usePreviewSdkSettingKey)); }
private async Task <IVsHierarchy?> TryGetIVsHierarchyAsync(Project project) { IVsSolution solutionService = await _solutionService.GetValueAsync(); if (solutionService.GetProjectOfUniqueName(project.UniqueName, out IVsHierarchy projectHierarchy) == HResult.OK) { return(projectHierarchy); } return(null); }
private async Task <Solution> PublishLatestSolutionAsync() { // WORKAROUND: We don't yet have a way to wait for the rename changes to propagate // to Roslyn (tracked by https://github.com/dotnet/project-system/issues/3425), so // instead we wait for the IntelliSense stage to finish for the entire solution // IVsOperationProgressStageStatus stageStatus = (await _operationProgressService.GetValueAsync()).GetStageStatus(CommonOperationProgressStageIds.Intellisense); await stageStatus.WaitForCompletionAsync(); // The result of that wait, is basically a "new" published Solution, so grab it return(_workspace.CurrentSolution); }
private async Task WarnUserOfIncompatibleProjectAsync(CompatibilityLevel compatLevel, VersionCompatibilityData compatData) { // Warn the user. await _threadHandling.Value.SwitchToUIThread(); // Check if already warned - this could happen in the off chance two projects are added very quickly since the detection work is // scheduled on idle. if (_compatibilityLevelWarnedForThisSolution < compatLevel) { // Only want to warn once per solution _compatibilityLevelWarnedForThisSolution = compatLevel; IVsUIShell uiShell = await _vsUIShellService.GetValueAsync(); uiShell.GetAppName(out string caption); if (compatLevel == CompatibilityLevel.Supported) { // Get current dontShowAgain value ISettingsManager settingsManager = await _settingsManagerService.GetValueAsync(); bool suppressPrompt = false; if (settingsManager != null) { suppressPrompt = settingsManager.GetValueOrDefault(SuppressDotNewCoreWarningKey, defaultValue: false); } if (!suppressPrompt) { string msg = string.Format(compatData.OpenSupportedMessage, compatData.SupportedVersion.Major, compatData.SupportedVersion.Minor); suppressPrompt = _dialogServices.Value.DontShowAgainMessageBox(caption, msg, VSResources.DontShowAgain, false, VSResources.LearnMore, SupportedLearnMoreFwlink); if (suppressPrompt && settingsManager != null) { await settingsManager.SetValueAsync(SuppressDotNewCoreWarningKey, suppressPrompt, isMachineLocal : true); } } } else { string msg; if (compatData.UnsupportedVersion != null) { msg = string.Format(compatData.OpenUnsupportedMessage, compatData.UnsupportedVersion.Major, compatData.UnsupportedVersion.Minor); } else { msg = string.Format(compatData.OpenUnsupportedMessage, compatData.SupportedVersion.Major, compatData.SupportedVersion.Minor); } _dialogServices.Value.DontShowAgainMessageBox(caption, msg, null, false, VSResources.LearnMore, UnsupportedLearnMoreFwlink); } } }
public async Task <string?> GetRegistryRootAsync(IVsService <IVsShell> vsShellService) { await _threadingService.SwitchToUIThread(); IVsShell shell = await vsShellService.GetValueAsync(); if (ErrorHandler.Succeeded(shell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out object value))) { return(value as string); } return(null); }
private async Task RegisterFileWatcherAsync(string projectLockJsonFilePath) { // Note file change service is free-threaded if (projectLockJsonFilePath != null) { _previousContentsHash = GetFileHashOrNull(projectLockJsonFilePath); _taskDelayScheduler?.Dispose(); _taskDelayScheduler = new TaskDelayScheduler( s_notifyDelay, _projectServices.ThreadingService, CreateLinkedCancellationToken()); IVsAsyncFileChangeEx fileChangeService = await _fileChangeService.GetValueAsync(); _filechangeCookie = await fileChangeService.AdviseFileChangeAsync( projectLockJsonFilePath, _VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Add | _VSFILECHANGEFLAGS.VSFILECHG_Del, sink : this); } _fileBeingWatched = projectLockJsonFilePath; }
public async Task <string?> GetLocalAppDataFolderAsync(IVsService <IVsShell> vsShellService) { await _threadingService.SwitchToUIThread(); IVsShell?shell = await vsShellService.GetValueAsync(); if (ErrorHandler.Succeeded(shell !.GetProperty((int)__VSSPROPID4.VSSPROPID_LocalAppDataDir, out object objDataFolder)) && objDataFolder is string appDataFolder) { return(appDataFolder); } return(null); }
private async Task EnsureBuildManagerInitializedAsync() { // Switch to UI thread for querying the build manager service. await _threadingService.SwitchToUIThread(); if (_buildManager == null) { _buildManager = await _vsSolutionBuildManagerService.GetValueAsync(); // Register for solution build events. _buildManager !.AdviseUpdateSolutionEvents(this, out _solutionEventsCookie); } }
// This method is overridden in test code protected virtual async Task <bool> IsPreviewSDKInUseAsync() { ISetupInstanceCatalog setupInstanceCatalog = await TryGetSetupInstanceAsync(); if (setupInstanceCatalog?.IsPrerelease() == true) { return(true); } ISettingsManager settings = await _settingsManagerService?.GetValueAsync(); return(settings.GetValueOrDefault <bool>(UsePreviewSdkSettingKey)); }
private async Task <Project?> TryGetProjectFromPathAsync(string projectPath) { DTE dte = await _dte.GetValueAsync(); foreach (Project project in dte.Solution.Projects) { if (StringComparers.Paths.Equals(project.FullName, projectPath)) { return(project); } } return(null); }
protected override async Task InitializeCoreAsync(CancellationToken cancellationToken) { // AdviseUpdateSolutionEvents call needs UI thread. await JoinableFactory.SwitchToMainThreadAsync(cancellationToken); _solutionBuildManager = await _solutionBuildManagerService.GetValueAsync(cancellationToken); (_solutionBuildManager as IVsSolutionBuildManager2)?.AdviseUpdateSolutionEvents(this, out _cookie); ErrorHandler.ThrowOnFailure(_solutionBuildManager.AdviseUpdateSolutionEvents3(this, out _cookie3)); _skipAnalyzersForImplicitlyTriggeredBuild = await _options.GetSkipAnalyzersForImplicitlyTriggeredBuildAsync(cancellationToken); _options.RegisterOptionChangedEventHandler(OnOptionChangedAsync); }
public async Task <string?> GetLocalAppDataFolderAsync(IVsService <IVsShell> vsShellService) { await _threadingService.SwitchToUIThread(); IVsShell?shell = await vsShellService.GetValueAsync(); Assumes.Present(shell); if (ErrorHandler.Succeeded(shell.GetProperty((int)__VSSPROPID4.VSSPROPID_LocalAppDataDir, out object value))) { return(value as string); } return(null); }
public LanguageServiceErrorListProvider( UnconfiguredProject project, IActiveWorkspaceProjectContextHost projectContextHost, IVsService <SVsFeatureFlags, IVsFeatureFlags> featureFlagsService, JoinableTaskContext joinableTaskContext) { _project = project; _projectContextHost = projectContextHost; _isLspPullDiagnosticsEnabled = new AsyncLazy <bool>(async() => { IVsFeatureFlags?service = await featureFlagsService.GetValueAsync(); return(service.IsFeatureEnabled(LspPullDiagnosticsFeatureFlagName, defaultValue: false)); }, joinableTaskContext.Factory); }
public async Task InitializeAsync() { await _threadHandling.Value.SwitchToUIThread(); // Initialize our cache file string?appDataFolder = await _shellUtilitiesHelper.Value.GetLocalAppDataFolderAsync(_vsShellService); if (appDataFolder != null) { _versionDataCacheFile = new RemoteCacheFile(Path.Combine(appDataFolder, VersionDataFilename), VersionCompatibilityDownloadFwlink, TimeSpan.FromHours(CacheFileValidHours), _fileSystem.Value, _httpClient); } VisualStudioVersion = await _shellUtilitiesHelper.Value.GetVSVersionAsync(_vsAppIdService); _vsSolution = await _vsSolutionService.GetValueAsync(); Verify.HResult(_vsSolution.AdviseSolutionEvents(this, out _solutionCookie)); // Check to see if a solution is already open. If so we set _solutionOpened to true so that subsequent projects added to // this solution are processed. if (ErrorHandler.Succeeded(_vsSolution.GetProperty((int)__VSPROPID4.VSPROPID_IsSolutionFullyLoaded, out object isFullyLoaded)) && isFullyLoaded is bool isFullyLoadedBool && isFullyLoadedBool) { SolutionOpen = true; // do not block package initialization on this _threadHandling.Value.RunAndForget(async() => { // Perform file IO on the thread pool await TaskScheduler.Default; // First make sure that the cache file exists if (_versionDataCacheFile != null && !_versionDataCacheFile.CacheFileExists()) { await _versionDataCacheFile.TryToUpdateCacheFileAsync(); } // check if the project is compatible await CheckCompatibilityAsync(); }, unconfiguredProject: null); } }
private async Task <IVsContainedLanguageFactory> GetContainedLanguageFactoryAsync() { Guid languageServiceId = await GetLanguageServiceId(); if (languageServiceId == Guid.Empty) { return(null); } IOleAsyncServiceProvider serviceProvider = await _serviceProvider.GetValueAsync(); object service = await serviceProvider.QueryServiceAsync(ref languageServiceId); // NOTE: While this type is implemented in Roslyn, we force the cast on // the UI thread because they are free to change this to an STA object // which would result in an RPC call from a background thread. await _projectVsServices.ThreadingService.SwitchToUIThread(); return((IVsContainedLanguageFactory)service); }
private async Task <bool> CheckUserConfirmationAsync(string oldFileName) { ISettingsManager settings = await _settingsManagerService.GetValueAsync(); bool enableSymbolicRename = settings.GetValueOrDefault("SolutionNavigator.EnableSymbolicRename", false); await _projectVsServices.ThreadingService.SwitchToUIThread(); bool userNeedPrompt = _environmentOptions.GetOption("Environment", "ProjectsAndSolution", "PromptForRenameSymbol", false); if (!enableSymbolicRename || !userNeedPrompt) { return(enableSymbolicRename); } string renamePromptMessage = string.Format(CultureInfo.CurrentCulture, VSResources.RenameSymbolPrompt, oldFileName); bool userSelection = _userNotificationServices.Confirm(renamePromptMessage, out bool disablePromptMessage); _environmentOptions.SetOption("Environment", "ProjectsAndSolution", "PromptForRenameSymbol", !disablePromptMessage); return(userSelection); }
private async Task <bool> CheckUserConfirmationAsync(string oldFileName) { ISettingsManager settings = await _settingsManagerService.GetValueAsync(); // Default value needs to match the default value in the checkbox Tools|Options|Project and Solutions|Enable symbolic renaming. bool enableSymbolicRename = settings.GetValueOrDefault(SymbolicRenameName, true); await _projectVsServices.ThreadingService.SwitchToUIThread(); bool userNeedPrompt = _environmentOptions.GetOption(RenameSymbolCategory, RenameSymbolPage, RenameSymbolOption, false); if (!enableSymbolicRename || !userNeedPrompt) { return(enableSymbolicRename); } string renamePromptMessage = string.Format(CultureInfo.CurrentCulture, VSResources.RenameSymbolPrompt, oldFileName); bool userSelection = _userNotificationServices.Confirm(renamePromptMessage, out bool disablePromptMessage); _environmentOptions.SetOption(RenameSymbolCategory, RenameSymbolPage, RenameSymbolOption, !disablePromptMessage); return(userSelection); }
private async Task <T> GetSettingValueOrDefaultAsync <T>(string name, T defaultValue, CancellationToken cancellationToken) { ISettingsManager settingsManager = await _settingsManager.GetValueAsync(cancellationToken); return(settingsManager.GetValueOrDefault(name, defaultValue)); }