Skip to content

Commit

Permalink
Add more improvements (#749)
Browse files Browse the repository at this point in the history
More cody docs improvements
  • Loading branch information
MaedahBatool authored Nov 5, 2024
1 parent e7289d0 commit 29faa2a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 135 deletions.
60 changes: 16 additions & 44 deletions docs/cody/capabilities/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,26 @@ Promoted Prompts are marked with an icon next to their name and appear at the to

Cody offers quick, ready-to-use **commands** for common actions to write, describe, fix, and smell code. These allow you to run predefined actions with smart context-fetching anywhere in the editor. Like autocomplete and chat, commands will search for context in your codebase to provide more contextually aware and informed answers.

Commands are available in VS Code, JetBrains, and the Sourcegraph web app. Commands can handle tasks like:
Commands are available in VS Code, JetBrains, Visual Studio, and the Sourcegraph web app. Commands can handle tasks like:

- Editing and fixing code `edit`
- Explaining code `explain`
- Generating unit tests `test`
- Writing documentation `doc`
- Improving code quality `smell`

Support for commands may vary by IDE extension. Read the [feature parity reference to learn what commands are available in your IDE](/cody/clients/feature-reference#commands).

<Callout type="note">Cody’s responses to commands are often better than responses to chats since they’ve been pre-packaged and prompt-engineered.</Callout>
- Edit Code
- Document Code
- Explain Code
- Generate Unit Tests
- Find Code Smells

## Running commands

The process of running a command varies from one IDE to another. For example, in VS Code, there are several ways to run a command:

1. Select code in the editor and use the Cody commands sidebar to run a command:

<video width="1920" height="1080" loop playsInline controls style={{ width: '100%', height: 'auto' }}>
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/code-comments-cody-0724.mp4" type="video/mp4" />
</video>
Commands are available in the Cody chat panel under the Prompts drop-down in the editor extensions and on the web. You can run the commands via:

2. Run **Cody: Commands** in the VS Code command palette.
3. Right-click in the editor and select a command in the **Cody** submenu.
1. Select code in the editor and use the Cody commands from the Prompts drop-down to run a command:
2. Right-click in the editor and select a command in the **Cody** submenu.

## Custom commands

<Callout type="info">Custom Commands are currently in Beta and only supported in VS Code.</Callout>

**Custom Commands** allow you to create and define reusable [prompts](#prompts) for Cody tailored to your development workflows. They are defined in `JSON` format and will enable you to call CLI tools, write custom prompts, and select context to be sent to Cody. This provides a flexible way to configure Cody to handle use cases like:
**Custom Commands** allow you to create your own commands for Cody that are tailored to your development workflows. They are defined in `JSON` format and will enable you to call CLI tools, write custom prompts, and select context to be sent to Cody. This provides a flexible way to configure Cody to handle use cases like:

- Integrate with your build system to suggest fixes for errors/warnings in the latest build
- Analyze software dependencies output to explain compatibility or suggest upgrades
Expand All @@ -112,35 +102,26 @@ The process of running a command varies from one IDE to another. For example, in

You can create a custom command by editing the configuration JSON file or using the command builder within the VS Code editor. To access the command builder within VS Code:

- Open the Cody commands menu (**Cody: Commands** in the command palette)
- Select **Custom commands > New Custom Command**
- Enter the name for your new custom command, such as `my-custom-command`.
- Next, write a description for the command. For example, `Compare files in open tabs` or `Explain current directory`
- Go to Cody settings, then select **Custom Commands Settings**
- Select **New Custom Command**
- Enter the name for your new custom command, such as `my-custom-command`
- Choose the method about how the command should be executed
- Provide the relevant instructions for Cody to follow. This is the `prompt` that Cody will use to pass relevant context to the LLM
- Then, select one or more options for the context Cody should use to generate responses
- Finally, choose whether to save the command locally or share it with your workspace
- Press **Enter** to complete the process, and your custom command is successfully created
- You can hit `esc` key at any time to discard a new custom command

### Running Custom Commands

You can invoke custom commands in 2 ways.

- Run **Cody Command: Custom Commands** in the VS Code command palette.
- Right-click in the editor and select **Cody > Custom Commands**.

Then select the command you want to run. If your custom command expects a code selection, be sure to select code in the editor before running the custom command.

### Configuring file paths

Custom Commands can be defined in the following two file paths:

- **User Settings (`~/.vscode/cody.json`)**: Stored locally. Use this for personal commands to use across all your projects
- **Workspace Settings (`.vscode/cody.json`)**: Stored in your project’s repository. Use this to share commands with others working on the same codebase and for project-specific commands

If you select **User Settings**, the new custom command will only be available to you. If you select **Workspace Settings** (as an enterprise user), the custom command will also be available to your teammates.
If you select User Settings, the new custom command will only be available to you. If you choose Workspace Settings (as an enterprise user), your teammates will also be able to use the custom command.

See the [examples](#examples) and [configuration properties](#configuration-properties) below for more details on configuring custom commands.
For more details on configuring custom commands, see the [examples](#examples) and [configuration properties](#configuration-properties) below.

<Accordion title="Custom Commands Examples">

Expand Down Expand Up @@ -338,13 +319,4 @@ See the [examples](#examples) and [configuration properties](#configuration-prop
- Type: `boolean`
- Default: `false`


{/* <!-- ### Defining commands in the `cody.json` file
You can define custom commands for Cody in the `cody.json` file. To make commands only available for a specific project, create the `cody.json` file in that project's `.vscode` directory. When you work on that project, these workspace-specific custom commands will be available.
To make custom commands globally available across multiple projects, create a new `cody.json` file in your home directory's `.vscode` folder. These global custom commands will be available in Cody in any workspace. --> */}

</Accordion>

<Callout type="note">Commands and Custom Commands are soon going to be replaced by [prompts](#prompts) and [Prompt Library](#prompt-library) in the coming future.</Callout>
44 changes: 13 additions & 31 deletions docs/cody/capabilities/debug-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,41 @@ Cody is optimized to identify and fix errors in your code. Its debugging capabil

When you encounter a code error, you can use the chat interface and ask Cody about it. You can paste the faulty code snippets directly in the chat window, and Cody will provide a fix.

The suggestions can be a corrected code snippet that you can copy and paste into your code. Or you can ask a follow-up question for additional context to help you debug the code further. Moreover, you can also paste an error message in chat and ask Cody to provide you with a list of possible solutions.
The suggestions can be a corrected code snippet you can copy and paste into your code. Or you can ask a follow-up question for additional context to help debug the code. Moreover, you can paste an error message in the chat and ask Cody to provide a list of possible solutions.

Let's look at a simple example to understand how Cody can help you debug your code. The following code snippet should print the sum of two numbers.

```js
function sum(a, b) {
var result = a + b;
console.log('The sum is: ' + $result);
var result = a + b;
console.log('The sum is: ' + $result);
}

sum(3 , 4);
```

When you try to `console.log` the `result`, it does not print the correct summed value. Cody can help you both identify the error and provide a solution to fix it. Let's debug the code snippet. Paste the code snippet inside the Cody chat window and ask Cody to fix it.

<video width="1920" height="1080" loop playsInline controls style={{ width: '100%', height: 'auto' }}>
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/fix-code.mp4" type="video/mp4" />
</video>
<video width="1920" height="1080" loop playsInline controls style={{ width: '100%', height: 'auto' }}>
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/fix-code.mp4" type="video/mp4" />
</video>

In addition, Cody helps you reduce the chances of getting syntax and typo errors. The Cody IDE extensions provide context-aware suggestions based on your codebase, helping you avoid common mistakes and reduce your debugging time.
In addition, Cody helps you reduce the chances of getting syntax and typo errors. The Cody IDE extensions provide context-aware suggestions based on your codebase, helping you avoid common mistakes and reduce debugging time.

## Detecting code smell

Cody can detect early code smells to ensure coding best practices and quality and provide suggestions to improve your code. By detecting such potential errors early on, you can avoid scalability and code maintainability issues that might arise in the future.

VS Code users can detect code smells by the `/smell` command, and JetBrains users can achieve the same by clicking the **Smell Code** button from the **Commands** tab.

Let's identify code smells on the same function from the previous example.

<video width="1920" height="1080" loop playsInline controls style={{ width: '100%', height: 'auto' }}>
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/code-smells.mp4" type="video/mp4" />
</video>


As you can see, Cody not only detects code smells but also provides suggestions to improve your code.
You can detect code smells by the **Find Code Smells** command from the Prompts drop-down menu in the chat panel.

## Code Actions

Cody VS Code extension users also get to use the **Code Actions** feature whenever there's an error in code syntax. When you make a mistake while writing code, Cody's Code Actions come into play, and a red warning triggers. Along this appears a lightbulb icon.

### How Code Actions work
<Callout type="info">Code Actions are available onlyin Cody VS Code extension.</Callout>

Let's assume there's an error in the code, and the red warning triggers. Now follow these steps:
When you make a mistake while writing code, Cody's **Code Actions** come into play and a red warning triggers. Along with this, you get a lightbulb icon. If you click on this lightbulb icon, there is an **Ask Cody to fix** option.

- Click this lightbulb icon in the project file
- Click the lightbulb icon in the project file
- Select **Ask Cody to fix** option
- **Cody is working** notice will appear and provide a quick fix with options for **Edits Applied**, **Retry**, **Undo**, and **Done**
- If you are satisfied with the fix, click **Edits Applied**
- To verify the applied changes, you can see a diff view of the fix in a new tab
- If you are not satisfied with the fix, you can **Retry** or **Undo** the changes

Here's a demo that shows how Code Actions work:
- **Cody is working** notice will appear and provide a quick fix that you can **Accept**, **Reject**, or **Open Diff** view to see the changes

<video width="1920" height="1080" loop playsInline controls style={{ width: '100%', height: 'auto' }}>
<source src="https://storage.googleapis.com/sourcegraph-assets/Docs/Media/code-actions.mp4" type="video/mp4" />
</video>
![code-actions](https://storage.googleapis.com/sourcegraph-assets/Docs/cody-code-actions-vscode-1124.png)
28 changes: 20 additions & 8 deletions docs/cody/capabilities/openctx.mdx
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
# OpenCtx Context Providers

<p className="subtitle">Use additional context sources from outside of your code base by leveraging OpenCtx Providers.</p>
<p className="subtitle">Use additional context sources from outside of your codebase by leveraging OpenCtx providers.</p>

## Enable
<Callout type="info">OpenCtx context providers are in the Experimental stage for all Cody users. Enterprise users can also use this, but with limited support. If you have feedback or questions, please visit our [support forum](https://community.sourcegraph.com/c/openctx/10).</Callout>

This feature is available in the Cody VS Code extension. In the Cody Settings, check the box for **OpenCtx: enable**. This will enable OpenCtx. **There is no need to install the OpenCtx extension; Cody comes with OpenCtx built-in.**
[OpenCtx](https://openctx.org/) is an open standard for bringing contextual info about code into your dev tools. Cody Free and Pro users can use OpenCtx providers to fetch and use context from the following sources:

## Configuration
- [Webpages](https://openctx.org/docs/providers/web) (via URL)
- [Jira tickets](https://openctx.org/docs/providers/jira)
- [Linear issues](https://openctx.org/docs/providers/linear-issues)
- [Notion pages](https://openctx.org/docs/providers/notion)
- [Google Docs](https://openctx.org/docs/providers/google-docs)
- [Sourcegraph code search](https://openctx.org/docs/providers/sourcegraph-search)

OpenCtx Providers are added via your `settings.json` file in VS Code. The configuration looks something like this:
## Enable OpenCtx context providers

<Callout type="note">OpenCtx context providers are only supported with Cody VS Code extension.</Callout>

To try OpenCtx context providers with Cody, you must add to your VS Code extension settings. Go to Cody Settings, and check the box for **OpenCtx: Enable**. This will enable OpenCtx. You don't need the OpenCtx VS Code extension to use context fetching with OpenCtx. You should uninstall the extension before using this feature in Cody.

For example, to use the [DevDocs provider](https://openctx.org/docs/providers/devdocs), add the following to your `settings.json`:

```json
"openctx.providers": {
// ...other providers...
"https://openctx.org/npm/@openctx/provider-devdocs": true,
"https://openctx.org/npm/@openctx/provider-devdocs": {
"urls": ["https://devdocs.io/go/", "https://devdocs.io/angular~16/"]
}
},
```

Please refer to the [context providers documentation](https://openctx.org/) for instructions and examples of configuring other providers such as Confluence, Jira, GitHub, Slack, Notion, Linear Issues, Linear Docs, Google Docs, and more.
Please refer to the [context providers docs](https://openctx.org/) for instructions and examples of configuring other providers such as Confluence, Jira, GitHub, Slack, Notion, Linear Issues, Linear Docs, Google Docs, and more.
4 changes: 2 additions & 2 deletions docs/cody/capabilities/supported-models.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Supported LLMs

## Chat and Commands
## Chat and Prompts

Cody supports a variety of cutting-edge large language models for use in Chat and Commands, allowing you to select the best model for your use case.
Cody supports a variety of cutting-edge large language models for use in chat and prompts, allowing you to select the best model for your use case.

<Callout type="note">Newer versions of Sourcegraph Enterprise, starting from v5.6, it will be even easier to add support for new models and providers, see [Model Configuration](/cody/clients/model-configuration) for more information.</Callout>

Expand Down
Loading

0 comments on commit 29faa2a

Please sign in to comment.