Skip to content

Commit 99afcde

Browse files
Fix CLI rename-symbol support for top-level statement (#1721)
* Fix CLI rename-symbol ignore implicitly declared method parameters (e.g. top-level statement string[] args) * Fix CLI rename-symbol: add support for top-level statements in LocalSymbolFinder.FindLocalSymbols * Use explicit type instead of 'var' * Update src/Workspaces.Core/Rename/SymbolListHelpers.cs * Changelog update --------- Co-authored-by: Josef Pihrt <[email protected]>
1 parent 89355b2 commit 99afcde

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Fix analyzer [RCS1172](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1172) ([PR](https://github.com/dotnet/roslynator/pull/1710))
1919
- [CLI] Fix `loc` command ([PR](https://github.com/dotnet/roslynator/pull/1711))
2020
- Exclude ref-field backed properties from [RCS1085](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1085) ([PR](https://github.com/dotnet/roslynator/pull/1718) by @ovska)
21+
- [CLI] Fix `rename-symbol` support for top-level statement ([PR](https://github.com/dotnet/roslynator/pull/1721))
2122

2223
## [4.14.1] - 2025-10-05
2324

src/CSharp.Workspaces/CSharp/FindSymbols/LocalSymbolFinder.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System.Collections.Immutable;
44
using System.Diagnostics;
5+
using System.Linq;
56
using System.Threading;
67
using Microsoft.CodeAnalysis;
78
using Microsoft.CodeAnalysis.CSharp;
@@ -102,6 +103,15 @@ public static ImmutableArray<ISymbol> FindLocalSymbols(
102103
walker.Visit(declaration.BodyOrExpressionBody());
103104
break;
104105
}
106+
case SyntaxKind.CompilationUnit:
107+
{
108+
var declaration = (CompilationUnitSyntax)node;
109+
foreach (GlobalStatementSyntax globalStatement in declaration.Members.OfType<GlobalStatementSyntax>())
110+
{
111+
walker.Visit(globalStatement);
112+
}
113+
break;
114+
}
105115
case SyntaxKind.Parameter:
106116
case SyntaxKind.RecordDeclaration:
107117
{

src/Workspaces.Core/Rename/SymbolListHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static List<ISymbol> SortAndFilterMemberSymbols(IEnumerable<ISymbol> symb
9393
results.Add(symbol);
9494

9595
results.AddRange(methodSymbol.TypeParameters);
96-
results.AddRange(methodSymbol.Parameters);
96+
results.AddRange(methodSymbol.Parameters.Where(p => !p.IsImplicitlyDeclared));
9797
}
9898
else
9999
{

0 commit comments

Comments
 (0)