Skip to content

Commit

Permalink
Introduce InlineCompletionProvider (#9777)
Browse files Browse the repository at this point in the history
This pull request introduces a new `InlineCompletionProvider` trait,
which enables making `Editor` copilot-agnostic and lets us push all the
copilot functionality into the `copilot_ui` module. Long-term, I would
like to merge `copilot` and `copilot_ui`, but right now `project`
depends on `copilot`, which makes this impossible.

The reason for adding this new trait is so that we can experiment with
other inline completion providers and swap them at runtime using config
settings.

Please, note also that we renamed some of the existing copilot actions
to be more agnostic (see release notes below). We still kept the old
actions bound for backwards-compatibility, but we should probably remove
them at some later version.

Also, as a drive-by, we added new methods to the `Global` trait that let
you read or mutate a global directly, e.g.:

```rs
MyGlobal::update(cx, |global, cx| {
});
```

Release Notes:

- Renamed the `copilot::Suggest` action to
`editor::ShowInlineCompletion`
- Renamed the `copilot::NextSuggestion` action to
`editor::NextInlineCompletion`
- Renamed the `copilot::PreviousSuggestion` action to
`editor::PreviousInlineCompletion`
- Renamed the `editor::AcceptPartialCopilotSuggestion` action to
`editor::AcceptPartialInlineCompletion`

---------

Co-authored-by: Nathan <nathan@zed.dev>
Co-authored-by: Kyle <kylek@zed.dev>
Co-authored-by: Kyle Kelley <rgbkrk@gmail.com>
  • Loading branch information
4 people committed Mar 26, 2024
1 parent b8663e5 commit fb6cff8
Show file tree
Hide file tree
Showing 45 changed files with 1,471 additions and 1,137 deletions.
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions assets/keymaps/default-linux.json
Expand Up @@ -140,17 +140,17 @@
}
},
{
"context": "Editor && mode == full && copilot_suggestion",
"context": "Editor && mode == full && inline_completion",
"bindings": {
"alt-]": "copilot::NextSuggestion",
"alt-[": "copilot::PreviousSuggestion",
"alt-right": "editor::AcceptPartialCopilotSuggestion"
"alt-]": "editor::NextInlineCompletion",
"alt-[": "editor::PreviousInlineCompletion",
"alt-right": "editor::AcceptPartialInlineCompletion"
}
},
{
"context": "Editor && !copilot_suggestion",
"context": "Editor && !inline_completion",
"bindings": {
"alt-\\": "copilot::Suggest"
"alt-\\": "editor::ShowInlineCompletion"
}
},
{
Expand Down
12 changes: 6 additions & 6 deletions assets/keymaps/default-macos.json
Expand Up @@ -182,17 +182,17 @@
}
},
{
"context": "Editor && mode == full && copilot_suggestion",
"context": "Editor && mode == full && inline_completion",
"bindings": {
"alt-]": "copilot::NextSuggestion",
"alt-[": "copilot::PreviousSuggestion",
"alt-right": "editor::AcceptPartialCopilotSuggestion"
"alt-]": "editor::NextInlineCompletion",
"alt-[": "editor::PreviousInlineCompletion",
"alt-right": "editor::AcceptPartialInlineCompletion"
}
},
{
"context": "Editor && !copilot_suggestion",
"context": "Editor && !inline_completion",
"bindings": {
"alt-\\": "copilot::Suggest"
"alt-\\": "editor::ShowInlineCompletion"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion assets/keymaps/vim.json
Expand Up @@ -510,7 +510,7 @@
"ctrl-[": "vim::NormalBefore",
"ctrl-x ctrl-o": "editor::ShowCompletions",
"ctrl-x ctrl-a": "assistant::InlineAssist", // zed specific
"ctrl-x ctrl-c": "copilot::Suggest", // zed specific
"ctrl-x ctrl-c": "editor::ShowInlineCompletion", // zed specific
"ctrl-x ctrl-l": "editor::ToggleCodeActions", // zed specific
"ctrl-x ctrl-z": "editor::Cancel",
"ctrl-w": "editor::DeleteToPreviousWordStart",
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant/src/assistant.rs
Expand Up @@ -12,7 +12,7 @@ use chrono::{DateTime, Local};
use client::{proto, Client};
use command_palette_hooks::CommandPaletteFilter;
pub(crate) use completion_provider::*;
use gpui::{actions, AppContext, Global, SharedString};
use gpui::{actions, AppContext, BorrowAppContext, Global, SharedString};
pub(crate) use saved_conversation::*;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsStore};
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant/src/assistant_settings.rs
Expand Up @@ -383,7 +383,7 @@ fn merge<T: Copy>(target: &mut T, value: Option<T>) {

#[cfg(test)]
mod tests {
use gpui::AppContext;
use gpui::{AppContext, BorrowAppContext};
use settings::SettingsStore;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant/src/completion_provider.rs
Expand Up @@ -15,7 +15,7 @@ use crate::{
use anyhow::Result;
use client::Client;
use futures::{future::BoxFuture, stream::BoxStream};
use gpui::{AnyView, AppContext, Task, WindowContext};
use gpui::{AnyView, AppContext, BorrowAppContext, Task, WindowContext};
use settings::{Settings, SettingsStore};
use std::sync::Arc;

Expand Down
2 changes: 1 addition & 1 deletion crates/audio/src/audio.rs
@@ -1,6 +1,6 @@
use assets::SoundRegistry;
use derive_more::{Deref, DerefMut};
use gpui::{AppContext, AssetSource, Global};
use gpui::{AppContext, AssetSource, BorrowAppContext, Global};
use rodio::{OutputStream, OutputStreamHandle};
use util::ResultExt;

Expand Down
3 changes: 2 additions & 1 deletion crates/client/src/client.rs
Expand Up @@ -17,7 +17,8 @@ use futures::{
TryFutureExt as _, TryStreamExt,
};
use gpui::{
actions, AnyModel, AnyWeakModel, AppContext, AsyncAppContext, Global, Model, Task, WeakModel,
actions, AnyModel, AnyWeakModel, AppContext, AsyncAppContext, BorrowAppContext, Global, Model,
Task, WeakModel,
};
use lazy_static::lazy_static;
use parking_lot::RwLock;
Expand Down
2 changes: 1 addition & 1 deletion crates/collab/src/tests/editor_tests.rs
Expand Up @@ -12,7 +12,7 @@ use editor::{
Editor,
};
use futures::StreamExt;
use gpui::{TestAppContext, VisualContext, VisualTestContext};
use gpui::{BorrowAppContext, TestAppContext, VisualContext, VisualTestContext};
use indoc::indoc;
use language::{
language_settings::{AllLanguageSettings, InlayHintSettings},
Expand Down
4 changes: 2 additions & 2 deletions crates/collab/src/tests/following_tests.rs
Expand Up @@ -7,8 +7,8 @@ use collab_ui::{
};
use editor::{Editor, ExcerptRange, MultiBuffer};
use gpui::{
point, BackgroundExecutor, Context, Entity, SharedString, TestAppContext, View, VisualContext,
VisualTestContext,
point, BackgroundExecutor, BorrowAppContext, Context, Entity, SharedString, TestAppContext,
View, VisualContext, VisualTestContext,
};
use language::Capability;
use live_kit_client::MacOSDisplay;
Expand Down
4 changes: 2 additions & 2 deletions crates/collab/src/tests/integration_tests.rs
Expand Up @@ -8,8 +8,8 @@ use collections::{HashMap, HashSet};
use fs::{repository::GitFileStatus, FakeFs, Fs as _, RemoveOptions};
use futures::StreamExt as _;
use gpui::{
px, size, AppContext, BackgroundExecutor, Model, Modifiers, MouseButton, MouseDownEvent,
TestAppContext,
px, size, AppContext, BackgroundExecutor, BorrowAppContext, Model, Modifiers, MouseButton,
MouseDownEvent, TestAppContext,
};
use language::{
language_settings::{AllLanguageSettings, Formatter},
Expand Down
2 changes: 1 addition & 1 deletion crates/command_palette_hooks/src/command_palette_hooks.rs
Expand Up @@ -6,7 +6,7 @@ use std::any::TypeId;

use collections::HashSet;
use derive_more::{Deref, DerefMut};
use gpui::{Action, AppContext, Global};
use gpui::{Action, AppContext, BorrowAppContext, Global};

/// Initializes the command palette hooks.
pub fn init(cx: &mut AppContext) {
Expand Down
8 changes: 8 additions & 0 deletions crates/copilot_ui/Cargo.toml
Expand Up @@ -14,6 +14,7 @@ doctest = false

[dependencies]
anyhow.workspace = true
client.workspace = true
copilot.workspace = true
editor.workspace = true
fs.workspace = true
Expand All @@ -27,4 +28,11 @@ workspace.workspace = true
zed_actions.workspace = true

[dev-dependencies]
copilot = { workspace = true, features = ["test-support"] }
editor = { workspace = true, features = ["test-support"] }
futures.workspace = true
indoc.workspace = true
lsp = { workspace = true, features = ["test-support"] }
project = { workspace = true, features = ["test-support"] }
serde_json.workspace = true
theme = { workspace = true, features = ["test-support"] }

0 comments on commit fb6cff8

Please sign in to comment.