public int OnRenamed(ContainedLanguageRenameType clrt, string bstrOldID, string bstrNewID) { int result = 0; var waitIndicator = this.ComponentModel.GetService <IWaitIndicator>(); waitIndicator.Wait( "Intellisense", allowCancel: false, action: c => { var refactorNotifyServices = this.ComponentModel.DefaultExportProvider.GetExportedValues <IRefactorNotifyService>(); if (!ContainedLanguageCodeSupport.TryRenameElement(GetThisDocument(), clrt, bstrOldID, bstrNewID, refactorNotifyServices, c.CancellationToken)) { result = s_CONTAINEDLANGUAGE_CANNOTFINDITEM; } else { result = VSConstants.S_OK; } }); return(result); }
private static ISymbol FindSymbol( Document document, ContainedLanguageRenameType renameType, string fullyQualifiedName, CancellationToken cancellationToken) { switch (renameType) { case ContainedLanguageRenameType.CLRT_CLASS: return(document.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken).GetTypeByMetadataName(fullyQualifiedName)); case ContainedLanguageRenameType.CLRT_CLASSMEMBER: var lastDot = fullyQualifiedName.LastIndexOf('.'); var typeName = fullyQualifiedName.Substring(0, lastDot); var memberName = fullyQualifiedName.Substring(lastDot + 1, fullyQualifiedName.Length - lastDot - 1); var type = document.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken).GetTypeByMetadataName(typeName); var semanticModel = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken); var membersOfName = type.GetMembers(memberName); return(membersOfName.SingleOrDefault()); case ContainedLanguageRenameType.CLRT_NAMESPACE: var ns = document.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken).GlobalNamespace; var parts = fullyQualifiedName.Split('.'); for (int i = 0; i < parts.Length && ns != null; i++) { ns = ns.GetNamespaceMembers().SingleOrDefault(n => n.Name == parts[i]); } return(ns); case ContainedLanguageRenameType.CLRT_OTHER: throw new NotSupportedException(ServicesVSResources.Can_t_rename_other_elements); default: throw new InvalidOperationException(ServicesVSResources.Unknown_rename_type); } }
/// <summary> /// Try to do a symbolic rename the specified symbol. /// </summary> /// <returns>False ONLY if it can't resolve the name. Other errors result in the normal /// exception being propagated.</returns> public static bool TryRenameElement( Document document, ContainedLanguageRenameType clrt, string oldFullyQualifiedName, string newFullyQualifiedName, IEnumerable <IRefactorNotifyService> refactorNotifyServices, CancellationToken cancellationToken) { var symbol = FindSymbol(document, clrt, oldFullyQualifiedName, cancellationToken); if (symbol == null) { return(false); } Workspace workspace; if (Workspace.TryGetWorkspace(document.GetTextAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken).Container, out workspace)) { var newName = newFullyQualifiedName.Substring(newFullyQualifiedName.LastIndexOf('.') + 1); var optionSet = document.Project.Solution.Workspace.Options; var newSolution = Renamer.RenameSymbolAsync(document.Project.Solution, symbol, newName, optionSet, cancellationToken).WaitAndGetResult_Venus(cancellationToken); var changedDocuments = newSolution.GetChangedDocuments(document.Project.Solution); var undoTitle = string.Format(EditorFeaturesResources.Rename_0_to_1, symbol.Name, newName); using (var workspaceUndoTransaction = workspace.OpenGlobalUndoTransaction(undoTitle)) { // Notify third parties about the coming rename operation on the workspace, and let // any exceptions propagate through refactorNotifyServices.TryOnBeforeGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: true); if (!workspace.TryApplyChanges(newSolution)) { Exceptions.ThrowEFail(); } // Notify third parties about the completed rename operation on the workspace, and // let any exceptions propagate through refactorNotifyServices.TryOnAfterGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: true); workspaceUndoTransaction.Commit(); } RenameTrackingDismisser.DismissRenameTracking(workspace, changedDocuments); return(true); } else { return(false); } }
public int OnRenamed(ContainedLanguageRenameType clrt, string bstrOldID, string bstrNewID) { // This method is called when a control is renamed; we don't want to do anything in this case. return(VSConstants.S_OK); }
private static ISymbol FindSymbol( Document document, ContainedLanguageRenameType renameType, string fullyQualifiedName, CancellationToken cancellationToken) { switch (renameType) { case ContainedLanguageRenameType.CLRT_CLASS: return document.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken).GetTypeByMetadataName(fullyQualifiedName); case ContainedLanguageRenameType.CLRT_CLASSMEMBER: var lastDot = fullyQualifiedName.LastIndexOf('.'); var typeName = fullyQualifiedName.Substring(0, lastDot); var memberName = fullyQualifiedName.Substring(lastDot + 1, fullyQualifiedName.Length - lastDot - 1); var type = document.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken).GetTypeByMetadataName(typeName); var semanticModel = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken); var membersOfName = type.GetMembers(memberName); return membersOfName.SingleOrDefault(); case ContainedLanguageRenameType.CLRT_NAMESPACE: var ns = document.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken).GlobalNamespace; var parts = fullyQualifiedName.Split('.'); for (int i = 0; i < parts.Length && ns != null; i++) { ns = ns.GetNamespaceMembers().SingleOrDefault(n => n.Name == parts[i]); } return ns; case ContainedLanguageRenameType.CLRT_OTHER: throw new NotSupportedException(ServicesVSResources.ElementRenameFailed); default: throw new InvalidOperationException(ServicesVSResources.UnknownRenameType); } }
/// <summary> /// Try to do a symbolic rename the specified symbol. /// </summary> /// <returns>False ONLY if it can't resolve the name. Other errors result in the normal /// exception being propagated.</returns> public static bool TryRenameElement( Document document, ContainedLanguageRenameType clrt, string oldFullyQualifiedName, string newFullyQualifiedName, IEnumerable<IRefactorNotifyService> refactorNotifyServices, CancellationToken cancellationToken) { var symbol = FindSymbol(document, clrt, oldFullyQualifiedName, cancellationToken); if (symbol == null) { return false; } Workspace workspace; if (Workspace.TryGetWorkspace(document.GetTextAsync(cancellationToken).WaitAndGetResult(cancellationToken).Container, out workspace)) { var newName = newFullyQualifiedName.Substring(newFullyQualifiedName.LastIndexOf('.') + 1); var optionSet = document.Project.Solution.Workspace.Options; var newSolution = Renamer.RenameSymbolAsync(document.Project.Solution, symbol, newName, optionSet, cancellationToken).WaitAndGetResult(cancellationToken); var changedDocuments = newSolution.GetChangedDocuments(document.Project.Solution); // Notify third parties about the coming rename operation on the workspace, and let // any exceptions propagate through refactorNotifyServices.TryOnBeforeGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: true); if (!workspace.TryApplyChanges(newSolution)) { Exceptions.ThrowEFail(); } // Notify third parties about the completed rename operation on the workspace, and // let any exceptions propagate through refactorNotifyServices.TryOnAfterGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: true); RenameTrackingDismisser.DismissRenameTracking(workspace, changedDocuments); return true; } else { return false; } }
public int OnRenamed(ContainedLanguageRenameType clrt, string bstrOldID, string bstrNewID) { // This method is called when a control is renamed; we don't want to do anything in this case. return VSConstants.S_OK; }
public int OnRenamed(ContainedLanguageRenameType clrt, string bstrOldID, string bstrNewID) { return(0); }
public int OnRenamed(ContainedLanguageRenameType clrt, string bstrOldID, string bstrNewID) { return 0; }