Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 17 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,24 @@ To get started quickly, follow these steps:
5. Open the `cody` repository in VS Code
6. After you have set the breakpoints, open the debug panel from selecting `View > Run`
7. In the drop down menu next to `RUN AND DEBUG`, select `Launch Agent port 3113` to start the debugger for Agent
8. To enable `Visual Studio` listening to the `Agent` running on Port 3113, set CODY_VS_DEV_PORT with `setx CODY_VS_DEV_PORT 3113`
8. To enable `Visual Studio` listening to the `Agent` running on Port 3113, open `src/CodyDevConfig.json` and set `RemoteAgentPort` property to `3113`
9. After the `Agent` is built and launched, start the debugger on the `Visual Studio` side following the steps above

### Developer configuration file
The Cody for Visual Studio project includes a configuration file that allows developers to customize behavior of the extension during development. Features such as tracing, agents verbose logs, debug mode can be activated using this configuration. File is located in the root directory of the solution and is named `CodyDevConfig.json`. During release process the file is removed from extension build which disables all developer settings.
The developer configuration can be applied even for the production version of the extension. To do this you must add `CODY_VS_DEV_CONFIG` environment variable containing the path to the configuration file. The configuration file contains the following properties:
- `AgentDebug`: enables debug messages from agent,
- `AgentVerboseDebug`: enables detailed debug messages from agent,
- `AllowNodeDebug`: starts node instance with debug mode,
- `AgentDirectory`: starts agent from the specified directory containing agent files,
- `RemoteAgentPort`: attach extension to the agent running on the specified port,
- `Trace`: enables trace messages from the extension,
- `TraceFile`: saves trace messages to the specified file,
- `TraceLogioHostname`: sets Logio hostname,
- `TraceLogioPort`: sets Logio port,
- `ShowCodyAgentOutput`: shows agent output in the additional output window,
- `ShowCodyNotificationsOutput`: shows agents notifications in the additional output window

### Running VS Integration Tests + Playwright

1. Open Cody.sln in the Visual Studio
Expand All @@ -73,7 +88,7 @@ This project uses different runtimes for various components:
- **Usage**: Used for build and run agent only
- **Note**: Not required for `Visual Studio` functionality

Please ensure you have the appropriate runtimes installed for the components you intend to work with. |
Please ensure you have the appropriate runtimes installed for the components you intend to work with.

## Access Token

Expand Down
2 changes: 1 addition & 1 deletion agent/agent.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
vscode-v1.44.0
vscode-v1.54.x
2 changes: 2 additions & 0 deletions src/Cody.Core/Cody.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<Compile Include="Agent\Protocol\ResolveWebviewViewParams.cs" />
<Compile Include="Agent\SetHtmlEvent.cs" />
<Compile Include="Agent\WebviewMessageHandler.cs" />
<Compile Include="Common\Configuration.cs" />
<Compile Include="Common\Configuration.Setup.cs" />
<Compile Include="DocumentSync\DocumentSyncCallback.cs" />
<Compile Include="DocumentSync\IDocumentSyncActions.cs" />
<Compile Include="Infrastructure\ConfigurationService.cs" />
Expand Down
60 changes: 60 additions & 0 deletions src/Cody.Core/Common/Configuration.Setup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Cody.Core.Common
{
public static partial class Configuration
{
private static Dictionary<string, object> config = new Dictionary<string, object>();

public static void AddFromJsonFile(string path)
{
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
try
{
var json = File.ReadAllText(path);
var configuration = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
AddFromDictionary(configuration);
}
catch { }
}
}

public static void AddFromEnviromentVariableJsonFile(string variable)
{
var path = Environment.GetEnvironmentVariable(variable);
AddFromJsonFile(path);
}

public static void AddFromDictionary(Dictionary<string, object> dictionary)
{
if (dictionary == null) return;

foreach (var pair in dictionary)
{
if (config.ContainsKey(pair.Key)) config[pair.Key] = pair.Value;
else config.Add(pair.Key, pair.Value);
}
}

private static T Get<T>(T defaultValue, [CallerMemberName] string key = null) => (T)(config.TryGetValue(key, out object value) ? value : defaultValue);


public static bool IsDebug
{
get
{
#if DEBUG
return true;
#else
return false;
#endif
}
}
}
}
31 changes: 31 additions & 0 deletions src/Cody.Core/Common/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;

