receive rather than fetch project diagnostics for file
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.Specialized;
|
||||
using Godot;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CodeActions;
|
||||
@@ -7,6 +8,8 @@ using Microsoft.CodeAnalysis.Rename.ConflictEngine;
|
||||
using Microsoft.CodeAnalysis.Shared.Extensions;
|
||||
using Microsoft.CodeAnalysis.Tags;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using ObservableCollections;
|
||||
using R3;
|
||||
using Roslyn.Utilities;
|
||||
using SharpIDE.Application;
|
||||
using SharpIDE.Application.Features.Analysis;
|
||||
@@ -107,8 +110,6 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
||||
await this.InvokeAsync(async () => SetSyntaxHighlightingModel(await documentSyntaxHighlighting, await razorSyntaxHighlighting));
|
||||
var documentDiagnostics = await _roslynAnalysis.GetDocumentDiagnostics(_currentFile, ct);
|
||||
await this.InvokeAsync(() => SetDiagnostics(documentDiagnostics));
|
||||
var projectDiagnostics = await _roslynAnalysis.GetProjectDiagnosticsForFile(_currentFile, ct);
|
||||
await this.InvokeAsync(() => SetProjectDiagnostics(projectDiagnostics));
|
||||
}
|
||||
|
||||
public enum LineEditOrigin
|
||||
@@ -255,11 +256,20 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
||||
var readFileTask = _openTabsFileManager.GetFileTextAsync(file);
|
||||
_currentFile.FileContentsChangedExternally.Subscribe(OnFileChangedExternally);
|
||||
_currentFile.FileDeleted.Subscribe(OnFileDeleted);
|
||||
var project = ((IChildSharpIdeNode)_currentFile).GetNearestProjectNode();
|
||||
if (project is not null)
|
||||
{
|
||||
project.Diagnostics.ObserveChanged()
|
||||
.SubscribeAwait(async (innerEvent, ct) =>
|
||||
{
|
||||
var projectDiagnosticsForFile = project.Diagnostics.Where(s => s.FilePath == _currentFile.Path).ToImmutableArray();
|
||||
await this.InvokeAsync(() => SetProjectDiagnostics(projectDiagnosticsForFile));
|
||||
});
|
||||
}
|
||||
|
||||
var syntaxHighlighting = _roslynAnalysis.GetDocumentSyntaxHighlighting(_currentFile);
|
||||
var razorSyntaxHighlighting = _roslynAnalysis.GetRazorDocumentSyntaxHighlighting(_currentFile);
|
||||
var diagnostics = _roslynAnalysis.GetDocumentDiagnostics(_currentFile);
|
||||
var projectDiagnosticsForFile = _roslynAnalysis.GetProjectDiagnosticsForFile(_currentFile);
|
||||
await readFileTask;
|
||||
var setTextTask = this.InvokeAsync(async () =>
|
||||
{
|
||||
@@ -275,8 +285,6 @@ public partial class SharpIdeCodeEdit : CodeEdit
|
||||
await this.InvokeAsync(async () => SetSyntaxHighlightingModel(await syntaxHighlighting, await razorSyntaxHighlighting));
|
||||
await diagnostics;
|
||||
await this.InvokeAsync(async () => SetDiagnostics(await diagnostics));
|
||||
await projectDiagnosticsForFile;
|
||||
await this.InvokeAsync(async () => SetProjectDiagnostics(await projectDiagnosticsForFile));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -79,14 +79,14 @@ public partial class ProblemsPanel : Control
|
||||
});
|
||||
}
|
||||
|
||||
private async Task CreateDiagnosticTreeItem(Tree tree, TreeItem parent, ViewChangedEvent<Diagnostic, TreeItemContainer> e)
|
||||
private async Task CreateDiagnosticTreeItem(Tree tree, TreeItem parent, ViewChangedEvent<SharpIdeDiagnostic, TreeItemContainer> e)
|
||||
{
|
||||
await this.InvokeAsync(() =>
|
||||
{
|
||||
var diagItem = tree.CreateItem(parent);
|
||||
diagItem.SetText(0, e.NewItem.Value.GetMessage());
|
||||
diagItem.SetMetadata(0, new RefCountedContainer<Diagnostic>(e.NewItem.Value));
|
||||
diagItem.SetIcon(0, e.NewItem.Value.Severity switch
|
||||
diagItem.SetText(0, e.NewItem.Value.Diagnostic.GetMessage());
|
||||
diagItem.SetMetadata(0, new RefCountedContainer<SharpIdeDiagnostic>(e.NewItem.Value));
|
||||
diagItem.SetIcon(0, e.NewItem.Value.Diagnostic.Severity switch
|
||||
{
|
||||
DiagnosticSeverity.Error => ErrorIcon,
|
||||
DiagnosticSeverity.Warning => WarningIcon,
|
||||
@@ -107,13 +107,13 @@ public partial class ProblemsPanel : Control
|
||||
private void TreeOnItemActivated()
|
||||
{
|
||||
var selected = _tree.GetSelected();
|
||||
var diagnosticContainer = selected.GetMetadata(0).As<RefCountedContainer<Diagnostic>?>();
|
||||
var diagnosticContainer = selected.GetMetadata(0).As<RefCountedContainer<SharpIdeDiagnostic>?>();
|
||||
if (diagnosticContainer is null) return;
|
||||
var diagnostic = diagnosticContainer.Item;
|
||||
var parentTreeItem = selected.GetParent();
|
||||
var projectContainer = parentTreeItem.GetMetadata(0).As<RefCountedContainer<SharpIdeProjectModel>?>();
|
||||
if (projectContainer is null) return;
|
||||
OpenDocumentContainingDiagnostic(diagnostic);
|
||||
OpenDocumentContainingDiagnostic(diagnostic.Diagnostic);
|
||||
}
|
||||
|
||||
private void OpenDocumentContainingDiagnostic(Diagnostic diagnostic)
|
||||
|
||||
Reference in New Issue
Block a user