protected async Task <bool> CheckUserConfirmation(string oldFileName) { if (_userPromptedOnce) { return(_userConfirmedRename); } await _threadingService.SwitchToUIThread(); var userNeedPrompt = _optionsSettings.GetPropertiesValue("Environment", "ProjectsAndSolution", "PromptForRenameSymbol", false); if (userNeedPrompt) { string renamePromptMessage = string.Format(CultureInfo.CurrentCulture, VSResources.RenameSymbolPrompt, oldFileName); await _threadingService.SwitchToUIThread(); _userConfirmedRename = _userNotificationServices.Confirm(renamePromptMessage); } _userPromptedOnce = true; return(_userConfirmedRename); }
public async Task RenameAsync(Project myNewProject) { Document newDocument = (from d in myNewProject.Documents where StringComparers.Paths.Equals(d.FilePath, _newFilePath) select d).FirstOrDefault(); if (newDocument == null) { return; } var root = await newDocument.GetSyntaxRootAsync().ConfigureAwait(false); if (root == null) { return; } string oldName = Path.GetFileNameWithoutExtension(_oldFilePath); string newName = Path.GetFileNameWithoutExtension(newDocument.FilePath); var declaration = root.DescendantNodes().Where(n => HasMatchingSyntaxNode(newDocument, n, oldName)).FirstOrDefault(); if (declaration == null) { return; } var semanticModel = await newDocument.GetSemanticModelAsync().ConfigureAwait(false); if (semanticModel == null) { return; } var symbol = semanticModel.GetDeclaredSymbol(declaration); if (symbol == null) { return; } var userConfirmed = true; await _threadingService.SwitchToUIThread(); var userNeedPrompt = _optionsSettings.GetPropertiesValue("Environment", "ProjectsAndSolution", "PromptForRenameSymbol", false); if (userNeedPrompt) { string renamePromptMessage = string.Format(Resources.RenameSymbolPrompt, oldName); await _threadingService.SwitchToUIThread(); userConfirmed = _userNotificationServices.Confirm(renamePromptMessage); } if (userConfirmed) { var renamedSolution = await _roslynServices.RenameSymbolAsync(newDocument.Project.Solution, symbol, newName).ConfigureAwait(false); await _threadingService.SwitchToUIThread(); var renamedSolutionApplied = _roslynServices.ApplyChangesToSolution(newDocument.Project.Solution.Workspace, renamedSolution); if (!renamedSolutionApplied) { string failureMessage = string.Format(Resources.RenameSymbolFailed, oldName); await _threadingService.SwitchToUIThread(); _userNotificationServices.NotifyFailure(failureMessage); } } }