namespace Cody.Core.Common
{
public static partial class Configuration
{

public static bool AgentDebug => Get(false);

public static bool AgentVerboseDebug => Get(false);

public static bool AllowNodeDebug => Get(false);

public static string AgentDirectory => Get((string)null);

public static int? RemoteAgentPort => Get((int?)null);

public static bool Trace => Get(false);

public static string TraceFile => Get((string)null);

public static string TraceLogioHostname => Get((string)null);

public static int? TraceLogioPort => Get((int?)null);

public static bool ShowCodyAgentOutput => Get(false);

public static bool ShowCodyNotificationsOutput => Get(false);
}
}
5 changes: 3 additions & 2 deletions src/Cody.Core/Infrastructure/ConfigurationService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cody.Core.Agent.Protocol;
using Cody.Core.Common;
using Cody.Core.Ide;
using Cody.Core.Inf;
using Cody.Core.Logging;
Expand Down Expand Up @@ -71,8 +72,8 @@ public ExtensionConfiguration GetConfiguration()
Proxy = null,
AccessToken = _userSettingsService.AccessToken,
AutocompleteAdvancedProvider = null,
Debug = true,
VerboseDebug = true,
Debug = Configuration.AgentDebug,
VerboseDebug = Configuration.AgentVerboseDebug,
CustomConfiguration = GetCustomConfiguration()
};

Expand Down
31 changes: 17 additions & 14 deletions src/Cody.Core/Logging/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Cody.Core.Common;
using System;
using System.IO;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -27,24 +28,26 @@ public void Info(string message, [CallerMemberName] string callerName = "")

public void Debug(string message, [CallerMemberName] string callerName = "", [CallerFilePath] string callerFilePath = null)
{
#if DEBUG
var callerTypeName = Path.GetFileNameWithoutExtension(callerFilePath);
callerName = $"{callerTypeName}.{callerName}";
var customMessage = FormatCallerName(message, callerName);

// TODO: _fileLogger.Debug(customMessage);
DebugWrite(customMessage);
_outputWindowPane?.Debug(message, callerName);
_testLogger?.WriteLog(message, "DEBUG", callerName);
#endif
if (Configuration.IsDebug)
{
var callerTypeName = Path.GetFileNameWithoutExtension(callerFilePath);
callerName = $"{callerTypeName}.{callerName}";
var customMessage = FormatCallerName(message, callerName);

// TODO: _fileLogger.Debug(customMessage);
DebugWrite(customMessage);
_outputWindowPane?.Debug(message, callerName);
_testLogger?.WriteLog(message, "DEBUG", callerName);
}
}

public void Debug(string message, Exception ex, [CallerMemberName] string callerName = "", [CallerFilePath] string callerFilePath = null)
{
#if DEBUG
Debug(message, callerName, callerFilePath);
Error(message, ex, callerName);
#endif
if (Configuration.IsDebug)
{
Debug(message, callerName, callerFilePath);
Error(message, ex, callerName);
}
}

public void Warn(string message, [CallerMemberName] string callerName = "")
Expand Down
5 changes: 2 additions & 3 deletions src/Cody.Core/Logging/SentryLog.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Cody.Core.Common;
using Sentry;
using System;
using System.Diagnostics;
Expand All @@ -19,8 +20,7 @@ public void Error(string message)

public static void Initialize()
{
#if !DEBUG
if (!Debugger.IsAttached)
if (!Configuration.IsDebug && !Debugger.IsAttached)
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
string env = "dev";
Expand All @@ -34,7 +34,6 @@ public static void Initialize()
options.Release = "cody-vs@" + version.ToString();
});
}
#endif
}
}
}
15 changes: 6 additions & 9 deletions src/Cody.UI/Controls/WebView2Dev.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Controls;
using System.Windows.Input;
using Cody.Core.Logging;
using Cody.Core.Common;

