Return completion proposals from inline completion providers (#17578)
Updates the inline completion provider to return a completion proposal which is then converted to a completion state. This completion proposal includes more detailed information about which inlays specifically should be rendered. Release Notes: - Added support for fill-in-the-middle style inline completions 
This commit is contained in:
parent
37b2f4b9d3
commit
d315405be1
4 changed files with 166 additions and 38 deletions
|
@ -1,14 +1,14 @@
|
|||
use crate::{Completion, Copilot};
|
||||
use anyhow::Result;
|
||||
use client::telemetry::Telemetry;
|
||||
use editor::{Direction, InlineCompletionProvider};
|
||||
use editor::{CompletionProposal, Direction, InlayProposal, InlineCompletionProvider};
|
||||
use gpui::{AppContext, EntityId, Model, ModelContext, Task};
|
||||
use language::{
|
||||
language_settings::{all_language_settings, AllLanguageSettings},
|
||||
Buffer, OffsetRangeExt, ToOffset,
|
||||
};
|
||||
use settings::Settings;
|
||||
use std::{ops::Range, path::Path, sync::Arc, time::Duration};
|
||||
use std::{path::Path, sync::Arc, time::Duration};
|
||||
|
||||
pub const COPILOT_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
|
||||
|
||||
|
@ -237,7 +237,7 @@ impl InlineCompletionProvider for CopilotCompletionProvider {
|
|||
buffer: &Model<Buffer>,
|
||||
cursor_position: language::Anchor,
|
||||
cx: &'a AppContext,
|
||||
) -> Option<(&'a str, Option<Range<language::Anchor>>)> {
|
||||
) -> Option<CompletionProposal> {
|
||||
let buffer_id = buffer.entity_id();
|
||||
let buffer = buffer.read(cx);
|
||||
let completion = self.active_completion()?;
|
||||
|
@ -267,7 +267,14 @@ impl InlineCompletionProvider for CopilotCompletionProvider {
|
|||
if completion_text.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some((completion_text, None))
|
||||
Some(CompletionProposal {
|
||||
inlays: vec![InlayProposal::Suggestion(
|
||||
cursor_position.bias_right(buffer),
|
||||
completion_text.into(),
|
||||
)],
|
||||
text: completion_text.into(),
|
||||
delete_range: None,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue