update project diagnostics for active document immediately
This commit is contained in:
@@ -301,15 +301,27 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildSe
|
|||||||
// Performance improvements of ~15% have been observed with a large solution (100+ projects) by parallelizing this with Task.WhenAll, however it seems much heavier (14700K crashes sometimes 😅) so re-evaluate later
|
// Performance improvements of ~15% have been observed with a large solution (100+ projects) by parallelizing this with Task.WhenAll, however it seems much heavier (14700K crashes sometimes 😅) so re-evaluate later
|
||||||
foreach (var project in _sharpIdeSolutionModel!.AllProjects)
|
foreach (var project in _sharpIdeSolutionModel!.AllProjects)
|
||||||
{
|
{
|
||||||
var projectDiagnostics = await GetProjectDiagnostics(project, cancellationToken);
|
await UpdateProjectDiagnostics(project, cancellationToken);
|
||||||
// TODO: only add and remove diffs
|
|
||||||
project.Diagnostics.RemoveRange(project.Diagnostics);
|
|
||||||
project.Diagnostics.AddRange(projectDiagnostics);
|
|
||||||
}
|
}
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
_logger.LogInformation("RoslynAnalysis: Solution diagnostics updated in {ElapsedMilliseconds}ms", timer.ElapsedMilliseconds);
|
_logger.LogInformation("RoslynAnalysis: Solution diagnostics updated in {ElapsedMilliseconds}ms", timer.ElapsedMilliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task UpdateProjectDiagnostics(SharpIdeProjectModel project, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var projectDiagnostics = await GetProjectDiagnostics(project, cancellationToken);
|
||||||
|
// TODO: only add and remove diffs
|
||||||
|
project.Diagnostics.RemoveRange(project.Diagnostics);
|
||||||
|
project.Diagnostics.AddRange(projectDiagnostics);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateProjectDiagnosticsForFile(SharpIdeFile sharpIdeFile, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var project = ((IChildSharpIdeNode) sharpIdeFile).GetNearestProjectNode();
|
||||||
|
Guard.Against.Null(project);
|
||||||
|
await UpdateProjectDiagnostics(project, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<ImmutableArray<SharpIdeDiagnostic>> GetProjectDiagnostics(SharpIdeProjectModel projectModel, CancellationToken cancellationToken = default)
|
public async Task<ImmutableArray<SharpIdeDiagnostic>> GetProjectDiagnostics(SharpIdeProjectModel projectModel, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(GetProjectDiagnostics)}");
|
using var _ = SharpIdeOtel.Source.StartActivity($"{nameof(RoslynAnalysis)}.{nameof(GetProjectDiagnostics)}");
|
||||||
|
|||||||
@@ -104,16 +104,22 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
|||||||
if (_fileDeleted) return;
|
if (_fileDeleted) return;
|
||||||
GD.Print($"[{_currentFile.Name}] Solution altered, updating project diagnostics for file");
|
GD.Print($"[{_currentFile.Name}] Solution altered, updating project diagnostics for file");
|
||||||
var newCt = _solutionAlteredCancellationTokenSeries.CreateNext();
|
var newCt = _solutionAlteredCancellationTokenSeries.CreateNext();
|
||||||
|
var hasFocus = this.InvokeAsync(HasFocus);
|
||||||
var documentSyntaxHighlighting = _roslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile, newCt);
|
var documentSyntaxHighlighting = _roslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile, newCt);
|
||||||
var razorSyntaxHighlighting = _roslynAnalysis.GetRazorDocumentSyntaxHighlighting(_currentFile, newCt);
|
var razorSyntaxHighlighting = _roslynAnalysis.GetRazorDocumentSyntaxHighlighting(_currentFile, newCt);
|
||||||
await Task.WhenAll(documentSyntaxHighlighting, razorSyntaxHighlighting).WaitAsync(newCt).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
|
await Task.WhenAll(documentSyntaxHighlighting, razorSyntaxHighlighting).WaitAsync(newCt).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
|
||||||
if (newCt.IsCancellationRequested) return;
|
if (newCt.IsCancellationRequested) return;
|
||||||
var documentDiagnosticsTask = _roslynAnalysis.GetDocumentDiagnostics(_currentFile, newCt);
|
var documentDiagnosticsTask = _roslynAnalysis.GetDocumentDiagnostics(_currentFile, newCt);
|
||||||
await this.InvokeAsync(async () => SetSyntaxHighlightingModel(await documentSyntaxHighlighting, await razorSyntaxHighlighting));
|
await this.InvokeAsync(async () => SetSyntaxHighlightingModel(await documentSyntaxHighlighting, await razorSyntaxHighlighting));
|
||||||
await ((Task)documentDiagnosticsTask).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
|
await documentDiagnosticsTask.AsTask().ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
|
||||||
if (newCt.IsCancellationRequested) return;
|
if (newCt.IsCancellationRequested) return;
|
||||||
var documentDiagnostics = await documentDiagnosticsTask;
|
var documentDiagnostics = await documentDiagnosticsTask;
|
||||||
await this.InvokeAsync(() => SetDiagnostics(documentDiagnostics));
|
await this.InvokeAsync(() => SetDiagnostics(documentDiagnostics));
|
||||||
|
if (await hasFocus)
|
||||||
|
{
|
||||||
|
await _roslynAnalysis.UpdateProjectDiagnosticsForFile(_currentFile, newCt).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
|
||||||
|
if (newCt.IsCancellationRequested) return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LineEditOrigin
|
public enum LineEditOrigin
|
||||||
|
|||||||
@@ -174,6 +174,11 @@ public static class NodeExtensions
|
|||||||
|
|
||||||
public static class GodotTask
|
public static class GodotTask
|
||||||
{
|
{
|
||||||
|
extension<T>(Task<T> task)
|
||||||
|
{
|
||||||
|
public Task AsTask() => task;
|
||||||
|
}
|
||||||
|
|
||||||
extension(Task task)
|
extension(Task task)
|
||||||
{
|
{
|
||||||
public static async Task GodotRun(Action action)
|
public static async Task GodotRun(Action action)
|
||||||
|
|||||||
Reference in New Issue
Block a user