namespace Cody.UI.Controls
{
Expand Down Expand Up @@ -84,18 +85,14 @@ private async Task<CoreWebView2Environment> CreateWebView2Environment()
try
{
Logger?.Debug("Initializing ...");
var codyDir = "Cody";
#if DEBUG
codyDir = "Cody\\Debug";
#endif
var codyDir = Configuration.IsDebug ? "Cody\\Debug" : "Cody";

var appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), codyDir);
var options = new CoreWebView2EnvironmentOptions
{
#if DEBUG
AdditionalBrowserArguments =
"--remote-debugging-port=9222 --disable-web-security --allow-file-access-from-files",
AllowSingleSignOnUsingOSPrimaryAccount = true,
#endif
AdditionalBrowserArguments = Configuration.IsDebug ?
"--remote-debugging-port=9222 --disable-web-security --allow-file-access-from-files" : null,
AllowSingleSignOnUsingOSPrimaryAccount = Configuration.IsDebug,
};

var webView2 = await CoreWebView2Environment.CreateAsync(null, appData, options);
Expand Down
9 changes: 3 additions & 6 deletions src/Cody.UI/Controls/WebviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows;
using System.Windows.Input;
using Cody.Core.Logging;
using Cody.Core.Common;

namespace Cody.UI.Controls
{
Expand Down Expand Up @@ -47,13 +48,9 @@ private void ConfigureWebView()
_webview.Settings.AreBrowserAcceleratorKeysEnabled = true;
_webview.Settings.IsGeneralAutofillEnabled = true;
// Enable below settings only in DEBUG mode.
_webview.Settings.AreDefaultContextMenusEnabled = false;
_webview.Settings.AreDevToolsEnabled = false;
_webview.Settings.AreDefaultContextMenusEnabled = Configuration.IsDebug;
_webview.Settings.AreDevToolsEnabled = Configuration.IsDebug;
_webview.Settings.IsStatusBarEnabled = false;
#if DEBUG
_webview.Settings.AreDefaultContextMenusEnabled = true;
_webview.Settings.AreDevToolsEnabled = true;
#endif
}

private void SetupEventHandlers()
Expand Down
14 changes: 6 additions & 8 deletions src/Cody.VisualStudio.Tests/ChatNotLoggedStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public ChatNotLoggedStateTests(ITestOutputHelper output) : base(output)
public async Task Cody_Free_Cody_Pro_Section_Is_Present()
{
// given
var sectionText = "Cody Free or Cody Pro";
var buttonText = "Sign In with GitHub";
var sectionText = "Free or Pro";
var buttonText = "Continue with GitHub";

// then
await NotInLoggedState(async () =>
Expand All @@ -41,25 +41,23 @@ await NotInLoggedState(async () =>
public async Task Cody_Enterprise_Section_Is_Present()
{
// given
var sectionText = "Cody Enterprise";
var browserButtonText = " Sign In with Browser";
var tokenButtonText = " Sign In with Access Token";
var sectionText = "Enterprise";
var browserButtonText = "Continue with a URL";

// then
await NotInLoggedState(async () =>
{
await AssertTextIsPresent(sectionText);
await AssertTextIsPresent(browserButtonText);
await AssertTextIsPresent(tokenButtonText);
});
}

[VsFact(Version = VsVersion.VS2022)]
public async Task Logins_With_GitLab_Google_Are_Present()
{
// given
var gitlabButtonText = "Sign In with GitLab";
var googleButtonText = "Sign In with Google";
var gitlabButtonText = "Continue with GitLab";
var googleButtonText = "Continue with Google";

// then
await NotInLoggedState(async () =>
Expand Down
6 changes: 5 additions & 1 deletion src/Cody.VisualStudio/Cody.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="..\CodyDevConfig.json">
<Link>CodyDevConfig.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="publishManifest.json" />
<None Include="..\..\README.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -99,7 +103,7 @@
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Remove="Agent\index.js.map" Condition="'$(Configuration)' == 'Release'"/>
<Content Remove="Agent\index.js.map" Condition="'$(Configuration)' == 'Release'" />
<Content Include="Agent\webviews\*.*">
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Loading
Loading