From 0c21c57878f745289946df71aab0434043531047 Mon Sep 17 00:00:00 2001 From: Shen Chen Date: Wed, 26 Apr 2023 11:12:53 -0700 Subject: [PATCH] Add missing rename service --- .../Microsoft.CodeAnalysis.Features.csproj | 1 + ...eActionOperationFactoryWorkspaceService.cs | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/Rename/LanguageServerSymbolRenamedCodeActionOperationFactoryWorkspaceService.cs diff --git a/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj b/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj index 3b57a428d8359..0bf24142cafac 100644 --- a/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj +++ b/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj @@ -83,6 +83,7 @@ + diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/Rename/LanguageServerSymbolRenamedCodeActionOperationFactoryWorkspaceService.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/Rename/LanguageServerSymbolRenamedCodeActionOperationFactoryWorkspaceService.cs new file mode 100644 index 0000000000000..76bb62f588bbd --- /dev/null +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/Rename/LanguageServerSymbolRenamedCodeActionOperationFactoryWorkspaceService.cs @@ -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; + } + } +}