Truncate line when accepting inline suggestions for Supermaven (#13884)
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>
This commit is contained in:
parent
c703e20a06
commit
a20e92a8c1
6 changed files with 51 additions and 19 deletions
|
@ -27,6 +27,7 @@ serde_json.workspace = true
|
|||
settings.workspace = true
|
||||
supermaven_api.workspace = true
|
||||
smol.workspace = true
|
||||
text.workspace = true
|
||||
ui.workspace = true
|
||||
util.workspace = true
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ use editor::{Direction, InlineCompletionProvider};
|
|||
use futures::StreamExt as _;
|
||||
use gpui::{AppContext, EntityId, Model, ModelContext, Task};
|
||||
use language::{language_settings::all_language_settings, Anchor, Buffer};
|
||||
use std::{path::Path, sync::Arc, time::Duration};
|
||||
use std::{ops::Range, path::Path, sync::Arc, time::Duration};
|
||||
use text::ToPoint;
|
||||
|
||||
pub const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
|
||||
|
||||
|
@ -139,7 +140,7 @@ impl InlineCompletionProvider for SupermavenCompletionProvider {
|
|||
buffer: &Model<Buffer>,
|
||||
cursor_position: Anchor,
|
||||
cx: &'a AppContext,
|
||||
) -> Option<&'a str> {
|
||||
) -> Option<(&'a str, Option<Range<Anchor>>)> {
|
||||
let completion_text = self
|
||||
.supermaven
|
||||
.read(cx)
|
||||
|
@ -150,7 +151,11 @@ impl InlineCompletionProvider for SupermavenCompletionProvider {
|
|||
let completion_text = completion_text.trim_end();
|
||||
|
||||
if !completion_text.trim().is_empty() {
|
||||
Some(completion_text)
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
let mut point = cursor_position.to_point(&snapshot);
|
||||
point.column = snapshot.line_len(point.row);
|
||||
let range = cursor_position..snapshot.anchor_after(point);
|
||||
Some((completion_text, Some(range)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue