- 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
dotnet cake
inside thesrc
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, set CODY_VS_DEV_PORT withsetx CODY_VS_DEV_PORT 3113
- After the
Agent
is built and launched, start the debugger on theVisual Studio
side following the steps above
- 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 processes only
- Note: Not required for
Visual Studio
functionality
- Runtime: .NET 8
- Platform: Cross-platform
- Usage: Exclusively used by Cake build automation system
Please ensure you have the appropriate runtimes installed for the components you intend to work with.
We use Cake as our build automation system. The build script can be found in the build.cake
file. Our building and publishing process includes the following steps:
- Downloading the agent repository
- Selecting the commit for building the agent
- Building the agent
- Copying agent files to the VS extension folder
- Downloading node binary files (x64 and arm64 versions)
- Copying node files to the VS extension folder
- Building the VS extension using MSBuild
- Publishing to the marketplace
Execute these commands from the directory containing the build.cake
file:
Command | Description |
---|---|
dotnet cake |
Download and build agent, download required node files, build extension |
dotnet cake --target Build |
Same as above |
dotnet cake --target Tests |
Run tests from Cody.VisualStudio.Tests |
dotnet cake --target Publish |
Build extension and publish it to the marketplace |
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.
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.