Skip to content

Commit

Permalink
proposal source fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Gołębiowski committed Dec 30, 2024
1 parent e9d23c4 commit a1d22a2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Cody.VisualStudio.Tests/AutocompleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task Autocomplete_Is_Working()
Dte.ActiveDocument.Close(vsSaveChanges.vsSaveChangesNo);
}

(int Line, int Column)? FindPositionAfterText(string document, string textToFind)
private (int Line, int Column)? FindPositionAfterText(string document, string textToFind)
{
var lines = document.Split(new[] { "\r\n" }, StringSplitOptions.None);
var line = Array.FindIndex(lines, x => x.StartsWith(textToFind));
Expand Down
4 changes: 2 additions & 2 deletions src/Cody.VisualStudio/CodyPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke

private void InitializeServices()
{
//TraceManager.Listeners.Add(new FileTraceListener(@"c:\tmp\cody.log"));
//TraceManager.Enabled = true;
TraceManager.Listeners.Add(new FileTraceListener(@"c:\tmp\cody.log"));
TraceManager.Enabled = true;

var loggerFactory = new LoggerFactory();
AgentLogger = loggerFactory.Create(WindowPaneLogger.CodyAgent);
Expand Down
9 changes: 3 additions & 6 deletions src/Cody.VisualStudio/Completions/CodyProposalSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ public class CodyProposalSource : ProposalSourceBase

private IAgentService agentService;
private ITextDocument textDocument;
private IVsTextView vsTextView;
private readonly ITextView view;
private static uint sessionCounter = 0;

private ITextSnapshot trackedSnapshot;

public CodyProposalSource(ITextDocument textDocument, IVsTextView vsTextView, ITextView view)
public CodyProposalSource(ITextDocument textDocument, ITextView view)
{
this.textDocument = textDocument;
this.vsTextView = vsTextView;
this.view = view;
var currentSnapshot = textDocument.TextBuffer.CurrentSnapshot;
trackedSnapshot = textDocument.TextBuffer.CurrentSnapshot;
textDocument.TextBuffer.ChangedHighPriority += OnTextBufferChanged;
}

Expand Down Expand Up @@ -116,9 +114,8 @@ public override async Task<ProposalCollectionBase> RequestProposalsAsync(
else foreach (var item in autocomplete.Items) trace.TraceEvent("AutocompliteResult", item);

var newPosition = caret.Position.TranslateTo(textDocument.TextBuffer.CurrentSnapshot, PointTrackingMode.Positive);
vsTextView.GetLineAndColumn(newPosition, out int newCaretLine, out int newCaretCol);
var newText = newPosition.GetContainingLine().GetText();
trace.TraceEvent("AfterResponse", "session: {0}, newCaret: {1}:{2} lineText:'{3}'", session, newCaretLine, newCaretCol, newText);
trace.TraceEvent("AfterResponse", "session: {0}, newCaret: {1} lineText:'{2}'", session, newPosition.Position, newText);

var collection = CreateProposals(autocomplete, caret, completionState, session);
if (cancel.IsCancellationRequested) trace.TraceEvent("AutocompliteCanceled2", "session: {0}", session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -97,11 +96,10 @@ public async override Task<ProposalSourceBase> GetProposalSourceAsync(ITextView
if (wpfTextView != null && view.Roles.Contains("DOCUMENT") && view.Roles.Contains("EDITABLE"))
{
textDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out var document);
var vsTextView = editorAdaptersFactoryService.GetViewAdapter(view);
if (document != null && vsTextView != null)
if (document != null)
{
trace.TraceEvent("CreateProposalSource", "Created for '{0}'", document.FilePath);
return view.Properties.GetOrCreateSingletonProperty(() => new CodyProposalSource(document, vsTextView, view));
return view.Properties.GetOrCreateSingletonProperty(() => new CodyProposalSource(document, view));
}
}

Expand Down

0 comments on commit a1d22a2

Please sign in to comment.