Skip to content

Commit 46b6638

Browse files
author
Jefferson Pires
committed
- Added support for OSX-arm64 with `libgit2-a2bde63.dylib
- Updated README.md with release notes for version 2.6.0, introducing the "Generate Git Changes Comment" command and improvements to command results. - Added `git.png resource for UI representation of Git functionality. - Updated version to 2.6.0 in `source.extension.vsixmanifest for both VisualChatGPT Studio and VisualChatGPT Studio 2019. - Included `libgit2-a2bde63.dylib in the project output and updated package references to include `LibGit2Sharp and its native binaries. - Modified `AddSummaryForAll.cs to remove code tags from OpenAI responses. - Refactored `BaseGenericCommand.cs to simplify code and added a method to determine if a command is a code-related command. - Updated `TerminalWindowCommand.cs to support removing code tags from OpenAI responses. - Added a new option in `OptionPageGrid.cs for the "Generate Git Changes Comment" command. - Enhanced `TerminalWindow and its control to support the new Git comment generation feature, including UI updates and logic to handle Git changes. - Added `GitChangesComment.cs utility class for generating comments based on Git changes. - Updated `TextFormat.cs with a method to remove code tags from OpenAI responses. - Included `GitChangesComment.cs in the shared project items.
1 parent 9fa7cc2 commit 46b6638

20 files changed

+216
-53
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ You can check your quota here: [https://platform.openai.com/account/usage](https
181181

182182
## Release Notes 📜
183183

184-
### 2.5.3
184+
### 2.6.0
185185

186-
- Improvements for the Add Tests, Complete and Optimize commands result. In most cases will only write the code from OpenAI responses, ignoring any additional comments that could come with the OpenAI response. Work better when "Single Response" option is on.
186+
- Added the new "Generate Git Changes Comment" Command on the Visual chatGPT Studio Tool Window.
187+
- Improvements for the Add Summary, Add Tests, Complete and Optimize commands result. In most cases will only write the code from OpenAI responses, ignoring any additional comments that could come with the OpenAI response. Work better when "Single Response" option is on.
187188

188189
### 2.5.2
189190

Resources/git.png

1.56 KB
Loading

VisualChatGPTStudio.csproj

+23
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
</Compile>
6565
</ItemGroup>
6666
<ItemGroup>
67+
<Content Include="lib\osx-arm64\libgit2-a2bde63.dylib">
68+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
69+
<IncludeInVSIX>true</IncludeInVSIX>
70+
</Content>
6771
<None Include="README-zh.md" />
6872
<None Include="README.md" />
6973
<None Include="source.extension.vsixmanifest">
@@ -102,6 +106,12 @@
102106
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.507" ExcludeAssets="Runtime">
103107
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
104108
</PackageReference>
109+
<PackageReference Include="LibGit2Sharp">
110+
<Version>0.29.0</Version>
111+
</PackageReference>
112+
<PackageReference Include="LibGit2Sharp.NativeBinaries">
113+
<Version>2.0.321</Version>
114+
</PackageReference>
105115
<PackageReference Include="Microsoft.CodeAnalysis.CSharp">
106116
<Version>4.7.0</Version>
107117
</PackageReference>
@@ -169,6 +179,19 @@
169179
<Resource Include="Resources\edit_color.png" />
170180
<Resource Include="Resources\garbage_color.png" />
171181
<Resource Include="Resources\close.png" />
182+
<Content Include="lib\win32\arm64\git2-a2bde63.dll">
183+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
184+
<IncludeInVSIX>true</IncludeInVSIX>
185+
</Content>
186+
<Content Include="lib\win32\x64\git2-a2bde63.dll">
187+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
188+
<IncludeInVSIX>true</IncludeInVSIX>
189+
</Content>
190+
<Content Include="lib\win32\x86\git2-a2bde63.dll">
191+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
192+
<IncludeInVSIX>true</IncludeInVSIX>
193+
</Content>
194+
<Resource Include="Resources\git.png" />
172195
<Content Include="Resources\Icon.png">
173196
<IncludeInVSIX>true</IncludeInVSIX>
174197
</Content>

VisualChatGPTStudio2019/VisualChatGPTStudio2019.csproj

+29
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
</Compile>
6868
</ItemGroup>
6969
<ItemGroup>
70+
<Content Include="..\lib\osx-arm64\libgit2-a2bde63.dylib">
71+
<Link>lib\osx-arm64\libgit2-a2bde63.dylib</Link>
72+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
73+
<IncludeInVSIX>true</IncludeInVSIX>
74+
</Content>
7075
<None Include="..\README.md">
7176
<Link>README.md</Link>
7277
</None>
@@ -102,6 +107,12 @@
102107
<Version>16.0.507</Version>
103108
</PackageReference>
104109
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
110+
<PackageReference Include="LibGit2Sharp">
111+
<Version>0.29.0</Version>
112+
</PackageReference>
113+
<PackageReference Include="LibGit2Sharp.NativeBinaries">
114+
<Version>2.0.321</Version>
115+
</PackageReference>
105116
<PackageReference Include="Microsoft.CodeAnalysis.CSharp">
106117
<Version>4.7.0</Version>
107118
</PackageReference>
@@ -135,6 +146,21 @@
135146
<Resource Include="..\Resources\addSummaryForAll.png">
136147
<Link>Resources\addSummaryForAll.png</Link>
137148
</Resource>
149+
<Content Include="..\lib\win32\arm64\git2-a2bde63.dll">
150+
<Link>lib\win32\arm64\git2-a2bde63.dll</Link>
151+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
152+
<IncludeInVSIX>true</IncludeInVSIX>
153+
</Content>
154+
<Content Include="..\lib\win32\x64\git2-a2bde63.dll">
155+
<Link>lib\win32\x64\git2-a2bde63.dll</Link>
156+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
157+
<IncludeInVSIX>true</IncludeInVSIX>
158+
</Content>
159+
<Content Include="..\lib\win32\x86\git2-a2bde63.dll">
160+
<Link>lib\win32\x86\git2-a2bde63.dll</Link>
161+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
162+
<IncludeInVSIX>true</IncludeInVSIX>
163+
</Content>
138164
<Content Include="..\Resources\cancelCommand.png">
139165
<Link>Resources\cancelCommand.png</Link>
140166
</Content>
@@ -204,6 +230,9 @@
204230
<Resource Include="..\Resources\close.png">
205231
<Link>Resources\close.png</Link>
206232
</Resource>
233+
<Resource Include="..\Resources\git.png">
234+
<Link>Resources\git.png</Link>
235+
</Resource>
207236
<Content Include="Icon2019.png">
208237
<IncludeInVSIX>true</IncludeInVSIX>
209238
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

VisualChatGPTStudio2019/source.extension.vsixmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<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">
33
<Metadata>
4-
<Identity Id="VisualChatGPTStudio2019.4854bc98-735d-4622-a0cf-30454b50aa0f" Version="2.5.2" Language="en-US" Publisher="Jefferson Pires" />
4+
<Identity Id="VisualChatGPTStudio2019.4854bc98-735d-4622-a0cf-30454b50aa0f" Version="2.6.0" Language="en-US" Publisher="Jefferson Pires" />
55
<DisplayName>Visual chatGPT Studio 2019</DisplayName>
66
<Description xml:space="preserve">Add chatGPT functionalities directly on Visual Studio.</Description>
77
<Icon>Icon2019.png</Icon>

VisualChatGPTStudioShared/Commands/AddSummaryForAll.cs

+2
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ private async System.Threading.Tasks.Task<string> AddSummaryToClassMemberAsync(S
195195

196196
summary = await RequestAsync(code);
197197

198+
summary = TextFormat.RemoveCodeTagsFromOpenAIResponses(true, summary);
199+
198200
if (string.IsNullOrWhiteSpace(summary))
199201
{
200202
return editedCode;

VisualChatGPTStudioShared/Commands/BaseGenericCommand.cs

+8-40
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using Community.VisualStudio.Toolkit;using JeffPires.VisualChatGPTStudio.ToolWindows.Turbo;
2-
using JeffPires.VisualChatGPTStudio.Utils;using Microsoft.VisualStudio.Shell;using Microsoft.VisualStudio.Text;using System;using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading;
1+
using Community.VisualStudio.Toolkit;using JeffPires.VisualChatGPTStudio.Utils;using Microsoft.VisualStudio.Shell;using Microsoft.VisualStudio.Text;using System;using System.Threading;
62
using System.Windows.Input;using Constants = JeffPires.VisualChatGPTStudio.Utils.Constants;using Span = Microsoft.VisualStudio.Text.Span;namespace JeffPires.VisualChatGPTStudio.Commands{
73
/// <summary>
84
/// Base abstract class for generic commands
@@ -44,7 +40,8 @@
4440
/// Requests a response from ChatGPT and handles the result.
4541
/// </summary>
4642
/// <param name="selectedText">The selected text.</param>
47-
private async System.Threading.Tasks.Task RequestAsync(string selectedText) { string command = GetCommand(selectedText); if (typeof(TCommand) != typeof(AskAnything) && string.IsNullOrWhiteSpace(command)) { await VS.MessageBox.ShowAsync(Constants.EXTENSION_NAME, string.Format(Constants.MESSAGE_SET_COMMAND, typeof(TCommand).Name), buttons: Microsoft.VisualStudio.Shell.Interop.OLEMSGBUTTON.OLEMSGBUTTON_OK); return; } if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) { await TerminalWindowCommand.Instance.RequestToWindowAsync(command, selectedText); return; } await VS.StatusBar.ShowProgressAsync(Constants.MESSAGE_WAITING_CHATGPT, 1, 2); string[] stopSequences = OptionsGeneral.StopSequences.Split(','); if (typeof(TCommand) == typeof(AddSummary)) { stopSequences = new[] { "public", "private", "internal" }; } CancellationTokenSource = new CancellationTokenSource(); if (OptionsGeneral.SingleResponse) { string result = await ChatGPT.GetResponseAsync(OptionsGeneral, command, selectedText, stopSequences, CancellationTokenSource.Token); ResultHandler(result); } else { await ChatGPT.GetResponseAsync(OptionsGeneral, command, selectedText, stopSequences, ResultHandler, CancellationTokenSource.Token); } await FormatDocumentAsync(); }
43+
private async System.Threading.Tasks.Task RequestAsync(string selectedText) { string command = GetCommand(selectedText); if (typeof(TCommand) != typeof(AskAnything) && string.IsNullOrWhiteSpace(command)) { await VS.MessageBox.ShowAsync(Constants.EXTENSION_NAME, string.Format(Constants.MESSAGE_SET_COMMAND, typeof(TCommand).Name), buttons: Microsoft.VisualStudio.Shell.Interop.OLEMSGBUTTON.OLEMSGBUTTON_OK); return; } if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) {
44+
await TerminalWindowCommand.Instance.RequestToWindowAsync(command, selectedText, IsCodeCommand()); return; } await VS.StatusBar.ShowProgressAsync(Constants.MESSAGE_WAITING_CHATGPT, 1, 2); string[] stopSequences = OptionsGeneral.StopSequences.Split(','); if (typeof(TCommand) == typeof(AddSummary)) { stopSequences = new[] { "public", "private", "internal" }; } CancellationTokenSource = new CancellationTokenSource(); if (OptionsGeneral.SingleResponse) { string result = await ChatGPT.GetResponseAsync(OptionsGeneral, command, selectedText, stopSequences, CancellationTokenSource.Token); ResultHandler(result); } else { await ChatGPT.GetResponseAsync(OptionsGeneral, command, selectedText, stopSequences, ResultHandler, CancellationTokenSource.Token); } await FormatDocumentAsync(); }
4845

4946
/// <summary>
5047
/// Handles the result of a command sent to ChatGPT.
@@ -59,7 +56,7 @@
5956
_ = docView.TextBuffer?.Replace(new Span(position, docView.TextView.Selection.StreamSelectionSpan.GetText().Length), String.Empty); } else if (commandType == CommandType.InsertBefore) { position = positionStart; InsertANewLine(false); } else { position = positionEnd; InsertANewLine(true); } if (typeof(TCommand) == typeof(Explain) || typeof(TCommand) == typeof(FindBugs)) { AddCommentChars(); } firstIteration = false; } if (OptionsGeneral.SingleResponse) { result = RemoveBlankLinesFromResult(result); } else if (!responseStarted && (result.Equals("\n") || result.Equals("\r") || result.Equals(Environment.NewLine))) {
6057
//Do nothing when API send only break lines on response begin
6158
return; } responseStarted = true; if (typeof(TCommand) == typeof(AddSummary) && (result.Contains("{") || result.Contains("}"))) { return; } else if (typeof(TCommand) == typeof(Explain) || typeof(TCommand) == typeof(FindBugs)) { result = FormatResultToAddCommentsCharForEachLine(result); }
62-
else if (typeof(TCommand) == typeof(AddTests) || typeof(TCommand) == typeof(Complete) || typeof(TCommand) == typeof(Optimize)) { result = FormatResultForCodeCommands(result); } docView.TextBuffer?.Insert(position, result); position += result.Length;
59+
else if (IsCodeCommand()) { result = TextFormat.RemoveCodeTagsFromOpenAIResponses(OptionsGeneral.SingleResponse, result); } docView.TextBuffer?.Insert(position, result); position += result.Length;
6360
} catch (Exception ex) { Logger.Log(ex); } }
6461

6562
/// <summary>
@@ -105,40 +102,11 @@
105102
return result; }
106103

107104
/// <summary>
108-
/// Formats the result for code commands by extracting the code segments avoiding show additional comments.
109-
/// </summary>
110-
/// <param name="result">The result.</param>
111-
/// <returns>The formatted result for code commands.</returns>
112-
private string FormatResultForCodeCommands(string result)
105+
/// Determines if the generic type TCommand is one of the specified command types.
106+
/// </summary>
107+
private bool IsCodeCommand()
113108
{
114-
if (!OptionsGeneral.SingleResponse)
115-
{
116-
if (result.StartsWith("`"))
117-
{
118-
return string.Empty;
119-
}
120-
121-
return result;
122-
}
123-
124-
List<ChatMessageSegment> segments = TextFormat.GetChatTurboResponseSegments(result);
125-
126-
if (!segments.Any(s => s.Author == AuthorEnum.ChatGPTCode))
127-
{
128-
return result;
129-
}
130-
131-
StringBuilder content = new();
132-
133-
foreach (ChatMessageSegment segment in segments)
134-
{
135-
if (segment.Author == AuthorEnum.ChatGPTCode)
136-
{
137-
content.AppendLine(segment.Content);
138-
}
139-
}
140-
141-
return content.ToString();
109+
return typeof(TCommand) == typeof(AddSummary) || typeof(TCommand) == typeof(AddTests) || typeof(TCommand) == typeof(Complete) || typeof(TCommand) == typeof(Optimize);
142110
} }
143111

