Configures inline completions to delete the remaining text on the given line. This doesn't affect the github copilot inline completion provider since it seems to only generate suggestions if the cursor is at the end of the line but fixes the usability issues related to Supermaven. https://github.com/user-attachments/assets/1b8bc9a3-4666-4665-a436-96e4beee01bb Release Notes: - Fixed https://github.com/zed-industries/zed/issues/13039 --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
126 lines
3.4 KiB
Rust
126 lines
3.4 KiB
Rust
use crate::Direction;
|
|
use gpui::{AppContext, Model, ModelContext};
|
|
use language::Buffer;
|
|
use std::ops::Range;
|
|
|
|
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<(&'a str, Option<Range<language::Anchor>>)>;
|
|
}
|
|
|
|
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<(&'a str, Option<Range<language::Anchor>>)>;
|
|
}
|
|
|
|
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<(&'a str, Option<Range<language::Anchor>>)> {
|
|
self.read(cx)
|
|
.active_completion_text(buffer, cursor_position, cx)
|
|
}
|
|
}
|