From 29c9f0f6a1879ac9bdacfa044f821ad46b68b2b9 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Nov 2024 16:51:13 -0500 Subject: [PATCH] Extract `InlineCompletionProvider` to its own crate (#20935) This PR extracts the `InlineCompletionProvider` trait and its related types out of `editor` and into a new `inline_completion` crate. By doing so we're able to remove a dependency on `editor` from the `copilot` and `supermaven` crates. We did have to move `editor::Direction` into the `inline_completion` crate, as it is referenced by the `InlineCompletionProvider`. This should find a better home, at some point. Release Notes: - N/A --- Cargo.lock | 13 +++++++++++++ Cargo.toml | 2 ++ crates/copilot/Cargo.toml | 8 ++++---- .../copilot/src/copilot_completion_provider.rs | 2 +- crates/editor/Cargo.toml | 1 + crates/editor/src/editor.rs | 10 ++-------- crates/inline_completion/Cargo.toml | 18 ++++++++++++++++++ crates/inline_completion/LICENSE-GPL | 1 + .../src/inline_completion.rs} | 11 ++++++++++- crates/supermaven/Cargo.toml | 6 +++--- .../src/supermaven_completion_provider.rs | 2 +- 11 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 crates/inline_completion/Cargo.toml create mode 120000 crates/inline_completion/LICENSE-GPL rename crates/{editor/src/inline_completion_provider.rs => inline_completion/src/inline_completion.rs} (93%) diff --git a/Cargo.lock b/Cargo.lock index c0f9fd746ff655d4fd990ca75bc394ae128f3171..c27b9b303c05a748e796b33fa819261ce5f38b3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2876,6 +2876,7 @@ dependencies = [ "gpui", "http_client", "indoc", + "inline_completion", "language", "lsp", "menu", @@ -3721,6 +3722,7 @@ dependencies = [ "gpui", "http_client", "indoc", + "inline_completion", "itertools 0.13.0", "language", "linkify", @@ -6056,6 +6058,16 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "inline_completion" +version = "0.1.0" +dependencies = [ + "gpui", + "language", + "project", + "text", +] + [[package]] name = "inline_completion_button" version = "0.1.0" @@ -11781,6 +11793,7 @@ dependencies = [ "futures 0.3.31", "gpui", "http_client", + "inline_completion", "language", "log", "postage", diff --git a/Cargo.toml b/Cargo.toml index 98922a7ca22a879fae91b8cfc4507c0235f20460..252549d1164103b56798cb384e9522ec369c0f1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ members = [ "crates/http_client", "crates/image_viewer", "crates/indexed_docs", + "crates/inline_completion", "crates/inline_completion_button", "crates/install_cli", "crates/journal", @@ -221,6 +222,7 @@ html_to_markdown = { path = "crates/html_to_markdown" } http_client = { path = "crates/http_client" } image_viewer = { path = "crates/image_viewer" } indexed_docs = { path = "crates/indexed_docs" } +inline_completion = { path = "crates/inline_completion" } inline_completion_button = { path = "crates/inline_completion_button" } install_cli = { path = "crates/install_cli" } journal = { path = "crates/journal" } diff --git a/crates/copilot/Cargo.toml b/crates/copilot/Cargo.toml index 2a54497562a243c0ff6dab735dc13f6ae5e515c2..2cbe76c16ec4b36f4e3ef135f32c95cd69b7477e 100644 --- a/crates/copilot/Cargo.toml +++ b/crates/copilot/Cargo.toml @@ -29,14 +29,14 @@ anyhow.workspace = true async-compression.workspace = true async-tar.workspace = true chrono.workspace = true -collections.workspace = true client.workspace = true +collections.workspace = true command_palette_hooks.workspace = true -editor.workspace = true fs.workspace = true futures.workspace = true gpui.workspace = true http_client.workspace = true +inline_completion.workspace = true language.workspace = true lsp.workspace = true menu.workspace = true @@ -44,12 +44,12 @@ node_runtime.workspace = true parking_lot.workspace = true paths.workspace = true project.workspace = true +schemars = { workspace = true, optional = true } serde.workspace = true serde_json.workspace = true -schemars = { workspace = true, optional = true } -strum.workspace = true settings.workspace = true smol.workspace = true +strum.workspace = true task.workspace = true ui.workspace = true util.workspace = true diff --git a/crates/copilot/src/copilot_completion_provider.rs b/crates/copilot/src/copilot_completion_provider.rs index 059d3a4236adc3b05a3ca2b97ab94facc55ea3f9..85fe20f1ae54f469eb9d9f0c95631d162e35ecba 100644 --- a/crates/copilot/src/copilot_completion_provider.rs +++ b/crates/copilot/src/copilot_completion_provider.rs @@ -1,8 +1,8 @@ use crate::{Completion, Copilot}; use anyhow::Result; use client::telemetry::Telemetry; -use editor::{CompletionProposal, Direction, InlayProposal, InlineCompletionProvider}; use gpui::{AppContext, EntityId, Model, ModelContext, Task}; +use inline_completion::{CompletionProposal, Direction, InlayProposal, InlineCompletionProvider}; use language::{ language_settings::{all_language_settings, AllLanguageSettings}, Buffer, OffsetRangeExt, ToOffset, diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index a27ac97d41cad76bed27aea22fbff7e31ab185e2..8d03fa79f07cc504091a794b16488f9f5edc337a 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -46,6 +46,7 @@ git.workspace = true gpui.workspace = true http_client.workspace = true indoc.workspace = true +inline_completion.workspace = true itertools.workspace = true language.workspace = true linkify.workspace = true diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 7f31cdedd3761db8d0135882b00055829abcc6c1..1435681587b3b15c11cb339b6a59fb081d115650 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -28,7 +28,6 @@ mod hover_popover; mod hunk_diff; mod indent_guides; mod inlay_hint_cache; -mod inline_completion_provider; pub mod items; mod linked_editing_ranges; mod lsp_ext; @@ -87,7 +86,8 @@ pub(crate) use hunk_diff::HoveredHunk; use hunk_diff::{diff_hunk_to_display, ExpandedHunks}; use indent_guides::ActiveIndentGuidesState; use inlay_hint_cache::{InlayHintCache, InlaySplice, InvalidationStrategy}; -pub use inline_completion_provider::*; +pub use inline_completion::Direction; +use inline_completion::{InlayProposal, InlineCompletionProvider, InlineCompletionProviderHandle}; pub use items::MAX_TAB_TITLE_LEN; use itertools::Itertools; use language::{ @@ -273,12 +273,6 @@ enum DocumentHighlightRead {} enum DocumentHighlightWrite {} enum InputComposition {} -#[derive(Copy, Clone, PartialEq, Eq)] -pub enum Direction { - Prev, - Next, -} - #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Navigated { Yes, diff --git a/crates/inline_completion/Cargo.toml b/crates/inline_completion/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..237b0ff43ffb499d457e15241ed2b7c400055f49 --- /dev/null +++ b/crates/inline_completion/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "inline_completion" +version = "0.1.0" +edition = "2021" +publish = false +license = "GPL-3.0-or-later" + +[lints] +workspace = true + +[lib] +path = "src/inline_completion.rs" + +[dependencies] +gpui.workspace = true +language.workspace = true +project.workspace = true +text.workspace = true diff --git a/crates/inline_completion/LICENSE-GPL b/crates/inline_completion/LICENSE-GPL new file mode 120000 index 0000000000000000000000000000000000000000..89e542f750cd3860a0598eff0dc34b56d7336dc4 --- /dev/null +++ b/crates/inline_completion/LICENSE-GPL @@ -0,0 +1 @@ +../../LICENSE-GPL \ No newline at end of file diff --git a/crates/editor/src/inline_completion_provider.rs b/crates/inline_completion/src/inline_completion.rs similarity index 93% rename from crates/editor/src/inline_completion_provider.rs rename to crates/inline_completion/src/inline_completion.rs index 1085a6294ef80727be11f984c6d19e0da07b73e7..689bc0317445f6708f6ada5034e5d5e82cfbbe9f 100644 --- a/crates/editor/src/inline_completion_provider.rs +++ b/crates/inline_completion/src/inline_completion.rs @@ -1,9 +1,18 @@ -use crate::Direction; use gpui::{AppContext, Model, ModelContext}; use language::Buffer; use std::ops::Range; use text::{Anchor, Rope}; +// TODO: Find a better home for `Direction`. +// +// This should live in an ancestor crate of `editor` and `inline_completion`, +// but at time of writing there isn't an obvious spot. +#[derive(Copy, Clone, PartialEq, Eq)] +pub enum Direction { + Prev, + Next, +} + pub enum InlayProposal { Hint(Anchor, project::InlayHint), Suggestion(Anchor, Rope), diff --git a/crates/supermaven/Cargo.toml b/crates/supermaven/Cargo.toml index e04d0ef51bbf8311018022e9e2ff132d813986a6..fd0adb0d982998edba189ca1458bbf1f45c287e6 100644 --- a/crates/supermaven/Cargo.toml +++ b/crates/supermaven/Cargo.toml @@ -16,17 +16,17 @@ doctest = false anyhow.workspace = true client.workspace = true collections.workspace = true -editor.workspace = true -gpui.workspace = true futures.workspace = true +gpui.workspace = true +inline_completion.workspace = true language.workspace = true log.workspace = true postage.workspace = true serde.workspace = true serde_json.workspace = true settings.workspace = true -supermaven_api.workspace = true smol.workspace = true +supermaven_api.workspace = true text.workspace = true ui.workspace = true unicode-segmentation.workspace = true diff --git a/crates/supermaven/src/supermaven_completion_provider.rs b/crates/supermaven/src/supermaven_completion_provider.rs index b9185c97627477b519e76bdd8f972898267f9486..5e77cc21ef8e28b6a0d2e67fe3eafcccafe92b78 100644 --- a/crates/supermaven/src/supermaven_completion_provider.rs +++ b/crates/supermaven/src/supermaven_completion_provider.rs @@ -1,9 +1,9 @@ use crate::{Supermaven, SupermavenCompletionStateId}; use anyhow::Result; use client::telemetry::Telemetry; -use editor::{CompletionProposal, Direction, InlayProposal, InlineCompletionProvider}; use futures::StreamExt as _; use gpui::{AppContext, EntityId, Model, ModelContext, Task}; +use inline_completion::{CompletionProposal, Direction, InlayProposal, InlineCompletionProvider}; use language::{language_settings::all_language_settings, Anchor, Buffer, BufferSnapshot}; use std::{ ops::{AddAssign, Range},