144112
/// <summary>

VisualChatGPTStudioShared/Commands/TerminalWindowCommand.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage pac
7777
/// </summary>
7878
/// <param name="command">The command to send to the ChatGPT window.</param>
7979
/// <param name="selectedText">The selected text to be sent.</param>
80-
public async System.Threading.Tasks.Task RequestToWindowAsync(string command, string selectedText)
80+
/// <param name="removeCodeTagsFromOpenAIResponses">Indicates if the code tags from OpenAI responses need to be removed from the result.</param>
81+
public async System.Threading.Tasks.Task RequestToWindowAsync(string command, string selectedText, bool removeCodeTagsFromOpenAIResponses)
8182
{
8283
if (window == null)
8384
{
8485
throw new Exception("Please, open the tool window first.");
8586
}
8687

87-
await window.RequestToWindowAsync(command, selectedText);
88+
await window.RequestToWindowAsync(command, selectedText, removeCodeTagsFromOpenAIResponses);
8889
}
8990

9091
/// <summary>

VisualChatGPTStudioShared/Options/OptionPageGrid.cs

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public class OptionPageGridGeneral : DialogPage
6161
[DefaultValue(false)]
6262
public bool LogResponses { get; set; } = false;
6363

64+
[Category("General")]
65+
[DisplayName("Generate Git Changes Comment Command")]
66+
[Description("Command to request to OpenAI generates a comment based on current repository git changes.")]
67+
[DefaultValue("Based on the changes, write a concise comment for I can use in readme file and/or git changes push comment. Write each change in a new line. Use Markdown format.")]
68+
public string GenerateGitCommentCommand { get; set; } = "Based on the changes, write a concise comment for I can use in readme file and/or git changes push comment. Write each change in a new line. Use Markdown format.";
69+
6470
#endregion General
6571

6672
#region Model Parameters

VisualChatGPTStudioShared/ToolWindows/TerminalWindow/TerminalWindow.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ public void SetTerminalWindowProperties(OptionPageGridGeneral options, Package p
4747
/// </summary>
4848
/// <param name="command">The command to send to the ChatGPT window.</param>
4949
/// <param name="selectedText">The selected text to be sent.</param>
50-
public async System.Threading.Tasks.Task RequestToWindowAsync(string command, string selectedText)
50+
/// <param name="removeCodeTagsFromOpenAIResponses">Indicates if the code tags from OpenAI responses need to be removed from the result.</param>
51+
public async System.Threading.Tasks.Task RequestToWindowAsync(string command, string selectedText, bool removeCodeTagsFromOpenAIResponses)
5152
{
52-
await ((TerminalWindowControl)this.Content).RequestToWindowAsync(command, selectedText);
53+
await ((TerminalWindowControl)this.Content).RequestToWindowAsync(command, selectedText, removeCodeTagsFromOpenAIResponses);
5354
}
5455
}
5556
}

0 commit comments

Comments
 (0)