diff --git a/src/SharpIDE.Application/Features/Search/SearchService.cs b/src/SharpIDE.Application/Features/Search/SearchService.cs index 6ab9391..9ea826d 100644 --- a/src/SharpIDE.Application/Features/Search/SearchService.cs +++ b/src/SharpIDE.Application/Features/Search/SearchService.cs @@ -1,13 +1,16 @@ using System.Collections.Concurrent; using System.Diagnostics; using System.IO.MemoryMappedFiles; +using Microsoft.Extensions.Logging; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.Search; -public static class SearchService +public class SearchService(ILogger logger) { - public static async Task> FindInFiles(SharpIdeSolutionModel solutionModel, string searchTerm, CancellationToken cancellationToken) + private readonly ILogger _logger = logger; + + public async Task> FindInFiles(SharpIdeSolutionModel solutionModel, string searchTerm, CancellationToken cancellationToken) { if (searchTerm.Length < 4) // TODO: halt search once 100 results are found, and remove this restriction { @@ -37,11 +40,11 @@ public static class SearchService } ).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing); timer.Stop(); - Console.WriteLine($"Search completed in {timer.ElapsedMilliseconds} ms. Found {results.Count} results. {(cancellationToken.IsCancellationRequested ? "(Cancelled)" : "")}"); + _logger.LogInformation("Search completed in {ElapsedMilliseconds}ms. Found {ResultCount} results. {Cancelled}", timer.ElapsedMilliseconds, results.Count, cancellationToken.IsCancellationRequested ? "(Cancelled)" : ""); return results.ToList(); } - public static async Task> FindFiles(SharpIdeSolutionModel solutionModel, string searchTerm, CancellationToken cancellationToken) + public async Task> FindFiles(SharpIdeSolutionModel solutionModel, string searchTerm, CancellationToken cancellationToken) { if (searchTerm.Length < 2) // TODO: halt search once 100 results are found, and remove this restriction { @@ -64,7 +67,7 @@ public static class SearchService } ).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing); timer.Stop(); - Console.WriteLine($"File search completed in {timer.ElapsedMilliseconds} ms. Found {results.Count} results. {(cancellationToken.IsCancellationRequested ? "(Cancelled)" : "")}"); + _logger.LogInformation("File search completed in {ElapsedMilliseconds}ms. Found {ResultCount} results. {Cancelled}", timer.ElapsedMilliseconds, results.Count, cancellationToken.IsCancellationRequested ? "(Cancelled)" : ""); return results.ToList(); } } diff --git a/src/SharpIDE.Godot/DiAutoload.cs b/src/SharpIDE.Godot/DiAutoload.cs index c7789d3..7c91278 100644 --- a/src/SharpIDE.Godot/DiAutoload.cs +++ b/src/SharpIDE.Godot/DiAutoload.cs @@ -8,6 +8,7 @@ using SharpIDE.Application.Features.Build; using SharpIDE.Application.Features.FilePersistence; using SharpIDE.Application.Features.FileWatching; using SharpIDE.Application.Features.Run; +using SharpIDE.Application.Features.Search; namespace SharpIDE.Godot; @@ -26,6 +27,7 @@ public partial class DiAutoload : Node // Register services here services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/SharpIDE.Godot/Features/Search/SearchAllFiles/SearchAllFilesWindow.cs b/src/SharpIDE.Godot/Features/Search/SearchAllFiles/SearchAllFilesWindow.cs index 0f03e31..8443e64 100644 --- a/src/SharpIDE.Godot/Features/Search/SearchAllFiles/SearchAllFilesWindow.cs +++ b/src/SharpIDE.Godot/Features/Search/SearchAllFiles/SearchAllFilesWindow.cs @@ -14,6 +14,8 @@ public partial class SearchAllFilesWindow : PopupPanel private CancellationTokenSource _cancellationTokenSource = new(); + [Inject] private readonly SearchService _searchService = null!; + public override void _Ready() { _resultCountLabel = GetNode