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);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OperationProgressToolWindowControl"/> class.
        /// </summary>
        public OperationProgressToolWindowControl()
        {
            this.vsOperationProgressService       = OperationProgressPackage.Instance.VsOperationProgressService;
            this.vsOperationProgressStatusService = OperationProgressPackage.Instance.VsOperationProgressStatusService;
            this.joinableTaskFactory = OperationProgressPackage.Instance.JoinableTaskFactory;

            this.InitializeComponent();

            this.intelliSenseStageStatus = vsOperationProgressStatusService.GetStageStatus(CommonOperationProgressStageIds.Intellisense);

            this.intelliSenseStageStatus.InProgressChanged += IntelliSenseStatus_InProgressChanged;

            // Update the status textblock with the current value
            this.UpdateintelliSenseStatusTextBlock(intelliSenseStageStatus.Status);
        }
        public override async Task RenameAsync(IProjectTreeActionHandlerContext context, IProjectTree node, string value)
        {
            Requires.NotNull(context, nameof(Context));
            Requires.NotNull(node, nameof(node));
            Requires.NotNullOrEmpty(value, nameof(value));

            string?oldFilePath          = node.FilePath;
            string oldName              = Path.GetFileNameWithoutExtension(oldFilePath);
            string newFileWithExtension = value;

            CodeAnalysis.Project?project = GetCurrentProject();

            // Rename the file
            await CPSRenameAsync(context, node, value);

            if (await IsAutomationFunctionAsync() || node.IsFolder || _vsOnlineServices.ConnectedToVSOnline)
            {
                // Do not display rename Prompt
                return;
            }

            if (project is null)
            {
                return;
            }

            string newName = Path.GetFileNameWithoutExtension(newFileWithExtension);

            if (!await CanRenameType(project, oldName, newName))
            {
                return;
            }

            (bool result, Renamer.RenameDocumentActionSet? documentRenameResult) = await GetRenameSymbolsActions(project, oldFilePath, newFileWithExtension);

            if (result == false || documentRenameResult == null)
            {
                return;
            }

            // Ask if the user wants to rename the symbol
            bool userWantsToRenameSymbol = await CheckUserConfirmation(oldName);

            if (!userWantsToRenameSymbol)
            {
                return;
            }

            _threadingService.RunAndForget(async() =>
            {
                // TODO - implement PublishAsync() to sync with LanguageService
                // https://github.com/dotnet/project-system/issues/3425)
                // await _languageService.PublishAsync(treeVersion);
                IVsOperationProgressStageStatus stageStatus = (await _operationProgressService.GetValueAsync()).GetStageStatus(CommonOperationProgressStageIds.Intellisense);
                await stageStatus.WaitForCompletionAsync();

                // Apply actions and notify other VS features
                CodeAnalysis.Solution?currentSolution = GetCurrentProject()?.Solution;
                if (currentSolution == null)
                {
                    return;
                }
                string renameOperationName = string.Format(CultureInfo.CurrentCulture, VSResources.Renaming_Type_from_0_to_1, oldName, value);
                (WaitIndicatorResult result, CodeAnalysis.Solution renamedSolution) = _waitService.WaitForAsyncFunctionWithResult(
                    title: VSResources.Renaming_Type,
                    message: renameOperationName,
                    allowCancel: true,
                    token => documentRenameResult.UpdateSolutionAsync(currentSolution, token));

                // Do not warn the user if the rename was cancelled by the user
                if (result.WasCanceled())
                {
                    return;
                }

                await _projectVsServices.ThreadingService.SwitchToUIThread();
                if (!_roslynServices.ApplyChangesToSolution(currentSolution.Workspace, renamedSolution))
                {
                    string failureMessage = string.Format(CultureInfo.CurrentCulture, VSResources.RenameSymbolFailed, oldName);
                    _userNotificationServices.ShowWarning(failureMessage);
                }
                return;
            }, _unconfiguredProject);
        }