Compare commits

...
Sign in to create a new pull request.

8 commits

Author SHA1 Message Date
Max Brunsfeld
d979d32cae zed 0.74.3 2023-02-24 09:51:43 -08:00
Petros Amoiridis
fd3d944ba9 Merge pull request #2191 from zed-industries/petros/z-53-reveal-in-finder-crashes-zed
Move reveal_path to ForegroundPlatform
2023-02-24 09:51:20 -08:00
Max Brunsfeld
d272c551ba v0.74.x stable 2023-02-22 12:34:15 -08:00
Max Brunsfeld
8d15281a5f zed 0.74.2 2023-02-21 09:33:35 -08:00
Max Brunsfeld
ade1a53193 Merge pull request #2193 from zed-industries/autoclose-fixes
Restructure scope-specific auto-close pairs, fix regression in skipping over auto-closed brackets
2023-02-21 09:32:37 -08:00
Max Brunsfeld
770e80c5f0 zed 0.74.1 2023-02-15 14:06:31 -08:00
Max Brunsfeld
dc103389f4 Merge pull request #2175 from zed-industries/restore-toggle-dock-binding
Put back shift-escape binding for FocusDock action
2023-02-15 14:06:01 -08:00
Joseph Lyons
51aea3a294 v0.74.x preview 2023-02-15 14:57:27 -05:00
34 changed files with 541 additions and 484 deletions

2
Cargo.lock generated
View file

