Skip to content

Commit

Permalink
Visible range fix (#212)
Browse files Browse the repository at this point in the history
- System.ObjectDisposedException on GetVisibleRange
- Running StatusBar service from UI thread
## Test plan
Start VS and start editing files, check the output window for errors.
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

---------

Co-authored-by: Tomasz Gołębiowski <tgolebiowski@virtuslab.com>
  • Loading branch information
tomaszgolebiowski and Tomasz Gołębiowski authored Feb 6, 2025
1 parent 45be1ee commit 573c2d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Cody.VisualStudio/CodyPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ private void ReportSentryVsVersion()
scope.SetTag("vs", VsVersionService.DisplayVersion);
scope.SetTag("agent", VersionService.Agent);
});

VsShellUtilities.ShutdownToken.Register(() => SentrySdk.ConfigureScope(s => s.SetTag("isShuttingDown", "true")));
}

private static void InitializeTrace()
Expand Down
16 changes: 13 additions & 3 deletions src/Cody.VisualStudio/Services/DocumentsSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,19 @@ private DocumentRange GetVisibleRange(ITextView textView)
if (ThreadHelper.CheckAccess())
{
var lines = textView.TextViewLines;

firstVisiblePosition = ToDocumentPosition(lines.FirstVisibleLine.Start);
lastVisiblePosition = ToDocumentPosition(lines.LastVisibleLine.End);
if(lines != null && lines.IsValid)
{
try
{
firstVisiblePosition = ToDocumentPosition(lines.FirstVisibleLine.Start);
lastVisiblePosition = ToDocumentPosition(lines.LastVisibleLine.End);
}
catch(ObjectDisposedException)
{
return null;
}
}
else return null;
}
else return null;

Expand Down
4 changes: 3 additions & 1 deletion src/Cody.VisualStudio/Services/StatusbarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public class StatusbarService : IStatusbarService
{
public void SetText(string text)
{
ThreadHelper.JoinableTaskFactory.Run(delegate
ThreadHelper.JoinableTaskFactory.Run(async delegate
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

var statusBar = (IVsStatusbar)Package.GetGlobalService(typeof(SVsStatusbar));
int frozen;

Expand Down

0 comments on commit 573c2d2

Please sign in to comment.