- Install chocolatey - Package Manager for Windows
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
- Install node.js, required for building and running Cody Agent
choco install pnpm --version=8.6.7
- Install Visual Studio Pro with the required component:
- Visual Studio Extension
- Install git for Windows
- Configure it with
git config core.autocrlf false
to not change line endings
- Configure it with
- Install .NET SDK
- Clone this repository:
git clone [email protected]:sourcegraph/cody-vs.git
For Sourcegraph teammates:
- Install UTM and set up Windows 11 following the Testing on Windows docs
- Ask in #ask-it-tech-ops for a Windows 11 Pro and Visual Studio Pro license.
To get started quickly, follow these steps:
- In Visual Studio's Get started page, select
Open a project or solution
- Open the Cody.sln solution file
Note
You must build the agent before debugging for the first time.
- Run
runBuildAgent.ps1
inside theagent
directory to build the agent. - In your Cody project, click
Debug
>Start Debugging
(or pressF5
) to start the debugger - In the new window created by the debugger, open an existing project or create a new project
- Now you can start setting breakpoints and debugging Cody!
- Download and install VS Code on your machine
- Clone the main Cody repository:
git clone [email protected]:sourcegraph/cody.git
- Makes sure the
cody
repository is in the same directory as thecody-vs
repository cd
into thecody
repository and runpnpm install
- Open the
cody
repository in VS Code - After you have set the breakpoints, open the debug panel from selecting
View > Run
- In the drop down menu next to
RUN AND DEBUG
, selectLaunch Agent port 3113
to start the debugger for Agent - To enable
Visual Studio
listening to theAgent
running on Port 3113, opensrc/CodyDevConfig.json
and setRemoteAgentPort
property to3113
- After the
Agent
is built and launched, start the debugger on theVisual Studio
side following the steps above
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
- Open Cody.sln in the Visual Studio
- Select Visual Studio menu Test->Test Explorer
- Right-click on the
Cody.VisualStudio.Tests
, select Run
This project uses different runtimes for various components:
- Runtime: .NET Framework 4.7.2
- Platform: Windows only
- Note: This runtime is typically included with Windows and
Visual Studio
installations.
- Runtime: Node.js
- 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.
Create an account and go to https://sourcegraph.com/user/settings/tokens to create a token.
During development, you can use your own Cody access token by setting an environment variable. This eliminates the need to register and create a new token for each session.
To set your access token:
setx SourcegraphCodyToken YOUR_TOKEN
To display your token:
echo $env:SourcegraphCodyToken
Note
After setting an environment variable, you may need to restart Visual Studio
and any open
command prompts for the changes to take effect.
The token from the environment variable always overrides the value from the user settings and is never saved in the user settings.
To debug the agent:
- Start the agent with the debugger enabled:
node --inspect --enable-source-maps ../cody-dist/agent/dist/index.js api jsonrpc-stdio
- Open Chrome and navigate to
chrome://inspect/
- Click "Open dedicated DevTools for Node"
- Wait for DevTools to detect the new debugging session
Note
Starting to debug the extension in Visual Studio will automatically start the agent with appropriate arguments.
Additional debugging options:
- Use
--inspect-brk
instead of--inspect
to break before user code starts - For more debugging options, refer to the Node.js debugging documentation
See the Releases page for details on how to release a new version of the Cody extension. To understand the issues of release and versioning, refer to versioning
This repository is configured to use line endings for Windows machines. If you encounter issues with files stuck in the Git working tree, you can try one of the following solutions:
- Configure Git to handle line endings: Follow the instructions in the Configuring Git to handle line endings documentation to resolve the issue. This will help Git automatically handle line ending conversions based on your operating system.
- Remove cached files and reset the repository: You can remove all the cached files and reset the repository to the latest state of the main branch by running the following commands in your terminal:
git rm -rf --cached .
git reset --hard origin/main
This will remove all cached files and reset your local repository to match the remote main branch, effectively resolving any line ending-related issues.
The experimental instance in debug mode may keep using the previous version of the extension, which can be resolved by resetting the experimental instance following the instructions in The Experimental Instance docs.
- Developer Docs for Cody
- Developer Docs for Agent
- Visual Studio Extensibility
- Publish an Extension
- dotPeek
- Use dotPeek to decompile the Visual Studio extension to view the source code.