Skip to content

Commit 8e9ee7c

Browse files
tomaszgolebiowskiTomasz Gołębiowski
andauthored
Smart apply (#326)
This PR adds the possibility of dynamically insert code from Cody chat into files in solution. This can be accomplished by using Smart apply, inserting code at cursor or saving code to a new file. Each of these options is available under the code snippet in the chat window. ## Test plan 1. Use chat so that Cody suggests a piece of code 2. Under the code snippet, use the buttons: - Apply - code should be smartly inserted into an already existing file - Insert - code should be inserted in place of the cursor - Save - after selecting the location and file name, it will be created with the suggested code <!-- REQUIRED; info at https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles --> --------- Co-authored-by: Tomasz Gołębiowski <[email protected]>
1 parent 72160a3 commit 8e9ee7c

38 files changed

+1191
-145
lines changed

src/Cody.AgentTester/Cody.AgentTester.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,17 @@
5353
<Compile Include="FakeInfobarNotifications.cs" />
5454
<Compile Include="FakeSecretStorageProvider.cs" />
5555
<Compile Include="FakeServiceProvider.cs" />
56+
<Compile Include="FakeVsEditorAdaptersFactoryService.cs" />
57+
<Compile Include="FakeVsSolution.cs" />
5658
<Compile Include="MemorySettingsProvider.cs" />
5759
<Compile Include="Program.cs" />
5860
<Compile Include="Properties\AssemblyInfo.cs" />
5961
</ItemGroup>
62+
<ItemGroup>
63+
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop">
64+
<Version>3.11.2177</Version>
65+
</PackageReference>
66+
</ItemGroup>
6067
<ItemGroup>
6168
<ProjectReference Include="..\Cody.Core\Cody.Core.csproj">
6269
<Project>{9ff2cc40-78e9-46c8-b2ef-30a1f1be82f2}</Project>
@@ -67,10 +74,5 @@
6774
<Name>Cody.VisualStudio</Name>
6875
</ProjectReference>
6976
</ItemGroup>
70-
<ItemGroup>
71-
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop">
72-
<Version>3.11.2177</Version>
73-
</PackageReference>
74-
</ItemGroup>
7577
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7678
</Project>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using Microsoft.VisualStudio.Editor;
2+
using Microsoft.VisualStudio.Text;
3+
using Microsoft.VisualStudio.Text.Editor;
4+
using Microsoft.VisualStudio.TextManager.Interop;
5+
using Microsoft.VisualStudio.Utilities;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace Cody.AgentTester
13+
{
14+
public class FakeVsEditorAdaptersFactoryService : IVsEditorAdaptersFactoryService
15+
{
16+
public IVsCodeWindow CreateVsCodeWindowAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider)
17+
{
18+
throw new NotImplementedException();
19+
}
20+
21+
public IVsTextBuffer CreateVsTextBufferAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider)
22+
{
23+
throw new NotImplementedException();
24+
}
25+
26+
public IVsTextBuffer CreateVsTextBufferAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider, IContentType contentType)
27+
{
28+
throw new NotImplementedException();
29+
}
30+
31+
public IVsTextBuffer CreateVsTextBufferAdapterForSecondaryBuffer(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider, ITextBuffer secondaryBuffer)
32+
{
33+
throw new NotImplementedException();
34+
}
35+
36+
public IVsTextBufferCoordinator CreateVsTextBufferCoordinatorAdapter()
37+
{
38+
throw new NotImplementedException();
39+
}
40+
41+
public IVsTextView CreateVsTextViewAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider)
42+
{
43+
throw new NotImplementedException();
44+
}
45+
46+
public IVsTextView CreateVsTextViewAdapter(Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider, ITextViewRoleSet roles)
47+
{
48+
throw new NotImplementedException();
49+
}
50+
51+
public IVsTextBuffer GetBufferAdapter(ITextBuffer textBuffer)
52+
{
53+
throw new NotImplementedException();
54+
}
55+
56+
public ITextBuffer GetDataBuffer(IVsTextBuffer bufferAdapter)
57+
{
58+
throw new NotImplementedException();
59+
}
60+
61+
public ITextBuffer GetDocumentBuffer(IVsTextBuffer bufferAdapter)
62+
{
63+
throw new NotImplementedException();
64+
}
65+
66+
public IVsTextView GetViewAdapter(ITextView textView)
67+
{
68+
throw new NotImplementedException();
69+
}
70+
71+
public IWpfTextView GetWpfTextView(IVsTextView viewAdapter)
72+
{
73+
throw new NotImplementedException();
74+
}
75+
76+
public IWpfTextViewHost GetWpfTextViewHost(IVsTextView viewAdapter)
77+
{
78+
throw new NotImplementedException();
79+
}
80+
81+
public void SetDataBuffer(IVsTextBuffer bufferAdapter, ITextBuffer dataBuffer)
82+
{
83+
throw new NotImplementedException();
84+
}
85+
}
86+
}
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
using Microsoft.VisualStudio.Shell.Interop;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Cody.AgentTester
9+
{
10+
public class FakeVsSolution : IVsSolution
11+
{
12+
public int GetProjectEnum(uint grfEnumFlags, ref Guid rguidEnumOnlyThisType, out IEnumHierarchies ppenum)
13+
{
14+
throw new NotImplementedException();
15+
}
16+
17+
public int CreateProject(ref Guid rguidProjectType, string lpszMoniker, string lpszLocation, string lpszName, uint grfCreateFlags, ref Guid iidProject, out IntPtr ppProject)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
22+
public int GenerateUniqueProjectName(string lpszRoot, out string pbstrProjectName)
23+
{
24+
throw new NotImplementedException();
25+
}
26+
27+
public int GetProjectOfGuid(ref Guid rguidProjectID, out IVsHierarchy ppHierarchy)
28+
{
29+
throw new NotImplementedException();
30+
}
31+
32+
public int GetGuidOfProject(IVsHierarchy pHierarchy, out Guid pguidProjectID)
33+
{
34+
throw new NotImplementedException();
35+
}
36+
37+
public int GetSolutionInfo(out string pbstrSolutionDirectory, out string pbstrSolutionFile, out string pbstrUserOptsFile)
38+
{
39+
throw new NotImplementedException();
40+
}
41+
42+
public int AdviseSolutionEvents(IVsSolutionEvents pSink, out uint pdwCookie)
43+
{
44+
throw new NotImplementedException();
45+
}
46+
47+
public int UnadviseSolutionEvents(uint dwCookie)
48+
{
49+
throw new NotImplementedException();
50+
}
51+
52+
public int SaveSolutionElement(uint grfSaveOpts, IVsHierarchy pHier, uint docCookie)
53+
{
54+
throw new NotImplementedException();
55+
}
56+
57+
public int CloseSolutionElement(uint grfCloseOpts, IVsHierarchy pHier, uint docCookie)
58+
{
59+
throw new NotImplementedException();
60+
}
61+
62+
public int GetProjectOfProjref(string pszProjref, out IVsHierarchy ppHierarchy, out string pbstrUpdatedProjref, VSUPDATEPROJREFREASON[] puprUpdateReason)
63+
{
64+
throw new NotImplementedException();
65+
}
66+
67+
public int GetProjrefOfProject(IVsHierarchy pHierarchy, out string pbstrProjref)
68+
{
69+
throw new NotImplementedException();
70+
}
71+
72+
public int GetProjectInfoOfProjref(string pszProjref, int propid, out object pvar)
73+
{
74+
throw new NotImplementedException();
75+
}
76+
77+
public int AddVirtualProject(IVsHierarchy pHierarchy, uint grfAddVPFlags)
78+
{
79+
throw new NotImplementedException();
80+
}
81+
82+
public int GetItemOfProjref(string pszProjref, out IVsHierarchy ppHierarchy, out uint pitemid, out string pbstrUpdatedProjref, VSUPDATEPROJREFREASON[] puprUpdateReason)
83+
{
84+
throw new NotImplementedException();
85+
}
86+
87+
public int GetProjrefOfItem(IVsHierarchy pHierarchy, uint itemid, out string pbstrProjref)
88+
{
89+
throw new NotImplementedException();
90+
}
91+
92+
public int GetItemInfoOfProjref(string pszProjref, int propid, out object pvar)
93+
{
94+
throw new NotImplementedException();
95+
}
96+
97+
public int GetProjectOfUniqueName(string pszUniqueName, out IVsHierarchy ppHierarchy)
98+
{
99+
throw new NotImplementedException();
100+
}
101+
102+
public int GetUniqueNameOfProject(IVsHierarchy pHierarchy, out string pbstrUniqueName)
103+
{
104+
throw new NotImplementedException();
105+
}
106+
107+
public int GetProperty(int propid, out object pvar)
108+
{
109+
throw new NotImplementedException();
110+
}
111+
112+
public int SetProperty(int propid, object var)
113+
{
114+
throw new NotImplementedException();
115+
}
116+
117+
public int OpenSolutionFile(uint grfOpenOpts, string pszFilename)
118+
{
119+
throw new NotImplementedException();
120+
}
121+
122+
public int QueryEditSolutionFile(out uint pdwEditResult)
123+
{
124+
throw new NotImplementedException();
125+
}
126+
127+
public int CreateSolution(string lpszLocation, string lpszName, uint grfCreateFlags)
128+
{
129+
throw new NotImplementedException();
130+
}
131+
132+
public int GetProjectFactory(uint dwReserved, Guid[] pguidProjectType, string pszMkProject, out IVsProjectFactory ppProjectFactory)
133+
{
134+
throw new NotImplementedException();
135+
}
136+
137+
public int GetProjectTypeGuid(uint dwReserved, string pszMkProject, out Guid pguidProjectType)
138+
{
139+
throw new NotImplementedException();
140+
}
141+
142+
public int OpenSolutionViaDlg(string pszStartDirectory, int fDefaultToAllProjectsFilter)
143+
{
144+
throw new NotImplementedException();
145+
}
146+
147+
public int AddVirtualProjectEx(IVsHierarchy pHierarchy, uint grfAddVPFlags, ref Guid rguidProjectID)
148+
{
149+
throw new NotImplementedException();
150+
}
151+
152+
public int QueryRenameProject(IVsProject pProject, string pszMkOldName, string pszMkNewName, uint dwReserved, out int pfRenameCanContinue)
153+
{
154+
throw new NotImplementedException();
155+
}
156+
157+
public int OnAfterRenameProject(IVsProject pProject, string pszMkOldName, string pszMkNewName, uint dwReserved)
158+
{
159+
throw new NotImplementedException();
160+
}
161+
162+
public int RemoveVirtualProject(IVsHierarchy pHierarchy, uint grfRemoveVPFlags)
163+
{
164+
throw new NotImplementedException();
165+
}
166+
167+
public int CreateNewProjectViaDlg(string pszExpand, string pszSelect, uint dwReserved)
168+
{
169+
throw new NotImplementedException();
170+
}
171+
172+
public int GetVirtualProjectFlags(IVsHierarchy pHierarchy, out uint pgrfAddVPFlags)
173+
{
174+
throw new NotImplementedException();
175+
}
176+
177+
public int GenerateNextDefaultProjectName(string pszBaseName, string pszLocation, out string pbstrProjectName)
178+
{
179+
throw new NotImplementedException();
180+
}
181+
182+
public int GetProjectFilesInSolution(uint grfGetOpts, uint cProjects, string[] rgbstrProjectNames, out uint pcProjectsFetched)
183+
{
184+
throw new NotImplementedException();
185+
}
186+
187+
public int CanCreateNewProjectAtLocation(int fCreateNewSolution, string pszFullProjectFilePath, out int pfCanCreate)
188+
{
189+
throw new NotImplementedException();
190+
}
191+
}
192+
}

