-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18693 from dpoeschl/NamingStylesUpdateXAML
Notify XAML of renames caused by Naming Rule fixes
- Loading branch information
Showing
8 changed files
with
201 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...s/TestUtilities/Workspaces/TestSymbolRenamedCodeActionOperationFactoryWorkspaceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Composition; | ||
using Microsoft.CodeAnalysis.CodeActions; | ||
using Microsoft.CodeAnalysis.CodeActions.WorkspaceServices; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces | ||
{ | ||
[ExportWorkspaceService(typeof(ISymbolRenamedCodeActionOperationFactoryWorkspaceService), TestWorkspace.WorkspaceName), Shared] | ||
public class TestSymbolRenamedCodeActionOperationFactoryWorkspaceService : ISymbolRenamedCodeActionOperationFactoryWorkspaceService | ||
{ | ||
public CodeActionOperation CreateSymbolRenamedOperation(ISymbol symbol, string newName, Solution startingSolution, Solution updatedSolution) | ||
{ | ||
return new Operation(symbol, newName, startingSolution, updatedSolution); | ||
} | ||
|
||
public class Operation : CodeActionOperation | ||
{ | ||
public ISymbol _symbol; | ||
public string _newName; | ||
public Solution _startingSolution; | ||
public Solution _updatedSolution; | ||
|
||
public Operation(ISymbol symbol, string newName, Solution startingSolution, Solution updatedSolution) | ||
{ | ||
_symbol = symbol; | ||
_newName = newName; | ||
_startingSolution = startingSolution; | ||
_updatedSolution = updatedSolution; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...efactorings/WorkspaceServices/ISymbolRenamedCodeActionOperationFactoryWorkspaceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.CodeAnalysis.Host; | ||
|
||
namespace Microsoft.CodeAnalysis.CodeActions.WorkspaceServices | ||
{ | ||
internal interface ISymbolRenamedCodeActionOperationFactoryWorkspaceService : IWorkspaceService | ||
{ | ||
CodeActionOperation CreateSymbolRenamedOperation(ISymbol symbol, string newName, Solution startingSolution, Solution updatedSolution); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...entation/Workspace/VisualStudioSymbolRenamedCodeActionOperationFactoryWorkspaceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.Linq; | ||
using System.Threading; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CodeActions; | ||
using Microsoft.CodeAnalysis.CodeActions.WorkspaceServices; | ||
using Microsoft.CodeAnalysis.Editor; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.Implementation | ||
{ | ||
[ExportWorkspaceService(typeof(ISymbolRenamedCodeActionOperationFactoryWorkspaceService), ServiceLayer.Host), Shared] | ||
internal sealed class VisualStudioSymbolRenamedCodeActionOperationFactoryWorkspaceService : ISymbolRenamedCodeActionOperationFactoryWorkspaceService | ||
{ | ||
private readonly IEnumerable<IRefactorNotifyService> _refactorNotifyServices; | ||
|
||
[ImportingConstructor] | ||
public VisualStudioSymbolRenamedCodeActionOperationFactoryWorkspaceService( | ||
[ImportMany] IEnumerable<IRefactorNotifyService> refactorNotifyServices) | ||
{ | ||
_refactorNotifyServices = refactorNotifyServices; | ||
} | ||
|
||
public CodeActionOperation CreateSymbolRenamedOperation(ISymbol symbol, string newName, Solution startingSolution, Solution updatedSolution) | ||
{ | ||
return new RenameSymbolOperation( | ||
_refactorNotifyServices, | ||
symbol ?? throw new ArgumentNullException(nameof(symbol)), | ||
newName ?? throw new ArgumentNullException(nameof(newName)), | ||
startingSolution ?? throw new ArgumentNullException(nameof(startingSolution)), | ||
updatedSolution ?? throw new ArgumentNullException(nameof(updatedSolution))); | ||
} | ||
|
||
private class RenameSymbolOperation : CodeActionOperation | ||
{ | ||
private readonly IEnumerable<IRefactorNotifyService> _refactorNotifyServices; | ||
private readonly ISymbol _symbol; | ||
private readonly string _newName; | ||
private readonly Solution _startingSolution; | ||
private readonly Solution _updatedSolution; | ||
|
||
public RenameSymbolOperation( | ||
IEnumerable<IRefactorNotifyService> refactorNotifyServices, | ||
ISymbol symbol, | ||
string newName, | ||
Solution startingSolution, | ||
Solution updatedSolution) | ||
{ | ||
_refactorNotifyServices = refactorNotifyServices; | ||
_symbol = symbol; | ||
_newName = newName; | ||
_startingSolution = startingSolution; | ||
_updatedSolution = updatedSolution; | ||
} | ||
|
||
public override void Apply(Workspace workspace, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
var updatedDocumentIds = _updatedSolution.GetChanges(_startingSolution).GetProjectChanges().SelectMany(p => p.GetChangedDocuments()); | ||
|
||
foreach (var refactorNotifyService in _refactorNotifyServices) | ||
{ | ||
// If something goes wrong and some language service rejects the rename, we | ||
// can't really do anything about it because we're potentially in the middle of | ||
// some unknown set of CodeActionOperations. This is a best effort approach. | ||
|
||
if (refactorNotifyService.TryOnBeforeGlobalSymbolRenamed(workspace, updatedDocumentIds, _symbol, _newName, throwOnFailure: false)) | ||
{ | ||
refactorNotifyService.TryOnAfterGlobalSymbolRenamed(workspace, updatedDocumentIds, _symbol, _newName, throwOnFailure: false); | ||
} | ||
} | ||
} | ||
|
||
public override string Title => string.Format(EditorFeaturesResources.Rename_0_to_1, _symbol.Name, _newName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters