Skip to content

Commit

Permalink
Disposing document when file closes
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
madskristensen committed Dec 22, 2021
1 parent c49e2d9 commit 247241b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Language/ErrorListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private IEnumerable<ErrorListItem> CreateErrorListItem(ParseItem item)
protected override void Closed(IWpfTextView textView)
{
_document.Parsed -= ParseErrors;
_document.Dispose();
_dataSource.CleanAllErrors();
}
}
Expand Down
17 changes: 14 additions & 3 deletions src/PkgdefDocument.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Linq;
using System;
using System.Linq;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;

namespace PkgdefLanguage
{
public class PkgdefDocument : Document
public class PkgdefDocument : Document, IDisposable
{
private readonly ITextBuffer _buffer;
private bool _isDisposed;

public PkgdefDocument(ITextBuffer buffer)
: base(buffer.CurrentSnapshot.Lines.Select(line => line.GetTextIncludingLineBreak()).ToArray())
Expand All @@ -25,5 +27,14 @@ public static PkgdefDocument FromTextbuffer(ITextBuffer buffer)
{
return buffer.Properties.GetOrCreateSingletonProperty(() => new PkgdefDocument(buffer));
}

public void Dispose()
{
if (!_isDisposed)
{
_buffer.Changed -= BufferChanged;
_isDisposed = true;
}
}
}
}
}

0 comments on commit 247241b

Please sign in to comment.