replace more console logs
This commit is contained in:
@@ -33,9 +33,10 @@ using DiagnosticSeverity = Microsoft.CodeAnalysis.DiagnosticSeverity;
|
|||||||
|
|
||||||
namespace SharpIDE.Application.Features.Analysis;
|
namespace SharpIDE.Application.Features.Analysis;
|
||||||
|
|
||||||
public class RoslynAnalysis(ILogger<RoslynAnalysis> logger)
|
public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildService)
|
||||||
{
|
{
|
||||||
private readonly ILogger<RoslynAnalysis> _logger = logger;
|
private readonly ILogger<RoslynAnalysis> _logger = logger;
|
||||||
|
private readonly BuildService _buildService = buildService;
|
||||||
|
|
||||||
public static AdhocWorkspace? _workspace;
|
public static AdhocWorkspace? _workspace;
|
||||||
private static CustomMsBuildProjectLoader? _msBuildProjectLoader;
|
private static CustomMsBuildProjectLoader? _msBuildProjectLoader;
|
||||||
@@ -99,7 +100,7 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger)
|
|||||||
//_msBuildProjectLoader!.LoadMetadataForReferencedProjects = true;
|
//_msBuildProjectLoader!.LoadMetadataForReferencedProjects = true;
|
||||||
|
|
||||||
// MsBuildProjectLoader doesn't do a restore which is absolutely required for resolving PackageReferences, if they have changed. I am guessing it just reads from project.assets.json
|
// MsBuildProjectLoader doesn't do a restore which is absolutely required for resolving PackageReferences, if they have changed. I am guessing it just reads from project.assets.json
|
||||||
await BuildService.Instance.MsBuildAsync(_sharpIdeSolutionModel.FilePath, BuildType.Restore, cancellationToken);
|
await _buildService.MsBuildAsync(_sharpIdeSolutionModel.FilePath, BuildType.Restore, cancellationToken);
|
||||||
var solutionInfo = await _msBuildProjectLoader!.LoadSolutionInfoAsync(_sharpIdeSolutionModel.FilePath, cancellationToken: cancellationToken);
|
var solutionInfo = await _msBuildProjectLoader!.LoadSolutionInfoAsync(_sharpIdeSolutionModel.FilePath, cancellationToken: cancellationToken);
|
||||||
_workspace.ClearSolution();
|
_workspace.ClearSolution();
|
||||||
var solution = _workspace.AddSolution(solutionInfo);
|
var solution = _workspace.AddSolution(solutionInfo);
|
||||||
@@ -171,7 +172,7 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger)
|
|||||||
Guard.Against.Null(_msBuildProjectLoader, nameof(_msBuildProjectLoader));
|
Guard.Against.Null(_msBuildProjectLoader, nameof(_msBuildProjectLoader));
|
||||||
|
|
||||||
// It is important to note that a Workspace has no concept of MSBuild, nuget packages etc. It is just told about project references and "metadata" references, which are dlls. This is the what MSBuild does - it reads the csproj, and most importantly resolves nuget package references to dlls
|
// It is important to note that a Workspace has no concept of MSBuild, nuget packages etc. It is just told about project references and "metadata" references, which are dlls. This is the what MSBuild does - it reads the csproj, and most importantly resolves nuget package references to dlls
|
||||||
await BuildService.Instance.MsBuildAsync(_sharpIdeSolutionModel!.FilePath, BuildType.Restore, cancellationToken);
|
await _buildService.MsBuildAsync(_sharpIdeSolutionModel!.FilePath, BuildType.Restore, cancellationToken);
|
||||||
var __ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.MSBuildProjectLoader.LoadSolutionInfoAsync");
|
var __ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.MSBuildProjectLoader.LoadSolutionInfoAsync");
|
||||||
// This call is the expensive part - MSBuild is slow. There doesn't seem to be any incrementalism for solutions.
|
// This call is the expensive part - MSBuild is slow. There doesn't seem to be any incrementalism for solutions.
|
||||||
// The best we could do to speed it up is do .LoadProjectInfoAsync for the single project, and somehow munge that into the existing solution
|
// The best we could do to speed it up is do .LoadProjectInfoAsync for the single project, and somehow munge that into the existing solution
|
||||||
@@ -197,7 +198,7 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger)
|
|||||||
Guard.Against.Null(_workspace, nameof(_workspace));
|
Guard.Against.Null(_workspace, nameof(_workspace));
|
||||||
Guard.Against.Null(_msBuildProjectLoader, nameof(_msBuildProjectLoader));
|
Guard.Against.Null(_msBuildProjectLoader, nameof(_msBuildProjectLoader));
|
||||||
|
|
||||||
await BuildService.Instance.MsBuildAsync(_sharpIdeSolutionModel!.FilePath, BuildType.Restore, cancellationToken);
|
await _buildService.MsBuildAsync(_sharpIdeSolutionModel!.FilePath, BuildType.Restore, cancellationToken);
|
||||||
var __ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(CustomMsBuildProjectLoader)}.{nameof(CustomMsBuildProjectLoader.LoadProjectInfosAsync)}");
|
var __ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(CustomMsBuildProjectLoader)}.{nameof(CustomMsBuildProjectLoader.LoadProjectInfosAsync)}");
|
||||||
|
|
||||||
var thisProject = _workspace.CurrentSolution.Projects.Single(s => s.FilePath == projectModel.FilePath);
|
var thisProject = _workspace.CurrentSolution.Projects.Single(s => s.FilePath == projectModel.FilePath);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Ardalis.GuardClauses;
|
|||||||
using Microsoft.Build.Execution;
|
using Microsoft.Build.Execution;
|
||||||
using Microsoft.Build.Framework;
|
using Microsoft.Build.Framework;
|
||||||
using Microsoft.Build.Logging;
|
using Microsoft.Build.Logging;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using SharpIDE.Application.Features.Logging;
|
using SharpIDE.Application.Features.Logging;
|
||||||
|
|
||||||
namespace SharpIDE.Application.Features.Build;
|
namespace SharpIDE.Application.Features.Build;
|
||||||
@@ -14,9 +15,10 @@ public enum BuildType
|
|||||||
Clean,
|
Clean,
|
||||||
Restore
|
Restore
|
||||||
}
|
}
|
||||||
public class BuildService
|
public class BuildService(ILogger<BuildService> logger)
|
||||||
{
|
{
|
||||||
public static BuildService Instance { get; set; } = null!;
|
private readonly ILogger<BuildService> _logger = logger;
|
||||||
|
|
||||||
public event Func<Task> BuildStarted = () => Task.CompletedTask;
|
public event Func<Task> BuildStarted = () => Task.CompletedTask;
|
||||||
public ChannelTextWriter BuildTextWriter { get; } = new ChannelTextWriter();
|
public ChannelTextWriter BuildTextWriter { get; } = new ChannelTextWriter();
|
||||||
public async Task MsBuildAsync(string solutionOrProjectFilePath, BuildType buildType = BuildType.Build, CancellationToken cancellationToken = default)
|
public async Task MsBuildAsync(string solutionOrProjectFilePath, BuildType buildType = BuildType.Build, CancellationToken cancellationToken = default)
|
||||||
@@ -54,11 +56,7 @@ public class BuildService
|
|||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
var buildResult = await BuildManager.DefaultBuildManager.BuildAsync(buildParameters, buildRequest, cancellationToken).ConfigureAwait(false);
|
var buildResult = await BuildManager.DefaultBuildManager.BuildAsync(buildParameters, buildRequest, cancellationToken).ConfigureAwait(false);
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
Console.WriteLine($"Build result: {buildResult.OverallResult} in {timer.ElapsedMilliseconds}ms");
|
_logger.LogInformation(buildResult.Exception, "Build result: {BuildResult} in {ElapsedMilliseconds}ms", buildResult.OverallResult, timer.ElapsedMilliseconds);
|
||||||
if (buildResult.OverallResult != BuildResultCode.Success)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{buildResult.Exception}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string[] TargetsToBuild(BuildType buildType)
|
private static string[] TargetsToBuild(BuildType buildType)
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ public partial class IdeRoot : Control
|
|||||||
{
|
{
|
||||||
GodotGlobalEvents.Instance = new GodotGlobalEvents();
|
GodotGlobalEvents.Instance = new GodotGlobalEvents();
|
||||||
GlobalEvents.Instance = new GlobalEvents();
|
GlobalEvents.Instance = new GlobalEvents();
|
||||||
BuildService.Instance = new BuildService(); // TODO: Sort out this mess with singletons, especially access across Application services
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree()
|
public override void _ExitTree()
|
||||||
|
|||||||
Reference in New Issue
Block a user