File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
12
12
- Fix analyzer [ RCS0053] ( https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0053 ) ([ PR] ( https://github.com/dotnet/roslynator/pull/1547 ) )
13
13
- Fix analyzer [ RCS1223] ( https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1223 ) ([ PR] ( https://github.com/dotnet/roslynator/pull/1552 ) )
14
+ - [ CLI] Improve removing of unused symbols ([ PR] ( https://github.com/dotnet/roslynator/pull/1550 ) )
14
15
15
16
## [ 4.12.7] - 2024-10-01
16
17
Original file line number Diff line number Diff line change 1
1
// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2
2
3
- using System ;
4
3
using System . Collections . Generic ;
5
4
using System . Collections . Immutable ;
6
5
using System . Diagnostics ;
@@ -171,13 +170,20 @@ private static async Task<Project> RemoveSymbolsAsync(
171
170
Project project ,
172
171
CancellationToken cancellationToken )
173
172
{
174
- foreach ( IGrouping < DocumentId , SyntaxReference > grouping in symbols
175
- . SelectMany ( f => f . DeclaringSyntaxReferences )
176
- . GroupBy ( f => project . GetDocument ( f . SyntaxTree ) . Id ) )
173
+ foreach ( IGrouping < DocumentId , ( ISymbol Symbol , SyntaxReference Reference ) > grouping in symbols
174
+ . SelectMany ( s => s . DeclaringSyntaxReferences . Select ( r => ( Symbol : s , Reference : r ) ) )
175
+ . GroupBy ( f => project . GetDocument ( f . Reference . SyntaxTree ) ! . Id ) )
177
176
{
178
- foreach ( SyntaxReference reference in grouping . OrderByDescending ( f => f . Span . Start ) )
177
+ foreach ( ( ISymbol symbol , SyntaxReference reference ) in grouping . OrderByDescending ( f => f . Reference . Span . Start ) )
179
178
{
180
179
Document document = project . GetDocument ( grouping . Key ) ;
180
+
181
+ if ( document is null )
182
+ {
183
+ Debug . Fail ( $ "Document not found for a symbol declaration '{ symbol . ToDisplayString ( SymbolDisplayFormats . Test ) } '") ;
184
+ continue ;
185
+ }
186
+
181
187
SyntaxNode root = await document . GetSyntaxRootAsync ( cancellationToken ) ;
182
188
SyntaxNode node = root . FindNode ( reference . Span ) ;
183
189
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ internal static class UnusedSymbolUtility
19
19
MetadataName . Parse ( "Microsoft.CodeAnalysis.CodeRefactorings.ExportCodeRefactoringProviderAttribute" ) ,
20
20
MetadataName . Parse ( "Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzerAttribute" ) ,
21
21
MetadataName . Parse ( "System.Composition.ExportAttribute" ) ,
22
+ MetadataName . Parse ( "Microsoft.Extensions.Options.OptionsValidatorAttribute" ) ,
22
23
} ) ;
23
24
24
25
private static readonly MetadataNameSet _methodAttributeSymbols = new ( new [ ]
You can’t perform that action at this time.
0 commit comments