Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -17,7 +17,7 @@ use crate::{
|
|||
LanguageScope, Outline, OutlineConfig, RunnableCapture, RunnableTag, TextObject,
|
||||
TreeSitterOptions,
|
||||
};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use async_watch as watch;
|
||||
use clock::Lamport;
|
||||
pub use clock::ReplicaId;
|
||||
|
@ -25,8 +25,8 @@ use collections::HashMap;
|
|||
use fs::MTime;
|
||||
use futures::channel::oneshot;
|
||||
use gpui::{
|
||||
AnyElement, AppContext, Context as _, EventEmitter, HighlightStyle, Model, ModelContext,
|
||||
Pixels, SharedString, Task, TaskLabel, WindowContext,
|
||||
AnyElement, App, AppContext as _, Context, Entity, EventEmitter, HighlightStyle, Pixels,
|
||||
SharedString, Task, TaskLabel, Window,
|
||||
};
|
||||
use lsp::LanguageServerId;
|
||||
use parking_lot::Mutex;
|
||||
|
@ -137,7 +137,7 @@ pub enum ParseStatus {
|
|||
}
|
||||
|
||||
struct BufferBranchState {
|
||||
base_buffer: Model<Buffer>,
|
||||
base_buffer: Entity<Buffer>,
|
||||
merged_operations: Vec<Lamport>,
|
||||
}
|
||||
|
||||
|
@ -371,22 +371,22 @@ pub trait File: Send + Sync {
|
|||
|
||||
/// Returns the path of this file relative to the worktree's parent directory (this means it
|
||||
/// includes the name of the worktree's root folder).
|
||||
fn full_path(&self, cx: &AppContext) -> PathBuf;
|
||||
fn full_path(&self, cx: &App) -> PathBuf;
|
||||
|
||||
/// Returns the last component of this handle's absolute path. If this handle refers to the root
|
||||
/// of its worktree, then this method will return the name of the worktree itself.
|
||||
fn file_name<'a>(&'a self, cx: &'a AppContext) -> &'a OsStr;
|
||||
fn file_name<'a>(&'a self, cx: &'a App) -> &'a OsStr;
|
||||
|
||||
/// Returns the id of the worktree to which this file belongs.
|
||||
///
|
||||
/// This is needed for looking up project-specific settings.
|
||||
fn worktree_id(&self, cx: &AppContext) -> WorktreeId;
|
||||
fn worktree_id(&self, cx: &App) -> WorktreeId;
|
||||
|
||||
/// Converts this file into an [`Any`] trait object.
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
|
||||
/// Converts this file into a protobuf message.
|
||||
fn to_proto(&self, cx: &AppContext) -> rpc::proto::File;
|
||||
fn to_proto(&self, cx: &App) -> rpc::proto::File;
|
||||
|
||||
/// Return whether Zed considers this to be a private file.
|
||||
fn is_private(&self) -> bool;
|
||||
|
@ -420,13 +420,13 @@ impl DiskState {
|
|||
/// The file associated with a buffer, in the case where the file is on the local disk.
|
||||
pub trait LocalFile: File {
|
||||
/// Returns the absolute path of this file
|
||||
fn abs_path(&self, cx: &AppContext) -> PathBuf;
|
||||
fn abs_path(&self, cx: &App) -> PathBuf;
|
||||
|
||||
/// Loads the file contents from disk and returns them as a UTF-8 encoded string.
|
||||
fn load(&self, cx: &AppContext) -> Task<Result<String>>;
|
||||
fn load(&self, cx: &App) -> Task<Result<String>>;
|
||||
|
||||
/// Loads the file's contents from disk.
|
||||
fn load_bytes(&self, cx: &AppContext) -> Task<Result<Vec<u8>>>;
|
||||
fn load_bytes(&self, cx: &App) -> Task<Result<Vec<u8>>>;
|
||||
}
|
||||
|
||||
/// The auto-indent behavior associated with an editing operation.
|
||||
|
@ -527,7 +527,8 @@ pub struct ChunkRenderer {
|
|||
}
|
||||
|
||||
pub struct ChunkRendererContext<'a, 'b> {
|
||||
pub context: &'a mut WindowContext<'b>,
|
||||
pub window: &'a mut Window,
|
||||
pub context: &'b mut App,
|
||||
pub max_width: Pixels,
|
||||
}
|
||||
|
||||
|
@ -540,7 +541,7 @@ impl fmt::Debug for ChunkRenderer {
|
|||
}
|
||||
|
||||
impl<'a, 'b> Deref for ChunkRendererContext<'a, 'b> {
|
||||
type Target = WindowContext<'b>;
|
||||
type Target = App;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.context
|
||||
|
@ -605,7 +606,7 @@ impl EditPreview {
|
|||
current_snapshot: &BufferSnapshot,
|
||||
edits: &[(Range<Anchor>, String)],
|
||||
include_deletions: bool,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> HighlightedEdits {
|
||||
let mut text = String::new();
|
||||
let mut highlights = Vec::new();
|
||||
|
@ -682,7 +683,7 @@ impl EditPreview {
|
|||
text: &mut String,
|
||||
highlights: &mut Vec<(Range<usize>, HighlightStyle)>,
|
||||
override_style: Option<HighlightStyle>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) {
|
||||
for chunk in self.highlighted_chunks(range) {
|
||||
let start = text.len();
|
||||
|
@ -745,7 +746,7 @@ impl EditPreview {
|
|||
|
||||
impl Buffer {
|
||||
/// Create a new buffer with the given base text.
|
||||
pub fn local<T: Into<String>>(base_text: T, cx: &ModelContext<Self>) -> Self {
|
||||
pub fn local<T: Into<String>>(base_text: T, cx: &Context<Self>) -> Self {
|
||||
Self::build(
|
||||
TextBuffer::new(0, cx.entity_id().as_non_zero_u64().into(), base_text.into()),
|
||||
None,
|
||||
|
@ -757,7 +758,7 @@ impl Buffer {
|
|||
pub fn local_normalized(
|
||||
base_text_normalized: Rope,
|
||||
line_ending: LineEnding,
|
||||
cx: &ModelContext<Self>,
|
||||
cx: &Context<Self>,
|
||||
) -> Self {
|
||||
Self::build(
|
||||
TextBuffer::new_normalized(
|
||||
|
@ -807,7 +808,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Serialize the buffer's state to a protobuf message.
|
||||
pub fn to_proto(&self, cx: &AppContext) -> proto::BufferState {
|
||||
pub fn to_proto(&self, cx: &App) -> proto::BufferState {
|
||||
proto::BufferState {
|
||||
id: self.remote_id().into(),
|
||||
file: self.file.as_ref().map(|f| f.to_proto(cx)),
|
||||
|
@ -822,7 +823,7 @@ impl Buffer {
|
|||
pub fn serialize_ops(
|
||||
&self,
|
||||
since: Option<clock::Global>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Task<Vec<proto::Operation>> {
|
||||
let mut operations = Vec::new();
|
||||
operations.extend(self.deferred_ops.iter().map(proto::serialize_operation));
|
||||
|
@ -869,7 +870,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Assign a language to the buffer, returning the buffer.
|
||||
pub fn with_language(mut self, language: Arc<Language>, cx: &mut ModelContext<Self>) -> Self {
|
||||
pub fn with_language(mut self, language: Arc<Language>, cx: &mut Context<Self>) -> Self {
|
||||
self.set_language(Some(language), cx);
|
||||
self
|
||||
}
|
||||
|
@ -925,7 +926,7 @@ impl Buffer {
|
|||
text: Rope,
|
||||
language: Option<Arc<Language>>,
|
||||
language_registry: Option<Arc<LanguageRegistry>>,
|
||||
cx: &mut AppContext,
|
||||
cx: &mut App,
|
||||
) -> impl Future<Output = BufferSnapshot> {
|
||||
let entity_id = cx.reserve_model::<Self>().entity_id();
|
||||
let buffer_id = entity_id.as_non_zero_u64().into();
|
||||
|
@ -970,9 +971,9 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn branch(&mut self, cx: &mut ModelContext<Self>) -> Model<Self> {
|
||||
let this = cx.handle();
|
||||
cx.new_model(|cx| {
|
||||
pub fn branch(&mut self, cx: &mut Context<Self>) -> Entity<Self> {
|
||||
let this = cx.model();
|
||||
cx.new(|cx| {
|
||||
let mut branch = Self {
|
||||
branch_state: Some(BufferBranchState {
|
||||
base_buffer: this.clone(),
|
||||
|
@ -998,7 +999,7 @@ impl Buffer {
|
|||
pub fn preview_edits(
|
||||
&self,
|
||||
edits: Arc<[(Range<Anchor>, String)]>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Task<EditPreview> {
|
||||
let registry = self.language_registry();
|
||||
let language = self.language().cloned();
|
||||
|
@ -1027,7 +1028,7 @@ impl Buffer {
|
|||
///
|
||||
/// If `ranges` is empty, then all changes will be applied. This buffer must
|
||||
/// be a branch buffer to call this method.
|
||||
pub fn merge_into_base(&mut self, ranges: Vec<Range<usize>>, cx: &mut ModelContext<Self>) {
|
||||
pub fn merge_into_base(&mut self, ranges: Vec<Range<usize>>, cx: &mut Context<Self>) {
|
||||
let Some(base_buffer) = self.base_buffer() else {
|
||||
debug_panic!("not a branch buffer");
|
||||
return;
|
||||
|
@ -1080,9 +1081,9 @@ impl Buffer {
|
|||
|
||||
fn on_base_buffer_event(
|
||||
&mut self,
|
||||
_: Model<Buffer>,
|
||||
_: Entity<Buffer>,
|
||||
event: &BufferEvent,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let BufferEvent::Operation { operation, .. } = event else {
|
||||
return;
|
||||
|
@ -1137,7 +1138,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Assign a language to the buffer.
|
||||
pub fn set_language(&mut self, language: Option<Arc<Language>>, cx: &mut ModelContext<Self>) {
|
||||
pub fn set_language(&mut self, language: Option<Arc<Language>>, cx: &mut Context<Self>) {
|
||||
self.non_text_state_update_count += 1;
|
||||
self.syntax_map.lock().clear(&self.text);
|
||||
self.language = language;
|
||||
|
@ -1158,7 +1159,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Assign the buffer a new [`Capability`].
|
||||
pub fn set_capability(&mut self, capability: Capability, cx: &mut ModelContext<Self>) {
|
||||
pub fn set_capability(&mut self, capability: Capability, cx: &mut Context<Self>) {
|
||||
self.capability = capability;
|
||||
cx.emit(BufferEvent::CapabilityChanged)
|
||||
}
|
||||
|
@ -1168,7 +1169,7 @@ impl Buffer {
|
|||
&mut self,
|
||||
version: clock::Global,
|
||||
mtime: Option<MTime>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.saved_version = version;
|
||||
self.has_unsaved_edits
|
||||
|
@ -1180,13 +1181,13 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// This method is called to signal that the buffer has been discarded.
|
||||
pub fn discarded(&self, cx: &mut ModelContext<Self>) {
|
||||
pub fn discarded(&self, cx: &mut Context<Self>) {
|
||||
cx.emit(BufferEvent::Discarded);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Reloads the contents of the buffer from disk.
|
||||
pub fn reload(&mut self, cx: &ModelContext<Self>) -> oneshot::Receiver<Option<Transaction>> {
|
||||
pub fn reload(&mut self, cx: &Context<Self>) -> oneshot::Receiver<Option<Transaction>> {
|
||||
let (tx, rx) = futures::channel::oneshot::channel();
|
||||
let prev_version = self.text.version();
|
||||
self.reload_task = Some(cx.spawn(|this, mut cx| async move {
|
||||
|
@ -1234,7 +1235,7 @@ impl Buffer {
|
|||
version: clock::Global,
|
||||
line_ending: LineEnding,
|
||||
mtime: Option<MTime>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.saved_version = version;
|
||||
self.has_unsaved_edits
|
||||
|
@ -1247,7 +1248,7 @@ impl Buffer {
|
|||
|
||||
/// Updates the [`File`] backing this buffer. This should be called when
|
||||
/// the file has changed or has been deleted.
|
||||
pub fn file_updated(&mut self, new_file: Arc<dyn File>, cx: &mut ModelContext<Self>) {
|
||||
pub fn file_updated(&mut self, new_file: Arc<dyn File>, cx: &mut Context<Self>) {
|
||||
let was_dirty = self.is_dirty();
|
||||
let mut file_changed = false;
|
||||
|
||||
|
@ -1279,7 +1280,7 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn base_buffer(&self) -> Option<Model<Self>> {
|
||||
pub fn base_buffer(&self) -> Option<Entity<Self>> {
|
||||
Some(self.branch_state.as_ref()?.base_buffer.clone())
|
||||
}
|
||||
|
||||
|
@ -1345,7 +1346,7 @@ impl Buffer {
|
|||
/// initiate an additional reparse recursively. To avoid concurrent parses
|
||||
/// for the same buffer, we only initiate a new parse if we are not already
|
||||
/// parsing in the background.
|
||||
pub fn reparse(&mut self, cx: &mut ModelContext<Self>) {
|
||||
pub fn reparse(&mut self, cx: &mut Context<Self>) {
|
||||
if self.parsing_in_background {
|
||||
return;
|
||||
}
|
||||
|
@ -1411,7 +1412,7 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
fn did_finish_parsing(&mut self, syntax_snapshot: SyntaxSnapshot, cx: &mut ModelContext<Self>) {
|
||||
fn did_finish_parsing(&mut self, syntax_snapshot: SyntaxSnapshot, cx: &mut Context<Self>) {
|
||||
self.non_text_state_update_count += 1;
|
||||
self.syntax_map.lock().did_parse(syntax_snapshot);
|
||||
self.request_autoindent(cx);
|
||||
|
@ -1429,7 +1430,7 @@ impl Buffer {
|
|||
&mut self,
|
||||
server_id: LanguageServerId,
|
||||
diagnostics: DiagnosticSet,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let lamport_timestamp = self.text.lamport_clock.tick();
|
||||
let op = Operation::UpdateDiagnostics {
|
||||
|
@ -1441,7 +1442,7 @@ impl Buffer {
|
|||
self.send_operation(op, true, cx);
|
||||
}
|
||||
|
||||
fn request_autoindent(&mut self, cx: &mut ModelContext<Self>) {
|
||||
fn request_autoindent(&mut self, cx: &mut Context<Self>) {
|
||||
if let Some(indent_sizes) = self.compute_autoindents() {
|
||||
let indent_sizes = cx.background_executor().spawn(indent_sizes);
|
||||
match cx
|
||||
|
@ -1637,7 +1638,7 @@ impl Buffer {
|
|||
fn apply_autoindents(
|
||||
&mut self,
|
||||
indent_sizes: BTreeMap<u32, IndentSize>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.autoindent_requests.clear();
|
||||
|
||||
|
@ -1695,7 +1696,7 @@ impl Buffer {
|
|||
|
||||
/// Spawns a background task that asynchronously computes a `Diff` between the buffer's text
|
||||
/// and the given new text.
|
||||
pub fn diff(&self, mut new_text: String, cx: &AppContext) -> Task<Diff> {
|
||||
pub fn diff(&self, mut new_text: String, cx: &App) -> Task<Diff> {
|
||||
let old_text = self.as_rope().clone();
|
||||
let base_version = self.version();
|
||||
cx.background_executor()
|
||||
|
@ -1768,7 +1769,7 @@ impl Buffer {
|
|||
|
||||
/// Spawns a background task that searches the buffer for any whitespace
|
||||
/// at the ends of a lines, and returns a `Diff` that removes that whitespace.
|
||||
pub fn remove_trailing_whitespace(&self, cx: &AppContext) -> Task<Diff> {
|
||||
pub fn remove_trailing_whitespace(&self, cx: &App) -> Task<Diff> {
|
||||
let old_text = self.as_rope().clone();
|
||||
let line_ending = self.line_ending();
|
||||
let base_version = self.version();
|
||||
|
@ -1788,7 +1789,7 @@ impl Buffer {
|
|||
|
||||
/// Ensures that the buffer ends with a single newline character, and
|
||||
/// no other whitespace.
|
||||
pub fn ensure_final_newline(&mut self, cx: &mut ModelContext<Self>) {
|
||||
pub fn ensure_final_newline(&mut self, cx: &mut Context<Self>) {
|
||||
let len = self.len();
|
||||
let mut offset = len;
|
||||
for chunk in self.as_rope().reversed_chunks_in_range(0..len) {
|
||||
|
@ -1810,7 +1811,7 @@ impl Buffer {
|
|||
/// Applies a diff to the buffer. If the buffer has changed since the given diff was
|
||||
/// calculated, then adjust the diff to account for those changes, and discard any
|
||||
/// parts of the diff that conflict with those changes.
|
||||
pub fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
||||
pub fn apply_diff(&mut self, diff: Diff, cx: &mut Context<Self>) -> Option<TransactionId> {
|
||||
// Check for any edits to the buffer that have occurred since this diff
|
||||
// was computed.
|
||||
let snapshot = self.snapshot();
|
||||
|
@ -1916,7 +1917,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Terminates the current transaction, if this is the outermost transaction.
|
||||
pub fn end_transaction(&mut self, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
||||
pub fn end_transaction(&mut self, cx: &mut Context<Self>) -> Option<TransactionId> {
|
||||
self.end_transaction_at(Instant::now(), cx)
|
||||
}
|
||||
|
||||
|
@ -1926,7 +1927,7 @@ impl Buffer {
|
|||
pub fn end_transaction_at(
|
||||
&mut self,
|
||||
now: Instant,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<TransactionId> {
|
||||
assert!(self.transaction_depth > 0);
|
||||
self.transaction_depth -= 1;
|
||||
|
@ -2002,7 +2003,7 @@ impl Buffer {
|
|||
selections: Arc<[Selection<Anchor>]>,
|
||||
line_mode: bool,
|
||||
cursor_shape: CursorShape,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let lamport_timestamp = self.text.lamport_clock.tick();
|
||||
self.remote_selections.insert(
|
||||
|
@ -2030,7 +2031,7 @@ impl Buffer {
|
|||
|
||||
/// Clears the selections, so that other replicas of the buffer do not see any selections for
|
||||
/// this replica.
|
||||
pub fn remove_active_selections(&mut self, cx: &mut ModelContext<Self>) {
|
||||
pub fn remove_active_selections(&mut self, cx: &mut Context<Self>) {
|
||||
if self
|
||||
.remote_selections
|
||||
.get(&self.text.replica_id())
|
||||
|
@ -2041,7 +2042,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Replaces the buffer's entire text.
|
||||
pub fn set_text<T>(&mut self, text: T, cx: &mut ModelContext<Self>) -> Option<clock::Lamport>
|
||||
pub fn set_text<T>(&mut self, text: T, cx: &mut Context<Self>) -> Option<clock::Lamport>
|
||||
where
|
||||
T: Into<Arc<str>>,
|
||||
{
|
||||
|
@ -2062,7 +2063,7 @@ impl Buffer {
|
|||
&mut self,
|
||||
edits_iter: I,
|
||||
autoindent_mode: Option<AutoindentMode>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<clock::Lamport>
|
||||
where
|
||||
I: IntoIterator<Item = (Range<S>, T)>,
|
||||
|
@ -2184,12 +2185,7 @@ impl Buffer {
|
|||
Some(edit_id)
|
||||
}
|
||||
|
||||
fn did_edit(
|
||||
&mut self,
|
||||
old_version: &clock::Global,
|
||||
was_dirty: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
fn did_edit(&mut self, old_version: &clock::Global, was_dirty: bool, cx: &mut Context<Self>) {
|
||||
if self.edits_since::<usize>(old_version).next().is_none() {
|
||||
return;
|
||||
}
|
||||
|
@ -2203,7 +2199,7 @@ impl Buffer {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn autoindent_ranges<I, T>(&mut self, ranges: I, cx: &mut ModelContext<Self>)
|
||||
pub fn autoindent_ranges<I, T>(&mut self, ranges: I, cx: &mut Context<Self>)
|
||||
where
|
||||
I: IntoIterator<Item = Range<T>>,
|
||||
T: ToOffset + Copy,
|
||||
|
@ -2234,7 +2230,7 @@ impl Buffer {
|
|||
position: impl ToPoint,
|
||||
space_above: bool,
|
||||
space_below: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Point {
|
||||
let mut position = position.to_point(self);
|
||||
|
||||
|
@ -2283,11 +2279,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Applies the given remote operations to the buffer.
|
||||
pub fn apply_ops<I: IntoIterator<Item = Operation>>(
|
||||
&mut self,
|
||||
ops: I,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
pub fn apply_ops<I: IntoIterator<Item = Operation>>(&mut self, ops: I, cx: &mut Context<Self>) {
|
||||
self.pending_autoindent.take();
|
||||
let was_dirty = self.is_dirty();
|
||||
let old_version = self.version.clone();
|
||||
|
@ -2318,7 +2310,7 @@ impl Buffer {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
fn flush_deferred_ops(&mut self, cx: &mut ModelContext<Self>) {
|
||||
fn flush_deferred_ops(&mut self, cx: &mut Context<Self>) {
|
||||
let mut deferred_ops = Vec::new();
|
||||
for op in self.deferred_ops.drain().iter().cloned() {
|
||||
if self.can_apply_op(&op) {
|
||||
|
@ -2353,7 +2345,7 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
fn apply_op(&mut self, operation: Operation, cx: &mut ModelContext<Self>) {
|
||||
fn apply_op(&mut self, operation: Operation, cx: &mut Context<Self>) {
|
||||
match operation {
|
||||
Operation::Buffer(_) => {
|
||||
unreachable!("buffer operations should never be applied at this layer")
|
||||
|
@ -2423,7 +2415,7 @@ impl Buffer {
|
|||
server_id: LanguageServerId,
|
||||
diagnostics: DiagnosticSet,
|
||||
lamport_timestamp: clock::Lamport,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if lamport_timestamp > self.diagnostics_timestamp {
|
||||
let ix = self.diagnostics.binary_search_by_key(&server_id, |e| e.0);
|
||||
|
@ -2445,7 +2437,7 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
fn send_operation(&self, operation: Operation, is_local: bool, cx: &mut ModelContext<Self>) {
|
||||
fn send_operation(&self, operation: Operation, is_local: bool, cx: &mut Context<Self>) {
|
||||
cx.emit(BufferEvent::Operation {
|
||||
operation,
|
||||
is_local,
|
||||
|
@ -2453,13 +2445,13 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Removes the selections for a given peer.
|
||||
pub fn remove_peer(&mut self, replica_id: ReplicaId, cx: &mut ModelContext<Self>) {
|
||||
pub fn remove_peer(&mut self, replica_id: ReplicaId, cx: &mut Context<Self>) {
|
||||
self.remote_selections.remove(&replica_id);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Undoes the most recent transaction.
|
||||
pub fn undo(&mut self, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
||||
pub fn undo(&mut self, cx: &mut Context<Self>) -> Option<TransactionId> {
|
||||
let was_dirty = self.is_dirty();
|
||||
let old_version = self.version.clone();
|
||||
|
||||
|
@ -2476,7 +2468,7 @@ impl Buffer {
|
|||
pub fn undo_transaction(
|
||||
&mut self,
|
||||
transaction_id: TransactionId,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> bool {
|
||||
let was_dirty = self.is_dirty();
|
||||
let old_version = self.version.clone();
|
||||
|
@ -2493,7 +2485,7 @@ impl Buffer {
|
|||
pub fn undo_to_transaction(
|
||||
&mut self,
|
||||
transaction_id: TransactionId,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> bool {
|
||||
let was_dirty = self.is_dirty();
|
||||
let old_version = self.version.clone();
|
||||
|
@ -2509,11 +2501,7 @@ impl Buffer {
|
|||
undone
|
||||
}
|
||||
|
||||
pub fn undo_operations(
|
||||
&mut self,
|
||||
counts: HashMap<Lamport, u32>,
|
||||
cx: &mut ModelContext<Buffer>,
|
||||
) {
|
||||
pub fn undo_operations(&mut self, counts: HashMap<Lamport, u32>, cx: &mut Context<Buffer>) {
|
||||
let was_dirty = self.is_dirty();
|
||||
let operation = self.text.undo_operations(counts);
|
||||
let old_version = self.version.clone();
|
||||
|
@ -2522,7 +2510,7 @@ impl Buffer {
|
|||
}
|
||||
|
||||
/// Manually redoes a specific transaction in the buffer's redo history.
|
||||
pub fn redo(&mut self, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
||||
pub fn redo(&mut self, cx: &mut Context<Self>) -> Option<TransactionId> {
|
||||
let was_dirty = self.is_dirty();
|
||||
let old_version = self.version.clone();
|
||||
|
||||
|
@ -2539,7 +2527,7 @@ impl Buffer {
|
|||
pub fn redo_to_transaction(
|
||||
&mut self,
|
||||
transaction_id: TransactionId,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> bool {
|
||||
let was_dirty = self.is_dirty();
|
||||
let old_version = self.version.clone();
|
||||
|
@ -2560,7 +2548,7 @@ impl Buffer {
|
|||
&mut self,
|
||||
server_id: LanguageServerId,
|
||||
triggers: BTreeSet<String>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.completion_triggers_timestamp = self.text.lamport_clock.tick();
|
||||
if triggers.is_empty() {
|
||||
|
@ -2614,7 +2602,7 @@ impl Buffer {
|
|||
&mut self,
|
||||
marked_string: &str,
|
||||
autoindent_mode: Option<AutoindentMode>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let edits = self.edits_for_marked_text(marked_string);
|
||||
self.edit(edits, autoindent_mode, cx);
|
||||
|
@ -2624,12 +2612,8 @@ impl Buffer {
|
|||
self.text.set_group_interval(group_interval);
|
||||
}
|
||||
|
||||
pub fn randomly_edit<T>(
|
||||
&mut self,
|
||||
rng: &mut T,
|
||||
old_range_count: usize,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) where
|
||||
pub fn randomly_edit<T>(&mut self, rng: &mut T, old_range_count: usize, cx: &mut Context<Self>)
|
||||
where
|
||||
T: rand::Rng,
|
||||
{
|
||||
let mut edits: Vec<(Range<usize>, String)> = Vec::new();
|
||||
|
@ -2656,7 +2640,7 @@ impl Buffer {
|
|||
self.edit(edits, None, cx);
|
||||
}
|
||||
|
||||
pub fn randomly_undo_redo(&mut self, rng: &mut impl rand::Rng, cx: &mut ModelContext<Self>) {
|
||||
pub fn randomly_undo_redo(&mut self, rng: &mut impl rand::Rng, cx: &mut Context<Self>) {
|
||||
let was_dirty = self.is_dirty();
|
||||
let old_version = self.version.clone();
|
||||
|
||||
|
@ -2687,7 +2671,7 @@ impl BufferSnapshot {
|
|||
}
|
||||
/// Returns [`IndentSize`] for a given position that respects user settings
|
||||
/// and language preferences.
|
||||
pub fn language_indent_size_at<T: ToOffset>(&self, position: T, cx: &AppContext) -> IndentSize {
|
||||
pub fn language_indent_size_at<T: ToOffset>(&self, position: T, cx: &App) -> IndentSize {
|
||||
let settings = language_settings(
|
||||
self.language_at(position).map(|l| l.name()),
|
||||
self.file(),
|
||||
|
@ -3027,7 +3011,7 @@ impl BufferSnapshot {
|
|||
pub fn settings_at<'a, D: ToOffset>(
|
||||
&'a self,
|
||||
position: D,
|
||||
cx: &'a AppContext,
|
||||
cx: &'a App,
|
||||
) -> Cow<'a, LanguageSettings> {
|
||||
language_settings(
|
||||
self.language_at(position).map(|l| l.name()),
|
||||
|
@ -4000,7 +3984,7 @@ impl BufferSnapshot {
|
|||
}
|
||||
|
||||
/// Resolves the file path (relative to the worktree root) associated with the underlying file.
|
||||
pub fn resolve_file_path(&self, cx: &AppContext, include_root: bool) -> Option<PathBuf> {
|
||||
pub fn resolve_file_path(&self, cx: &App, include_root: bool) -> Option<PathBuf> {
|
||||
if let Some(file) = self.file() {
|
||||
if file.path().file_name().is_none() || include_root {
|
||||
Some(file.full_path(cx))
|
||||
|
@ -4403,7 +4387,7 @@ impl File for TestFile {
|
|||
&self.path
|
||||
}
|
||||
|
||||
fn full_path(&self, _: &gpui::AppContext) -> PathBuf {
|
||||
fn full_path(&self, _: &gpui::App) -> PathBuf {
|
||||
PathBuf::from(&self.root_name).join(self.path.as_ref())
|
||||
}
|
||||
|
||||
|
@ -4415,11 +4399,11 @@ impl File for TestFile {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
fn file_name<'a>(&'a self, _: &'a gpui::AppContext) -> &'a std::ffi::OsStr {
|
||||
fn file_name<'a>(&'a self, _: &'a gpui::App) -> &'a std::ffi::OsStr {
|
||||
self.path().file_name().unwrap_or(self.root_name.as_ref())
|
||||
}
|
||||
|
||||
fn worktree_id(&self, _: &AppContext) -> WorktreeId {
|
||||
fn worktree_id(&self, _: &App) -> WorktreeId {
|
||||
WorktreeId::from_usize(0)
|
||||
}
|
||||
|
||||
|
@ -4427,7 +4411,7 @@ impl File for TestFile {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
fn to_proto(&self, _: &AppContext) -> rpc::proto::File {
|
||||
fn to_proto(&self, _: &App) -> rpc::proto::File {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ use crate::Buffer;
|
|||
use clock::ReplicaId;
|
||||
use collections::BTreeMap;
|
||||
use futures::FutureExt as _;
|
||||
use gpui::{AppContext, BorrowAppContext, Model};
|
||||
use gpui::{Context, TestAppContext};
|
||||
use gpui::TestAppContext;
|
||||
use gpui::{App, AppContext as _, BorrowAppContext, Entity};
|
||||
use indoc::indoc;
|
||||
use proto::deserialize_operation;
|
||||
use rand::prelude::*;
|
||||
|
@ -42,10 +42,10 @@ fn init_logger() {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_line_endings(cx: &mut gpui::AppContext) {
|
||||
fn test_line_endings(cx: &mut gpui::App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer =
|
||||
Buffer::local("one\r\ntwo\rthree", cx).with_language(Arc::new(rust_lang()), cx);
|
||||
assert_eq!(buffer.text(), "one\ntwo\nthree");
|
||||
|
@ -67,7 +67,7 @@ fn test_line_endings(cx: &mut gpui::AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_select_language(cx: &mut AppContext) {
|
||||
fn test_select_language(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
|
@ -256,13 +256,13 @@ fn file(path: &str) -> Arc<dyn File> {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_edit_events(cx: &mut gpui::AppContext) {
|
||||
fn test_edit_events(cx: &mut gpui::App) {
|
||||
let mut now = Instant::now();
|
||||
let buffer_1_events = Arc::new(Mutex::new(Vec::new()));
|
||||
let buffer_2_events = Arc::new(Mutex::new(Vec::new()));
|
||||
|
||||
let buffer1 = cx.new_model(|cx| Buffer::local("abcdef", cx));
|
||||
let buffer2 = cx.new_model(|cx| {
|
||||
let buffer1 = cx.new(|cx| Buffer::local("abcdef", cx));
|
||||
let buffer2 = cx.new(|cx| {
|
||||
Buffer::remote(
|
||||
BufferId::from(cx.entity_id().as_non_zero_u64()),
|
||||
1,
|
||||
|
@ -354,7 +354,7 @@ fn test_edit_events(cx: &mut gpui::AppContext) {
|
|||
#[gpui::test]
|
||||
async fn test_apply_diff(cx: &mut TestAppContext) {
|
||||
let text = "a\nbb\nccc\ndddd\neeeee\nffffff\n";
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx));
|
||||
let anchor = buffer.update(cx, |buffer, _| buffer.anchor_before(Point::new(3, 3)));
|
||||
|
||||
let text = "a\nccc\ndddd\nffffff\n";
|
||||
|
@ -386,7 +386,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
|
|||
]
|
||||
.join("\n");
|
||||
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx));
|
||||
|
||||
// Spawn a task to format the buffer's whitespace.
|
||||
// Pause so that the formatting task starts running.
|
||||
|
@ -450,8 +450,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
|
|||
#[gpui::test]
|
||||
async fn test_reparse(cx: &mut gpui::TestAppContext) {
|
||||
let text = "fn a() {}";
|
||||
let buffer =
|
||||
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
|
||||
// Wait for the initial text to parse
|
||||
cx.executor().run_until_parked();
|
||||
|
@ -577,7 +576,7 @@ async fn test_reparse(cx: &mut gpui::TestAppContext) {
|
|||
|
||||
#[gpui::test]
|
||||
async fn test_resetting_language(cx: &mut gpui::TestAppContext) {
|
||||
let buffer = cx.new_model(|cx| {
|
||||
let buffer = cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("{}", cx).with_language(Arc::new(rust_lang()), cx);
|
||||
buffer.set_sync_parse_timeout(Duration::ZERO);
|
||||
buffer
|
||||
|
@ -626,8 +625,7 @@ async fn test_outline(cx: &mut gpui::TestAppContext) {
|
|||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer =
|
||||
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let outline = buffer
|
||||
.update(cx, |buffer, _| buffer.snapshot().outline(None))
|
||||
.unwrap();
|
||||
|
@ -711,8 +709,7 @@ async fn test_outline_nodes_with_newlines(cx: &mut gpui::TestAppContext) {
|
|||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer =
|
||||
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let outline = buffer
|
||||
.update(cx, |buffer, _| buffer.snapshot().outline(None))
|
||||
.unwrap();
|
||||
|
@ -748,7 +745,7 @@ async fn test_outline_with_extra_context(cx: &mut gpui::TestAppContext) {
|
|||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(language), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(language), cx));
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
||||
// extra context nodes are included in the outline.
|
||||
|
@ -774,7 +771,7 @@ async fn test_outline_with_extra_context(cx: &mut gpui::TestAppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_outline_annotations(cx: &mut AppContext) {
|
||||
fn test_outline_annotations(cx: &mut App) {
|
||||
// Add this new test case
|
||||
let text = r#"
|
||||
/// This is a doc comment
|
||||
|
@ -794,8 +791,7 @@ fn test_outline_annotations(cx: &mut AppContext) {
|
|||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer =
|
||||
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let outline = buffer
|
||||
.update(cx, |buffer, _| buffer.snapshot().outline(None))
|
||||
.unwrap();
|
||||
|
@ -845,8 +841,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
|
|||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer =
|
||||
cx.new_model(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
||||
// point is at the start of an item
|
||||
|
@ -916,7 +911,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_text_objects(cx: &mut AppContext) {
|
||||
fn test_text_objects(cx: &mut App) {
|
||||
let (text, ranges) = marked_text_ranges(
|
||||
indoc! {r#"
|
||||
impl Hello {
|
||||
|
@ -927,7 +922,7 @@ fn test_text_objects(cx: &mut AppContext) {
|
|||
);
|
||||
|
||||
let buffer =
|
||||
cx.new_model(|cx| Buffer::local(text.clone(), cx).with_language(Arc::new(rust_lang()), cx));
|
||||
cx.new(|cx| Buffer::local(text.clone(), cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
||||
let matches = snapshot
|
||||
|
@ -949,7 +944,7 @@ fn test_text_objects(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_enclosing_bracket_ranges(cx: &mut AppContext) {
|
||||
fn test_enclosing_bracket_ranges(cx: &mut App) {
|
||||
let mut assert = |selection_text, range_markers| {
|
||||
assert_bracket_pairs(selection_text, range_markers, rust_lang(), cx)
|
||||
};
|
||||
|
@ -1065,7 +1060,7 @@ fn test_enclosing_bracket_ranges(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: &mut AppContext) {
|
||||
fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: &mut App) {
|
||||
let mut assert = |selection_text, bracket_pair_texts| {
|
||||
assert_bracket_pairs(selection_text, bracket_pair_texts, javascript_lang(), cx)
|
||||
};
|
||||
|
@ -1097,8 +1092,8 @@ fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: &
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_range_for_syntax_ancestor(cx: &mut AppContext) {
|
||||
cx.new_model(|cx| {
|
||||
fn test_range_for_syntax_ancestor(cx: &mut App) {
|
||||
cx.new(|cx| {
|
||||
let text = "fn a() { b(|c| {}) }";
|
||||
let buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let snapshot = buffer.snapshot();
|
||||
|
@ -1147,10 +1142,10 @@ fn test_range_for_syntax_ancestor(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_with_soft_tabs(cx: &mut AppContext) {
|
||||
fn test_autoindent_with_soft_tabs(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = "fn a() {}";
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
|
||||
|
@ -1187,12 +1182,12 @@ fn test_autoindent_with_soft_tabs(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_with_hard_tabs(cx: &mut AppContext) {
|
||||
fn test_autoindent_with_hard_tabs(cx: &mut App) {
|
||||
init_settings(cx, |settings| {
|
||||
settings.defaults.hard_tabs = Some(true);
|
||||
});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = "fn a() {}";
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
|
||||
|
@ -1229,10 +1224,10 @@ fn test_autoindent_with_hard_tabs(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppContext) {
|
||||
fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local(
|
||||
"
|
||||
fn a() {
|
||||
|
@ -1371,7 +1366,7 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppC
|
|||
buffer
|
||||
});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
eprintln!("second buffer: {:?}", cx.entity_id());
|
||||
|
||||
let mut buffer = Buffer::local(
|
||||
|
@ -1434,10 +1429,10 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut AppC
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut AppContext) {
|
||||
fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local(
|
||||
"
|
||||
fn a() {
|
||||
|
@ -1495,10 +1490,10 @@ fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut Ap
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut AppContext) {
|
||||
fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local(
|
||||
"
|
||||
fn a() {}
|
||||
|
@ -1551,10 +1546,10 @@ fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut AppContext) {
|
||||
fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = "a\nb";
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
buffer.edit(
|
||||
|
@ -1568,10 +1563,10 @@ fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_multi_line_insertion(cx: &mut AppContext) {
|
||||
fn test_autoindent_multi_line_insertion(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = "
|
||||
const a: usize = 1;
|
||||
fn b() {
|
||||
|
@ -1609,10 +1604,10 @@ fn test_autoindent_multi_line_insertion(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_block_mode(cx: &mut AppContext) {
|
||||
fn test_autoindent_block_mode(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = r#"
|
||||
fn a() {
|
||||
b();
|
||||
|
@ -1692,10 +1687,10 @@ fn test_autoindent_block_mode(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut AppContext) {
|
||||
fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = r#"
|
||||
fn a() {
|
||||
if b() {
|
||||
|
@ -1771,10 +1766,10 @@ fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut AppContex
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_block_mode_multiple_adjacent_ranges(cx: &mut AppContext) {
|
||||
fn test_autoindent_block_mode_multiple_adjacent_ranges(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let (text, ranges_to_replace) = marked_text_ranges(
|
||||
&"
|
||||
mod numbers {
|
||||
|
@ -1834,10 +1829,10 @@ fn test_autoindent_block_mode_multiple_adjacent_ranges(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_language_without_indents_query(cx: &mut AppContext) {
|
||||
fn test_autoindent_language_without_indents_query(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = "
|
||||
* one
|
||||
- a
|
||||
|
@ -1878,7 +1873,7 @@ fn test_autoindent_language_without_indents_query(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_with_injected_languages(cx: &mut AppContext) {
|
||||
fn test_autoindent_with_injected_languages(cx: &mut App) {
|
||||
init_settings(cx, |settings| {
|
||||
settings.languages.extend([
|
||||
(
|
||||
|
@ -1906,7 +1901,7 @@ fn test_autoindent_with_injected_languages(cx: &mut AppContext) {
|
|||
language_registry.add(html_language.clone());
|
||||
language_registry.add(javascript_language.clone());
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let (text, ranges) = marked_text_ranges(
|
||||
&"
|
||||
<div>ˇ
|
||||
|
@ -1952,12 +1947,12 @@ fn test_autoindent_with_injected_languages(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_query_with_outdent_captures(cx: &mut AppContext) {
|
||||
fn test_autoindent_query_with_outdent_captures(cx: &mut App) {
|
||||
init_settings(cx, |settings| {
|
||||
settings.defaults.tab_size = Some(2.try_into().unwrap());
|
||||
});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("", cx).with_language(Arc::new(ruby_lang()), cx);
|
||||
|
||||
let text = r#"
|
||||
|
@ -2001,7 +1996,7 @@ async fn test_async_autoindents_preserve_preview(cx: &mut TestAppContext) {
|
|||
|
||||
// First we insert some newlines to request an auto-indent (asynchronously).
|
||||
// Then we request that a preview tab be preserved for the new version, even though it's edited.
|
||||
let buffer = cx.new_model(|cx| {
|
||||
let buffer = cx.new(|cx| {
|
||||
let text = "fn a() {}";
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
|
||||
|
@ -2053,11 +2048,11 @@ async fn test_async_autoindents_preserve_preview(cx: &mut TestAppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_insert_empty_line(cx: &mut AppContext) {
|
||||
fn test_insert_empty_line(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
// Insert empty line at the beginning, requesting an empty line above
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(0, 0), true, false, cx);
|
||||
assert_eq!(buffer.text(), "\nabc\ndef\nghi");
|
||||
|
@ -2066,7 +2061,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
});
|
||||
|
||||
// Insert empty line at the beginning, requesting an empty line above and below
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(0, 0), true, true, cx);
|
||||
assert_eq!(buffer.text(), "\n\nabc\ndef\nghi");
|
||||
|
@ -2075,7 +2070,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
});
|
||||
|
||||
// Insert empty line at the start of a line, requesting empty lines above and below
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(2, 0), true, true, cx);
|
||||
assert_eq!(buffer.text(), "abc\ndef\n\n\n\nghi");
|
||||
|
@ -2084,7 +2079,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
});
|
||||
|
||||
// Insert empty line in the middle of a line, requesting empty lines above and below
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndefghi\njkl", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(1, 3), true, true, cx);
|
||||
assert_eq!(buffer.text(), "abc\ndef\n\n\n\nghi\njkl");
|
||||
|
@ -2093,7 +2088,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
});
|
||||
|
||||
// Insert empty line in the middle of a line, requesting empty line above only
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndefghi\njkl", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(1, 3), true, false, cx);
|
||||
assert_eq!(buffer.text(), "abc\ndef\n\n\nghi\njkl");
|
||||
|
@ -2102,7 +2097,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
});
|
||||
|
||||
// Insert empty line in the middle of a line, requesting empty line below only
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndefghi\njkl", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(1, 3), false, true, cx);
|
||||
assert_eq!(buffer.text(), "abc\ndef\n\n\nghi\njkl");
|
||||
|
@ -2111,7 +2106,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
});
|
||||
|
||||
// Insert empty line at the end, requesting empty lines above and below
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(2, 3), true, true, cx);
|
||||
assert_eq!(buffer.text(), "abc\ndef\nghi\n\n\n");
|
||||
|
@ -2120,7 +2115,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
});
|
||||
|
||||
// Insert empty line at the end, requesting empty line above only
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(2, 3), true, false, cx);
|
||||
assert_eq!(buffer.text(), "abc\ndef\nghi\n\n");
|
||||
|
@ -2129,7 +2124,7 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
});
|
||||
|
||||
// Insert empty line at the end, requesting empty line below only
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc\ndef\nghi", cx);
|
||||
let point = buffer.insert_empty_line(Point::new(2, 3), false, true, cx);
|
||||
assert_eq!(buffer.text(), "abc\ndef\nghi\n\n");
|
||||
|
@ -2139,10 +2134,10 @@ fn test_insert_empty_line(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_language_scope_at_with_javascript(cx: &mut AppContext) {
|
||||
fn test_language_scope_at_with_javascript(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let language = Language::new(
|
||||
LanguageConfig {
|
||||
name: "JavaScript".into(),
|
||||
|
@ -2281,10 +2276,10 @@ fn test_language_scope_at_with_javascript(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_language_scope_at_with_rust(cx: &mut AppContext) {
|
||||
fn test_language_scope_at_with_rust(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let language = Language::new(
|
||||
LanguageConfig {
|
||||
name: "Rust".into(),
|
||||
|
@ -2350,10 +2345,10 @@ fn test_language_scope_at_with_rust(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_language_scope_at_with_combined_injections(cx: &mut AppContext) {
|
||||
fn test_language_scope_at_with_combined_injections(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = r#"
|
||||
<ol>
|
||||
<% people.each do |person| %>
|
||||
|
@ -2398,10 +2393,10 @@ fn test_language_scope_at_with_combined_injections(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_language_at_with_hidden_languages(cx: &mut AppContext) {
|
||||
fn test_language_at_with_hidden_languages(cx: &mut App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new_model(|cx| {
|
||||
cx.new(|cx| {
|
||||
let text = r#"
|
||||
this is an *emphasized* word.
|
||||
"#
|
||||
|
@ -2437,10 +2432,10 @@ fn test_language_at_with_hidden_languages(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_serialization(cx: &mut gpui::AppContext) {
|
||||
fn test_serialization(cx: &mut gpui::App) {
|
||||
let mut now = Instant::now();
|
||||
|
||||
let buffer1 = cx.new_model(|cx| {
|
||||
let buffer1 = cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("abc", cx);
|
||||
buffer.edit([(3..3, "D")], None, cx);
|
||||
|
||||
|
@ -2463,7 +2458,7 @@ fn test_serialization(cx: &mut gpui::AppContext) {
|
|||
let ops = cx
|
||||
.background_executor()
|
||||
.block(buffer1.read(cx).serialize_ops(None, cx));
|
||||
let buffer2 = cx.new_model(|cx| {
|
||||
let buffer2 = cx.new(|cx| {
|
||||
let mut buffer = Buffer::from_proto(1, Capability::ReadWrite, state, None).unwrap();
|
||||
buffer.apply_ops(
|
||||
ops.into_iter()
|
||||
|
@ -2479,10 +2474,10 @@ fn test_serialization(cx: &mut gpui::AppContext) {
|
|||
fn test_branch_and_merge(cx: &mut TestAppContext) {
|
||||
cx.update(|cx| init_settings(cx, |_| {}));
|
||||
|
||||
let base = cx.new_model(|cx| Buffer::local("one\ntwo\nthree\n", cx));
|
||||
let base = cx.new(|cx| Buffer::local("one\ntwo\nthree\n", cx));
|
||||
|
||||
// Create a remote replica of the base buffer.
|
||||
let base_replica = cx.new_model(|cx| {
|
||||
let base_replica = cx.new(|cx| {
|
||||
Buffer::from_proto(1, Capability::ReadWrite, base.read(cx).to_proto(cx), None).unwrap()
|
||||
});
|
||||
base.update(cx, |_buffer, cx| {
|
||||
|
@ -2566,7 +2561,7 @@ fn test_branch_and_merge(cx: &mut TestAppContext) {
|
|||
fn test_merge_into_base(cx: &mut TestAppContext) {
|
||||
cx.update(|cx| init_settings(cx, |_| {}));
|
||||
|
||||
let base = cx.new_model(|cx| Buffer::local("abcdefghijk", cx));
|
||||
let base = cx.new(|cx| Buffer::local("abcdefghijk", cx));
|
||||
let branch = base.update(cx, |buffer, cx| buffer.branch(cx));
|
||||
|
||||
// Make 3 edits, merge one into the base.
|
||||
|
@ -2606,7 +2601,7 @@ fn test_merge_into_base(cx: &mut TestAppContext) {
|
|||
fn test_undo_after_merge_into_base(cx: &mut TestAppContext) {
|
||||
cx.update(|cx| init_settings(cx, |_| {}));
|
||||
|
||||
let base = cx.new_model(|cx| Buffer::local("abcdefghijk", cx));
|
||||
let base = cx.new(|cx| Buffer::local("abcdefghijk", cx));
|
||||
let branch = base.update(cx, |buffer, cx| buffer.branch(cx));
|
||||
|
||||
// Make 2 edits, merge one into the base.
|
||||
|
@ -2655,7 +2650,7 @@ async fn test_preview_edits(cx: &mut TestAppContext) {
|
|||
LanguageConfig::default(),
|
||||
Some(tree_sitter_rust::LANGUAGE.into()),
|
||||
));
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx).with_language(language, cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(language, cx));
|
||||
let highlighted_edits = preview_edits(
|
||||
&buffer,
|
||||
cx,
|
||||
|
@ -2672,7 +2667,7 @@ async fn test_preview_edits(cx: &mut TestAppContext) {
|
|||
);
|
||||
|
||||
async fn preview_edits(
|
||||
buffer: &Model<Buffer>,
|
||||
buffer: &Entity<Buffer>,
|
||||
cx: &mut TestAppContext,
|
||||
edits: impl IntoIterator<Item = (Range<Point>, &'static str)>,
|
||||
) -> HighlightedEdits {
|
||||
|
@ -2714,7 +2709,7 @@ async fn test_preview_edits_interpolate(cx: &mut TestAppContext) {
|
|||
LanguageConfig::default(),
|
||||
Some(tree_sitter_rust::LANGUAGE.into()),
|
||||
));
|
||||
let buffer = cx.new_model(|cx| Buffer::local(text, cx).with_language(language, cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(language, cx));
|
||||
|
||||
let edits = construct_edits(&buffer, [(Point::new(1, 4)..Point::new(1, 4), "first")], cx);
|
||||
let edit_preview = buffer
|
||||
|
@ -2754,7 +2749,7 @@ async fn test_preview_edits_interpolate(cx: &mut TestAppContext) {
|
|||
);
|
||||
|
||||
fn construct_edits(
|
||||
buffer: &Model<Buffer>,
|
||||
buffer: &Entity<Buffer>,
|
||||
edits: impl IntoIterator<Item = (Range<Point>, &'static str)>,
|
||||
cx: &mut TestAppContext,
|
||||
) -> Arc<[(Range<Anchor>, String)]> {
|
||||
|
@ -2775,7 +2770,7 @@ async fn test_preview_edits_interpolate(cx: &mut TestAppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test(iterations = 100)]
|
||||
fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
|
||||
fn test_random_collaboration(cx: &mut App, mut rng: StdRng) {
|
||||
let min_peers = env::var("MIN_PEERS")
|
||||
.map(|i| i.parse().expect("invalid `MIN_PEERS` variable"))
|
||||
.unwrap_or(1);
|
||||
|
@ -2793,10 +2788,10 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
|
|||
let mut replica_ids = Vec::new();
|
||||
let mut buffers = Vec::new();
|
||||
let network = Arc::new(Mutex::new(Network::new(rng.clone())));
|
||||
let base_buffer = cx.new_model(|cx| Buffer::local(base_text.as_str(), cx));
|
||||
let base_buffer = cx.new(|cx| Buffer::local(base_text.as_str(), cx));
|
||||
|
||||
for i in 0..rng.gen_range(min_peers..=max_peers) {
|
||||
let buffer = cx.new_model(|cx| {
|
||||
let buffer = cx.new(|cx| {
|
||||
let state = base_buffer.read(cx).to_proto(cx);
|
||||
let ops = cx
|
||||
.background_executor()
|
||||
|
@ -2810,7 +2805,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
|
|||
);
|
||||
buffer.set_group_interval(Duration::from_millis(rng.gen_range(0..=200)));
|
||||
let network = network.clone();
|
||||
cx.subscribe(&cx.handle(), move |buffer, _, event, _| {
|
||||
cx.subscribe(&cx.model(), move |buffer, _, event, _| {
|
||||
if let BufferEvent::Operation {
|
||||
operation,
|
||||
is_local: true,
|
||||
|
@ -2920,7 +2915,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
|
|||
new_replica_id,
|
||||
replica_id
|
||||
);
|
||||
new_buffer = Some(cx.new_model(|cx| {
|
||||
new_buffer = Some(cx.new(|cx| {
|
||||
let mut new_buffer = Buffer::from_proto(
|
||||
new_replica_id,
|
||||
Capability::ReadWrite,
|
||||
|
@ -2941,7 +2936,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
|
|||
);
|
||||
new_buffer.set_group_interval(Duration::from_millis(rng.gen_range(0..=200)));
|
||||
let network = network.clone();
|
||||
cx.subscribe(&cx.handle(), move |buffer, _, event, _| {
|
||||
cx.subscribe(&cx.model(), move |buffer, _, event, _| {
|
||||
if let BufferEvent::Operation {
|
||||
operation,
|
||||
is_local: true,
|
||||
|
@ -3357,7 +3352,7 @@ pub fn markdown_inline_lang() -> Language {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
fn get_tree_sexp(buffer: &Model<Buffer>, cx: &mut gpui::TestAppContext) -> String {
|
||||
fn get_tree_sexp(buffer: &Entity<Buffer>, cx: &mut gpui::TestAppContext) -> String {
|
||||
buffer.update(cx, |buffer, _| {
|
||||
let snapshot = buffer.snapshot();
|
||||
let layers = snapshot.syntax.layers(buffer.as_text_snapshot());
|
||||
|
@ -3370,12 +3365,11 @@ fn assert_bracket_pairs(
|
|||
selection_text: &'static str,
|
||||
bracket_pair_texts: Vec<&'static str>,
|
||||
language: Language,
|
||||
cx: &mut AppContext,
|
||||
cx: &mut App,
|
||||
) {
|
||||
let (expected_text, selection_ranges) = marked_text_ranges(selection_text, false);
|
||||
let buffer = cx.new_model(|cx| {
|
||||
Buffer::local(expected_text.clone(), cx).with_language(Arc::new(language), cx)
|
||||
});
|
||||
let buffer =
|
||||
cx.new(|cx| Buffer::local(expected_text.clone(), cx).with_language(Arc::new(language), cx));
|
||||
let buffer = buffer.update(cx, |buffer, _cx| buffer.snapshot());
|
||||
|
||||
let selection_range = selection_ranges[0].clone();
|
||||
|
@ -3395,7 +3389,7 @@ fn assert_bracket_pairs(
|
|||
);
|
||||
}
|
||||
|
||||
fn init_settings(cx: &mut AppContext, f: fn(&mut AllLanguageSettingsContent)) {
|
||||
fn init_settings(cx: &mut App, f: fn(&mut AllLanguageSettingsContent)) {
|
||||
let settings_store = SettingsStore::test(cx);
|
||||
cx.set_global(settings_store);
|
||||
crate::init(cx);
|
||||
|
|
|
@ -22,12 +22,12 @@ pub mod buffer_tests;
|
|||
pub mod markdown;
|
||||
|
||||
use crate::language_settings::SoftWrap;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use async_trait::async_trait;
|
||||
use collections::{HashMap, HashSet};
|
||||
use fs::Fs;
|
||||
use futures::Future;
|
||||
use gpui::{AppContext, AsyncAppContext, Model, SharedString, Task};
|
||||
use gpui::{App, AsyncAppContext, Entity, SharedString, Task};
|
||||
pub use highlight_map::HighlightMap;
|
||||
use http_client::HttpClient;
|
||||
pub use language_registry::{LanguageName, LoadedLanguage};
|
||||
|
@ -86,7 +86,7 @@ pub use tree_sitter::{Node, Parser, Tree, TreeCursor};
|
|||
/// Initializes the `language` crate.
|
||||
///
|
||||
/// This should be called before making use of items from the create.
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut App) {
|
||||
language_settings::init(cx);
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ pub trait ToLspPosition {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Location {
|
||||
pub buffer: Model<Buffer>,
|
||||
pub buffer: Entity<Buffer>,
|
||||
pub range: Range<Anchor>,
|
||||
}
|
||||
|
||||
|
@ -266,7 +266,7 @@ impl CachedLspAdapter {
|
|||
// e.g. to display a notification or fetch data from the web.
|
||||
#[async_trait]
|
||||
pub trait LspAdapterDelegate: Send + Sync {
|
||||
fn show_notification(&self, message: &str, cx: &mut AppContext);
|
||||
fn show_notification(&self, message: &str, cx: &mut App);
|
||||
fn http_client(&self) -> Arc<dyn HttpClient>;
|
||||
fn worktree_id(&self) -> WorktreeId;
|
||||
fn worktree_root_path(&self) -> &Path;
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
with_parser, CachedLspAdapter, File, Language, LanguageConfig, LanguageId, LanguageMatcher,
|
||||
LanguageServerName, LspAdapter, ToolchainLister, PLAIN_TEXT,
|
||||
};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use anyhow::{anyhow, Context as _, Result};
|
||||
use collections::{hash_map, HashMap, HashSet};
|
||||
|
||||
use futures::{
|
||||
|
@ -14,7 +14,7 @@ use futures::{
|
|||
Future,
|
||||
};
|
||||
use globset::GlobSet;
|
||||
use gpui::{AppContext, BackgroundExecutor};
|
||||
use gpui::{App, BackgroundExecutor};
|
||||
use lsp::LanguageServerId;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use postage::watch;
|
||||
|
@ -613,7 +613,7 @@ impl LanguageRegistry {
|
|||
self: &Arc<Self>,
|
||||
file: &Arc<dyn File>,
|
||||
content: Option<&Rope>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Option<AvailableLanguage> {
|
||||
let user_file_types = all_language_settings(Some(file), cx);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use ec4rs::{
|
|||
Properties as EditorconfigProperties,
|
||||
};
|
||||
use globset::{Glob, GlobMatcher, GlobSet, GlobSetBuilder};
|
||||
use gpui::AppContext;
|
||||
use gpui::App;
|
||||
use itertools::{Either, Itertools};
|
||||
use schemars::{
|
||||
schema::{InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec},
|
||||
|
@ -27,7 +27,7 @@ use std::{borrow::Cow, num::NonZeroU32, path::Path, sync::Arc};
|
|||
use util::serde::default_true;
|
||||
|
||||
/// Initializes the language settings.
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut App) {
|
||||
AllLanguageSettings::register(cx);
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ pub fn init(cx: &mut AppContext) {
|
|||
pub fn language_settings<'a>(
|
||||
language: Option<LanguageName>,
|
||||
file: Option<&'a Arc<dyn File>>,
|
||||
cx: &'a AppContext,
|
||||
cx: &'a App,
|
||||
) -> Cow<'a, LanguageSettings> {
|
||||
let location = file.map(|f| SettingsLocation {
|
||||
worktree_id: f.worktree_id(cx),
|
||||
|
@ -47,7 +47,7 @@ pub fn language_settings<'a>(
|
|||
/// Returns the settings for all languages from the provided file.
|
||||
pub fn all_language_settings<'a>(
|
||||
file: Option<&'a Arc<dyn File>>,
|
||||
cx: &'a AppContext,
|
||||
cx: &'a App,
|
||||
) -> &'a AllLanguageSettings {
|
||||
let location = file.map(|f| SettingsLocation {
|
||||
worktree_id: f.worktree_id(cx),
|
||||
|
@ -857,7 +857,7 @@ impl AllLanguageSettings {
|
|||
&'a self,
|
||||
location: Option<SettingsLocation<'a>>,
|
||||
language_name: Option<&LanguageName>,
|
||||
cx: &'a AppContext,
|
||||
cx: &'a App,
|
||||
) -> Cow<'a, LanguageSettings> {
|
||||
let settings = language_name
|
||||
.and_then(|name| self.languages.get(name))
|
||||
|
@ -890,7 +890,7 @@ impl AllLanguageSettings {
|
|||
&self,
|
||||
language: Option<&Arc<Language>>,
|
||||
path: Option<&Path>,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> bool {
|
||||
if let Some(path) = path {
|
||||
if !self.inline_completions_enabled_for_path(path) {
|
||||
|
@ -979,7 +979,7 @@ impl settings::Settings for AllLanguageSettings {
|
|||
|
||||
type FileContent = AllLanguageSettingsContent;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
|
||||
let default_value = sources.default;
|
||||
|
||||
// A default is provided for all settings.
|
||||
|
@ -1095,7 +1095,7 @@ impl settings::Settings for AllLanguageSettings {
|
|||
fn json_schema(
|
||||
generator: &mut schemars::gen::SchemaGenerator,
|
||||
params: &settings::SettingsJsonSchemaParams,
|
||||
_: &AppContext,
|
||||
_: &App,
|
||||
) -> schemars::schema::RootSchema {
|
||||
let mut root_schema = generator.root_schema_for::<Self::FileContent>();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
|||
buffer_tests::{markdown_inline_lang, markdown_lang},
|
||||
LanguageConfig, LanguageMatcher,
|
||||
};
|
||||
use gpui::AppContext;
|
||||
use gpui::App;
|
||||
use rand::rngs::StdRng;
|
||||
use std::{env, ops::Range, sync::Arc};
|
||||
use text::{Buffer, BufferId};
|
||||
|
@ -83,7 +83,7 @@ fn test_splice_included_ranges() {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_syntax_map_layers_for_range(cx: &mut AppContext) {
|
||||
fn test_syntax_map_layers_for_range(cx: &mut App) {
|
||||
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
let language = Arc::new(rust_lang());
|
||||
registry.add(language.clone());
|
||||
|
@ -180,7 +180,7 @@ fn test_syntax_map_layers_for_range(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_dynamic_language_injection(cx: &mut AppContext) {
|
||||
fn test_dynamic_language_injection(cx: &mut App) {
|
||||
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
let markdown = Arc::new(markdown_lang());
|
||||
let markdown_inline = Arc::new(markdown_inline_lang());
|
||||
|
@ -268,7 +268,7 @@ fn test_dynamic_language_injection(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_typing_multiple_new_injections(cx: &mut AppContext) {
|
||||
fn test_typing_multiple_new_injections(cx: &mut App) {
|
||||
let (buffer, syntax_map) = test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -298,7 +298,7 @@ fn test_typing_multiple_new_injections(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_pasting_new_injection_line_between_others(cx: &mut AppContext) {
|
||||
fn test_pasting_new_injection_line_between_others(cx: &mut App) {
|
||||
let (buffer, syntax_map) = test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -346,7 +346,7 @@ fn test_pasting_new_injection_line_between_others(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_joining_injections_with_child_injections(cx: &mut AppContext) {
|
||||
fn test_joining_injections_with_child_injections(cx: &mut App) {
|
||||
let (buffer, syntax_map) = test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -391,7 +391,7 @@ fn test_joining_injections_with_child_injections(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_editing_edges_of_injection(cx: &mut AppContext) {
|
||||
fn test_editing_edges_of_injection(cx: &mut App) {
|
||||
test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -421,7 +421,7 @@ fn test_editing_edges_of_injection(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_edits_preceding_and_intersecting_injection(cx: &mut AppContext) {
|
||||
fn test_edits_preceding_and_intersecting_injection(cx: &mut App) {
|
||||
test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -434,7 +434,7 @@ fn test_edits_preceding_and_intersecting_injection(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_non_local_changes_create_injections(cx: &mut AppContext) {
|
||||
fn test_non_local_changes_create_injections(cx: &mut App) {
|
||||
test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -454,7 +454,7 @@ fn test_non_local_changes_create_injections(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_creating_many_injections_in_one_edit(cx: &mut AppContext) {
|
||||
fn test_creating_many_injections_in_one_edit(cx: &mut App) {
|
||||
test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -485,7 +485,7 @@ fn test_creating_many_injections_in_one_edit(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_editing_across_injection_boundary(cx: &mut AppContext) {
|
||||
fn test_editing_across_injection_boundary(cx: &mut App) {
|
||||
test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -514,7 +514,7 @@ fn test_editing_across_injection_boundary(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_removing_injection_by_replacing_across_boundary(cx: &mut AppContext) {
|
||||
fn test_removing_injection_by_replacing_across_boundary(cx: &mut App) {
|
||||
test_edit_sequence(
|
||||
"Rust",
|
||||
&[
|
||||
|
@ -541,7 +541,7 @@ fn test_removing_injection_by_replacing_across_boundary(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_combined_injections_simple(cx: &mut AppContext) {
|
||||
fn test_combined_injections_simple(cx: &mut App) {
|
||||
let (buffer, syntax_map) = test_edit_sequence(
|
||||
"ERB",
|
||||
&[
|
||||
|
@ -589,7 +589,7 @@ fn test_combined_injections_simple(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_combined_injections_empty_ranges(cx: &mut AppContext) {
|
||||
fn test_combined_injections_empty_ranges(cx: &mut App) {
|
||||
test_edit_sequence(
|
||||
"ERB",
|
||||
&[
|
||||
|
@ -608,7 +608,7 @@ fn test_combined_injections_empty_ranges(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_combined_injections_edit_edges_of_ranges(cx: &mut AppContext) {
|
||||
fn test_combined_injections_edit_edges_of_ranges(cx: &mut App) {
|
||||
let (buffer, syntax_map) = test_edit_sequence(
|
||||
"ERB",
|
||||
&[
|
||||
|
@ -640,7 +640,7 @@ fn test_combined_injections_edit_edges_of_ranges(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_combined_injections_splitting_some_injections(cx: &mut AppContext) {
|
||||
fn test_combined_injections_splitting_some_injections(cx: &mut App) {
|
||||
let (_buffer, _syntax_map) = test_edit_sequence(
|
||||
"ERB",
|
||||
&[
|
||||
|
@ -666,7 +666,7 @@ fn test_combined_injections_splitting_some_injections(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_combined_injections_editing_after_last_injection(cx: &mut AppContext) {
|
||||
fn test_combined_injections_editing_after_last_injection(cx: &mut App) {
|
||||
test_edit_sequence(
|
||||
"ERB",
|
||||
&[
|
||||
|
@ -687,7 +687,7 @@ fn test_combined_injections_editing_after_last_injection(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_combined_injections_inside_injections(cx: &mut AppContext) {
|
||||
fn test_combined_injections_inside_injections(cx: &mut App) {
|
||||
let (buffer, syntax_map) = test_edit_sequence(
|
||||
"Markdown",
|
||||
&[
|
||||
|
@ -764,7 +764,7 @@ fn test_combined_injections_inside_injections(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_empty_combined_injections_inside_injections(cx: &mut AppContext) {
|
||||
fn test_empty_combined_injections_inside_injections(cx: &mut App) {
|
||||
let (buffer, syntax_map) = test_edit_sequence(
|
||||
"Markdown",
|
||||
&[r#"
|
||||
|
@ -798,7 +798,7 @@ fn test_empty_combined_injections_inside_injections(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test(iterations = 50)]
|
||||
fn test_random_syntax_map_edits_rust_macros(rng: StdRng, cx: &mut AppContext) {
|
||||
fn test_random_syntax_map_edits_rust_macros(rng: StdRng, cx: &mut App) {
|
||||
let text = r#"
|
||||
fn test_something() {
|
||||
let vec = vec![5, 1, 3, 8];
|
||||
|
@ -824,7 +824,7 @@ fn test_random_syntax_map_edits_rust_macros(rng: StdRng, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test(iterations = 50)]
|
||||
fn test_random_syntax_map_edits_with_erb(rng: StdRng, cx: &mut AppContext) {
|
||||
fn test_random_syntax_map_edits_with_erb(rng: StdRng, cx: &mut App) {
|
||||
let text = r#"
|
||||
<div id="main">
|
||||
<% if one?(:two) %>
|
||||
|
@ -853,7 +853,7 @@ fn test_random_syntax_map_edits_with_erb(rng: StdRng, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test(iterations = 50)]
|
||||
fn test_random_syntax_map_edits_with_heex(rng: StdRng, cx: &mut AppContext) {
|
||||
fn test_random_syntax_map_edits_with_heex(rng: StdRng, cx: &mut App) {
|
||||
let text = r#"
|
||||
defmodule TheModule do
|
||||
def the_method(assigns) do
|
||||
|
@ -1060,11 +1060,7 @@ fn check_interpolation(
|
|||
}
|
||||
}
|
||||
|
||||
fn test_edit_sequence(
|
||||
language_name: &str,
|
||||
steps: &[&str],
|
||||
cx: &mut AppContext,
|
||||
) -> (Buffer, SyntaxMap) {
|
||||
fn test_edit_sequence(language_name: &str, steps: &[&str], cx: &mut App) -> (Buffer, SyntaxMap) {
|
||||
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
registry.add(Arc::new(elixir_lang()));
|
||||
registry.add(Arc::new(heex_lang()));
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{LanguageToolchainStore, Location, Runnable};
|
|||
|
||||
use anyhow::Result;
|
||||
use collections::HashMap;
|
||||
use gpui::{AppContext, Task};
|
||||
use gpui::{App, Task};
|
||||
use task::{TaskTemplates, TaskVariables};
|
||||
use text::BufferId;
|
||||
|
||||
|
@ -27,7 +27,7 @@ pub trait ContextProvider: Send + Sync {
|
|||
_location: &Location,
|
||||
_project_env: Option<HashMap<String, String>>,
|
||||
_toolchains: Arc<dyn LanguageToolchainStore>,
|
||||
_cx: &mut AppContext,
|
||||
_cx: &mut App,
|
||||
) -> Task<Result<TaskVariables>> {
|
||||
Task::ready(Ok(TaskVariables::default()))
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ pub trait ContextProvider: Send + Sync {
|
|||
fn associated_tasks(
|
||||
&self,
|
||||
_: Option<Arc<dyn crate::File>>,
|
||||
_cx: &AppContext,
|
||||
_cx: &App,
|
||||
) -> Option<TaskTemplates> {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue