Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix [RCS1164](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1164) ([#1196](https://github.com/JosefPihrt/Roslynator/pull/1196)).
- Fix [RCS1241](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1241) ([#1197](https://github.com/JosefPihrt/Roslynator/pull/1197)).
- Fix [RCS1250](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1250) ([#1205](https://github.com/JosefPihrt/Roslynator/pull/1205)).
- [CLI] Fix globbing ([#1215](https://github.com/JosefPihrt/Roslynator/pull/1215)).

## [4.5.0] - 2023-08-27

Expand Down
3 changes: 3 additions & 0 deletions src/CommandLine/Commands/MSBuildWorkspaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ private async Task<TCommandResult> ExecuteAsync(string path, MSBuildWorkspace wo
return null;
}

if (FileSystemFilter is not null)
FileSystemFilter.RootDirectoryPath = Path.GetDirectoryName(path);

return await ExecuteAsync(projectOrSolution, cancellationToken);
}

Expand Down
8 changes: 7 additions & 1 deletion src/CommandLine/Rename/CliSymbolRenameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public CliSymbolRenameState(

public ConsoleDialog UserDialog { get; set; }

protected override async Task RenameSymbolsAsync(ImmutableArray<ProjectId> projects, CancellationToken cancellationToken = default)
protected override async Task RenameSymbolsAsync(
ImmutableArray<ProjectId> projects,
bool isSolution,
CancellationToken cancellationToken = default)
{
Stopwatch stopwatch = Stopwatch.StartNew();
TimeSpan lastElapsed = TimeSpan.Zero;
Expand All @@ -65,6 +68,9 @@ protected override async Task RenameSymbolsAsync(ImmutableArray<ProjectId> proje

WriteLine($" Rename {GetScopePluralName(renameScopes[i])} in '{project.Name}' {$"{j + 1}/{projects.Length}"}", ConsoleColors.Cyan, Verbosity.Minimal);

if (!isSolution)
CurrentDirectoryPath = Path.GetDirectoryName(project.FilePath);

await AnalyzeProjectAsync(project, renameScopes[i], cancellationToken);

WriteLine($" Done renaming {GetScopePluralName(renameScopes[i])} in '{project.Name}' in {stopwatch.Elapsed - lastElapsed:mm\\:ss\\.ff}", Verbosity.Normal);
Expand Down
12 changes: 8 additions & 4 deletions src/Workspaces.Core/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ namespace Roslynator;

internal static class Extensions
{
public static bool IsMatch(this Matcher matcher, ISymbol symbol)
public static bool IsMatch(this Matcher matcher, ISymbol symbol, string rootDirectoryPath)
{
foreach (Location location in symbol.Locations)
{
SyntaxTree tree = location.SourceTree;

if (tree is not null
&& !matcher.Match(tree.FilePath).HasMatches)
if (tree is not null)
{
return false;
PatternMatchingResult result = (rootDirectoryPath is not null)
? matcher.Match(tree.FilePath, rootDirectoryPath)
: matcher.Match(tree.FilePath);

if (!result.HasMatches)
return false;
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/Workspaces.Core/FileSystemFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private FileSystemFilter(Matcher matcher)

public Matcher Matcher { get; }

public string RootDirectoryPath { get; set; }

public static FileSystemFilter CreateOrDefault(
IEnumerable<string> include,
IEnumerable<string> exclude)
Expand Down Expand Up @@ -51,7 +53,7 @@ public static FileSystemFilter CreateOrDefault(

public bool IsMatch(ISymbol symbol)
{
bool isMatch = Matcher.IsMatch(symbol);
bool isMatch = Matcher.IsMatch(symbol, RootDirectoryPath);
#if DEBUG
if (!isMatch
&& Logger.ShouldWrite(Verbosity.Diagnostic))
Expand All @@ -65,7 +67,9 @@ public bool IsMatch(ISymbol symbol)

public bool IsMatch(string filePath)
{
PatternMatchingResult result = Matcher.Match(filePath);
PatternMatchingResult result = (RootDirectoryPath is not null)
? Matcher.Match(RootDirectoryPath, filePath)
: Matcher.Match(filePath);

#if DEBUG
Debug.Assert(result.Files.Count() <= 1, result.Files.Count().ToString());
Expand Down
7 changes: 6 additions & 1 deletion src/Workspaces.Core/Rename/SymbolProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ internal class SymbolProvider

public Matcher FileSystemMatcher { get; init; }

public string RootDirectoryPath { get; init; }

public async Task<IEnumerable<ISymbol>> GetSymbolsAsync(
Project project,
RenameScope scope,
Expand Down Expand Up @@ -50,6 +52,7 @@ public async Task<IEnumerable<ISymbol>> GetSymbolsAsync(
{
IncludeGeneratedCode = IncludeGeneratedCode,
FileSystemMatcher = FileSystemMatcher,
RootDirectoryPath = RootDirectoryPath,
};

analyzer.SymbolKinds.AddRange(symbolKinds);
Expand Down Expand Up @@ -90,6 +93,8 @@ private class Analyzer : DiagnosticAnalyzer

public Matcher FileSystemMatcher { get; init; }

public string RootDirectoryPath { get; init; }

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
Expand Down Expand Up @@ -146,7 +151,7 @@ private void AnalyzeSymbol(SymbolAnalysisContext context)

private void AddSymbol(ISymbol symbol)
{
if (FileSystemMatcher?.IsMatch(symbol) != false)
if (FileSystemMatcher?.IsMatch(symbol, RootDirectoryPath) != false)
Symbols.Add(symbol);
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/Workspaces.Core/Rename/SymbolRenameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -48,14 +49,18 @@ public SymbolRenameState(

private bool DryRun => Options.DryRun;

protected string CurrentDirectoryPath { get; set; }

public Task RenameSymbolsAsync(CancellationToken cancellationToken = default)
{
ImmutableArray<ProjectId> projectIds = CurrentSolution
.GetProjectDependencyGraph()
.GetTopologicallySortedProjects(cancellationToken)
.ToImmutableArray();

return RenameSymbolsAsync(projectIds, cancellationToken);
CurrentDirectoryPath = Path.GetDirectoryName(CurrentSolution.FilePath);

return RenameSymbolsAsync(projectIds, isSolution: true, cancellationToken);
}

public Task RenameSymbolsAsync(
Expand All @@ -68,11 +73,12 @@ public Task RenameSymbolsAsync(
.Join(projects, id => id, p => p.Id, (id, _) => id)
.ToImmutableArray();

return RenameSymbolsAsync(projectIds, cancellationToken);
return RenameSymbolsAsync(projectIds, isSolution: false, cancellationToken);
}

protected virtual async Task RenameSymbolsAsync(
ImmutableArray<ProjectId> projects,
bool isSolution,
CancellationToken cancellationToken = default)
{
foreach (RenameScope renameScope in GetRenameScopes())
Expand All @@ -83,6 +89,9 @@ protected virtual async Task RenameSymbolsAsync(

Project project = CurrentSolution.GetProject(projects[j]);

if (!isSolution)
CurrentDirectoryPath = Path.GetDirectoryName(project.FilePath);

await AnalyzeProjectAsync(project, renameScope, cancellationToken).ConfigureAwait(false);
}
}
Expand All @@ -92,6 +101,8 @@ public virtual async Task RenameSymbolsAsync(
Project project,
CancellationToken cancellationToken = default)
{
CurrentDirectoryPath = Path.GetDirectoryName(project.FilePath);

foreach (RenameScope renameScope in GetRenameScopes())
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -135,6 +146,7 @@ protected async Task AnalyzeProjectAsync(
{
IncludeGeneratedCode = Options.IncludeGeneratedCode,
FileSystemMatcher = Options.FileSystemMatcher,
RootDirectoryPath = CurrentDirectoryPath,
};

IEnumerable<ISymbol> symbols = await symbolProvider.GetSymbolsAsync(project, scope, cancellationToken).ConfigureAwait(false);
Expand Down