Skip to content

Commit fa3e9f4

Browse files
authored
Merge pull request #8784 from MiYanni/Fix8591
Replace deprecated uses of RenameDocumentAsync/RenameSymbolAsync
2 parents 9692d91 + bbe7b4f commit fa3e9f4

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/FileMoveNotificationListener.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Rename
1717
[AppliesTo(ProjectCapability.CSharpOrVisualBasicLanguageService)]
1818
internal class FileMoveNotificationListener : IFileMoveNotificationListener
1919
{
20+
private static readonly DocumentRenameOptions s_renameOptions = new();
21+
2022
private readonly UnconfiguredProject _unconfiguredProject;
2123
private readonly IUserNotificationServices _userNotificationServices;
2224
private readonly IUnconfiguredProjectVsServices _projectVsServices;
@@ -136,10 +138,7 @@ void RecursiveTryGetFilesToMove(IFileMoveItem? item, ref List<(string file, stri
136138
}
137139

138140
// This is a file item to another directory, it should only detect this a Update Namespace action.
139-
// TODO Upgrade this api to get rid of the exclamation sign
140-
#pragma warning disable CS0618 // Type or member is obsolete https://github.com/dotnet/project-system/issues/8591
141-
Renamer.RenameDocumentActionSet documentAction = await Renamer.RenameDocumentAsync(oldDocument, null!, documentFolders);
142-
#pragma warning restore CS0618 // Type or member is obsolete
141+
Renamer.RenameDocumentActionSet documentAction = await Renamer.RenameDocumentAsync(oldDocument, s_renameOptions, null, documentFolders);
143142

144143
if (documentAction.ApplicableActions.IsEmpty ||
145144
documentAction.ApplicableActions.Any(a => !a.GetErrors().IsEmpty))

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Rename/RenamerProjectTreeActionHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Rename
1919
[AppliesTo(ProjectCapability.CSharpOrVisualBasicLanguageService)]
2020
internal partial class RenamerProjectTreeActionHandler : ProjectTreeActionHandlerBase
2121
{
22+
private static readonly DocumentRenameOptions s_renameOptions = new();
23+
2224
private readonly IEnvironmentOptions _environmentOptions;
2325
private readonly IUnconfiguredProjectVsServices _projectVsServices;
2426
private readonly IProjectThreadingService _threadingService;
@@ -165,9 +167,7 @@ private async Task<Solution> PublishLatestSolutionAsync(CancellationToken cancel
165167
}
166168

167169
// Get the list of possible actions to execute
168-
#pragma warning disable CS0618 // Type or member is obsolete https://github.com/dotnet/project-system/issues/8591
169-
Renamer.RenameDocumentActionSet documentRenameResult = await Renamer.RenameDocumentAsync(oldDocument, newFileWithExtension);
170-
#pragma warning restore CS0618 // Type or member is obsolete
170+
Renamer.RenameDocumentActionSet documentRenameResult = await Renamer.RenameDocumentAsync(oldDocument, s_renameOptions, newFileWithExtension);
171171

172172
// Check if there are any symbols that need to be renamed
173173
if (documentRenameResult.ApplicableActions.IsEmpty)

src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/RoslynServices.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
// 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.md file in the project root for more information.
22

33
using Microsoft.CodeAnalysis;
4+
using Microsoft.CodeAnalysis.Rename;
45
using Microsoft.VisualStudio.ProjectSystem.LanguageServices;
56

6-
using RoslynRenamer = Microsoft.CodeAnalysis.Rename;
77
using Workspace = Microsoft.CodeAnalysis.Workspace;
88

99
namespace Microsoft.VisualStudio.ProjectSystem.VS
1010
{
1111
[Export(typeof(IRoslynServices))]
1212
internal class RoslynServices : IRoslynServices
1313
{
14+
private static readonly SymbolRenameOptions s_renameOptions = new();
1415
private readonly IProjectThreadingService _threadingService;
1516

1617
[ImportingConstructor]
@@ -25,19 +26,11 @@ public RoslynServices(
2526
[ImportMany]
2627
protected OrderPrecedenceImportCollection<ISyntaxFactsService> SyntaxFactsServicesImpl { get; }
2728

28-
private ISyntaxFactsService? SyntaxFactsService
29-
{
30-
get
31-
{
32-
return SyntaxFactsServicesImpl.FirstOrDefault()?.Value;
33-
}
34-
}
29+
private ISyntaxFactsService? SyntaxFactsService => SyntaxFactsServicesImpl.FirstOrDefault()?.Value;
3530

3631
public Task<Solution> RenameSymbolAsync(Solution solution, ISymbol symbol, string newName, CancellationToken token = default)
3732
{
38-
#pragma warning disable CS0618 // Type or member is obsolete https://github.com/dotnet/project-system/issues/8591
39-
return RoslynRenamer.Renamer.RenameSymbolAsync(solution, symbol, newName, solution.Workspace.Options, token);
40-
#pragma warning restore CS0618 // Type or member is obsolete
33+
return Renamer.RenameSymbolAsync(solution, symbol, s_renameOptions, newName, token);
4134
}
4235

4336
public bool ApplyChangesToSolution(Workspace ws, Solution renamedSolution)

0 commit comments

Comments
 (0)