forked from dotnet/roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 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
48 changes: 48 additions & 0 deletions
48
.../Services/Rename/LanguageServerSymbolRenamedCodeActionOperationFactoryWorkspaceService.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,48 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.CodeActions; | ||
using Microsoft.CodeAnalysis.CodeActions.WorkspaceServices; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
|
||
namespace Microsoft.CodeAnalysis.LanguageServer.Services.Rename | ||
{ | ||
[ExportWorkspaceService(typeof(ISymbolRenamedCodeActionOperationFactoryWorkspaceService), ServiceLayer.Host), Shared] | ||
internal class LanguageServerSymbolRenamedCodeActionOperationFactoryWorkspaceService : ISymbolRenamedCodeActionOperationFactoryWorkspaceService | ||
{ | ||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public LanguageServerSymbolRenamedCodeActionOperationFactoryWorkspaceService() | ||
{ | ||
} | ||
|
||
public CodeActionOperation CreateSymbolRenamedOperation(ISymbol symbol, string newName, Solution startingSolution, Solution updatedSolution) | ||
=> new RenameCodeActionOperation( | ||
title: string.Format(WorkspacesResources.Rename_0_to_1, symbol.Name, newName), | ||
updateSolution: updatedSolution); | ||
|
||
private class RenameCodeActionOperation : CodeActionOperation | ||
{ | ||
private readonly string _title; | ||
private readonly Solution _updateSolution; | ||
|
||
public RenameCodeActionOperation(string title, Solution updateSolution) | ||
{ | ||
_title = title; | ||
_updateSolution = updateSolution; | ||
} | ||
|
||
public override void Apply(Workspace workspace, CancellationToken cancellationToken = default) | ||
=> workspace.TryApplyChanges(_updateSolution); | ||
|
||
public override string? Title => _title; | ||
} | ||
} | ||
} |