Skip to content

Commit

Permalink
Merge pull request #66 from Exafunction/rahul/fix-more-crashes
Browse files Browse the repository at this point in the history
Bump version to 1.8.16. Call AddTrackedWorkspace per project
  • Loading branch information
fortenforge authored Mar 30, 2024
2 parents 27290c1 + 44a1021 commit 4ccd2b8
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 29 deletions.
37 changes: 25 additions & 12 deletions CodeiumVS/LanguageServer/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ namespace CodeiumVS;
public class LanguageServer
{
private string _languageServerURL;
private string _languageServerVersion = "1.8.14";
private string _languageServerVersion = "1.8.16";

private int _port = 0;
private System.Diagnostics.Process _process;
private bool _intializedWorkspace = false;
private bool _initializedWorkspace = false;

private readonly Metadata _metadata;
private readonly HttpClient _httpClient;
Expand Down Expand Up @@ -726,15 +726,28 @@ await _package.LogAsync(
return default;
}

private async Task IntializeTrackedWorkspaceAsync()
private async Task InitializeTrackedWorkspaceAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
EnvDTE.DTE dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
AddTrackedWorkspaceResponse response = await AddTrackedWorkspaceAsync(solutionDir);
if (response != null)
DTE dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
foreach (EnvDTE.Project project in dte.Solution.Projects)
{
_intializedWorkspace = true;
try
{
string projectDir = Path.GetDirectoryName(project.FullName);
if (!string.IsNullOrEmpty(projectDir))
{
AddTrackedWorkspaceResponse response = await AddTrackedWorkspaceAsync(projectDir);
if (response != null)
{
_initializedWorkspace = true;
}
}
}
catch (Exception)
{
continue;
}
}
}

Expand All @@ -751,9 +764,9 @@ public async Task<IList<CompletionItem>?>
int cursorPosition, string lineEnding, int tabSize, bool insertSpaces,
CancellationToken token)
{
if (!_intializedWorkspace)
if (!_initializedWorkspace)
{
await IntializeTrackedWorkspaceAsync();
await InitializeTrackedWorkspaceAsync();
}
GetCompletionsRequest data =
new() { metadata = GetMetadata(),
Expand Down Expand Up @@ -786,9 +799,9 @@ public async Task AcceptCompletionAsync(string completionId)

public async Task<GetProcessesResponse?> GetProcessesAsync()
{
if (!_intializedWorkspace)
if (!_initializedWorkspace)
{
await IntializeTrackedWorkspaceAsync();
await InitializeTrackedWorkspaceAsync();
}
return await RequestCommandAsync<GetProcessesResponse>("GetProcesses", new {});
}
Expand Down
1 change: 1 addition & 0 deletions CodeiumVS/SuggestionUI/InlineGreyTextTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void MarkDirty()
{
try
{
if (!view.TextViewLines.IsValid) { return; }
var changeStart = view.TextViewLines.FirstVisibleLine.Start;
var changeEnd = view.TextViewLines.LastVisibleLine.Start;

Expand Down
30 changes: 17 additions & 13 deletions CodeiumVS/SuggestionUI/SuggestionTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,24 +499,28 @@ public void ClearSuggestion()
// triggers refresh of the screen
void MarkDirty()
{
GetTagger().MarkDirty();
ITextSnapshot newSnapshot = buffer.CurrentSnapshot;
this.snapshot = newSnapshot;
try
{
GetTagger().MarkDirty();
ITextSnapshot newSnapshot = buffer.CurrentSnapshot;
this.snapshot = newSnapshot;

if (view.TextViewLines == null) return;
if (view.TextViewLines == null) return;
if (!view.TextViewLines.IsValid) return;

var changeStart = view.TextViewLines.FirstVisibleLine.Start;
var changeEnd = view.TextViewLines.LastVisibleLine.Start;
var changeStart = view.TextViewLines.FirstVisibleLine.Start;
var changeEnd = view.TextViewLines.LastVisibleLine.Start;

var startLine = view.TextSnapshot.GetLineFromPosition(changeStart);
var endLine = view.TextSnapshot.GetLineFromPosition(changeEnd);
var startLine = view.TextSnapshot.GetLineFromPosition(changeStart);
var endLine = view.TextSnapshot.GetLineFromPosition(changeEnd);

var span = new SnapshotSpan(startLine.Start, endLine.EndIncludingLineBreak)
.TranslateTo(targetSnapshot: newSnapshot, SpanTrackingMode.EdgePositive);
var span = new SnapshotSpan(startLine.Start, endLine.EndIncludingLineBreak)
.TranslateTo(targetSnapshot: newSnapshot, SpanTrackingMode.EdgePositive);

// lines we are marking dirty
// currently all of them for simplicity
if (this.TagsChanged != null) { this.TagsChanged(this, new SnapshotSpanEventArgs(span)); }
// lines we are marking dirty
// currently all of them for simplicity
if (this.TagsChanged != null) { TagsChanged(this, new SnapshotSpanEventArgs(span)); }
} catch (Exception e) { Debug.Write(e); }
}
}

Expand Down
24 changes: 22 additions & 2 deletions CodeiumVS/SuggestionUI/TextViewListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,35 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv
// gets lsp completions on added character or deletions
if (!typedChar.Equals(char.MinValue) || commandID == (uint)VSConstants.VSStd2KCmdID.RETURN || regenerateSuggestion)
{
_ = Task.Run(() => GetCompletion());
_ = Task.Run(() =>
{
try
{
GetCompletion();
}
catch (Exception e)
{
Debug.Write(e);
}
});
handled = true;
}
else if (commandID == (uint)VSConstants.VSStd2KCmdID.BACKSPACE ||
commandID == (uint)VSConstants.VSStd2KCmdID.DELETE)
{
ClearSuggestion();

_ = Task.Run(() => GetCompletion());
_ = Task.Run(() =>
{
try
{
GetCompletion();
}
catch (Exception e)
{
Debug.Write(e);
}
});
handled = true;
}

Expand Down
2 changes: 1 addition & 1 deletion CodeiumVS/source.extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed partial class Vsix
public const string Name = "Codeium";
public const string Description = @"The modern coding superpower: free AI code acceleration plugin for your favorite languages. Type less. Code more. Ship faster.";
public const string Language = "en-US";
public const string Version = "1.8.14";
public const string Version = "1.8.17";
public const string Author = "Codeium";
public const string Tags = "";
}
Expand Down
2 changes: 1 addition & 1 deletion CodeiumVS/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="Codeium.VisualStudio" Version="1.8.14" Language="en-US" Publisher="Codeium" />
<Identity Id="Codeium.VisualStudio" Version="1.8.17" Language="en-US" Publisher="Codeium" />
<DisplayName>Codeium</DisplayName>
<Description xml:space="preserve">The modern coding superpower: free AI code acceleration plugin for your favorite languages. Type less. Code more. Ship faster.</Description>
<MoreInfo>https://www.codeium.com</MoreInfo>
Expand Down

0 comments on commit 4ccd2b8

Please sign in to comment.