Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document sync & completions fix #192

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Cody.Core.Tests/Cody.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="CustomConfigurationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringExtensionsTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cody.Core\Cody.Core.csproj">
Expand Down
38 changes: 38 additions & 0 deletions src/Cody.Core.Tests/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Cody.Core.Common;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cody.Core.Tests
{
[TestFixture]
public class StringExtensionsTests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

{

[TestCase(@"c:\path\to\file", "file:///c%3A/path/to/file")]
[TestCase(@"c:/path/to/file", "file:///c%3A/path/to/file")]
[TestCase(@"c:/file.txt", "file:///c%3A/file.txt")]
public void Can_Convert_Path_To_Valid_Uri(string path, string expectedPath)
{
var result = StringExtensions.ToUri(path);

Assert.That(result, Is.EqualTo(expectedPath));
}

[TestCase("line1\rline2\rline3\r", "line1\nline2\nline3\n")]
[TestCase("line1\nline2\nline3\n", "line1\nline2\nline3\n")]
[TestCase("line1\r\nline2\r\nline3\r\n", "line1\nline2\nline3\n")]
[TestCase("line1\r\nline2\rline3\n", "line1\nline2\nline3\n")]
public void Can_Replace_Line_Brakers(string text, string expectedText)
{
var result = StringExtensions.ConvertLineBreaks(text, "\n");

Assert.That(result, Is.EqualTo(expectedText));
}
}
}
2 changes: 0 additions & 2 deletions src/Cody.Core/DocumentSync/DocumentSyncCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ public void OnChanged(string fullPath, DocumentRange visibleRange, DocumentRange
};

agentService.DidChange(docState);
//var result = agentService.GetWorkspaceDocuments(new GetDocumentsParams { Uris = new[] { fullPath.ToUri() } }).Result;
//trace.TraceEvent("AfterDidChange", result.Documents.First().Content);
}

public void OnClosed(string fullPath)
Expand Down
2 changes: 1 addition & 1 deletion src/Cody.VisualStudio/Completions/CodyProposalSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -163,6 +162,7 @@ private void UpdateCaretAndCompletion(ref VirtualSnapshotPoint caret, ref Comple
if (trackedSnapshot == null || trackedSnapshot.Version.VersionNumber < caret.Position.Snapshot.Version.VersionNumber)
{
trace.TraceEvent("TrackinSnapshotFailed");
return;
}

caret = caret.TranslateTo(trackedSnapshot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class CodyProposalSourceProvider : ProposalSourceProviderBase, IDisposabl
private static TraceLogger trace = new TraceLogger(nameof(CodyProposalSourceProvider));

private readonly ITextDocumentFactoryService textDocumentFactoryService;
private readonly IVsEditorAdaptersFactoryService editorAdaptersFactoryService;
private readonly SuggestionServiceBase suggestionServiceBase;

public const string ProposalIdPrefix = "cody";
Expand All @@ -35,11 +34,9 @@ public class CodyProposalSourceProvider : ProposalSourceProviderBase, IDisposabl
[ImportingConstructor]
public CodyProposalSourceProvider(
ITextDocumentFactoryService textDocumentFactoryService,
IVsEditorAdaptersFactoryService editorAdaptersFactoryService,
SuggestionServiceBase suggestionServiceBase)
{
this.textDocumentFactoryService = textDocumentFactoryService;
this.editorAdaptersFactoryService = editorAdaptersFactoryService;
this.suggestionServiceBase = suggestionServiceBase;

//suggestionServiceBase.ProposalRejected += OnProposalRejected;
Expand Down Expand Up @@ -93,12 +90,6 @@ private void OnSuggestionAccepted(object sender, SuggestionAcceptedEventArgs e)

public async override Task<ProposalSourceBase> GetProposalSourceAsync(ITextView view, CancellationToken cancel)
{
//var list = Input.ToArray();
Copy link
Collaborator

@PiotrKarczmarz PiotrKarczmarz Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not used for debugging //[ImportMany] public IEnumerable<ProposalSourceProviderBase> Input { get; set; }?

I would say it could stay then, as useful debugging help.

//foreach (var zm in Input)
//{
// var pom = zm.GetType().Assembly.Location;
//}

trace.TraceEvent("Enter");
IWpfTextView wpfTextView = view as IWpfTextView;
if (wpfTextView != null && view.Roles.Contains("DOCUMENT") && view.Roles.Contains("EDITABLE"))
Expand Down
5 changes: 3 additions & 2 deletions src/Cody.VisualStudio/Services/DocumentsSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ private DocumentRange GetVisibleRange(IVsTextView textView, ITextSnapshot snapsh
{
DocumentPosition firstVisiblePosition = null, lastVisiblePosition = null;

if (textView != null)
if (textView != null && ThreadHelper.CheckAccess())
{
var wpfTextView = editorAdaptersFactoryService.GetWpfTextView(textView);
if (wpfTextView == null) return null;
snapshot = snapshot ?? wpfTextView.TextSnapshot;
var lines = wpfTextView.TextViewLines;

Expand All @@ -158,7 +159,7 @@ private DocumentRange GetDocumentSelection(IVsTextView textView, ITextSnapshot s
{
bool swap = false;
DocumentPosition start = null, end = null;
if (textView != null)
if (textView != null && ThreadHelper.CheckAccess())
{
var wpfTextView = editorAdaptersFactoryService.GetWpfTextView(textView);
if (wpfTextView != null)
Expand Down
Loading