Skip to content

Commit

Permalink
Fix for missing selection data (#193)
Browse files Browse the repository at this point in the history
## Test plan
Check for errors in logs after loading WPF solution
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

---------

Co-authored-by: Tomasz Gołębiowski <[email protected]>
  • Loading branch information
tomaszgolebiowski and Tomasz Gołębiowski authored Jan 6, 2025
1 parent 8c4074e commit a519f38
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
79 changes: 46 additions & 33 deletions src/Cody.Core/DocumentSync/DocumentSyncCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,47 +104,60 @@ public void OnFocus(string fullPath)

public void OnOpened(string fullPath, string content, DocumentRange visibleRange, DocumentRange selection)
{
trace.TraceEvent("DidOpen", "sel:{0}, vr:{1}, path:{2}", selection, visibleRange, fullPath);

Range vRange = null;
if (visibleRange != null)
try
{
vRange = new Range
trace.TraceEvent("DidOpen", "sel:{0}, vr:{1}, path:{2}", selection, visibleRange, fullPath);

Range vRange = null;
if (visibleRange != null)
{
Start = new Position
vRange = new Range
{
Line = visibleRange.Start.Line,
Character = visibleRange.Start.Column
},
End = new Position
{
Line = visibleRange.End.Line,
Character = visibleRange.End.Column
}
};
}
Start = new Position
{
Line = visibleRange.Start.Line,
Character = visibleRange.Start.Column
},
End = new Position
{
Line = visibleRange.End.Line,
Character = visibleRange.End.Column
}
};
}

var docState = new ProtocolTextDocument
{
Uri = fullPath.ToUri(),
Content = content.ConvertLineBreaks("\n"),
VisibleRange = vRange,
Selection = new Range
Range selRange = null;
if (selection != null)
{
Start = new Position
selRange = new Range
{
Line = selection.Start.Line,
Character = selection.Start.Column
},
End = new Position
{
Line = selection.End.Line,
Character = selection.End.Column
}
Start = new Position
{
Line = selection.Start.Line,
Character = selection.Start.Column
},
End = new Position
{
Line = selection.End.Line,
Character = selection.End.Column
}
};
}
};

agentService.DidOpen(docState);
var docState = new ProtocolTextDocument
{
Uri = fullPath.ToUri(),
Content = content.ConvertLineBreaks("\n"),
VisibleRange = vRange,
Selection = selRange
};

agentService.DidOpen(docState);
}
catch (Exception ex)
{
logger.Error("Exception in OnOpened()", ex);
}
}

public void OnSaved(string fullPath)
Expand Down
2 changes: 1 addition & 1 deletion src/Cody.VisualStudio.Tests/ChatLoggedBasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ChatLoggedBasicTests(ITestOutputHelper output) : base(output)
});
}

[VsFact(Version = VsVersion.VS2022)]
[VsFact(Version = VsVersion.VS2022, Skip = "Unstable")]
public async Task Solution_Name_Is_Added_To_Chat_Input()
{
// given
Expand Down
2 changes: 1 addition & 1 deletion src/Cody.VisualStudio.Tests/ChatNotLoggedStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ await NotInLoggedState(async () =>

}

[VsFact(Version = VsVersion.VS2022)]
[VsFact(Version = VsVersion.VS2022, Skip = "Unstable")]
public async Task Cody_Enterprise_Section_Is_Present()
{
// given
Expand Down
4 changes: 2 additions & 2 deletions src/Cody.VisualStudio/Services/DocumentsSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public void Initialize()
var content = rdt.GetRunningDocumentContents(docCookie);
var textView = GetTextView(frame);
var visibleRange = GetVisibleRange(textView);
var docRange = GetDocumentSelection(textView);
var selection = GetDocumentSelection(textView);

documentActions.OnOpened(path, content, visibleRange, docRange);
documentActions.OnOpened(path, content, visibleRange, selection);
}
catch (Exception ex)
{
Expand Down

0 comments on commit a519f38

Please sign in to comment.