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 5 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
15 changes: 11 additions & 4 deletions CodeiumVS/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ protected override void BeforeQueryStatus(EventArgs e)

protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
{
await CodeiumVSPackage.Instance.LogAsync("IN WINDOW DILAOG");
Copy link
Collaborator

Choose a reason for hiding this comment

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

might as well spell this right if you're gonna leave it in

// get the caret screen position and create the dialog at that position
TextBounds caretLine = docView.TextView.TextViewLines.GetCharacterBounds(
docView.TextView.Caret.Position.BufferPosition);
Expand All @@ -318,7 +319,7 @@ 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

await CodeiumVSPackage.Instance.LogAsync("IN WINDOW DILAOG1");
var dialog = RefactorCodeDialogWindow.GetOrCreate();
string? prompt =
await dialog.ShowAndGetPromptAsync(languageInfo, caretScreenPos.X, caretScreenPos.Y);
Expand All @@ -330,18 +331,24 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)

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

CodeiumVSPackage.Instance.Log("CALLING refactor");
if (is_function)
{
CodeiumVSPackage.Instance.Log("CALLING FUNC");
FunctionInfo? functionInfo = await GetFunctionInfoAsync();

if (functionInfo != null)
await controller.RefactorFunctionAsync(
prompt, docView.Document.FilePath, functionInfo);
{
CodeiumVSPackage.Instance.Log("CALLING FUNC");
await controller.RefactorFunctionAsync(
prompt, docView.Document.FilePath, functionInfo);
}
}
else
{
CodeiumVSPackage.Instance.Log("CALLING NOIN FUNC");
CodeBlockInfo codeBlockInfo = GetCodeBlockInfo();
CodeiumVSPackage.Instance.Log("CALLING NOIN FUNC2");
await controller.RefactorCodeBlockAsync(
prompt, docView.Document.FilePath, languageInfo.Type, codeBlockInfo);
}
Expand Down
8 changes: 4 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,7 @@ public async Task<IList<CompletionItem>?>
cursor_offset = (ulong)cursorPosition,
line_ending = lineEnding,
absolute_path = absolutePath,
absolute_path_migrate_me_to_uri = absolutePath,
//absolute_path_migrate_me_to_uri = absolutePath,
relative_path = Path.GetFileName(absolutePath) },
editor_options = new() {
tab_size = (ulong)tabSize,
Expand Down
25 changes: 13 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 @@ -248,11 +246,12 @@ await Package.ShowToolWindowAsync(
public async Task RefactorCodeBlockAsync(string prompt, string filePath, Language language,
CodeBlockInfo codeBlockInfo)
{
CodeiumVSPackage.Instance.Log("Calling refactor code block.");
var request = WebChatServer.NewRequest();
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,
//file_path_migrate_me_to_uri = filePath,
language = language,
refactor_description = prompt } };

Expand All @@ -264,17 +263,19 @@ await Package.ShowToolWindowAsync(
public async Task RefactorFunctionAsync(string prompt, string filePath,
FunctionInfo functionInfo)
{
CodeiumVSPackage.Instance.Log("Calling refactor function.");
var request = WebChatServer.NewRequest();
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,
//file_path_migrate_me_to_uri = filePath,
language = functionInfo.Language,
refactor_description = prompt } };

CodeiumVSPackage.Instance.Log("Calling refactor function1.");
if (request.Send(ws))
await Package.ShowToolWindowAsync(
typeof(ChatToolWindow), 0, create: true, Package.DisposalToken);
CodeiumVSPackage.Instance.Log("Calling refactor function2.");
}

public async Task ExplainProblemAsync(string problemMessage, SnapshotSpan span)
Expand Down Expand Up @@ -306,7 +307,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
Loading
Loading