dispose project diagnostics subscription

This commit is contained in:
Matt Parker
2025-11-24 18:41:47 +10:00
parent e48bd78aac
commit f56db8d663
2 changed files with 4 additions and 2 deletions

View File

@@ -983,7 +983,7 @@ public class RoslynAnalysis(ILogger<RoslynAnalysis> logger, BuildService buildSe
{ {
return false; return false;
} }
// This may not be perfect, as None Include="" seems to be returned here as one of the globs as Include, with no distinction of Compile vs None etc // This may not be perfect, as None Include="" seems to be returned here as one of the globs as Include, with no distinction of Compile vs None etc
// TODO: Investigate getting the glob type (Compile, None, etc) // TODO: Investigate getting the glob type (Compile, None, etc)
var matchers = projectFileInfo.FileGlobs.Select(glob => var matchers = projectFileInfo.FileGlobs.Select(glob =>

View File

@@ -51,6 +51,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
private bool _fileChangingSuppressBreakpointToggleEvent; private bool _fileChangingSuppressBreakpointToggleEvent;
private bool _settingWholeDocumentTextSuppressLineEditsEvent; // A dodgy workaround - setting the whole document doesn't guarantee that the line count stayed the same etc. We are still going to have broken highlighting. TODO: Investigate getting minimal text change ranges, and change those ranges only private bool _settingWholeDocumentTextSuppressLineEditsEvent; // A dodgy workaround - setting the whole document doesn't guarantee that the line count stayed the same etc. We are still going to have broken highlighting. TODO: Investigate getting minimal text change ranges, and change those ranges only
private bool _fileDeleted; private bool _fileDeleted;
private IDisposable? _projectDiagnosticsObserveDisposable;
[Inject] private readonly IdeOpenTabsFileManager _openTabsFileManager = null!; [Inject] private readonly IdeOpenTabsFileManager _openTabsFileManager = null!;
[Inject] private readonly RunService _runService = null!; [Inject] private readonly RunService _runService = null!;
@@ -151,6 +152,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
{ {
_currentFile?.FileContentsChangedExternally.Unsubscribe(OnFileChangedExternally); _currentFile?.FileContentsChangedExternally.Unsubscribe(OnFileChangedExternally);
_currentFile?.FileDeleted.Unsubscribe(OnFileDeleted); _currentFile?.FileDeleted.Unsubscribe(OnFileDeleted);
_projectDiagnosticsObserveDisposable?.Dispose();
GlobalEvents.Instance.SolutionAltered.Unsubscribe(OnSolutionAltered); GlobalEvents.Instance.SolutionAltered.Unsubscribe(OnSolutionAltered);
if (_currentFile is not null) _openTabsFileManager.CloseFile(_currentFile); if (_currentFile is not null) _openTabsFileManager.CloseFile(_currentFile);
} }
@@ -259,7 +261,7 @@ public partial class SharpIdeCodeEdit : CodeEdit
var project = ((IChildSharpIdeNode)_currentFile).GetNearestProjectNode(); var project = ((IChildSharpIdeNode)_currentFile).GetNearestProjectNode();
if (project is not null) if (project is not null)
{ {
project.Diagnostics.ObserveChanged() _projectDiagnosticsObserveDisposable = project.Diagnostics.ObserveChanged()
.SubscribeAwait(async (innerEvent, ct) => .SubscribeAwait(async (innerEvent, ct) =>
{ {
var projectDiagnosticsForFile = project.Diagnostics.Where(s => s.FilePath == _currentFile.Path).ToImmutableArray(); var projectDiagnosticsForFile = project.Diagnostics.Where(s => s.FilePath == _currentFile.Path).ToImmutableArray();