Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into language-api-docs

Max Brunsfeldb65cf6d2d957
diff --cc crates/language/src/buffer.rs
index 8feb566c7e7,08210875b84..bfb37e91ebe
--- a/crates/language/src/buffer.rs
+++ b/crates/language/src/buffer.rs
@@@ -60,15 -54,12 +60,17 @@@ pub use {tree_sitter_rust, tree_sitter_
pub use lsp::DiagnosticSeverity;
lazy_static! {
- static ref BUFFER_DIFF_TASK: TaskLabel = TaskLabel::new();
++ /// A label for the background task spawned by the buffer to compute
++ /// a diff against the contents of its file.
+ pub static ref BUFFER_DIFF_TASK: TaskLabel = TaskLabel::new();
}
+/// Indicate whether a [Buffer] has permissions to edit.
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum Capability {
+ /// The buffer is a mutable replica.
ReadWrite,
+ /// The buffer is a read-only replica.
ReadOnly,
}
@@@ -313,31 -242,19 +315,33 @@@ pub enum Operation
},
}
+/// An event that occurs in a buffer.
#[derive(Clone, Debug, PartialEq)]
pub enum Event {
+ /// The buffer was changed in a way that must be
+ /// propagated to its other replicas.
Operation(Operation),
+ /// The buffer was edited.
Edited,
+ /// The buffer's `dirty` bit changed.
DirtyChanged,
+ /// The buffer was saved.
Saved,
+ /// The buffer's file was changed on disk.
FileHandleChanged,
+ /// The buffer was reloaded.
Reloaded,
+ /// The buffer's diff_base changed.
DiffBaseChanged,
+ /// The buffer's language was changed.
LanguageChanged,
+ /// The buffer's syntax trees were updated.
Reparsed,
+ /// The buffer's diagnostics were updated.
DiagnosticsUpdated,
++ /// The buffer gained or lost editing capabilities.
+ CapabilityChanged,
+ /// The buffer was explicitly requested to close.
Closed,
}
@@@ -711,7 -595,7 +715,8 @@@ impl Buffer
}
}
- pub fn as_text_snapshot(&self) -> &text::BufferSnapshot {
++ #[cfg(test)]
+ pub(crate) fn as_text_snapshot(&self) -> &text::BufferSnapshot {
&self.text
}
@@@ -731,6 -611,6 +736,7 @@@
&self.saved_version
}
++ /// The fingerprint of the buffer's text when the buffer was last saved or reloaded from disk.
pub fn saved_version_fingerprint(&self) -> RopeFingerprint {
self.file_fingerprint
}
@@@ -756,7 -632,11 +762,13 @@@
.set_language_registry(language_registry);
}
++ /// Assign the buffer a new [Capability].
+ pub fn set_capability(&mut self, capability: Capability, cx: &mut ModelContext<Self>) {
+ self.capability = capability;
+ cx.emit(Event::CapabilityChanged)
+ }
+
+ /// This method is called to signal that the buffer has been saved.
pub fn did_save(
&mut self,
version: clock::Global,
@@@ -967,6 -835,6 +979,8 @@@
self.parsing_in_background
}
++ /// Indicates whether the buffer contains any regions that may be
++ /// written in a language that hasn't been loaded yet.
pub fn contains_unknown_injections(&self) -> bool {
self.syntax_map.lock().contains_unknown_injections()
}
diff --cc crates/language/src/language_settings.rs
index c1bd3aa57fa,5359d184d65..292e2ad9dcc
--- a/crates/language/src/language_settings.rs
+++ b/crates/language/src/language_settings.rs
@@@ -13,8 -11,7 +13,8 @@@ use serde::{Deserialize, Serialize}
use settings::Settings;
use std::{num::NonZeroU32, path::Path, sync::Arc};
+/// Initializes the language settings.
- pub(crate) fn init(cx: &mut AppContext) {
+ pub fn init(cx: &mut AppContext) {
AllLanguageSettings::register(cx);
}
diff --cc crates/language_tools/src/syntax_tree_view.rs
index 493ce162cb0,be677b215b7..082e77fc365
--- a/crates/language_tools/src/syntax_tree_view.rs
+++ b/crates/language_tools/src/syntax_tree_view.rs
@@@ -2,15 -2,14 +2,14 @@@ use editor::{scroll::Autoscroll, Anchor
use gpui::{
actions, canvas, div, rems, uniform_list, AnyElement, AppContext, AvailableSpace, Div,
EventEmitter, FocusHandle, FocusableView, Hsla, InteractiveElement, IntoElement, Model,
- MouseButton, MouseDownEvent, MouseMoveEvent, ParentElement, Pixels, Render, Styled,
+ MouseButton, MouseDownEvent, MouseMoveEvent, ParentElement, Render, Styled,
UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WindowContext,
};
-use language::{Buffer, OwnedSyntaxLayerInfo};
+use language::{Buffer, OwnedSyntaxLayer};
- use settings::Settings;
use std::{mem, ops::Range};
- use theme::{ActiveTheme, ThemeSettings};
+ use theme::ActiveTheme;
use tree_sitter::{Node, TreeCursor};
- use ui::{h_stack, popover_menu, ButtonLike, Color, ContextMenu, Label, LabelCommon, PopoverMenu};
+ use ui::{h_flex, popover_menu, ButtonLike, Color, ContextMenu, Label, LabelCommon, PopoverMenu};
use workspace::{
item::{Item, ItemHandle},
SplitDirection, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
diff --cc crates/vim/src/motion.rs
index 685c7a28f9b,6215e4c16c0..63c0c2a192e
--- a/crates/vim/src/motion.rs
+++ b/crates/vim/src/motion.rs
@@@ -12,6 -11,6 +11,7 @@@ use workspace::Workspace
use crate::{
normal::normal_motion,
state::{Mode, Operator},
++ utils::coerce_punctuation,
visual::visual_motion,
Vim,
};
@@@ -711,8 -710,8 +711,8 @@@ fn next_word_end
*point.column_mut() = 0;
}
point = movement::find_boundary(map, point, FindRange::MultiLine, |left, right| {
- let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);
- let right_kind = char_kind(&scope, right).coerce_punctuation(ignore_punctuation);
+ let left_kind = coerce_punctuation(char_kind(&scope, left), ignore_punctuation);
- let right_kind = ccoerce_punctuation(har_kind(&scope, right), ignore_punctuation);
++ let right_kind = coerce_punctuation(char_kind(&scope, right), ignore_punctuation);
left_kind != right_kind && left_kind != CharKind::Whitespace
});
diff --cc crates/vim/src/normal/change.rs
index bf2a25a98d5,86b77038461..52de1f7e0a4
--- a/crates/vim/src/normal/change.rs
+++ b/crates/vim/src/normal/change.rs
@@@ -1,13 -1,12 +1,18 @@@
--use crate::{motion::Motion, object::Object, state::Mode, utils::copy_selections_content, Vim};
++use crate::{
++ motion::Motion,
++ object::Object,
++ state::Mode,
++ utils::{coerce_punctuation, copy_selections_content},
++ Vim,
++};
use editor::{
- char_kind,
display_map::DisplaySnapshot,
movement::{self, FindRange, TextLayoutDetails},
- scroll::autoscroll::Autoscroll,
- CharKind, DisplayPoint,
+ scroll::Autoscroll,
+ DisplayPoint,
};
use gpui::WindowContext;
- use language::Selection;
+ use language::{char_kind, CharKind, Selection};
pub fn change_motion(vim: &mut Vim, motion: Motion, times: Option<usize>, cx: &mut WindowContext) {
// Some motions ignore failure when switching to normal mode
@@@ -103,9 -102,9 +108,9 @@@ fn expand_changed_word_selection
if in_word {
selection.end =
movement::find_boundary(map, selection.end, FindRange::MultiLine, |left, right| {
-- let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);
++ let left_kind = coerce_punctuation(char_kind(&scope, left), ignore_punctuation);
let right_kind =
-- char_kind(&scope, right).coerce_punctuation(ignore_punctuation);
++ coerce_punctuation(char_kind(&scope, right), ignore_punctuation);
left_kind != right_kind && left_kind != CharKind::Whitespace
});
diff --cc crates/vim/src/object.rs
index 47d1647dc76,1e9361618c5..03333c962ec
--- a/crates/vim/src/object.rs
+++ b/crates/vim/src/object.rs
@@@ -11,7 -10,7 +10,10 @@@ use language::{char_kind, CharKind, Sel
use serde::Deserialize;
use workspace::Workspace;
--use crate::{motion::right, normal::normal_object, state::Mode, visual::visual_object, Vim};
++use crate::{
++ motion::right, normal::normal_object, state::Mode, utils::coerce_punctuation,
++ visual::visual_object, Vim,
++};
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Object {
@@@ -213,14 -212,14 +215,14 @@@ fn in_word
right(map, relative_to, 1),
movement::FindRange::SingleLine,
|left, right| {
-- char_kind(&scope, left).coerce_punctuation(ignore_punctuation)
-- != char_kind(&scope, right).coerce_punctuation(ignore_punctuation)
++ coerce_punctuation(char_kind(&scope, left), ignore_punctuation)
++ != coerce_punctuation(char_kind(&scope, right), ignore_punctuation)
},
);
let end = movement::find_boundary(map, relative_to, FindRange::SingleLine, |left, right| {
-- char_kind(&scope, left).coerce_punctuation(ignore_punctuation)
-- != char_kind(&scope, right).coerce_punctuation(ignore_punctuation)
++ coerce_punctuation(char_kind(&scope, left), ignore_punctuation)
++ != coerce_punctuation(char_kind(&scope, right), ignore_punctuation)
});
Some(start..end)
@@@ -282,15 -281,15 +284,15 @@@ fn around_next_word
right(map, relative_to, 1),
FindRange::SingleLine,
|left, right| {
-- char_kind(&scope, left).coerce_punctuation(ignore_punctuation)
-- != char_kind(&scope, right).coerce_punctuation(ignore_punctuation)
++ coerce_punctuation(char_kind(&scope, left), ignore_punctuation)
++ != coerce_punctuation(char_kind(&scope, right), ignore_punctuation)
},
);
let mut word_found = false;
let end = movement::find_boundary(map, relative_to, FindRange::MultiLine, |left, right| {
-- let left_kind = char_kind(&scope, left).coerce_punctuation(ignore_punctuation);
-- let right_kind = char_kind(&scope, right).coerce_punctuation(ignore_punctuation);
++ let left_kind = coerce_punctuation(char_kind(&scope, left), ignore_punctuation);
++ let right_kind = coerce_punctuation(char_kind(&scope, right), ignore_punctuation);
let found = (word_found && left_kind != right_kind) || right == '\n' && left == '\n';
diff --cc crates/vim/src/utils.rs
index 797e94b0fa0,797e94b0fa0..0ff857af9cd
--- a/crates/vim/src/utils.rs
+++ b/crates/vim/src/utils.rs
@@@ -1,6 -1,6 +1,6 @@@
use editor::{ClipboardSelection, Editor};
use gpui::{AppContext, ClipboardItem};
--use language::Point;
++use language::{CharKind, Point};
pub fn copy_selections_content(editor: &mut Editor, linewise: bool, cx: &mut AppContext) {
let selections = editor.selections.all_adjusted(cx);
@@@ -48,3 -48,3 +48,11 @@@
cx.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
}
++
++pub fn coerce_punctuation(kind: CharKind, treat_punctuation_as_word: bool) -> CharKind {
++ if treat_punctuation_as_word && kind == CharKind::Punctuation {
++ CharKind::Word
++ } else {
++ kind
++ }
++}