Detailed changes
@@ -262,6 +262,13 @@
"down": "search::NextHistoryQuery"
}
},
+ {
+ "context": "ProjectSearchBar && in_replace",
+ "bindings": {
+ "enter": "search::ReplaceNext",
+ "cmd-enter": "search::ReplaceAll"
+ }
+ },
{
"context": "ProjectSearchView",
"bindings": {
@@ -499,6 +506,22 @@
"cmd-k cmd-down": [
"workspace::ActivatePaneInDirection",
"Down"
+ ],
+ "cmd-k shift-left": [
+ "workspace::SwapPaneInDirection",
+ "Left"
+ ],
+ "cmd-k shift-right": [
+ "workspace::SwapPaneInDirection",
+ "Right"
+ ],
+ "cmd-k shift-up": [
+ "workspace::SwapPaneInDirection",
+ "Up"
+ ],
+ "cmd-k shift-down": [
+ "workspace::SwapPaneInDirection",
+ "Down"
]
}
},
@@ -563,7 +586,7 @@
}
},
{
- "context": "ProjectSearchBar",
+ "context": "ProjectSearchBar && !in_replace",
"bindings": {
"cmd-enter": "project_search::SearchInNew"
}
@@ -316,6 +316,38 @@
"workspace::ActivatePaneInDirection",
"Down"
],
+ "ctrl-w shift-left": [
+ "workspace::SwapPaneInDirection",
+ "Left"
+ ],
+ "ctrl-w shift-right": [
+ "workspace::SwapPaneInDirection",
+ "Right"
+ ],
+ "ctrl-w shift-up": [
+ "workspace::SwapPaneInDirection",
+ "Up"
+ ],
+ "ctrl-w shift-down": [
+ "workspace::SwapPaneInDirection",
+ "Down"
+ ],
+ "ctrl-w shift-h": [
+ "workspace::SwapPaneInDirection",
+ "Left"
+ ],
+ "ctrl-w shift-l": [
+ "workspace::SwapPaneInDirection",
+ "Right"
+ ],
+ "ctrl-w shift-k": [
+ "workspace::SwapPaneInDirection",
+ "Up"
+ ],
+ "ctrl-w shift-j": [
+ "workspace::SwapPaneInDirection",
+ "Down"
+ ],
"ctrl-w g t": "pane::ActivateNextItem",
"ctrl-w ctrl-g t": "pane::ActivateNextItem",
"ctrl-w g shift-t": "pane::ActivatePrevItem",
@@ -1,6 +1,7 @@
pub mod assistant_panel;
mod assistant_settings;
mod codegen;
+mod prompts;
mod streaming_diff;
use ai::completion::Role;
@@ -1,6 +1,7 @@
use crate::{
assistant_settings::{AssistantDockPosition, AssistantSettings, OpenAIModel},
codegen::{self, Codegen, CodegenKind},
+ prompts::generate_content_prompt,
MessageId, MessageMetadata, MessageStatus, Role, SavedConversation, SavedConversationMetadata,
SavedMessage,
};
@@ -541,11 +542,25 @@ impl AssistantPanel {
self.inline_prompt_history.pop_front();
}
- let snapshot = editor.read(cx).buffer().read(cx).snapshot(cx);
+ let multi_buffer = editor.read(cx).buffer().read(cx);
+ let multi_buffer_snapshot = multi_buffer.snapshot(cx);
+ let snapshot = if multi_buffer.is_singleton() {
+ multi_buffer.as_singleton().unwrap().read(cx).snapshot()
+ } else {
+ return;
+ };
+
let range = pending_assist.codegen.read(cx).range();
- let selected_text = snapshot.text_for_range(range.clone()).collect::<String>();
+ let language_range = snapshot.anchor_at(
+ range.start.to_offset(&multi_buffer_snapshot),
+ language::Bias::Left,
+ )
+ ..snapshot.anchor_at(
+ range.end.to_offset(&multi_buffer_snapshot),
+ language::Bias::Right,
+ );
- let language = snapshot.language_at(range.start);
+ let language = snapshot.language_at(language_range.start);
let language_name = if let Some(language) = language.as_ref() {
if Arc::ptr_eq(language, &language::PLAIN_TEXT) {
None
@@ -557,93 +572,15 @@ impl AssistantPanel {
};
let language_name = language_name.as_deref();
- let mut prompt = String::new();
- if let Some(language_name) = language_name {
- writeln!(prompt, "You're an expert {language_name} engineer.").unwrap();
- }
- match pending_assist.codegen.read(cx).kind() {
- CodegenKind::Transform { .. } => {
- writeln!(
- prompt,
- "You're currently working inside an editor on this file:"
- )
- .unwrap();
- if let Some(language_name) = language_name {
- writeln!(prompt, "```{language_name}").unwrap();
- } else {
- writeln!(prompt, "```").unwrap();
- }
- for chunk in snapshot.text_for_range(Anchor::min()..Anchor::max()) {
- write!(prompt, "{chunk}").unwrap();
- }
- writeln!(prompt, "```").unwrap();
-
- writeln!(
- prompt,
- "In particular, the user has selected the following text:"
- )
- .unwrap();
- if let Some(language_name) = language_name {
- writeln!(prompt, "```{language_name}").unwrap();
- } else {
- writeln!(prompt, "```").unwrap();
- }
- writeln!(prompt, "{selected_text}").unwrap();
- writeln!(prompt, "```").unwrap();
- writeln!(prompt).unwrap();
- writeln!(
- prompt,
- "Modify the selected text given the user prompt: {user_prompt}"
- )
- .unwrap();
- writeln!(
- prompt,
- "You MUST reply only with the edited selected text, not the entire file."
- )
- .unwrap();
- }
- CodegenKind::Generate { .. } => {
- writeln!(
- prompt,
- "You're currently working inside an editor on this file:"
- )
- .unwrap();
- if let Some(language_name) = language_name {
- writeln!(prompt, "```{language_name}").unwrap();
- } else {
- writeln!(prompt, "```").unwrap();
- }
- for chunk in snapshot.text_for_range(Anchor::min()..range.start) {
- write!(prompt, "{chunk}").unwrap();
- }
- write!(prompt, "<|>").unwrap();
- for chunk in snapshot.text_for_range(range.start..Anchor::max()) {
- write!(prompt, "{chunk}").unwrap();
- }
- writeln!(prompt).unwrap();
- writeln!(prompt, "```").unwrap();
- writeln!(
- prompt,
- "Assume the cursor is located where the `<|>` marker is."
- )
- .unwrap();
- writeln!(
- prompt,
- "Text can't be replaced, so assume your answer will be inserted at the cursor."
- )
- .unwrap();
- writeln!(
- prompt,
- "Complete the text given the user prompt: {user_prompt}"
- )
- .unwrap();
- }
- }
- if let Some(language_name) = language_name {
- writeln!(prompt, "Your answer MUST always be valid {language_name}.").unwrap();
- }
- writeln!(prompt, "Always wrap your response in a Markdown codeblock.").unwrap();
- writeln!(prompt, "Never make remarks about the output.").unwrap();
+ let codegen_kind = pending_assist.codegen.read(cx).kind().clone();
+ let prompt = generate_content_prompt(
+ user_prompt.to_string(),
+ language_name,
+ &snapshot,
+ language_range,
+ cx,
+ codegen_kind,
+ );
let mut messages = Vec::new();
let mut model = settings::get::<AssistantSettings>(cx)
@@ -0,0 +1,382 @@
+use gpui::AppContext;
+use language::{BufferSnapshot, OffsetRangeExt, ToOffset};
+use std::cmp;
+use std::ops::Range;
+use std::{fmt::Write, iter};
+
+use crate::codegen::CodegenKind;
+
+fn outline_for_prompt(
+ buffer: &BufferSnapshot,
+ range: Range<language::Anchor>,
+ cx: &AppContext,
+) -> Option<String> {
+ let indent = buffer
+ .language_indent_size_at(0, cx)
+ .chars()
+ .collect::<String>();
+ let outline = buffer.outline(None)?;
+ let range = range.to_offset(buffer);
+
+ let mut text = String::new();
+ let mut items = outline.items.into_iter().peekable();
+
+ let mut intersected = false;
+ let mut intersection_indent = 0;
+ let mut extended_range = range.clone();
+
+ while let Some(item) = items.next() {
+ let item_range = item.range.to_offset(buffer);
+ if item_range.end < range.start || item_range.start > range.end {
+ text.extend(iter::repeat(indent.as_str()).take(item.depth));
+ text.push_str(&item.text);
+ text.push('\n');
+ } else {
+ intersected = true;
+ let is_terminal = items
+ .peek()
+ .map_or(true, |next_item| next_item.depth <= item.depth);
+ if is_terminal {
+ if item_range.start <= extended_range.start {
+ extended_range.start = item_range.start;
+ intersection_indent = item.depth;
+ }
+ extended_range.end = cmp::max(extended_range.end, item_range.end);
+ } else {
+ let name_start = item_range.start + item.name_ranges.first().unwrap().start;
+ let name_end = item_range.start + item.name_ranges.last().unwrap().end;
+
+ if range.start > name_end {
+ text.extend(iter::repeat(indent.as_str()).take(item.depth));
+ text.push_str(&item.text);
+ text.push('\n');
+ } else {
+ if name_start <= extended_range.start {
+ extended_range.start = item_range.start;
+ intersection_indent = item.depth;
+ }
+ extended_range.end = cmp::max(extended_range.end, name_end);
+ }
+ }
+ }
+
+ if intersected
+ && items.peek().map_or(true, |next_item| {
+ next_item.range.start.to_offset(buffer) > range.end
+ })
+ {
+ intersected = false;
+ text.extend(iter::repeat(indent.as_str()).take(intersection_indent));
+ text.extend(buffer.text_for_range(extended_range.start..range.start));
+ text.push_str("<|START|");
+ text.extend(buffer.text_for_range(range.clone()));
+ if range.start != range.end {
+ text.push_str("|END|>");
+ } else {
+ text.push_str(">");
+ }
+ text.extend(buffer.text_for_range(range.end..extended_range.end));
+ text.push('\n');
+ }
+ }
+
+ Some(text)
+}
+
+pub fn generate_content_prompt(
+ user_prompt: String,
+ language_name: Option<&str>,
+ buffer: &BufferSnapshot,
+ range: Range<language::Anchor>,
+ cx: &AppContext,
+ kind: CodegenKind,
+) -> String {
+ let mut prompt = String::new();
+
+ // General Preamble
+ if let Some(language_name) = language_name {
+ writeln!(prompt, "You're an expert {language_name} engineer.\n").unwrap();
+ } else {
+ writeln!(prompt, "You're an expert engineer.\n").unwrap();
+ }
+
+ let outline = outline_for_prompt(buffer, range.clone(), cx);
+ if let Some(outline) = outline {
+ writeln!(
+ prompt,
+ "The file you are currently working on has the following outline:"
+ )
+ .unwrap();
+ if let Some(language_name) = language_name {
+ let language_name = language_name.to_lowercase();
+ writeln!(prompt, "```{language_name}\n{outline}\n```").unwrap();
+ } else {
+ writeln!(prompt, "```\n{outline}\n```").unwrap();
+ }
+ }
+
+ // Assume for now that we are just generating
+ if range.clone().start == range.end {
+ writeln!(prompt, "In particular, the user's cursor is current on the '<|START|>' span in the above outline, with no text selected.").unwrap();
+ } else {
+ writeln!(prompt, "In particular, the user has selected a section of the text between the '<|START|' and '|END|>' spans.").unwrap();
+ }
+
+ match kind {
+ CodegenKind::Generate { position: _ } => {
+ writeln!(
+ prompt,
+ "Assume the cursor is located where the `<|START|` marker is."
+ )
+ .unwrap();
+ writeln!(
+ prompt,
+ "Text can't be replaced, so assume your answer will be inserted at the cursor."
+ )
+ .unwrap();
+ writeln!(
+ prompt,
+ "Generate text based on the users prompt: {user_prompt}"
+ )
+ .unwrap();
+ }
+ CodegenKind::Transform { range: _ } => {
+ writeln!(
+ prompt,
+ "Modify the users code selected text based upon the users prompt: {user_prompt}"
+ )
+ .unwrap();
+ writeln!(
+ prompt,
+ "You MUST reply with only the adjusted code (within the '<|START|' and '|END|>' spans), not the entire file."
+ )
+ .unwrap();
+ }
+ }
+
+ if let Some(language_name) = language_name {
+ writeln!(prompt, "Your answer MUST always be valid {language_name}").unwrap();
+ }
+ writeln!(prompt, "Always wrap your response in a Markdown codeblock").unwrap();
+ writeln!(prompt, "Never make remarks about the output.").unwrap();
+
+ prompt
+}
+
+#[cfg(test)]
+pub(crate) mod tests {
+
+ use super::*;
+ use std::sync::Arc;
+
+ use gpui::AppContext;
+ use indoc::indoc;
+ use language::{language_settings, tree_sitter_rust, Buffer, Language, LanguageConfig, Point};
+ use settings::SettingsStore;
+
+ pub(crate) fn rust_lang() -> Language {
+ Language::new(
+ LanguageConfig {
+ name: "Rust".into(),
+ path_suffixes: vec!["rs".to_string()],
+ ..Default::default()
+ },
+ Some(tree_sitter_rust::language()),
+ )
+ .with_indents_query(
+ r#"
+ (call_expression) @indent
+ (field_expression) @indent
+ (_ "(" ")" @end) @indent
+ (_ "{" "}" @end) @indent
+ "#,
+ )
+ .unwrap()
+ .with_outline_query(
+ r#"
+ (struct_item
+ "struct" @context
+ name: (_) @name) @item
+ (enum_item
+ "enum" @context
+ name: (_) @name) @item
+ (enum_variant
+ name: (_) @name) @item
+ (field_declaration
+ name: (_) @name) @item
+ (impl_item
+ "impl" @context
+ trait: (_)? @name
+ "for"? @context
+ type: (_) @name) @item
+ (function_item
+ "fn" @context
+ name: (_) @name) @item
+ (mod_item
+ "mod" @context
+ name: (_) @name) @item
+ "#,
+ )
+ .unwrap()
+ }
+
+ #[gpui::test]
+ fn test_outline_for_prompt(cx: &mut AppContext) {
+ cx.set_global(SettingsStore::test(cx));
+ language_settings::init(cx);
+ let text = indoc! {"
+ struct X {
+ a: usize,
+ b: usize,
+ }
+
+ impl X {
+
+ fn new() -> Self {
+ let a = 1;
+ let b = 2;
+ Self { a, b }
+ }
+
+ pub fn a(&self, param: bool) -> usize {
+ self.a
+ }
+
+ pub fn b(&self) -> usize {
+ self.b
+ }
+ }
+ "};
+ let buffer =
+ cx.add_model(|cx| Buffer::new(0, 0, text).with_language(Arc::new(rust_lang()), cx));
+ let snapshot = buffer.read(cx).snapshot();
+
+ let outline = outline_for_prompt(
+ &snapshot,
+ snapshot.anchor_before(Point::new(1, 4))..snapshot.anchor_before(Point::new(1, 4)),
+ cx,
+ );
+ assert_eq!(
+ outline.as_deref(),
+ Some(indoc! {"
+ struct X
+ <|START|>a: usize
+ b
+ impl X
+ fn new
+ fn a
+ fn b
+ "})
+ );
+
+ let outline = outline_for_prompt(
+ &snapshot,
+ snapshot.anchor_before(Point::new(8, 12))..snapshot.anchor_before(Point::new(8, 14)),
+ cx,
+ );
+ assert_eq!(
+ outline.as_deref(),
+ Some(indoc! {"
+ struct X
+ a
+ b
+ impl X
+ fn new() -> Self {
+ let <|START|a |END|>= 1;
+ let b = 2;
+ Self { a, b }
+ }
+ fn a
+ fn b
+ "})
+ );
+
+ let outline = outline_for_prompt(
+ &snapshot,
+ snapshot.anchor_before(Point::new(6, 0))..snapshot.anchor_before(Point::new(6, 0)),
+ cx,
+ );
+ assert_eq!(
+ outline.as_deref(),
+ Some(indoc! {"
+ struct X
+ a
+ b
+ impl X
+ <|START|>
+ fn new
+ fn a
+ fn b
+ "})
+ );
+
+ let outline = outline_for_prompt(
+ &snapshot,
+ snapshot.anchor_before(Point::new(8, 12))..snapshot.anchor_before(Point::new(13, 9)),
+ cx,
+ );
+ assert_eq!(
+ outline.as_deref(),
+ Some(indoc! {"
+ struct X
+ a
+ b
+ impl X
+ fn new() -> Self {
+ let <|START|a = 1;
+ let b = 2;
+ Self { a, b }
+ }
+
+ pub f|END|>n a(&self, param: bool) -> usize {
+ self.a
+ }
+ fn b
+ "})
+ );
+
+ let outline = outline_for_prompt(
+ &snapshot,
+ snapshot.anchor_before(Point::new(5, 6))..snapshot.anchor_before(Point::new(12, 0)),
+ cx,
+ );
+ assert_eq!(
+ outline.as_deref(),
+ Some(indoc! {"
+ struct X
+ a
+ b
+ impl X<|START| {
+
+ fn new() -> Self {
+ let a = 1;
+ let b = 2;
+ Self { a, b }
+ }
+ |END|>
+ fn a
+ fn b
+ "})
+ );
+
+ let outline = outline_for_prompt(
+ &snapshot,
+ snapshot.anchor_before(Point::new(18, 8))..snapshot.anchor_before(Point::new(18, 8)),
+ cx,
+ );
+ assert_eq!(
+ outline.as_deref(),
+ Some(indoc! {"
+ struct X
+ a
+ b
+ impl X
+ fn new
+ fn a
+ pub fn b(&self) -> usize {
+ <|START|>self.b
+ }
+ "})
+ );
+ }
+}
@@ -206,9 +206,14 @@ impl ActiveCall {
cx.spawn(|this, mut cx| async move {
let result = invite.await;
+ if result.is_ok() {
+ this.update(&mut cx, |this, cx| this.report_call_event("invite", cx));
+ } else {
+ // TODO: Resport collaboration error
+ }
+
this.update(&mut cx, |this, cx| {
this.pending_invites.remove(&called_user_id);
- this.report_call_event("invite", cx);
cx.notify();
});
result
@@ -273,13 +278,7 @@ impl ActiveCall {
.borrow_mut()
.take()
.ok_or_else(|| anyhow!("no incoming call"))?;
- Self::report_call_event_for_room(
- "decline incoming",
- Some(call.room_id),
- None,
- &self.client,
- cx,
- );
+ report_call_event_for_room("decline incoming", call.room_id, None, &self.client, cx);
self.client.send(proto::DeclineCall {
room_id: call.room_id,
})?;
@@ -409,31 +408,46 @@ impl ActiveCall {
&self.pending_invites
}
- fn report_call_event(&self, operation: &'static str, cx: &AppContext) {
- let (room_id, channel_id) = match self.room() {
- Some(room) => {
- let room = room.read(cx);
- (Some(room.id()), room.channel_id())
- }
- None => (None, None),
- };
- Self::report_call_event_for_room(operation, room_id, channel_id, &self.client, cx)
+ pub fn report_call_event(&self, operation: &'static str, cx: &AppContext) {
+ if let Some(room) = self.room() {
+ let room = room.read(cx);
+ report_call_event_for_room(operation, room.id(), room.channel_id(), &self.client, cx);
+ }
}
+}
- pub fn report_call_event_for_room(
- operation: &'static str,
- room_id: Option<u64>,
- channel_id: Option<u64>,
- client: &Arc<Client>,
- cx: &AppContext,
- ) {
- let telemetry = client.telemetry();
- let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
- let event = ClickhouseEvent::Call {
- operation,
- room_id,
- channel_id,
- };
- telemetry.report_clickhouse_event(event, telemetry_settings);
- }
+pub fn report_call_event_for_room(
+ operation: &'static str,
+ room_id: u64,
+ channel_id: Option<u64>,
+ client: &Arc<Client>,
+ cx: &AppContext,
+) {
+ let telemetry = client.telemetry();
+ let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
+ let event = ClickhouseEvent::Call {
+ operation,
+ room_id: Some(room_id),
+ channel_id,
+ };
+ telemetry.report_clickhouse_event(event, telemetry_settings);
+}
+
+pub fn report_call_event_for_channel(
+ operation: &'static str,
+ channel_id: u64,
+ client: &Arc<Client>,
+ cx: &AppContext,
+) {
+ let room = ActiveCall::global(cx).read(cx).room();
+
+ let telemetry = client.telemetry();
+ let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
+
+ let event = ClickhouseEvent::Call {
+ operation,
+ room_id: room.map(|r| r.read(cx).id()),
+ channel_id: Some(channel_id),
+ };
+ telemetry.report_clickhouse_event(event, telemetry_settings);
}
@@ -1,5 +1,5 @@
use anyhow::{anyhow, Result};
-use call::ActiveCall;
+use call::report_call_event_for_channel;
use channel::{ChannelBuffer, ChannelBufferEvent, ChannelId};
use client::proto;
use clock::ReplicaId;
@@ -42,14 +42,9 @@ impl ChannelView {
cx.spawn(|mut cx| async move {
let channel_view = channel_view.await?;
pane.update(&mut cx, |pane, cx| {
- let room_id = ActiveCall::global(cx)
- .read(cx)
- .room()
- .map(|room| room.read(cx).id());
- ActiveCall::report_call_event_for_room(
+ report_call_event_for_channel(
"open channel notes",
- room_id,
- Some(channel_id),
+ channel_id,
&workspace.read(cx).app_state().client,
cx,
);
@@ -10,7 +10,7 @@ mod panel_settings;
mod project_shared_notification;
mod sharing_status_indicator;
-use call::{ActiveCall, Room};
+use call::{report_call_event_for_room, ActiveCall, Room};
use gpui::{
actions,
geometry::{
@@ -55,18 +55,18 @@ pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
let client = call.client();
let toggle_screen_sharing = room.update(cx, |room, cx| {
if room.is_screen_sharing() {
- ActiveCall::report_call_event_for_room(
+ report_call_event_for_room(
"disable screen share",
- Some(room.id()),
+ room.id(),
room.channel_id(),
&client,
cx,
);
Task::ready(room.unshare_screen(cx))
} else {
- ActiveCall::report_call_event_for_room(
+ report_call_event_for_room(
"enable screen share",
- Some(room.id()),
+ room.id(),
room.channel_id(),
&client,
cx,
@@ -83,23 +83,13 @@ pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
if let Some(room) = call.room().cloned() {
let client = call.client();
room.update(cx, |room, cx| {
- if room.is_muted(cx) {
- ActiveCall::report_call_event_for_room(
- "enable microphone",
- Some(room.id()),
- room.channel_id(),
- &client,
- cx,
- );
+ let operation = if room.is_muted(cx) {
+ "enable microphone"
} else {
- ActiveCall::report_call_event_for_room(
- "disable microphone",
- Some(room.id()),
- room.channel_id(),
- &client,
- cx,
- );
- }
+ "disable microphone"
+ };
+ report_call_event_for_room(operation, room.id(), room.channel_id(), &client, cx);
+
room.toggle_mute(cx)
})
.map(|task| task.detach_and_log_err(cx))
@@ -8588,6 +8588,29 @@ impl Editor {
self.handle_input(text, cx);
}
+
+ pub fn supports_inlay_hints(&self, cx: &AppContext) -> bool {
+ let Some(project) = self.project.as_ref() else {
+ return false;
+ };
+ let project = project.read(cx);
+
+ let mut supports = false;
+ self.buffer().read(cx).for_each_buffer(|buffer| {
+ if !supports {
+ supports = project
+ .language_servers_for_buffer(buffer.read(cx), cx)
+ .any(
+ |(_, server)| match server.capabilities().inlay_hint_provider {
+ Some(lsp::OneOf::Left(enabled)) => enabled,
+ Some(lsp::OneOf::Right(_)) => true,
+ None => false,
+ },
+ )
+ }
+ });
+ supports
+ }
}
fn inlay_hint_settings(
@@ -996,7 +996,9 @@ impl SearchableItem for Editor {
};
if let Some(replacement) = query.replacement_for(&text) {
- self.edit([(identifier.clone(), Arc::from(&*replacement))], cx);
+ self.transact(cx, |this, cx| {
+ this.edit([(identifier.clone(), Arc::from(&*replacement))], cx);
+ });
}
}
fn match_index_for_direction(
@@ -320,174 +320,114 @@ use crate as gpui2;
//
// Example:
// // Sets the padding to 0.5rem, just like class="p-2" in Tailwind.
-// fn p_2(mut self) -> Self where Self: Sized;
-pub trait StyleHelpers: Styleable<Style = Style> {
+// fn p_2(mut self) -> Self;
+pub trait StyleHelpers: Sized + Styleable<Style = Style> {
styleable_helpers!();
- fn full(mut self) -> Self
- where
- Self: Sized,
- {
+ fn full(mut self) -> Self {
self.declared_style().size.width = Some(relative(1.).into());
self.declared_style().size.height = Some(relative(1.).into());
self
}
- fn relative(mut self) -> Self
- where
- Self: Sized,
- {
+ fn relative(mut self) -> Self {
self.declared_style().position = Some(Position::Relative);
self
}
- fn absolute(mut self) -> Self
- where
- Self: Sized,
- {
+ fn absolute(mut self) -> Self {
self.declared_style().position = Some(Position::Absolute);
self
}
- fn block(mut self) -> Self
- where
- Self: Sized,
- {
+ fn block(mut self) -> Self {
self.declared_style().display = Some(Display::Block);
self
}
- fn flex(mut self) -> Self
- where
- Self: Sized,
- {
+ fn flex(mut self) -> Self {
self.declared_style().display = Some(Display::Flex);
self
}
- fn flex_col(mut self) -> Self
- where
- Self: Sized,
- {
+ fn flex_col(mut self) -> Self {
self.declared_style().flex_direction = Some(FlexDirection::Column);
self
}
- fn flex_row(mut self) -> Self
- where
- Self: Sized,
- {
+ fn flex_row(mut self) -> Self {
self.declared_style().flex_direction = Some(FlexDirection::Row);
self
}
- fn flex_1(mut self) -> Self
- where
- Self: Sized,
- {
+ fn flex_1(mut self) -> Self {
self.declared_style().flex_grow = Some(1.);
self.declared_style().flex_shrink = Some(1.);
self.declared_style().flex_basis = Some(relative(0.).into());
self
}
- fn flex_auto(mut self) -> Self
- where
- Self: Sized,
- {
+ fn flex_auto(mut self) -> Self {
self.declared_style().flex_grow = Some(1.);
self.declared_style().flex_shrink = Some(1.);
self.declared_style().flex_basis = Some(Length::Auto);
self
}
- fn flex_initial(mut self) -> Self
- where
- Self: Sized,
- {
+ fn flex_initial(mut self) -> Self {
self.declared_style().flex_grow = Some(0.);
self.declared_style().flex_shrink = Some(1.);
self.declared_style().flex_basis = Some(Length::Auto);
self
}
- fn flex_none(mut self) -> Self
- where
- Self: Sized,
- {
+ fn flex_none(mut self) -> Self {
self.declared_style().flex_grow = Some(0.);
self.declared_style().flex_shrink = Some(0.);
self
}
- fn grow(mut self) -> Self
- where
- Self: Sized,
- {
+ fn grow(mut self) -> Self {
self.declared_style().flex_grow = Some(1.);
self
}
- fn items_start(mut self) -> Self
- where
- Self: Sized,
- {
+ fn items_start(mut self) -> Self {
self.declared_style().align_items = Some(AlignItems::FlexStart);
self
}
- fn items_end(mut self) -> Self
- where
- Self: Sized,
- {
+ fn items_end(mut self) -> Self {
self.declared_style().align_items = Some(AlignItems::FlexEnd);
self
}
- fn items_center(mut self) -> Self
- where
- Self: Sized,
- {
+ fn items_center(mut self) -> Self {
self.declared_style().align_items = Some(AlignItems::Center);
self
}
- fn justify_between(mut self) -> Self
- where
- Self: Sized,
- {
+ fn justify_between(mut self) -> Self {
self.declared_style().justify_content = Some(JustifyContent::SpaceBetween);
self
}
- fn justify_center(mut self) -> Self
- where
- Self: Sized,
- {
+ fn justify_center(mut self) -> Self {
self.declared_style().justify_content = Some(JustifyContent::Center);
self
}
- fn justify_start(mut self) -> Self
- where
- Self: Sized,
- {
+ fn justify_start(mut self) -> Self {
self.declared_style().justify_content = Some(JustifyContent::Start);
self
}
- fn justify_end(mut self) -> Self
- where
- Self: Sized,
- {
+ fn justify_end(mut self) -> Self {
self.declared_style().justify_content = Some(JustifyContent::End);
self
}
- fn justify_around(mut self) -> Self
- where
- Self: Sized,
- {
+ fn justify_around(mut self) -> Self {
self.declared_style().justify_content = Some(JustifyContent::SpaceAround);
self
}
@@ -495,7 +435,6 @@ pub trait StyleHelpers: Styleable<Style = Style> {
fn fill<F>(mut self, fill: F) -> Self
where
F: Into<Fill>,
- Self: Sized,
{
self.declared_style().fill = Some(fill.into());
self
@@ -504,7 +443,6 @@ pub trait StyleHelpers: Styleable<Style = Style> {
fn border_color<C>(mut self, border_color: C) -> Self
where
C: Into<Hsla>,
- Self: Sized,
{
self.declared_style().border_color = Some(border_color.into());
self
@@ -513,72 +451,47 @@ pub trait StyleHelpers: Styleable<Style = Style> {
fn text_color<C>(mut self, color: C) -> Self
where
C: Into<Hsla>,
- Self: Sized,
{
self.declared_style().text_color = Some(color.into());
self
}
- fn text_xs(mut self) -> Self
- where
- Self: Sized,
- {
+ fn text_xs(mut self) -> Self {
self.declared_style().font_size = Some(0.75);
self
}
- fn text_sm(mut self) -> Self
- where
- Self: Sized,
- {
+ fn text_sm(mut self) -> Self {
self.declared_style().font_size = Some(0.875);
self
}
- fn text_base(mut self) -> Self
- where
- Self: Sized,
- {
+ fn text_base(mut self) -> Self {
self.declared_style().font_size = Some(1.0);
self
}
- fn text_lg(mut self) -> Self
- where
- Self: Sized,
- {
+ fn text_lg(mut self) -> Self {
self.declared_style().font_size = Some(1.125);
self
}
- fn text_xl(mut self) -> Self
- where
- Self: Sized,
- {
+ fn text_xl(mut self) -> Self {
self.declared_style().font_size = Some(1.25);
self
}
- fn text_2xl(mut self) -> Self
- where
- Self: Sized,
- {
+ fn text_2xl(mut self) -> Self {
self.declared_style().font_size = Some(1.5);
self
}
- fn text_3xl(mut self) -> Self
- where
- Self: Sized,
- {
+ fn text_3xl(mut self) -> Self {
self.declared_style().font_size = Some(1.875);
self
}
- fn font(mut self, family_name: impl Into<Arc<str>>) -> Self
- where
- Self: Sized,
- {
+ fn font(mut self, family_name: impl Into<Arc<str>>) -> Self {
self.declared_style().font_family = Some(family_name.into());
self
}
@@ -135,10 +135,6 @@ fn generate_predefined_setter(
}
};
- if negate {
- dbg!(method.to_string());
- }
-
method
}
@@ -48,24 +48,26 @@ impl View for QuickActionBar {
return Empty::new().into_any();
};
- let inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
- let mut bar = Flex::row().with_child(render_quick_action_bar_button(
- 0,
- "icons/inlay_hint.svg",
- inlay_hints_enabled,
- (
- "Toggle Inlay Hints".to_string(),
- Some(Box::new(editor::ToggleInlayHints)),
- ),
- cx,
- |this, cx| {
- if let Some(editor) = this.active_editor() {
- editor.update(cx, |editor, cx| {
- editor.toggle_inlay_hints(&editor::ToggleInlayHints, cx);
- });
- }
- },
- ));
+ let mut bar = Flex::row();
+ if editor.read(cx).supports_inlay_hints(cx) {
+ bar = bar.with_child(render_quick_action_bar_button(
+ 0,
+ "icons/inlay_hint.svg",
+ editor.read(cx).inlay_hints_enabled(),
+ (
+ "Toggle Inlay Hints".to_string(),
+ Some(Box::new(editor::ToggleInlayHints)),
+ ),
+ cx,
+ |this, cx| {
+ if let Some(editor) = this.active_editor() {
+ editor.update(cx, |editor, cx| {
+ editor.toggle_inlay_hints(&editor::ToggleInlayHints, cx);
+ });
+ }
+ },
+ ));
+ }
if editor.read(cx).buffer().read(cx).is_singleton() {
let search_bar_shown = !self.buffer_search_bar.read(cx).is_dismissed();
@@ -163,12 +165,18 @@ impl ToolbarItemView for QuickActionBar {
if let Some(editor) = active_item.downcast::<Editor>() {
let mut inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
+ let mut supports_inlay_hints = editor.read(cx).supports_inlay_hints(cx);
self._inlay_hints_enabled_subscription =
Some(cx.observe(&editor, move |_, editor, cx| {
- let new_inlay_hints_enabled = editor.read(cx).inlay_hints_enabled();
- if inlay_hints_enabled != new_inlay_hints_enabled {
- inlay_hints_enabled = new_inlay_hints_enabled;
- cx.notify();
+ let editor = editor.read(cx);
+ let new_inlay_hints_enabled = editor.inlay_hints_enabled();
+ let new_supports_inlay_hints = editor.supports_inlay_hints(cx);
+ let should_notify = inlay_hints_enabled != new_inlay_hints_enabled
+ || supports_inlay_hints != new_supports_inlay_hints;
+ inlay_hints_enabled = new_inlay_hints_enabled;
+ supports_inlay_hints = new_supports_inlay_hints;
+ if should_notify {
+ cx.notify()
}
}));
ToolbarItemLocation::PrimaryRight { flex: None }
@@ -60,7 +60,7 @@ pub fn init(cx: &mut AppContext) {
cx.set_global(ActiveSettings::default());
cx.add_action(ProjectSearchView::deploy);
cx.add_action(ProjectSearchView::move_focus_to_results);
- cx.add_action(ProjectSearchBar::search);
+ cx.add_action(ProjectSearchBar::confirm);
cx.add_action(ProjectSearchBar::search_in_new);
cx.add_action(ProjectSearchBar::select_next_match);
cx.add_action(ProjectSearchBar::select_prev_match);
@@ -1371,9 +1371,18 @@ impl ProjectSearchBar {
})
}
}
- fn search(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
+ fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
+ let mut should_propagate = true;
if let Some(search_view) = self.active_project_search.as_ref() {
- search_view.update(cx, |search_view, cx| search_view.search(cx));
+ search_view.update(cx, |search_view, cx| {
+ if !search_view.replacement_editor.is_focused(cx) {
+ should_propagate = false;
+ search_view.search(cx);
+ }
+ });
+ }
+ if should_propagate {
+ cx.propagate_action();
}
}
@@ -1678,6 +1687,28 @@ impl View for ProjectSearchBar {
"ProjectSearchBar"
}
+ fn update_keymap_context(
+ &self,
+ keymap: &mut gpui::keymap_matcher::KeymapContext,
+ cx: &AppContext,
+ ) {
+ Self::reset_to_default_keymap_context(keymap);
+ let in_replace = self
+ .active_project_search
+ .as_ref()
+ .map(|search| {
+ search
+ .read(cx)
+ .replacement_editor
+ .read_with(cx, |_, cx| cx.is_self_focused())
+ })
+ .flatten()
+ .unwrap_or(false);
+ if in_replace {
+ keymap.add_identifier("in_replace");
+ }
+ }
+
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(_search) = self.active_project_search.as_ref() {
let search = _search.read(cx);
@@ -2213,7 +2213,7 @@ fn dirty_message_for(buffer_path: Option<ProjectPath>) -> String {
let path = buffer_path
.as_ref()
.and_then(|p| p.path.to_str())
- .unwrap_or(&"Untitled buffer");
+ .unwrap_or(&"This buffer");
let path = truncate_and_remove_front(path, 80);
format!("{path} contains unsaved edits. Do you want to save it?")
}
@@ -84,6 +84,13 @@ impl PaneGroup {
}
}
+ pub fn swap(&mut self, from: &ViewHandle<Pane>, to: &ViewHandle<Pane>) {
+ match &mut self.root {
+ Member::Pane(_) => {}
+ Member::Axis(axis) => axis.swap(from, to),
+ };
+ }
+
pub(crate) fn render(
&self,
project: &ModelHandle<Project>,
@@ -428,6 +435,21 @@ impl PaneAxis {
}
}
+ fn swap(&mut self, from: &ViewHandle<Pane>, to: &ViewHandle<Pane>) {
+ for member in self.members.iter_mut() {
+ match member {
+ Member::Axis(axis) => axis.swap(from, to),
+ Member::Pane(pane) => {
+ if pane == from {
+ *member = Member::Pane(to.clone());
+ } else if pane == to {
+ *member = Member::Pane(from.clone())
+ }
+ }
+ }
+ }
+ }
+
fn bounding_box_for_pane(&self, pane: &ViewHandle<Pane>) -> Option<RectF> {
debug_assert!(self.members.len() == self.bounding_boxes.borrow().len());
@@ -157,6 +157,9 @@ pub struct ActivatePane(pub usize);
#[derive(Clone, Deserialize, PartialEq)]
pub struct ActivatePaneInDirection(pub SplitDirection);
+#[derive(Clone, Deserialize, PartialEq)]
+pub struct SwapPaneInDirection(pub SplitDirection);
+
#[derive(Clone, Deserialize, PartialEq)]
pub struct NewFileInDirection(pub SplitDirection);
@@ -233,6 +236,7 @@ impl_actions!(
[
ActivatePane,
ActivatePaneInDirection,
+ SwapPaneInDirection,
NewFileInDirection,
Toast,
OpenTerminal,
@@ -318,6 +322,12 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
},
);
+ cx.add_action(
+ |workspace: &mut Workspace, action: &SwapPaneInDirection, cx| {
+ workspace.swap_pane_in_direction(action.0, cx)
+ },
+ );
+
cx.add_action(|workspace: &mut Workspace, _: &ToggleLeftDock, cx| {
workspace.toggle_dock(DockPosition::Left, cx);
});
@@ -2236,11 +2246,32 @@ impl Workspace {
direction: SplitDirection,
cx: &mut ViewContext<Self>,
) {
- let bounding_box = match self.center.bounding_box_for_pane(&self.active_pane) {
- Some(coordinates) => coordinates,
- None => {
- return;
- }
+ if let Some(pane) = self.find_pane_in_direction(direction, cx) {
+ cx.focus(pane);
+ }
+ }
+
+ pub fn swap_pane_in_direction(
+ &mut self,
+ direction: SplitDirection,
+ cx: &mut ViewContext<Self>,
+ ) {
+ if let Some(to) = self
+ .find_pane_in_direction(direction, cx)
+ .map(|pane| pane.clone())
+ {
+ self.center.swap(&self.active_pane.clone(), &to);
+ cx.notify();
+ }
+ }
+
+ fn find_pane_in_direction(
+ &mut self,
+ direction: SplitDirection,
+ cx: &mut ViewContext<Self>,
+ ) -> Option<&ViewHandle<Pane>> {
+ let Some(bounding_box) = self.center.bounding_box_for_pane(&self.active_pane) else {
+ return None;
};
let cursor = self.active_pane.read(cx).pixel_position_of_cursor(cx);
let center = match cursor {
@@ -2256,10 +2287,7 @@ impl Workspace {
SplitDirection::Up => vec2f(center.x(), bounding_box.origin_y() - distance_to_next),
SplitDirection::Down => vec2f(center.x(), bounding_box.max_y() + distance_to_next),
};
-
- if let Some(pane) = self.center.pane_at_pixel_position(target) {
- cx.focus(pane);
- }
+ self.center.pane_at_pixel_position(target)
}
fn handle_pane_focused(&mut self, pane: ViewHandle<Pane>, cx: &mut ViewContext<Self>) {
@@ -9,3 +9,4 @@ brackets = [
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
]
word_characters = ["-"]
+block_comment = ["/* ", " */"]