src/Cody.AgentTester/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Cody.Core.Agent;
22
using Cody.Core.Agent.Protocol;
3+
using Cody.Core.Ide;
34
using Cody.Core.Logging;
45
using Cody.Core.Settings;
56
using Cody.VisualStudio.Client;
@@ -11,7 +12,6 @@
1112
using System.Reflection;
1213
using System.Runtime.InteropServices;
1314
using System.Threading.Tasks;
14-
using Cody.Core.Ide;
1515

1616
namespace Cody.AgentTester
1717
{
@@ -33,11 +33,11 @@ static async Task Main(string[] args)
3333
var logger = new Logger();
3434
var secretStorageService = new SecretStorageService(new FakeSecretStorageProvider(), logger);
3535
var settingsService = new UserSettingsService(new MemorySettingsProvider(), secretStorageService, logger);
36-
var editorService = new FileService(new FakeServiceProvider(), logger);
36+
var documentService = new DocumentService(logger, new FakeServiceProvider(), new FakeVsSolution(), new FakeVsEditorAdaptersFactoryService());
3737
var infobarNotifications = Task.FromResult<IInfobarNotifications>(new FakeInfobarNotifications());
3838
var options = new AgentClientOptions
3939
{
40-
CallbackHandlers = new List<object> { new NotificationHandlers(settingsService, logger, editorService, secretStorageService, infobarNotifications) },
40+
CallbackHandlers = new List<object> { new NotificationHandlers(settingsService, logger, documentService, secretStorageService, infobarNotifications) },
4141
AgentDirectory = "../../../Cody.VisualStudio/Agent",
4242
RestartAgentOnFailure = true,
4343
Debug = true,

0 commit comments

Comments
 (0)