more log replacement
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO.MemoryMappedFiles;
|
using System.IO.MemoryMappedFiles;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
|
||||||
|
|
||||||
namespace SharpIDE.Application.Features.Search;
|
namespace SharpIDE.Application.Features.Search;
|
||||||
|
|
||||||
public static class SearchService
|
public class SearchService(ILogger<SearchService> logger)
|
||||||
{
|
{
|
||||||
public static async Task<List<FindInFilesSearchResult>> FindInFiles(SharpIdeSolutionModel solutionModel, string searchTerm, CancellationToken cancellationToken)
|
private readonly ILogger<SearchService> _logger = logger;
|
||||||
|
|
||||||
|
public async Task<List<FindInFilesSearchResult>> FindInFiles(SharpIdeSolutionModel solutionModel, string searchTerm, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (searchTerm.Length < 4) // TODO: halt search once 100 results are found, and remove this restriction
|
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);
|
).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
|
||||||
timer.Stop();
|
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();
|
return results.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<FindFilesSearchResult>> FindFiles(SharpIdeSolutionModel solutionModel, string searchTerm, CancellationToken cancellationToken)
|
public async Task<List<FindFilesSearchResult>> FindFiles(SharpIdeSolutionModel solutionModel, string searchTerm, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (searchTerm.Length < 2) // TODO: halt search once 100 results are found, and remove this restriction
|
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);
|
).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
|
||||||
timer.Stop();
|
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();
|
return results.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using SharpIDE.Application.Features.Build;
|
|||||||
using SharpIDE.Application.Features.FilePersistence;
|
using SharpIDE.Application.Features.FilePersistence;
|
||||||
using SharpIDE.Application.Features.FileWatching;
|
using SharpIDE.Application.Features.FileWatching;
|
||||||
using SharpIDE.Application.Features.Run;
|
using SharpIDE.Application.Features.Run;
|
||||||
|
using SharpIDE.Application.Features.Search;
|
||||||
|
|
||||||
namespace SharpIDE.Godot;
|
namespace SharpIDE.Godot;
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ public partial class DiAutoload : Node
|
|||||||
// Register services here
|
// Register services here
|
||||||
services.AddScoped<BuildService>();
|
services.AddScoped<BuildService>();
|
||||||
services.AddScoped<RunService>();
|
services.AddScoped<RunService>();
|
||||||
|
services.AddScoped<SearchService>();
|
||||||
services.AddScoped<IdeFileExternalChangeHandler>();
|
services.AddScoped<IdeFileExternalChangeHandler>();
|
||||||
services.AddScoped<IdeCodeActionService>();
|
services.AddScoped<IdeCodeActionService>();
|
||||||
services.AddScoped<IdeCompletionService>();
|
services.AddScoped<IdeCompletionService>();
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public partial class SearchAllFilesWindow : PopupPanel
|
|||||||
|
|
||||||
private CancellationTokenSource _cancellationTokenSource = new();
|
private CancellationTokenSource _cancellationTokenSource = new();
|
||||||
|
|
||||||
|
[Inject] private readonly SearchService _searchService = null!;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_resultCountLabel = GetNode<Label>("%ResultCountLabel");
|
_resultCountLabel = GetNode<Label>("%ResultCountLabel");
|
||||||
@@ -43,7 +45,7 @@ public partial class SearchAllFilesWindow : PopupPanel
|
|||||||
|
|
||||||
private async Task Search(string text, CancellationToken cancellationToken)
|
private async Task Search(string text, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var result = await SearchService.FindFiles(Solution, text, cancellationToken);
|
var result = await _searchService.FindFiles(Solution, text, cancellationToken);
|
||||||
if (cancellationToken.IsCancellationRequested) return;
|
if (cancellationToken.IsCancellationRequested) return;
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public partial class SearchWindow : PopupPanel
|
|||||||
|
|
||||||
private CancellationTokenSource _cancellationTokenSource = new();
|
private CancellationTokenSource _cancellationTokenSource = new();
|
||||||
|
|
||||||
|
[Inject] private readonly SearchService _searchService = null!;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_resultCountLabel = GetNode<Label>("%ResultCountLabel");
|
_resultCountLabel = GetNode<Label>("%ResultCountLabel");
|
||||||
@@ -43,7 +45,7 @@ public partial class SearchWindow : PopupPanel
|
|||||||
|
|
||||||
private async Task Search(string text, CancellationToken cancellationToken)
|
private async Task Search(string text, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var result = await SearchService.FindInFiles(Solution, text, cancellationToken);
|
var result = await _searchService.FindInFiles(Solution, text, cancellationToken);
|
||||||
if (cancellationToken.IsCancellationRequested) return;
|
if (cancellationToken.IsCancellationRequested) return;
|
||||||
await this.InvokeAsync(() =>
|
await this.InvokeAsync(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user