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
This commit is contained in:
parent
e076f55d78
commit
29c9f0f6a1
11 changed files with 56 additions and 18 deletions
|
@ -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,
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
use crate::Direction;
|
||||
use gpui::{AppContext, Model, ModelContext};
|
||||
use language::Buffer;
|
||||
use std::ops::Range;
|
||||
use text::{Anchor, Rope};
|
||||
|
||||
pub enum InlayProposal {
|
||||
Hint(Anchor, project::InlayHint),
|
||||
Suggestion(Anchor, Rope),
|
||||
}
|
||||
|
||||
pub struct CompletionProposal {
|
||||
pub inlays: Vec<InlayProposal>,
|
||||
pub text: Rope,
|
||||
pub delete_range: Option<Range<Anchor>>,
|
||||
}
|
||||
|
||||
pub trait InlineCompletionProvider: 'static + Sized {
|
||||
fn name() -> &'static str;
|
||||
fn is_enabled(
|
||||
&self,
|
||||
buffer: &Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
cx: &AppContext,
|
||||
) -> bool;
|
||||
fn refresh(
|
||||
&mut self,
|
||||
buffer: Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
debounce: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
);
|
||||
fn cycle(
|
||||
&mut self,
|
||||
buffer: Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
direction: Direction,
|
||||
cx: &mut ModelContext<Self>,
|
||||
);
|
||||
fn accept(&mut self, cx: &mut ModelContext<Self>);
|
||||
fn discard(&mut self, should_report_inline_completion_event: bool, cx: &mut ModelContext<Self>);
|
||||
fn active_completion_text<'a>(
|
||||
&'a self,
|
||||
buffer: &Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
cx: &'a AppContext,
|
||||
) -> Option<CompletionProposal>;
|
||||
}
|
||||
|
||||
pub trait InlineCompletionProviderHandle {
|
||||
fn is_enabled(
|
||||
&self,
|
||||
buffer: &Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
cx: &AppContext,
|
||||
) -> bool;
|
||||
fn refresh(
|
||||
&self,
|
||||
buffer: Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
debounce: bool,
|
||||
cx: &mut AppContext,
|
||||
);
|
||||
fn cycle(
|
||||
&self,
|
||||
buffer: Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
direction: Direction,
|
||||
cx: &mut AppContext,
|
||||
);
|
||||
fn accept(&self, cx: &mut AppContext);
|
||||
fn discard(&self, should_report_inline_completion_event: bool, cx: &mut AppContext);
|
||||
fn active_completion_text<'a>(
|
||||
&'a self,
|
||||
buffer: &Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
cx: &'a AppContext,
|
||||
) -> Option<CompletionProposal>;
|
||||
}
|
||||
|
||||
impl<T> InlineCompletionProviderHandle for Model<T>
|
||||
where
|
||||
T: InlineCompletionProvider,
|
||||
{
|
||||
fn is_enabled(
|
||||
&self,
|
||||
buffer: &Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
cx: &AppContext,
|
||||
) -> bool {
|
||||
self.read(cx).is_enabled(buffer, cursor_position, cx)
|
||||
}
|
||||
|
||||
fn refresh(
|
||||
&self,
|
||||
buffer: Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
debounce: bool,
|
||||
cx: &mut AppContext,
|
||||
) {
|
||||
self.update(cx, |this, cx| {
|
||||
this.refresh(buffer, cursor_position, debounce, cx)
|
||||
})
|
||||
}
|
||||
|
||||
fn cycle(
|
||||
&self,
|
||||
buffer: Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
direction: Direction,
|
||||
cx: &mut AppContext,
|
||||
) {
|
||||
self.update(cx, |this, cx| {
|
||||
this.cycle(buffer, cursor_position, direction, cx)
|
||||
})
|
||||
}
|
||||
|
||||
fn accept(&self, cx: &mut AppContext) {
|
||||
self.update(cx, |this, cx| this.accept(cx))
|
||||
}
|
||||
|
||||
fn discard(&self, should_report_inline_completion_event: bool, cx: &mut AppContext) {
|
||||
self.update(cx, |this, cx| {
|
||||
this.discard(should_report_inline_completion_event, cx)
|
||||
})
|
||||
}
|
||||
|
||||
fn active_completion_text<'a>(
|
||||
&'a self,
|
||||
buffer: &Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
cx: &'a AppContext,
|
||||
) -> Option<CompletionProposal> {
|
||||
self.read(cx)
|
||||
.active_completion_text(buffer, cursor_position, cx)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue