Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Store buffer's diagnostic sets in a smallvec
Max Brunsfeld32c57bcd22fa
diff --git a/Cargo.toml b/Cargo.tomlindex 8113c0cfcfd..12755716684 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -76,6 +76,7 @@ serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }rand = { version = "0.8" }postage = { version = "0.5", features = ["futures-traits"] }+smallvec = { version = "1.6", features = ["union"] }[patch.crates-io]tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "c51896d32dcc11a38e41f36e3deb1a6a9c4f4b14" }diff --git a/crates/activity_indicator/Cargo.toml b/crates/activity_indicator/Cargo.tomlindex 78a4e752b25..b54271ee2df 100644--- a/crates/activity_indicator/Cargo.toml+++ b/crates/activity_indicator/Cargo.toml@@ -18,4 +18,4 @@ settings = { path = "../settings" }util = { path = "../util" }workspace = { path = "../workspace" }futures = "0.3"-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }diff --git a/crates/clock/Cargo.toml b/crates/clock/Cargo.tomlindex 1705fdc6d5a..2ea27796591 100644--- a/crates/clock/Cargo.toml+++ b/crates/clock/Cargo.toml@@ -9,4 +9,4 @@ path = "src/clock.rs"doctest = false[dependencies]-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }diff --git a/crates/context_menu/Cargo.toml b/crates/context_menu/Cargo.tomlindex d764d4ddb8f..64449bdc92c 100644--- a/crates/context_menu/Cargo.toml+++ b/crates/context_menu/Cargo.toml@@ -13,4 +13,4 @@ gpui = { path = "../gpui" }menu = { path = "../menu" }settings = { path = "../settings" }theme = { path = "../theme" }-smallvec = "1.6"+smallvec = { workspace = true }diff --git a/crates/diagnostics/Cargo.toml b/crates/diagnostics/Cargo.tomlindex 83ee243b82b..45621f10c64 100644--- a/crates/diagnostics/Cargo.toml+++ b/crates/diagnostics/Cargo.toml@@ -10,7 +10,7 @@ doctest = false[dependencies]anyhow = "1.0"-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }collections = { path = "../collections" }editor = { path = "../editor" }language = { path = "../language" }diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.tomlindex 82b70825760..4cd81df1dc6 100644--- a/crates/editor/Cargo.toml+++ b/crates/editor/Cargo.toml@@ -58,7 +58,7 @@ postage = { workspace = true }rand = { version = "0.8.3", optional = true }serde = { workspace = true }serde_derive = { workspace = true }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }smol = "1.2"tree-sitter-rust = { version = "*", optional = true }tree-sitter-html = { version = "*", optional = true }diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.tomlindex 8715142dd30..88c40665c20 100644--- a/crates/gpui/Cargo.toml+++ b/crates/gpui/Cargo.toml@@ -44,7 +44,7 @@ seahash = "4.1"serde = { workspace = true }serde_derive = { workspace = true }serde_json = { workspace = true }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }smol = "1.2"time = { version = "0.3", features = ["serde", "serde-well-known"] }tiny-skia = "0.5"diff --git a/crates/language/Cargo.toml b/crates/language/Cargo.tomlindex 4311f043915..4e15ccf679d 100644--- a/crates/language/Cargo.toml+++ b/crates/language/Cargo.toml@@ -50,7 +50,7 @@ serde = { workspace = true }serde_derive = { workspace = true }serde_json = { workspace = true }similar = "1.3"-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }smol = "1.2"tree-sitter = "0.20"tree-sitter-rust = { version = "*", optional = true }diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rsindex 25536adcbb1..65e4d3b8b6f 100644--- a/crates/language/src/buffer.rs+++ b/crates/language/src/buffer.rs@@ -13,7 +13,6 @@ use crate::{};use anyhow::{anyhow, Result};use clock::ReplicaId;-use collections::HashMap;use fs::LineEnding;use futures::FutureExt as _;use gpui::{fonts::HighlightStyle, AppContext, Entity, ModelContext, Task};@@ -21,6 +20,7 @@ use lsp::LanguageServerId;use parking_lot::Mutex;use settings::Settings;use similar::{ChangeTag, TextDiff};+use smallvec::SmallVec;use smol::future::yield_now;use std::{any::Any,@@ -73,7 +73,7 @@ pub struct Buffer {syntax_map: Mutex<SyntaxMap>,parsing_in_background: bool,parse_count: usize,- diagnostics: HashMap<LanguageServerId, DiagnosticSet>,+ diagnostics: SmallVec<[(LanguageServerId, DiagnosticSet); 2]>,remote_selections: TreeMap<ReplicaId, SelectionSet>,selections_update_count: usize,diagnostics_update_count: usize,@@ -90,7 +90,7 @@ pub struct BufferSnapshot {pub git_diff: git::diff::BufferDiff,pub(crate) syntax: SyntaxSnapshot,file: Option<Arc<dyn File>>,- diagnostics: HashMap<LanguageServerId, DiagnosticSet>,+ diagnostics: SmallVec<[(LanguageServerId, DiagnosticSet); 2]>,diagnostics_update_count: usize,file_update_count: usize,git_diff_update_count: usize,@@ -1652,7 +1652,10 @@ impl Buffer {cx: &mut ModelContext<Self>,) {if lamport_timestamp > self.diagnostics_timestamp {- self.diagnostics.insert(server_id, diagnostics);+ match self.diagnostics.binary_search_by_key(&server_id, |e| e.0) {+ Err(ix) => self.diagnostics.insert(ix, (server_id, diagnostics)),+ Ok(ix) => self.diagnostics[ix].1 = diagnostics,+ };self.diagnostics_timestamp = lamport_timestamp;self.diagnostics_update_count += 1;self.text.lamport_clock.observe(lamport_timestamp);@@ -2530,8 +2533,8 @@ impl BufferSnapshot {{let mut iterators: Vec<_> = self.diagnostics- .values()- .map(|collection| {+ .iter()+ .map(|(_, collection)| {collection.range::<T, O>(search_range.clone(), self, true, reversed).peekable()@@ -2555,12 +2558,17 @@ impl BufferSnapshot {let mut groups = Vec::new();if let Some(language_server_id) = language_server_id {- if let Some(diagnostics) = self.diagnostics.get(&language_server_id) {- diagnostics.groups(language_server_id, &mut groups, self);+ if let Ok(ix) = self+ .diagnostics+ .binary_search_by_key(&language_server_id, |e| e.0)+ {+ self.diagnostics[ix]+ .1+ .groups(language_server_id, &mut groups, self);}} else {- for (&language_server_id, diagnostics) in self.diagnostics.iter() {- diagnostics.groups(language_server_id, &mut groups, self);+ for (language_server_id, diagnostics) in self.diagnostics.iter() {+ diagnostics.groups(*language_server_id, &mut groups, self);}}@@ -2581,8 +2589,8 @@ impl BufferSnapshot {O: 'a + FromAnchor,{self.diagnostics- .values()- .flat_map(move |set| set.group(group_id, self))+ .iter()+ .flat_map(move |(_, set)| set.group(group_id, self))}pub fn diagnostics_update_count(&self) -> usize {diff --git a/crates/rope/Cargo.toml b/crates/rope/Cargo.tomlindex 4566b8397d8..bd72c7c263c 100644--- a/crates/rope/Cargo.toml+++ b/crates/rope/Cargo.toml@@ -9,7 +9,7 @@ path = "src/rope.rs"[dependencies]bromberg_sl2 = { git = "https://github.com/zed-industries/bromberg_sl2", rev = "950bc5482c216c395049ae33ae4501e08975f17f" }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }sum_tree = { path = "../sum_tree" }arrayvec = "0.7.1"log = { version = "0.4.16", features = ["kv_unstable_serde"] }diff --git a/crates/search/Cargo.toml b/crates/search/Cargo.tomlindex f786d4abc64..fb4e79a7033 100644--- a/crates/search/Cargo.toml+++ b/crates/search/Cargo.toml@@ -25,7 +25,7 @@ log = { version = "0.4.16", features = ["kv_unstable_serde"] }postage = { workspace = true }serde = { workspace = true }serde_derive = { workspace = true }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }smol = "1.2"[dev-dependencies]diff --git a/crates/snippet/Cargo.toml b/crates/snippet/Cargo.tomlindex 429f5d416e0..67f77e4483e 100644--- a/crates/snippet/Cargo.toml+++ b/crates/snippet/Cargo.toml@@ -10,4 +10,4 @@ doctest = false[dependencies]anyhow = "1.0"-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.tomlindex 56796fca592..107d325677f 100644--- a/crates/terminal/Cargo.toml+++ b/crates/terminal/Cargo.toml@@ -17,7 +17,7 @@ theme = { path = "../theme" }util = { path = "../util" }alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "a51dbe25d67e84d6ed4261e640d3954fbdd9be45" }procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }smol = "1.2.5"mio-extras = "2.0.6"futures = "0.3"diff --git a/crates/terminal_view/Cargo.toml b/crates/terminal_view/Cargo.tomlindex 726a1a674fd..f271cd118d8 100644--- a/crates/terminal_view/Cargo.toml+++ b/crates/terminal_view/Cargo.toml@@ -21,7 +21,7 @@ workspace = { path = "../workspace" }db = { path = "../db" }procinfo = { git = "https://github.com/zed-industries/wezterm", rev = "5cd757e5f2eb039ed0c6bb6512223e69d5efc64d", default-features = false }terminal = { path = "../terminal" }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }smol = "1.2.5"mio-extras = "2.0.6"futures = "0.3"diff --git a/crates/text/Cargo.toml b/crates/text/Cargo.tomlindex 362a060c1f5..d85464a4462 100644--- a/crates/text/Cargo.toml+++ b/crates/text/Cargo.toml@@ -24,7 +24,7 @@ log = { version = "0.4.16", features = ["kv_unstable_serde"] }parking_lot = "0.11"postage = { workspace = true }rand = { version = "0.8.3", optional = true }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }util = { path = "../util" }regex = "1.5"diff --git a/crates/theme_testbench/Cargo.toml b/crates/theme_testbench/Cargo.tomlindex 763727fc68d..ade8e39550a 100644--- a/crates/theme_testbench/Cargo.toml+++ b/crates/theme_testbench/Cargo.toml@@ -16,4 +16,4 @@ settings = { path = "../settings" }workspace = { path = "../workspace" }project = { path = "../project" }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.tomlindex 5a2380de3f4..84db04e9a67 100644--- a/crates/workspace/Cargo.toml+++ b/crates/workspace/Cargo.toml@@ -47,7 +47,7 @@ postage = { workspace = true }serde = { workspace = true }serde_derive = { workspace = true }serde_json = { workspace = true }-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }indoc = "1.0.4"uuid = { version = "1.1.2", features = ["v4"] }diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.tomlindex 180a1fce24b..3df019bb45a 100644--- a/crates/zed/Cargo.toml+++ b/crates/zed/Cargo.toml@@ -96,7 +96,7 @@ serde_derive = { workspace = true }serde_json = { workspace = true }serde_path_to_error = "0.1.4"simplelog = "0.9"-smallvec = { version = "1.6", features = ["union"] }+smallvec = { workspace = true }smol = "1.2.5"tempdir = { version = "0.3.7" }thiserror = "1.0.29"