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

add proto and path checks #118

Merged
merged 9 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 1 addition & 2 deletions CodeiumVS/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
// highlight the selected codeblock
TextHighlighter? highlighter = TextHighlighter.GetInstance(docView.TextView);
highlighter?.AddHighlight(start_position, end_position - start_position);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Eventually we should add a formatter to prevent these whitespace changes from making it in

var dialog = RefactorCodeDialogWindow.GetOrCreate();
string? prompt =
await dialog.ShowAndGetPromptAsync(languageInfo, caretScreenPos.X, caretScreenPos.Y);
Expand All @@ -330,14 +329,14 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)

LanguageServerController controller =
(Package as CodeiumVSPackage).LanguageServer.Controller;

if (is_function)
{
FunctionInfo? functionInfo = await GetFunctionInfoAsync();

if (functionInfo != null)
await controller.RefactorFunctionAsync(
prompt, docView.Document.FilePath, functionInfo);

}
else
{
Expand Down
7 changes: 3 additions & 4 deletions CodeiumVS/LanguageServer/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,10 @@ private async Task InitializeTrackedWorkspaceAsync()
{
try
{
string projectDir = Path.GetDirectoryName(project.FullName);
await _package.LogAsync($"Project Dir: {projectDir}");
if (!string.IsNullOrEmpty(projectDir))
if (!string.IsNullOrEmpty(project.FullName))
{
string projectDir = Path.GetDirectoryName(project.FullName);
await _package.LogAsync($"Project Dir: {projectDir}");
AddTrackedWorkspaceResponse response = await AddTrackedWorkspaceAsync(projectDir);
if (response != null)
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we log the project.FullName as well? Seeing as that's actually what's being used now?

Suggested change
if (!string.IsNullOrEmpty(project.FullName))
{
string projectDir = Path.GetDirectoryName(project.FullName);
await _package.LogAsync($"Project Dir: {projectDir}");
AddTrackedWorkspaceResponse response = await AddTrackedWorkspaceAsync(projectDir);
if (response != null)
{
await _package.LogAsync($"Project FullName: {project.FullName}");

Suggestion by Codeium

Expand Down Expand Up @@ -782,7 +782,6 @@ public async Task<IList<CompletionItem>?>
cursor_offset = (ulong)cursorPosition,
line_ending = lineEnding,
absolute_path = absolutePath,
absolute_path_migrate_me_to_uri = absolutePath,
relative_path = Path.GetFileName(absolutePath) },
editor_options = new() {
tab_size = (ulong)tabSize,
Expand Down
19 changes: 7 additions & 12 deletions CodeiumVS/LanguageServer/LanguageServerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ void OnMessage(object sender, MessageEventArgs msg)

if (request.ShouldSerializeopen_file_pointer())
{

var data = request.open_file_pointer;
OpenSelection(
data.file_path_migrate_me_to_uri.IsNullOrEmpty() ? data.file_path : data.file_path_migrate_me_to_uri, data.start_line, data.start_col, data.end_line, data.end_col);
data.file_uri.IsNullOrEmpty() ? data.file_path : data.file_uri, data.start_line, data.start_col, data.end_line, data.end_col);
}
else if (request.ShouldSerializeinsert_at_cursor())
{
Expand All @@ -64,8 +63,7 @@ void OnMessage(object sender, MessageEventArgs msg)
replacement += line.text + "\n";
}
}

ApplyDiff(data.file_path_migrate_me_to_uri.IsNullOrEmpty() ? data.file_path : data.file_path_migrate_me_to_uri, data.diff.start_line, data.diff.end_line, replacement);
ApplyDiff(data.uri.IsNullOrEmpty() ? data.file_path : data.uri, data.diff.start_line, data.diff.end_line, replacement);
}
}

Expand Down Expand Up @@ -186,7 +184,7 @@ public async Task ExplainCodeBlockAsync(string filePath, Language language,
new() { explain_code_block = new() {
code_block_info = codeBlockInfo,
file_path = filePath,
file_path_migrate_me_to_uri = filePath,
uri = filePath,
language = language,
} };

Expand All @@ -202,7 +200,7 @@ public async Task ExplainFunctionAsync(string filePath, FunctionInfo functionInf
new() { explain_function = new() {
function_info = functionInfo,
file_path = filePath,
file_path_migrate_me_to_uri = filePath,
uri = filePath,
language = functionInfo.Language,
} };

Expand All @@ -219,7 +217,7 @@ public async Task GenerateFunctionUnitTestAsync(string instructions, string file
new() { function_unit_tests = new() {
function_info = functionInfo,
file_path = filePath,
file_path_migrate_me_to_uri = filePath,
uri = filePath,
language = functionInfo.Language,
instructions = instructions,
} };
Expand All @@ -236,7 +234,7 @@ public async Task GenerateFunctionDocstringAsync(string filePath, FunctionInfo f
new() { function_docstring = new() {
function_info = functionInfo,
file_path = filePath,
file_path_migrate_me_to_uri = filePath,
uri = filePath,
language = functionInfo.Language,
} };

Expand All @@ -252,7 +250,6 @@ public async Task RefactorCodeBlockAsync(string prompt, string filePath, Languag
request.get_chat_message_request.chat_messages[0].intent =
new() { code_block_refactor = new() { code_block_info = codeBlockInfo,
file_path = filePath,
file_path_migrate_me_to_uri = filePath,
language = language,
refactor_description = prompt } };

Expand All @@ -268,10 +265,8 @@ public async Task RefactorFunctionAsync(string prompt, string filePath,
request.get_chat_message_request.chat_messages[0].intent =
new() { function_refactor = new() { function_info = functionInfo,
file_path = filePath,
file_path_migrate_me_to_uri = filePath,
language = functionInfo.Language,
refactor_description = prompt } };

if (request.Send(ws))
await Package.ShowToolWindowAsync(
typeof(ChatToolWindow), 0, create: true, Package.DisposalToken);
Expand Down Expand Up @@ -306,7 +301,7 @@ public async Task ExplainProblemAsync(string problemMessage, SnapshotSpan span)
surroundingLineStart.Start, surroundingLineEnd.End - surroundingLineStart.Start),
language = Languages.Mapper.GetLanguage(span.Snapshot.TextBuffer.ContentType).Type,
file_path = span.Snapshot.TextBuffer.GetFileName(),
file_path_migrate_me_to_uri = span.Snapshot.TextBuffer.GetFileName(),
uri = span.Snapshot.TextBuffer.GetFileName(),
line_number = problemLineStart.LineNumber + 1,
} };

Expand Down
120 changes: 5 additions & 115 deletions CodeiumVS/LanguageServer/Packets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,10 @@ public partial class Document : global::ProtoBuf.IExtensible
[global::System.ComponentModel.DefaultValue("")]
public string absolute_path { get; set; } = "";

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

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

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

[global::ProtoBuf.ProtoMember(2)]
[global::System.ComponentModel.DefaultValue("")]
public string relative_path
Expand Down Expand Up @@ -426,10 +415,6 @@ public partial class CodeContextItem : global::ProtoBuf.IExtensible
[global::System.ComponentModel.DefaultValue("")]
public string absolute_path { get; set; } = "";

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

[global::ProtoBuf.ProtoMember(16)]
[global::System.ComponentModel.DefaultValue("")]
public string absolute_uri { get; set; } = "";
Expand Down Expand Up @@ -510,10 +495,6 @@ public partial class WorkspacePath : global::ProtoBuf.IExtensible
[global::System.ComponentModel.DefaultValue("")]
public string workspace { get; set; } = "";

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

[global::ProtoBuf.ProtoMember(3)]
[global::System.ComponentModel.DefaultValue("")]
public string workspace_uri { get; set; } = "";
Expand Down Expand Up @@ -1351,12 +1332,6 @@ public Document active_document {
get;
} = new global::System.Collections.Generic.List<string>();

[global::ProtoBuf.ProtoMember(6)]
public global::System.Collections.Generic.List<string> open_document_paths_migrate_me_to_uris
{
get;
} = new global::System.Collections.Generic.List<string>();

[global::ProtoBuf.ProtoMember(12)]
public global::System.Collections.Generic.List<string> open_document_uris {
get;
Expand All @@ -1368,12 +1343,6 @@ public Document active_document {
get;
} = new global::System.Collections.Generic.List<string>();

[global::ProtoBuf.ProtoMember(7)]
public global::System.Collections.Generic.List<string> workspace_paths_migrate_me_to_uris
{
get;
} = new global::System.Collections.Generic.List<string>();

[global::ProtoBuf.ProtoMember(13)]
public global::System.Collections.Generic.List<string> workspace_uris {
get;
Expand Down Expand Up @@ -1602,13 +1571,6 @@ public Language language {
get; set;
}

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

[global::ProtoBuf.ProtoMember(3)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -1698,13 +1660,6 @@ public string file_path
get; set;
} = "";

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

[global::ProtoBuf.ProtoMember(4)]
[global::System.ComponentModel.DefaultValue("")]
public string uri {
Expand All @@ -1728,13 +1683,6 @@ public Language language {
get; set;
}

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

[global::ProtoBuf.ProtoMember(3)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -1771,13 +1719,6 @@ public Language language {
get; set;
}

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

[global::ProtoBuf.ProtoMember(3)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -1841,13 +1782,6 @@ public Language language {
get; set;
}

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

[global::ProtoBuf.ProtoMember(3)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -1884,13 +1818,6 @@ public Language language {
get; set;
}

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

[global::ProtoBuf.ProtoMember(3)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path {
Expand Down Expand Up @@ -1938,13 +1865,6 @@ public Language language {
get; set;
}

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

[global::ProtoBuf.ProtoMember(5)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -1981,13 +1901,6 @@ public Language language {
get; set;
}

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

[global::ProtoBuf.ProtoMember(3)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -2023,13 +1936,6 @@ public Language language {
get; set;
}

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

[global::ProtoBuf.ProtoMember(3)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -2159,13 +2065,6 @@ public partial class ChatMessageActionEdit : global::ProtoBuf.IExtensible
global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) =>
global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);

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

[global::ProtoBuf.ProtoMember(1)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -2368,13 +2267,6 @@ public partial class OpenFilePointer : global::ProtoBuf.IExtensible
global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) =>
global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);

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

[global::ProtoBuf.ProtoMember(1)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path { get; set; } = "";
Expand Down Expand Up @@ -2447,13 +2339,6 @@ public partial class ApplyDiff : global::ProtoBuf.IExtensible
[global::System.ComponentModel.DefaultValue("")]
public string message_id { get; set; } = "";

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

[global::ProtoBuf.ProtoMember(2)]
[global::System.ComponentModel.DefaultValue("")]
public string file_path
Expand Down Expand Up @@ -2981,6 +2866,11 @@ public enum StopReason
STOP_REASON_MIN_LOG_PROB = 4,
STOP_REASON_MAX_NEWLINES = 5,
STOP_REASON_EXIT_SCOPE = 6,
STOP_REASON_NONFINITE_LOGIT_OR_PROB = 7,
STOP_REASON_FIRST_NON_WHITESPACE_LINE = 8,
STOP_REASON_PARTIAL = 9,
STOP_REASON_FUNCTION_CALL = 10,
STOP_REASON_CONTENT_FILTER = 11,
}

[global::ProtoBuf.ProtoContract()]
Expand Down
Loading