Compare commits

...

1 Commits

Author SHA1 Message Date
Michael Sloan
5d11fc5bc4 Update edit predictions documentation 2025-02-13 04:47:19 -07:00
2 changed files with 124 additions and 37 deletions

View File

@@ -29,8 +29,14 @@ impl Template for KeybindingTemplate {
fn render(&self, context: &PreprocessorContext, args: &HashMap<String, String>) -> String {
let action = args.get("action").map(String::as_str).unwrap_or("");
let macos_binding = context.find_binding("macos", action).unwrap_or_default();
let linux_binding = context.find_binding("linux", action).unwrap_or_default();
let macos_binding = context
.find_binding("macos", action)
.unwrap_or_default()
.replace("\\", "&#92;");
let linux_binding = context
.find_binding("linux", action)
.unwrap_or_default()
.replace("\\", "&#92;");
format!("<kbd class=\"keybinding\">{macos_binding}|{linux_binding}</kbd>")
}
}

View File

@@ -3,11 +3,11 @@
Zed supports two sources for completions:
1. "Code Completions" provided by Language Servers (LSPs) automatically installed by Zed or via [Zed Language Extensions](languages.md).
2. "Edit Predictions" provided by external APIs like [GitHub Copilot](#github-copilot) or [Supermaven](#supermaven).
2. "Edit Predictions" provided by Zed's own Zeta model or by external providers like [GitHub Copilot](#github-copilot) or [Supermaven](#supermaven).
## Code Completions
## Language Server Code Completions {#code-completions}
When there is an appropriate language server available, Zed will by-default provide completions of variable names, functions, and other symbols in the current file. You can disable these by adding the following to your zed settings.json file:
When there is an appropriate language server available, Zed will provide completions of variable names, functions, and other symbols in the current file. You can disable these by adding the following to your Zed `settings.json` file:
```json
"show_completions_on_input": false
@@ -20,51 +20,99 @@ For more information, see:
- [Configuring Supported Languages](./configuring-languages.md)
- [List of Zed Supported Languages](./languages.md).
## Configuring Edit Predictions
## Edit Predictions {#edit-predictions}
### GitHub Copilot
Zed has built-in support for predicting multiple edits at a time via its Zeta model. Clicking "Introducing: Edit Prediction" on the top right will open a brief prompt setting up this feature.
To use GitHub Copilot (enabled by default), add the following to your `settings.json`:
Edit predictions appear as you type, and you can accept them by pressing `tab`. The `tab` key is already used for accepting language server completions and for indenting. In these cases, `alt-tab` is used instead to accept the prediction. When the completions menu is open, holding `alt` will cause it to temporarily disappear in order to view the prediction within the buffer.
On Linux, `alt-tab` is often used by the window manager for switching windows, so `alt-l` is provided as the default binding for accepting predictions. `tab` and `alt-tab` also work, but aren't displayed by default.
{#action editor::AcceptPartialEditPrediction} ({#kb editor::AcceptPartialEditPrediction}) can be used to accept the current edit prediction up to the next word boundary.
todo! document editor::Cancel to discard
See the [Configuring GitHub Copilot](#github-copilot) and [Configuring Supermaven](#supermaven) sections below for configuration of other providers. Only text insertions at the current cursor are supported for these providers, whereas the Zeta model provides multiple predictions including deletions.
## Default Behavior of Tab
The default behavior of `tab` varies based on the context:
* todo!
## Configuring Edit Prediction Keybindings
todo! document `edit_prediction_requires_modifier`
### Keybinding Example: Always Use Alt-Tab
The keybinding example below causes `alt-tab` to always be used instead of sometimes using `tab`. You might want this in order to have just one keybinding to use for accepting edit predictions, since the behavior of `tab` varies based on context.
```json
{
"features": {
"edit_prediction_provider": "copilot"
}
}
{
"context": "Editor && edit_prediction",
"bindings": {
"alt-tab": "editor::AcceptEditPrediction"
}
},
// Bind `tab` back to its original behavior.
{
"context": "Editor",
"bindings": {
"tab": "editor::Tab"
}
},
{
"context": "Editor && showing_completions",
"bindings": {
"tab": "editor::ComposeCompletion"
}
},
```
You should be able to sign-in to GitHub Copilot by clicking on the Copilot icon in the status bar and following the setup instructions.
### Supermaven
To use Supermaven, add the following to your `settings.json`:
If `"vim_mode": true` is set within `settings.json`, then additional bindings are needed after the above to return `tab` to its original behavior:
```json
{
"features": {
"edit_prediction_provider": "supermaven"
}
}
{
"context": "(VimControl && !menu) || vim_mode == replace || vim_mode == waiting",
"bindings": {
"tab": "vim::Tab"
}
},
{
"context": "vim_mode == literal",
"bindings": {
"tab": ["vim::Literal", ["tab", "\u0009"]]
}
},
```
You should be able to sign-in to Supermaven by clicking on the Supermaven icon in the status bar and following the setup instructions.
### Keybinding Example: Displaying Tab and Alt-Tab on Linux
## Using Edit Predictions
While `tab` and `alt-tab` are supported on Linux, `alt-l` is displayed instead. If your window manager does not reserve `alt-tab`, and you would prefer to use `tab` and `alt-tab`, include these bindings in `keymap.json`:
Once you have configured an Edit Prediction provider, you can start using edit predictions completions in your code. Edit predictions will appear as you type, and you can accept them by pressing `tab` or `enter` or hide them by pressing `esc`.
```json
{
"context": "Editor && edit_prediction",
"bindings": {
"alt-tab": "editor::AcceptEditPrediction",
// Optional: This makes the default `alt-l` binding do nothing.
"alt-l": null
}
},
{
"context": "Editor && edit_prediction && !edit_prediction_requires_modifier",
"bindings": {
"tab": "editor::AcceptEditPrediction",
// Optional: This makes the default `alt-l` binding do nothing.
"alt-l": null
}
},
```
There are a number of actions/shortcuts available to interact with edit predictions:
## Disabling Automatic Edit Prediction
- `editor: accept edit prediction` (`tab`): To accept the current edit prediction
- `editor: accept partial edit prediction` (`ctrl-cmd-right`): To accept the current edit prediction up to the next word boundary
- `editor: show edit prediction` (`alt-tab`): Trigger an edit prediction request manually
- `editor: next edit prediction` (`alt-tab`): To cycle to the next edit prediction
- `editor: previous edit prediction` (`alt-shift-tab`): To cycle to the previous edit prediction
### Disabling Edit Prediction
To disable predictions that appear automatically as you type, add the following to your `settings.json`:
To disable predictions that appear automatically as you type, set this within `settings.json`:
```json
{
@@ -72,7 +120,7 @@ To disable predictions that appear automatically as you type, add the following
}
```
You can trigger edit predictions manually by executing `editor: show edit prediction` (`alt-tab`).
You can trigger edit predictions manually by executing {#action editor::ShowEditPrediction} ({#kb editor::ShowEditPrediction}).
You can also add this as a language-specific setting in your `settings.json` to disable edit predictions for a specific language:
@@ -86,6 +134,39 @@ You can also add this as a language-specific setting in your `settings.json` to
}
```
## Configuring GitHub Copilot {#github-copilot}
To use GitHub Copilot, set this within `settings.json`:
```json
{
"features": {
"edit_prediction_provider": "copilot"
}
}
```
You should be able to sign-in to GitHub Copilot by clicking on the Copilot icon in the status bar and following the setup instructions.
Copilot can provide multiple completion alternatives, and these can be navigated with the following actions:
- {#action editor::NextEditPrediction} ({#kb editor::NextEditPrediction}): To cycle to the next edit prediction
- {#action editor::PreviousEditPrediction} ({#kb editor::PreviousEditPrediction}): To cycle to the previous edit prediction
## Configuring Supermaven {#supermaven}
To use Supermaven, set this within `settings.json`:
```json
{
"features": {
"edit_prediction_provider": "supermaven"
}
}
```
You should be able to sign-in to Supermaven by clicking on the Supermaven icon in the status bar and following the setup instructions.
## See also
You may also use the Assistant Panel or the Inline Assistant to interact with language models, see the [assistant](assistant/assistant.md) documentation for more information.