@ -8344,7 +8344,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]]
name = "zed"
version = "0.74.0"
version = "0.74.3"
dependencies = [
"activity_indicator",
"anyhow",

View file

@ -431,6 +431,12 @@
"cmd-enter": "project_search::SearchInNew"
}
},
{
"context": "Workspace",
"bindings": {
"shift-escape": "dock::FocusDock"
}
},
{
"bindings": {
"cmd-shift-k cmd-shift-right": "dock::AnchorDockRight",

View file

@ -1755,8 +1755,8 @@ impl Editor {
// bracket of any of this language's bracket pairs.
let mut bracket_pair = None;
let mut is_bracket_pair_start = false;
for pair in language.brackets() {
if pair.close && pair.start.ends_with(text.as_ref()) {
for (pair, enabled) in language.brackets() {
if enabled && pair.close && pair.start.ends_with(text.as_ref()) {
bracket_pair = Some(pair.clone());
is_bracket_pair_start = true;
break;
@ -1924,11 +1924,12 @@ impl Editor {
.map(|c| c.len_utf8())
.sum::<usize>();
insert_extra_newline = language.brackets().iter().any(|pair| {
insert_extra_newline = language.brackets().any(|(pair, enabled)| {
let pair_start = pair.start.trim_end();
let pair_end = pair.end.trim_start();
pair.newline
enabled
&& pair.newline
&& buffer
.contains_str_at(end + trailing_whitespace_len, pair_end)
&& buffer.contains_str_at(

View file

@ -13,8 +13,9 @@ use gpui::{
executor::Deterministic,
geometry::{rect::RectF, vector::vec2f},
platform::{WindowBounds, WindowOptions},
serde_json,
};
use language::{FakeLspAdapter, LanguageConfig, LanguageRegistry, Point};
use language::{BracketPairConfig, FakeLspAdapter, LanguageConfig, LanguageRegistry, Point};
use project::FakeFs;
use settings::EditorSettings;
use util::{
@ -3002,20 +3003,23 @@ async fn test_autoindent_selections(cx: &mut gpui::TestAppContext) {
let language = Arc::new(
Language::new(
LanguageConfig {
brackets: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: false,
newline: true,
},
BracketPair {
start: "(".to_string(),
end: ")".to_string(),
close: false,
newline: true,
},
],
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: false,
newline: true,
},
BracketPair {
start: "(".to_string(),
end: ")".to_string(),
close: false,
newline: true,
},
],
..Default::default()
},
..Default::default()
},
Some(tree_sitter_rust::language()),
@ -3059,38 +3063,41 @@ async fn test_autoclose_pairs(cx: &mut gpui::TestAppContext) {
let language = Arc::new(Language::new(
LanguageConfig {
brackets: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "(".to_string(),
end: ")".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "/*".to_string(),
end: " */".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "[".to_string(),
end: "]".to_string(),
close: false,
newline: true,
},
BracketPair {
start: "\"".to_string(),
end: "\"".to_string(),
close: true,
newline: false,
},
],
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "(".to_string(),
end: ")".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "/*".to_string(),
end: " */".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "[".to_string(),
end: "]".to_string(),
close: false,
newline: true,
},
BracketPair {
start: "\"".to_string(),
end: "\"".to_string(),
close: true,
newline: false,
},
],
..Default::default()
},
autoclose_before: "})]".to_string(),
..Default::default()
},
@ -3227,26 +3234,29 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) {
Language::new(
LanguageConfig {
name: "HTML".into(),
brackets: vec![
BracketPair {
start: "<".into(),
end: ">".into(),
close: true,
..Default::default()
},
BracketPair {
start: "{".into(),
end: "}".into(),
close: true,
..Default::default()
},
BracketPair {
start: "(".into(),
end: ")".into(),
close: true,
..Default::default()
},
],
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "<".into(),
end: ">".into(),
close: true,
..Default::default()
},
BracketPair {
start: "{".into(),
end: "}".into(),
close: true,
..Default::default()
},
BracketPair {
start: "(".into(),
end: ")".into(),
close: true,
..Default::default()
},
],
..Default::default()
},
autoclose_before: "})]>".into(),
..Default::default()
},
@ -3265,26 +3275,29 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) {
let javascript_language = Arc::new(Language::new(
LanguageConfig {
name: "JavaScript".into(),
brackets: vec![
BracketPair {
start: "/*".into(),
end: " */".into(),
close: true,
..Default::default()
},
BracketPair {
start: "{".into(),
end: "}".into(),
close: true,
..Default::default()
},
BracketPair {
start: "(".into(),
end: ")".into(),
close: true,
..Default::default()
},
],
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "/*".into(),
end: " */".into(),
close: true,
..Default::default()
},
BracketPair {
start: "{".into(),
end: "}".into(),
close: true,
..Default::default()
},
BracketPair {
start: "(".into(),
end: ")".into(),
close: true,
..Default::default()
},
],
..Default::default()
},
autoclose_before: "})]>".into(),
..Default::default()
},
@ -3447,25 +3460,125 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) {
);
}
#[gpui::test]
async fn test_autoclose_with_overrides(cx: &mut gpui::TestAppContext) {
let mut cx = EditorTestContext::new(cx);
let rust_language = Arc::new(
Language::new(
LanguageConfig {
name: "Rust".into(),
brackets: serde_json::from_value(json!([
{ "start": "{", "end": "}", "close": true, "newline": true },
{ "start": "\"", "end": "\"", "close": true, "newline": false, "not_in": ["string"] },
]))
.unwrap(),
autoclose_before: "})]>".into(),
..Default::default()
},
Some(tree_sitter_rust::language()),
)
.with_override_query("(string_literal) @string")
.unwrap(),
);
let registry = Arc::new(LanguageRegistry::test());
registry.add(rust_language.clone());
cx.update_buffer(|buffer, cx| {
buffer.set_language_registry(registry);
buffer.set_language(Some(rust_language), cx);
});
cx.set_state(
&r#"
let x = ˇ
"#
.unindent(),
);
// Inserting a quotation mark. A closing quotation mark is automatically inserted.
cx.update_editor(|editor, cx| {
editor.handle_input("\"", cx);
});
cx.assert_editor_state(
&r#"
let x = "ˇ"
"#
.unindent(),
);
// Inserting another quotation mark. The cursor moves across the existing
// automatically-inserted quotation mark.
cx.update_editor(|editor, cx| {
editor.handle_input("\"", cx);
});
cx.assert_editor_state(
&r#"
let x = ""ˇ
"#
.unindent(),
);
// Reset
cx.set_state(
&r#"
let x = ˇ
"#
.unindent(),
);
// Inserting a quotation mark inside of a string. A second quotation mark is not inserted.
cx.update_editor(|editor, cx| {
editor.handle_input("\"", cx);
editor.handle_input(" ", cx);
editor.move_left(&Default::default(), cx);
editor.handle_input("\\", cx);
editor.handle_input("\"", cx);
});
cx.assert_editor_state(
&r#"
let x = "\"ˇ "
"#
.unindent(),
);
// Inserting a closing quotation mark at the position of an automatically-inserted quotation
// mark. Nothing is inserted.
cx.update_editor(|editor, cx| {
editor.move_right(&Default::default(), cx);
editor.handle_input("\"", cx);
});
cx.assert_editor_state(
&r#"
let x = "\" "ˇ
"#
.unindent(),
);
}
#[gpui::test]
async fn test_surround_with_pair(cx: &mut gpui::TestAppContext) {
cx.update(|cx| cx.set_global(Settings::test(cx)));
let language = Arc::new(Language::new(
LanguageConfig {
brackets: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "/* ".to_string(),
end: "*/".to_string(),
close: true,
..Default::default()
},
],
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "/* ".to_string(),
end: "*/".to_string(),
close: true,
..Default::default()
},
],
..Default::default()
},
..Default::default()
},
Some(tree_sitter_rust::language()),
@ -3603,12 +3716,15 @@ async fn test_delete_autoclose_pair(cx: &mut gpui::TestAppContext) {
cx.update(|cx| cx.set_global(Settings::test(cx)));
let language = Arc::new(Language::new(
LanguageConfig {
brackets: vec![BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
newline: true,
}],
brackets: BracketPairConfig {
pairs: vec![BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
newline: true,
}],
..Default::default()
},
autoclose_before: "}".to_string(),
..Default::default()
},
@ -4897,20 +5013,23 @@ async fn test_extra_newline_insertion(cx: &mut gpui::TestAppContext) {
let language = Arc::new(
Language::new(
LanguageConfig {
brackets: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "/* ".to_string(),
end: " */".to_string(),
close: true,
newline: true,
},
],
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: true,
newline: true,
},
BracketPair {
start: "/* ".to_string(),
end: " */".to_string(),
close: true,
newline: true,
},
],
..Default::default()
},
..Default::default()
},
Some(tree_sitter_rust::language()),

View file

@ -32,11 +32,10 @@ pub fn refresh_matching_bracket_highlights(editor: &mut Editor, cx: &mut ViewCon
#[cfg(test)]
mod tests {
use crate::test::editor_lsp_test_context::EditorLspTestContext;
use super::*;
use crate::test::editor_lsp_test_context::EditorLspTestContext;
use indoc::indoc;
use language::{BracketPair, Language, LanguageConfig};
use language::{BracketPair, BracketPairConfig, Language, LanguageConfig};
#[gpui::test]
async fn test_matching_bracket_highlights(cx: &mut gpui::TestAppContext) {
@ -45,20 +44,23 @@ mod tests {
LanguageConfig {
name: "Rust".into(),
path_suffixes: vec!["rs".to_string()],
brackets: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: false,
newline: true,
},
BracketPair {
start: "(".to_string(),
end: ")".to_string(),
close: false,
newline: true,
},
],
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "{".to_string(),
end: "}".to_string(),
close: false,
newline: true,
},
BracketPair {
start: "(".to_string(),
end: ")".to_string(),
close: false,
newline: true,
},
],
..Default::default()
},
..Default::default()
},
Some(tree_sitter_rust::language()),

View file

@ -190,8 +190,8 @@ pub struct AsyncAppContext(Rc<RefCell<MutableAppContext>>);
impl App {
pub fn new(asset_source: impl AssetSource) -> Result<Self> {
let platform = platform::current::platform();
let foreground_platform = platform::current::foreground_platform();
let foreground = Rc::new(executor::Foreground::platform(platform.dispatcher())?);
let foreground_platform = platform::current::foreground_platform(foreground.clone());
let app = Self(Rc::new(RefCell::new(MutableAppContext::new(
foreground,
Arc::new(executor::Background::new()),
@ -900,6 +900,10 @@ impl MutableAppContext {
self.foreground_platform.prompt_for_new_path(directory)
}
pub fn reveal_path(&self, path: &Path) {
self.foreground_platform.reveal_path(path)
}
pub fn emit_global<E: Any>(&mut self, payload: E) {
self.pending_effects.push_back(Effect::GlobalEvent {
payload: Box::new(payload),
@ -3637,6 +3641,10 @@ impl<'a, T: View> ViewContext<'a, T> {
self.app.prompt_for_new_path(directory)
}
pub fn reveal_path(&self, path: &Path) {
self.app.reveal_path(path)
}
pub fn debug_elements(&self) -> crate::json::Value {
self.app.debug_elements(self.window_id).unwrap()
}

View file

@ -65,7 +65,6 @@ pub trait Platform: Send + Sync {
fn write_to_clipboard(&self, item: ClipboardItem);
fn read_from_clipboard(&self) -> Option<ClipboardItem>;
fn open_url(&self, url: &str);
fn reveal_path(&self, path: &Path);
fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Result<()>;
fn read_credentials(&self, url: &str) -> Result<Option<(String, Vec<u8>)>>;
@ -100,6 +99,7 @@ pub(crate) trait ForegroundPlatform {
options: PathPromptOptions,
) -> oneshot::Receiver<Option<Vec<PathBuf>>>;
fn prompt_for_new_path(&self, directory: &Path) -> oneshot::Receiver<Option<PathBuf>>;
fn reveal_path(&self, path: &Path);
}
pub trait Dispatcher: Send + Sync {

View file

@ -23,12 +23,16 @@ pub use renderer::Surface;
use std::{ops::Range, rc::Rc, sync::Arc};
use window::Window;
use crate::executor;
pub(crate) fn platform() -> Arc<dyn super::Platform> {
Arc::new(MacPlatform::new())
}
pub(crate) fn foreground_platform() -> Rc<dyn super::ForegroundPlatform> {
Rc::new(MacForegroundPlatform::default())
pub(crate) fn foreground_platform(
foreground: Rc<executor::Foreground>,
) -> Rc<dyn super::ForegroundPlatform> {
Rc::new(MacForegroundPlatform::new(foreground))
}
trait BoolExt {

View file

@ -16,7 +16,7 @@ use cocoa::{
NSEventModifierFlags, NSMenu, NSMenuItem, NSModalResponse, NSOpenPanel, NSPasteboard,
NSPasteboardTypeString, NSSavePanel, NSWindow,
},
base::{id, nil, selector, YES},
base::{id, nil, selector, BOOL, YES},
foundation::{
NSArray, NSAutoreleasePool, NSBundle, NSData, NSInteger, NSProcessInfo, NSString,
NSUInteger, NSURL,
@ -113,10 +113,8 @@ unsafe fn build_classes() {
}
}
#[derive(Default)]
pub struct MacForegroundPlatform(RefCell<MacForegroundPlatformState>);
#[derive(Default)]
pub struct MacForegroundPlatformState {
become_active: Option<Box<dyn FnMut()>>,
resign_active: Option<Box<dyn FnMut()>>,
@ -128,9 +126,26 @@ pub struct MacForegroundPlatformState {
open_urls: Option<Box<dyn FnMut(Vec<String>)>>,
finish_launching: Option<Box<dyn FnOnce()>>,
menu_actions: Vec<Box<dyn Action>>,
foreground: Rc<executor::Foreground>,
}
impl MacForegroundPlatform {
pub fn new(foreground: Rc<executor::Foreground>) -> Self {
Self(RefCell::new(MacForegroundPlatformState {
become_active: Default::default(),
resign_active: Default::default(),
quit: Default::default(),
event: Default::default(),
menu_command: Default::default(),
validate_menu_command: Default::default(),
will_open_menu: Default::default(),
open_urls: Default::default(),
finish_launching: Default::default(),
menu_actions: Default::default(),
foreground,
}))
}
unsafe fn create_menu_bar(
&self,
menus: Vec<Menu>,
@ -398,6 +413,26 @@ impl platform::ForegroundPlatform for MacForegroundPlatform {
done_rx
}
}
fn reveal_path(&self, path: &Path) {
unsafe {
let path = path.to_path_buf();
self.0
.borrow()
.foreground
.spawn(async move {
let full_path = ns_string(path.to_str().unwrap_or(""));
let root_full_path = ns_string("");
let workspace: id = msg_send![class!(NSWorkspace), sharedWorkspace];
let _: BOOL = msg_send![
workspace,
selectFile: full_path
inFileViewerRootedAtPath: root_full_path
];
})
.detach();
}
}
}
pub struct MacPlatform {
@ -599,19 +634,6 @@ impl platform::Platform for MacPlatform {
}
}
fn reveal_path(&self, path: &Path) {
unsafe {
let full_path = ns_string(path.to_str().unwrap_or(""));
let root_full_path = ns_string("");
let workspace: id = msg_send![class!(NSWorkspace), sharedWorkspace];
msg_send![
workspace,
selectFile: full_path
inFileViewerRootedAtPath: root_full_path
]
}
}
fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Result<()> {
let url = CFString::from(url);
let username = CFString::from(username);

View file

@ -92,6 +92,8 @@ impl super::ForegroundPlatform for ForegroundPlatform {
*self.last_prompt_for_new_path_args.borrow_mut() = Some((path.to_path_buf(), done_tx));
done_rx
}
fn reveal_path(&self, _: &Path) {}
}
pub fn platform() -> Platform {
@ -173,8 +175,6 @@ impl super::Platform for Platform {
fn open_url(&self, _: &str) {}
fn reveal_path(&self, _: &Path) {}
fn write_credentials(&self, _: &str, _: &str, _: &[u8]) -> Result<()> {
Ok(())
}

View file

@ -1480,42 +1480,34 @@ fn test_language_config_at(cx: &mut MutableAppContext) {
LanguageConfig {
name: "JavaScript".into(),
line_comment: Some("// ".into()),
brackets: vec![
BracketPair {
start: "{".into(),
end: "}".into(),
close: true,
newline: false,
},
BracketPair {
start: "'".into(),
end: "'".into(),
close: true,
newline: false,
},
],
overrides: [
(
"element".into(),
LanguageConfigOverride {
line_comment: Override::Remove { remove: true },
block_comment: Override::Set(("{/*".into(), "*/}".into())),
..Default::default()
brackets: BracketPairConfig {
pairs: vec![
BracketPair {
start: "{".into(),
end: "}".into(),
close: true,
newline: false,
},
),
(
"string".into(),
LanguageConfigOverride {
brackets: Override::Set(vec![BracketPair {
start: "{".into(),
end: "}".into(),
close: true,
newline: false,
}]),
..Default::default()
BracketPair {
start: "'".into(),
end: "'".into(),
close: true,
newline: false,
},
),
]
],
disabled_scopes_by_bracket_ix: vec![
Vec::new(), //
vec!["string".into()],
],
},
overrides: [(
"element".into(),
LanguageConfigOverride {
line_comment: Override::Remove { remove: true },
block_comment: Override::Set(("{/*".into(), "*/}".into())),
..Default::default()
},
)]
.into_iter()
.collect(),
..Default::default()
@ -1537,11 +1529,19 @@ fn test_language_config_at(cx: &mut MutableAppContext) {
let config = snapshot.language_scope_at(0).unwrap();
assert_eq!(config.line_comment_prefix().unwrap().as_ref(), "// ");
assert_eq!(config.brackets().len(), 2);
// Both bracket pairs are enabled
assert_eq!(
config.brackets().map(|e| e.1).collect::<Vec<_>>(),
&[true, true]
);
let string_config = snapshot.language_scope_at(3).unwrap();
assert_eq!(config.line_comment_prefix().unwrap().as_ref(), "// ");
assert_eq!(string_config.brackets().len(), 1);
assert_eq!(string_config.line_comment_prefix().unwrap().as_ref(), "// ");
// Second bracket pair is disabled
assert_eq!(
string_config.brackets().map(|e| e.1).collect::<Vec<_>>(),
&[true, false]
);
let element_config = snapshot.language_scope_at(10).unwrap();
assert_eq!(element_config.line_comment_prefix(), None);
@ -1549,7 +1549,11 @@ fn test_language_config_at(cx: &mut MutableAppContext) {
element_config.block_comment_delimiters(),
Some((&"{/*".into(), &"*/}".into()))
);
assert_eq!(element_config.brackets().len(), 2);
// Both bracket pairs are enabled
assert_eq!(
element_config.brackets().map(|e| e.1).collect::<Vec<_>>(),
&[true, true]
);
buffer
});

View file

@ -231,7 +231,7 @@ pub struct CodeLabel {
pub struct LanguageConfig {
pub name: Arc<str>,
pub path_suffixes: Vec<String>,
pub brackets: Vec<BracketPair>,
pub brackets: BracketPairConfig,
#[serde(default = "auto_indent_using_last_non_empty_line_default")]
pub auto_indent_using_last_non_empty_line: bool,
#[serde(default, deserialize_with = "deserialize_regex")]
@ -258,7 +258,7 @@ pub struct LanguageQueries {
pub overrides: Option<Cow<'static, str>>,
}
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct LanguageScope {
language: Arc<Language>,
override_id: Option<u32>,
@ -270,8 +270,8 @@ pub struct LanguageConfigOverride {
pub line_comment: Override<Arc<str>>,
#[serde(default)]
pub block_comment: Override<(Arc<str>, Arc<str>)>,
#[serde(default)]
pub brackets: Override<Vec<BracketPair>>,
#[serde(skip_deserializing)]
pub disabled_bracket_ixs: Vec<u16>,
}
#[derive(Deserialize, Debug)]
@ -336,7 +336,41 @@ pub struct FakeLspAdapter {
pub disk_based_diagnostics_sources: Vec<String>,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[derive(Clone, Debug, Default)]
pub struct BracketPairConfig {
pub pairs: Vec<BracketPair>,
pub disabled_scopes_by_bracket_ix: Vec<Vec<String>>,
}
impl<'de> Deserialize<'de> for BracketPairConfig {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
pub struct Entry {
#[serde(flatten)]
pub bracket_pair: BracketPair,
#[serde(default)]
pub not_in: Vec<String>,
}
let result = Vec::<Entry>::deserialize(deserializer)?;
let mut brackets = Vec::with_capacity(result.len());
let mut disabled_scopes_by_bracket_ix = Vec::with_capacity(result.len());
for entry in result {
brackets.push(entry.bracket_pair);
disabled_scopes_by_bracket_ix.push(entry.not_in);
}
Ok(BracketPairConfig {
pairs: brackets,
disabled_scopes_by_bracket_ix,
})
}
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
pub struct BracketPair {
pub start: String,
pub end: String,
@ -393,7 +427,7 @@ struct InjectionConfig {
struct OverrideConfig {
query: Query,
values: HashMap<u32, LanguageConfigOverride>,
values: HashMap<u32, (String, LanguageConfigOverride)>,
}
#[derive(Default, Clone)]
@ -967,16 +1001,11 @@ impl Language {
pub fn with_override_query(mut self, source: &str) -> Result<Self> {
let query = Query::new(self.grammar_mut().ts_language, source)?;
let mut values = HashMap::default();
let mut override_configs_by_id = HashMap::default();
for (ix, name) in query.capture_names().iter().enumerate() {
if !name.starts_with('_') {
let value = self.config.overrides.remove(name).ok_or_else(|| {
anyhow!(
"language {:?} has override in query but not in config: {name:?}",
self.config.name
)
})?;
values.insert(ix as u32, value);
let value = self.config.overrides.remove(name).unwrap_or_default();
override_configs_by_id.insert(ix as u32, (name.clone(), value));
}
}
@ -988,7 +1017,46 @@ impl Language {
))?;
}
self.grammar_mut().override_config = Some(OverrideConfig { query, values });
for disabled_scope_name in self
.config
.brackets
.disabled_scopes_by_bracket_ix
.iter()
.flatten()
{
if !override_configs_by_id
.values()
.any(|(scope_name, _)| scope_name == disabled_scope_name)
{
Err(anyhow!(
"language {:?} has overrides in config not in query: {disabled_scope_name:?}",
self.config.name
))?;
}
}
for (name, override_config) in override_configs_by_id.values_mut() {
override_config.disabled_bracket_ixs = self
.config
.brackets
.disabled_scopes_by_bracket_ix
.iter()
.enumerate()
.filter_map(|(ix, disabled_scope_names)| {
if disabled_scope_names.contains(name) {
Some(ix as u16)
} else {
None
}
})
.collect();
}
self.config.brackets.disabled_scopes_by_bracket_ix.clear();
self.grammar_mut().override_config = Some(OverrideConfig {
query,
values: override_configs_by_id,
});
Ok(self)
}
@ -1132,12 +1200,26 @@ impl LanguageScope {
.map(|e| (&e.0, &e.1))
}
pub fn brackets(&self) -> &[BracketPair] {
Override::as_option(
self.config_override().map(|o| &o.brackets),
Some(&self.language.config.brackets),
)
.map_or(&[], Vec::as_slice)
pub fn brackets(&self) -> impl Iterator<Item = (&BracketPair, bool)> {
let mut disabled_ids = self
.config_override()
.map_or(&[] as _, |o| o.disabled_bracket_ixs.as_slice());
self.language
.config
.brackets
.pairs
.iter()
.enumerate()
.map(move |(ix, bracket)| {
let mut is_enabled = true;
if let Some(next_disabled_ix) = disabled_ids.first() {
if ix == *next_disabled_ix as usize {
disabled_ids = &disabled_ids[1..];
is_enabled = false;
}
}
(bracket, is_enabled)
})
}
pub fn should_autoclose_before(&self, c: char) -> bool {
@ -1148,7 +1230,7 @@ impl LanguageScope {
let id = self.override_id?;
let grammar = self.language.grammar.as_ref()?;
let override_config = grammar.override_config.as_ref()?;
override_config.values.get(&id)
override_config.values.get(&id).map(|e| &e.1)
}
}

View file

@ -792,8 +792,7 @@ impl ProjectPanel {
fn reveal_in_finder(&mut self, _: &RevealInFinder, cx: &mut ViewContext<Self>) {
if let Some((worktree, entry)) = self.selected_entry(cx) {
cx.platform()
.reveal_path(&worktree.abs_path().join(&entry.path));
cx.reveal_path(&worktree.abs_path().join(&entry.path));
}
}

View file

@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
description = "The fast, collaborative code editor."
edition = "2021"
name = "zed"
version = "0.74.0"
version = "0.74.3"
publish = false
[lib]

View file

@ -1 +1 @@
dev
stable

View file

@ -6,21 +6,7 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
{ start = "/*", end = " */", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
]

View file

@ -6,21 +6,7 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
{ start = "/*", end = " */", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
]

View file

@ -5,20 +5,6 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
]

View file

@ -6,20 +6,6 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
]

View file

@ -6,21 +6,7 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
{ start = "/*", end = " */", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["comment", "string"] },
]

View file

@ -1,26 +1,12 @@
name = "HTML"
path_suffixes = ["html"]
autoclose_before = ">})"
brackets = [
{ start = "<", end = ">", close = true, newline = true },
{ start = "{", end = "}", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "!--", end = " --", close = true, newline = false },
]
block_comment = ["<!-- ", " -->"]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "<", end = ">", close = true, newline = true, not_in = ["comment", "string"] },
{ start = "!--", end = " --", close = true, newline = false, not_in = ["comment", "string"] },
]

View file

@ -6,25 +6,11 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
{ start = "`", end = "`", close = true, newline = false },
{ start = "/*", end = " */", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true, not_in = ["comment", "string"] },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "`", end = "`", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["comment", "string"] },
]
[overrides.element]

View file

@ -5,11 +5,5 @@ autoclose_before = ",]}"
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
]

View file

@ -3,13 +3,7 @@ path_suffixes = ["lua"]
line_comment = "-- "
autoclose_before = ",]}"
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
]

View file

@ -3,27 +3,13 @@ path_suffixes = ["py", "pyi"]
line_comment = "# "
autoclose_before = ";:.,=}])>"
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = false, newline = false },
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
{ start = "'", end = "'", close = false, newline = false, not_in = ["string"] },
]
auto_indent_using_last_non_empty_line = false
increase_indent_pattern = ":\\s*$"
decrease_indent_pattern = "^\\s*(else|elif|except|finally)\\b.*:"
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]

View file

@ -6,20 +6,6 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["comment", "string"] },
]

View file

@ -6,24 +6,7 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = false, newline = false },
{ start = "/*", end = " */", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true },
{ start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
]

View file

@ -5,17 +5,5 @@ autoclose_before = "])"
brackets = [
{ start = "[", end = "]", close = true, newline = false },
{ start = "(", end = ")", close = true, newline = false },
{ start = "\"", end = "\"", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
]

View file

@ -5,18 +5,6 @@ autoclose_before = ",]}"
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["comment", "string"] },
]

View file

@ -6,18 +6,13 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
{ start = "`", end = "`", close = true, newline = false },
{ start = "/*", end = " */", close = true, newline = false },
{ start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
{ start = "`", end = "`", close = true, newline = false, not_in = ["string"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
]
[overrides.element]
line_comment = { remove = true }
block_comment = ["{/* ", " */}"]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
]

View file

@ -1,7 +1,8 @@
(comment) @comment
(string) @string
[
(jsx_element)
(jsx_fragment)
(jsx_self_closing_element)
(jsx_expression)
] @element
(string) @string

View file

@ -6,23 +6,9 @@ brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "'", end = "'", close = true, newline = false },
{ start = "`", end = "`", close = true, newline = false },
{ start = "/*", end = " */", close = true, newline = false },
]
[overrides.comment]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
]
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
{ start = "`", end = "`", close = true, newline = false, not_in = ["string"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
]

View file

@ -5,13 +5,7 @@ autoclose_before = ",]}"
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
]
increase_indent_pattern = ":\\s*[|>]?\\s*$"
[overrides.string]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
]

View file

@ -696,8 +696,9 @@ mod tests {
use assets::Assets;
use editor::{scroll::autoscroll::Autoscroll, DisplayPoint, Editor};
use gpui::{
executor::Deterministic, AssetSource, MutableAppContext, TestAppContext, ViewHandle,
executor::Deterministic, AssetSource, MutableAppContext, Task, TestAppContext, ViewHandle,
};
use language::LanguageRegistry;
use project::{Project, ProjectPath};
use serde_json::json;
use std::{
@ -1881,6 +1882,18 @@ mod tests {
assert!(has_default_theme);
}
#[gpui::test]
fn test_bundled_languages(cx: &mut MutableAppContext) {
let mut languages = LanguageRegistry::new(Task::ready(()));
languages.set_executor(cx.background().clone());
let languages = Arc::new(languages);
languages::init(languages.clone());
for name in languages.language_names() {
languages.language_for_name(&name);
}
cx.foreground().run_until_parked();
}
fn init(cx: &mut TestAppContext) -> Arc<AppState> {
cx.foreground().forbid_parking();
cx.update(|cx| {