-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General refactor and unit tests generation feature (#1)
* chore: First tests generation implementation (wip) * chore: refactoring * chore: refactored tests prompt, increased version * chore: progress message revision * Added license file and set manifest variables * Added changelog; updated manifest
- Loading branch information
1 parent
02d319f
commit e5e3589
Showing
24 changed files
with
410 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### v1.5.0 Unit tests generation | ||
--- | ||
- General refactor; implemented unit tests generation (fc8af9b) | ||
|
||
### v1.0.0 First release | ||
--- | ||
- First release; code writing and refactor functions enabled (02d319f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Emiliano Musso | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using EntwineLlm.Enums; | ||
using EntwineLlm.Helpers; | ||
using Microsoft.VisualStudio.Shell; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace EntwineLlm.Commands | ||
{ | ||
internal class BaseCommand | ||
{ | ||
public AsyncPackage package; | ||
|
||
public string ActiveDocumentPath; | ||
|
||
public BaseCommand(AsyncPackage package) | ||
{ | ||
this.package = package ?? throw new ArgumentNullException(nameof(package)); | ||
} | ||
|
||
public string GetCurrentMethodCode() | ||
{ | ||
ThreadHelper.ThrowIfNotOnUIThread(); | ||
|
||
if (!(Package.GetGlobalService(typeof(EnvDTE.DTE)) is EnvDTE.DTE dte)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var activeDocument = dte.ActiveDocument; | ||
if (activeDocument == null) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
if (!(activeDocument.Selection is EnvDTE.TextSelection textSelection)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
ActiveDocumentPath = dte.ActiveDocument.FullName; | ||
return textSelection.Text; | ||
} | ||
|
||
public async Task PerformRefactoringSuggestionAsync(RequestedCodeType codeType) | ||
{ | ||
var message = "Waiting for LLM response (task requested: " + Enum.GetName(typeof(RequestedCodeType), codeType) + ") ..."; | ||
|
||
var progressBarHelper = new ProgressBarHelper(ServiceProvider.GlobalProvider); | ||
progressBarHelper.StartIndeterminateDialog(message); | ||
|
||
var methodCode = GetCurrentMethodCode(); | ||
var refactoringHelper = new RefactoringHelper(package); | ||
await refactoringHelper.RequestCodeSuggestionsAsync(methodCode, ActiveDocumentPath, codeType); | ||
|
||
progressBarHelper.StopDialog(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using EntwineLlm.Commands; | ||
using EntwineLlm.Commands.Interfaces; | ||
using Microsoft.VisualStudio.Shell; | ||
using System; | ||
|
||
namespace EntwineLlm | ||
{ | ||
internal sealed class GenerateTestsCommand : BaseCommand, IBaseCommand | ||
{ | ||
public int Id | ||
{ | ||
get | ||
{ | ||
return 251; | ||
} | ||
} | ||
|
||
public GenerateTestsCommand(AsyncPackage package) : base(package) { } | ||
|
||
public void Execute(object sender, EventArgs e) | ||
{ | ||
_ = PerformRefactoringSuggestionAsync(Enums.RequestedCodeType.Test); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace EntwineLlm.Commands.Interfaces | ||
{ | ||
internal interface IBaseCommand | ||
{ | ||
int Id { get; } | ||
void Execute(object sender, EventArgs e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,25 @@ | ||
using EntwineLlm.Helpers; | ||
using EntwineLlm.Commands; | ||
using EntwineLlm.Commands.Interfaces; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
using System; | ||
using System.ComponentModel.Design; | ||
using System.Threading.Tasks; | ||
using Task = System.Threading.Tasks.Task; | ||
|
||
namespace EntwineLlm | ||
{ | ||
internal sealed class RequestRefactorCommand | ||
internal sealed class RequestRefactorCommand : BaseCommand, IBaseCommand | ||
{ | ||
public const int CommandId = 256; | ||
|
||
public static readonly Guid CommandSet = new Guid("714b6862-aad7-434e-8415-dd928555ba0e"); | ||
|
||
private readonly AsyncPackage package; | ||
|
||
private static string _activeDocumentPath; | ||
|
||
private RequestRefactorCommand(AsyncPackage package, OleMenuCommandService commandService) | ||
{ | ||
this.package = package ?? throw new ArgumentNullException(nameof(package)); | ||
commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); | ||
|
||
var menuCommandID = new CommandID(CommandSet, CommandId); | ||
var menuItem = new MenuCommand(this.Execute, menuCommandID); | ||
commandService.AddCommand(menuItem); | ||
} | ||
|
||
public static RequestRefactorCommand Instance { get; private set; } | ||
|
||
public static async Task InitializeAsync(AsyncPackage package) | ||
public int Id | ||
{ | ||
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); | ||
|
||
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; | ||
Instance = new RequestRefactorCommand(package, commandService); | ||
} | ||
|
||
private void Execute(object sender, EventArgs e) | ||
{ | ||
_ = PerformRefactoringSuggestionAsync(); | ||
} | ||
|
||
private async Task PerformRefactoringSuggestionAsync() | ||
{ | ||
var progressBarHelper = new ProgressBarHelper(ServiceProvider.GlobalProvider); | ||
progressBarHelper.StartIndeterminateDialog(); | ||
|
||
var methodCode = GetCurrentMethodCode(); | ||
var refactoringHelper = new RefactoringHelper(package); | ||
await refactoringHelper.RequestAndShowRefactoringSuggestionAsync(methodCode, _activeDocumentPath); | ||
|
||
progressBarHelper.StopDialog(); | ||
} | ||
|
||
private static string GetCurrentMethodCode() | ||
{ | ||
ThreadHelper.ThrowIfNotOnUIThread(); | ||
|
||
if (!(Package.GetGlobalService(typeof(EnvDTE.DTE)) is EnvDTE.DTE dte)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var activeDocument = dte.ActiveDocument; | ||
if (activeDocument == null) | ||
get | ||
{ | ||
return string.Empty; | ||
return 250; | ||
} | ||
|
||
if (!(activeDocument.Selection is EnvDTE.TextSelection textSelection)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
_activeDocumentPath = dte.ActiveDocument.FullName; | ||
return textSelection.Text; | ||
} | ||
|
||
public async Task<ToolWindowPane> ShowToolWindowAsync() | ||
{ | ||
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); | ||
var window = await package.FindToolWindowAsync(typeof(RefactorSuggestionWindow), 0, true, package.DisposalToken); | ||
if (window == null || window.Frame == null) | ||
{ | ||
throw new NotSupportedException("Cannot create window"); | ||
} | ||
public RequestRefactorCommand(AsyncPackage package) : base(package) { } | ||
|
||
var windowFrame = (IVsWindowFrame)window.Frame; | ||
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); | ||
return window; | ||
public void Execute(object sender, EventArgs e) | ||
{ | ||
_ = PerformRefactoringSuggestionAsync(Enums.RequestedCodeType.Refactor); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using EntwineLlm.Commands.Interfaces; | ||
using Microsoft.VisualStudio.Shell; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Design; | ||
using System.Threading.Tasks; | ||
|
||
namespace EntwineLlm | ||
{ | ||
internal class CommandsMenu | ||
{ | ||
private static readonly Guid CommandSet = new Guid("714b6862-aad7-434e-8415-dd928555ba0e"); | ||
private OleMenuCommandService CommandService; | ||
|
||
public OleMenuCommandService Service | ||
{ | ||
get | ||
{ | ||
return CommandService; | ||
} | ||
} | ||
|
||
public async Task InitializeAsync(AsyncPackage package) | ||
{ | ||
CommandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; | ||
} | ||
|
||
public void AddCommand(IBaseCommand command) | ||
{ | ||
var menuCommandID = new CommandID(CommandSet, command.Id); | ||
var menuItem = new MenuCommand(command.Execute, menuCommandID); | ||
CommandService.AddCommand(menuItem); | ||
} | ||
|
||
public void AddCommands(IEnumerable<IBaseCommand> commands) | ||
{ | ||
foreach (var command in commands) | ||
{ | ||
AddCommand(command); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.