Skip to content

Commit

Permalink
Fix crashes; AddTrackedWorkspace
Browse files Browse the repository at this point in the history
  • Loading branch information
fortenforge committed Mar 6, 2024
1 parent 867b92d commit c50c50b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
18 changes: 15 additions & 3 deletions CodeiumVS/LanguageServer/LanguageServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CodeiumVS.Packets;
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Shell.Interop;
Expand Down Expand Up @@ -28,7 +29,7 @@ public class LanguageServer
private string _languageServerVersion = "1.8.0";

private int _port = 0;
private Process _process;
private System.Diagnostics.Process _process;

private readonly Metadata _metadata;
private readonly HttpClient _httpClient;
Expand Down Expand Up @@ -379,7 +380,7 @@ private void ThreadDownloadLanguageServer(IVsThreadedWaitDialog4 progressDialog)

// wait until the download is completed
while (webClient.IsBusy)
Thread.Sleep(100);
System.Threading.Thread.Sleep(100);

webClient.Dispose();
}
Expand Down Expand Up @@ -416,7 +417,7 @@ await _package.LogAsync(
false,
true);

Thread trd =
System.Threading.Thread trd =
new(() => ThreadDownloadLanguageServer(progressDialog)) { IsBackground = true };

trd.Start();
Expand Down Expand Up @@ -654,6 +655,11 @@ await _package.LogAsync(
if (File.Exists(apiKeyFilePath)) { _metadata.api_key = File.ReadAllText(apiKeyFilePath); }

await _package.UpdateSignedInStateAsync();

await WaitReadyAsync();
EnvDTE.DTE dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
await AddTrackedWorkspaceAsync(solutionDir);
}

private void LSP_OnExited(object sender, EventArgs e)
Expand Down Expand Up @@ -771,6 +777,12 @@ public async Task AcceptCompletionAsync(string completionId)
return await RequestCommandAsync<GetProcessesResponse>("GetProcesses", new {});
}

public async Task<AddTrackedWorkspaceResponse?> AddTrackedWorkspaceAsync(string workspacePath)
{
AddTrackedWorkspaceRequest data = new() { workspace = workspacePath };
return await RequestCommandAsync<AddTrackedWorkspaceResponse>("AddTrackedWorkspace", data);
}

public Metadata GetMetadata()
{
return new() { request_id = _metadata.request_id++,
Expand Down
22 changes: 22 additions & 0 deletions CodeiumVS/LanguageServer/Packets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,28 @@ public partial class AcceptCompletionResponse : global::ProtoBuf.IExtensible
global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
}

[global::ProtoBuf.ProtoContract()]
public partial class AddTrackedWorkspaceRequest : global::ProtoBuf.IExtensible
{
private global::ProtoBuf.IExtension __pbn__extensionData;
global::ProtoBuf.IExtension
global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) =>
global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);

[global::ProtoBuf.ProtoMember(1)]
[global::System.ComponentModel.DefaultValue("")]
public string workspace { get; set; }
}

[global::ProtoBuf.ProtoContract()]
public partial class AddTrackedWorkspaceResponse : global::ProtoBuf.IExtensible
{
private global::ProtoBuf.IExtension __pbn__extensionData;
global::ProtoBuf.IExtension
global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) =>
global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
}

[global::ProtoBuf.ProtoContract()]
public enum Language
{
Expand Down
14 changes: 10 additions & 4 deletions CodeiumVS/SuggestionUI/SuggestionTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,16 @@ void AddSuffixTextBlocks(int start, string line, string userText)
void AddInsertionTextBlock(int start, int end, string line)
{
if (line.Length <= suggestionIndex) return;

string remainder = line.Substring(start, end - start);
var textBlock = CreateTextBox(remainder, greyBrush);
GetTagger().UpdateAdornment(textBlock);
try
{
string remainder = line.Substring(start, end - start);
var textBlock = CreateTextBox(remainder, greyBrush);
GetTagger().UpdateAdornment(textBlock);
}
catch (ArgumentOutOfRangeException)
{
return;
}
}

// Updates the grey text
Expand Down
17 changes: 14 additions & 3 deletions CodeiumVS/SuggestionUI/TextViewListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,17 @@ await package.LogAsync(
Debug.Print("completions " + list.Count.ToString());

string prefix = line.Substring(0, Math.Min(characterN, line.Length));
List<Tuple<String, String>> suggestions =
ParseCompletion(list, text, line, prefix, characterN);

List<Tuple<String, String>> suggestions;
try
{
suggestions = ParseCompletion(list, text, line, prefix, characterN);
}
catch (NullReferenceException ex)
{
await package.LogAsync("Exception: " + ex.ToString());
return;
}

SuggestionTagger tagger = GetTagger();
if (suggestions != null && suggestions.Count > 0 && tagger != null)
Expand Down Expand Up @@ -164,7 +173,9 @@ List<Tuple<String, String>> ParseCompletion(IList<Packets.CompletionItem> comple
ICompletionSession session = m_provider.CompletionBroker.GetSessions(_view).FirstOrDefault();
if (session != null && session.SelectedCompletionSet != null)
{
string intellisenseSuggestion = session.SelectedCompletionSet.SelectionStatus.Completion.InsertionText;
var completion = session.SelectedCompletionSet.SelectionStatus.Completion;
if (completion == null) { continue; }
string intellisenseSuggestion = completion.InsertionText;
ITrackingSpan intellisenseSpan = session.SelectedCompletionSet.ApplicableTo;
SnapshotSpan span = intellisenseSpan.GetSpan(intellisenseSpan.TextBuffer.CurrentSnapshot);
string intellisenseInsertion = intellisenseSuggestion.Substring(span.Length);
Expand Down
21 changes: 10 additions & 11 deletions CodeiumVS/source.extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
// ------------------------------------------------------------------------------
namespace CodeiumVS
{
internal sealed partial class Vsix
{
public const string Id = "Codeium.VisualStudio";
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.0";
public const string Author = "Codeium";
public const string Tags = "";
}
internal sealed partial class Vsix
{
public const string Id = "Codeium.VisualStudio";
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.1";
public const string Author = "Codeium";
public const string Tags = "";
}
}
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.0" Language="en-US" Publisher="Codeium" />
<Identity Id="Codeium.VisualStudio" Version="1.8.1" 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 c50c50b

Please sign in to comment.