From 45d1690f6ed895d9542964ae176555c86cd2bedc Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sun, 5 Dec 2021 10:58:52 +0100 Subject: [PATCH 1/3] Use 16-bit float to store path windings Previously, we were using a normalized 8-bit unsigned integer which forced us to represent each increment of the winding number as a fraction of the max value (1 / 255) which we would then add up using additive alpha blending. This had three major drawbacks: - The max winding number could not be greater than 255. - Adding up (1 / 255) several times could result in a loss of precision. - Due to also computing anti-aliasing as a fractional winding number, we had to reduce the max winding number to 32. This was still not good enough because we would multiply a fractional value with `1 / 32`, thus introducing more and more loss of precision. This commit changes the texture type to an `f16` which doesn't require the division by 255 and enables greater precision in the computation of the anti-aliased parts of a curve. Note how this also removes the limitation of 255 windings at most per curve. The tradeoff is paying twice as much memory for storing the texture, but that seems totally valid to achieve rendering accuracy. Note that this kind of texture should be compatible with WebGL2 once we start working on a web version of Zed. --- crates/gpui/src/platform/mac/renderer.rs | 4 ++-- crates/gpui/src/platform/mac/shaders/shaders.metal | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/gpui/src/platform/mac/renderer.rs b/crates/gpui/src/platform/mac/renderer.rs index d291c9219ecf80b816f435f9a2261abe514a0216..2a97f4820ccd3da49104bb67a08f6d62718aacdf 100644 --- a/crates/gpui/src/platform/mac/renderer.rs +++ b/crates/gpui/src/platform/mac/renderer.rs @@ -107,7 +107,7 @@ impl Renderer { "path_atlas", "path_atlas_vertex", "path_atlas_fragment", - MTLPixelFormat::R8Unorm, + MTLPixelFormat::R16Float, ); Self { sprite_cache, @@ -827,7 +827,7 @@ fn build_path_atlas_texture_descriptor() -> metal::TextureDescriptor { let texture_descriptor = metal::TextureDescriptor::new(); texture_descriptor.set_width(2048); texture_descriptor.set_height(2048); - texture_descriptor.set_pixel_format(MTLPixelFormat::R8Unorm); + texture_descriptor.set_pixel_format(MTLPixelFormat::R16Float); texture_descriptor .set_usage(metal::MTLTextureUsage::RenderTarget | metal::MTLTextureUsage::ShaderRead); texture_descriptor.set_storage_mode(metal::MTLStorageMode::Private); diff --git a/crates/gpui/src/platform/mac/shaders/shaders.metal b/crates/gpui/src/platform/mac/shaders/shaders.metal index 13d2720fad7788ff93a58a8143dde44ced25cf41..0cf7d290f2f5bbd4ba6442b5d9bbfde855c1ed58 100644 --- a/crates/gpui/src/platform/mac/shaders/shaders.metal +++ b/crates/gpui/src/platform/mac/shaders/shaders.metal @@ -205,8 +205,6 @@ vertex SpriteFragmentInput sprite_vertex( }; } -#define MAX_WINDINGS 32. - fragment float4 sprite_fragment( SpriteFragmentInput input [[stage_in]], texture2d atlas [[ texture(GPUISpriteFragmentInputIndexAtlas) ]] @@ -216,7 +214,7 @@ fragment float4 sprite_fragment( float4 sample = atlas.sample(atlas_sampler, input.atlas_position); float mask; if (input.compute_winding) { - mask = 1. - abs(1. - fmod(sample.r * MAX_WINDINGS, 2.)); + mask = 1. - abs(1. - fmod(sample.r, 2.)); } else { mask = sample.a; } @@ -303,6 +301,6 @@ fragment float4 path_atlas_fragment( ); float f = (input.st_position.x * input.st_position.x) - input.st_position.y; float distance = f / length(gradient); - float alpha = saturate(0.5 - distance) / MAX_WINDINGS; + float alpha = saturate(0.5 - distance); return float4(alpha, 0., 0., 1.); } From 026c3476dbe2546e6940ee5bff32d9606e53fe4b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 5 Dec 2021 21:37:08 -0800 Subject: [PATCH 2/3] Upgrade tree-sitter to 0.20.1 --- Cargo.lock | 11 +++++------ Cargo.toml | 1 - crates/editor/Cargo.toml | 4 ++-- crates/gpui/Cargo.toml | 2 +- crates/gpui/grammars/context-predicate/Cargo.toml | 2 +- crates/language/Cargo.toml | 6 +++--- crates/workspace/Cargo.toml | 11 +---------- crates/zed/Cargo.toml | 4 ++-- 8 files changed, 15 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6227543798b09ad0afa62b93631e863fb7cdb2e..5d17718982d1717078b1dee702c101c8352bdb38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5135,8 +5135,9 @@ dependencies = [ [[package]] name = "tree-sitter" -version = "0.19.5" -source = "git+https://github.com/tree-sitter/tree-sitter?rev=d72771a19f4143530b1cfd23808e344f1276e176#d72771a19f4143530b1cfd23808e344f1276e176" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9394e9dbfe967b5f3d6ab79e302e78b5fb7b530c368d634ff3b8d67ede138bf1" dependencies = [ "cc", "regex", @@ -5144,9 +5145,9 @@ dependencies = [ [[package]] name = "tree-sitter-rust" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784f7ef9cdbd4c895dc2d4bb785e95b4a5364a602eec803681db83d1927ddf15" +checksum = "3df540a493d754015d22eaf57c38f58804be3713a22f6062db983ec15f85c3c9" dependencies = [ "cc", "tree-sitter", @@ -5643,8 +5644,6 @@ dependencies = [ "project", "serde_json", "theme", - "tree-sitter", - "tree-sitter-rust", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 98c5bf46d68deba42fc8fe7a07f2c05fa1abe081..f945561e7c934f1f965f6ea5365b87bb9ea19ee7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ default-members = ["crates/zed"] [patch.crates-io] async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" } -tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "d72771a19f4143530b1cfd23808e344f1276e176" } # TODO - Remove when a version is released with this PR: https://github.com/servo/core-foundation-rs/pull/457 cocoa = { git = "https://github.com/servo/core-foundation-rs", rev = "025dcb3c0d1ef01530f57ef65f3b1deb948f5737" } cocoa-foundation = { git = "https://github.com/servo/core-foundation-rs", rev = "025dcb3c0d1ef01530f57ef65f3b1deb948f5737" } diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index ed0d1b74133945a798bacb1f3b32c64361fec240..aa000c98c949057676154baf191af820b1ddb4a5 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -41,5 +41,5 @@ ctor = "0.1" env_logger = "0.8" rand = "0.8" unindent = "0.1.7" -tree-sitter = "0.19" -tree-sitter-rust = "0.19" +tree-sitter = "0.20" +tree-sitter-rust = "0.20" diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index 7c237d48e59c8d8605436814b4961f4febe8373f..4414936c9e3b81c8e46cd02f04f321007daab374 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -38,7 +38,7 @@ smallvec = { version = "1.6", features = ["union"] } smol = "1.2" time = { version = "0.3" } tiny-skia = "0.5" -tree-sitter = "0.19" +tree-sitter = "0.20" usvg = "0.14" waker-fn = "1.1.0" diff --git a/crates/gpui/grammars/context-predicate/Cargo.toml b/crates/gpui/grammars/context-predicate/Cargo.toml index 9e3316c0f2300f5bcbd48497f8d1db2d6efb2b6b..1dea1930fa461cc50f1cad48e5fa44dfcd081570 100644 --- a/crates/gpui/grammars/context-predicate/Cargo.toml +++ b/crates/gpui/grammars/context-predicate/Cargo.toml @@ -14,7 +14,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = "0.19.3" +tree-sitter = "0.20" [build-dependencies] cc = "1.0" diff --git a/crates/language/Cargo.toml b/crates/language/Cargo.toml index ad0f84b4dcd620309202ce14f0ab60b6cfb020b6..f4037ee70a1e49167afd4e73228a6ddeb55a2341 100644 --- a/crates/language/Cargo.toml +++ b/crates/language/Cargo.toml @@ -32,13 +32,13 @@ rand = { version = "0.8.3", optional = true } serde = { version = "1", features = ["derive"] } similar = "1.3" smol = "1.2" -tree-sitter = "0.19.5" -tree-sitter-rust = { version = "0.19.0", optional = true } +tree-sitter = "0.20.0" +tree-sitter-rust = { version = "0.20.0", optional = true } [dev-dependencies] text = { path = "../text", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] } lsp = { path = "../lsp", features = ["test-support"] } rand = "0.8.3" -tree-sitter-rust = "0.19.0" +tree-sitter-rust = "0.20.0" unindent = "0.1.7" diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.toml index 29e25148e5480c85dfc8a120d0d71eb40ead34b3..a5ca3c91e911b07601064e82c8a3f39dc1c6c96c 100644 --- a/crates/workspace/Cargo.toml +++ b/crates/workspace/Cargo.toml @@ -7,12 +7,7 @@ edition = "2018" path = "src/workspace.rs" [features] -test-support = [ - "client/test-support", - "project/test-support", - "tree-sitter", - "tree-sitter-rust", -] +test-support = ["client/test-support", "project/test-support"] [dependencies] client = { path = "../client" } @@ -23,13 +18,9 @@ theme = { path = "../theme" } anyhow = "1.0.38" log = "0.4" postage = { version = "0.4.1", features = ["futures-traits"] } -tree-sitter = { version = "0.19.5", optional = true } -tree-sitter-rust = { version = "0.19.0", optional = true } [dev-dependencies] client = { path = "../client", features = ["test-support"] } gpui = { path = "../gpui", features = ["test-support"] } project = { path = "../project", features = ["test-support"] } serde_json = { version = "1.0.64", features = ["preserve_order"] } -tree-sitter = "0.19.5" -tree-sitter-rust = "0.19.0" diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 9657691fc94947dfa65d580f80a699291b2db2bb..3c894f8894bd032b889b490dd8aa7e933223c14c 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -84,8 +84,8 @@ thiserror = "1.0.29" time = "0.3" tiny_http = "0.8" toml = "0.5" -tree-sitter = "0.19.5" -tree-sitter-rust = "0.19.0" +tree-sitter = "0.20.0" +tree-sitter-rust = "0.20.0" url = "2.2" [dev-dependencies] From b1ed9c88a490e7929c39e7c1125c83b7ddfbdc71 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 5 Dec 2021 21:37:31 -0800 Subject: [PATCH 3/3] Add tree-sitter-markdown, set up simple markdown higlighting --- Cargo.lock | 10 ++++++++ crates/zed/Cargo.toml | 1 + crates/zed/assets/themes/black.toml | 7 ++++++ crates/zed/assets/themes/dark.toml | 7 ++++++ crates/zed/assets/themes/light.toml | 9 +++++++- crates/zed/languages/markdown/highlights.scm | 24 ++++++++++++++++++++ crates/zed/src/language.rs | 5 +++- 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 crates/zed/languages/markdown/highlights.scm diff --git a/Cargo.lock b/Cargo.lock index 5d17718982d1717078b1dee702c101c8352bdb38..0aadd18f662e46f0702390405eb815a324f4caa8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5143,6 +5143,15 @@ dependencies = [ "regex", ] +[[package]] +name = "tree-sitter-markdown" +version = "0.0.1" +source = "git+https://github.com/maxbrunsfeld/tree-sitter-markdown?rev=b2b4eefd51ada972ef8bb581b83b6b8e7a28c7a6#b2b4eefd51ada972ef8bb581b83b6b8e7a28c7a6" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-rust" version = "0.20.0" @@ -5730,6 +5739,7 @@ dependencies = [ "tiny_http", "toml", "tree-sitter", + "tree-sitter-markdown", "tree-sitter-rust", "unindent", "url", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 3c894f8894bd032b889b490dd8aa7e933223c14c..e03ef6dcf9ccd02989c294f94cc495f2f97986be 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -86,6 +86,7 @@ tiny_http = "0.8" toml = "0.5" tree-sitter = "0.20.0" tree-sitter-rust = "0.20.0" +tree-sitter-markdown = { git = "https://github.com/maxbrunsfeld/tree-sitter-markdown", rev = "b2b4eefd51ada972ef8bb581b83b6b8e7a28c7a6" } url = "2.2" [dev-dependencies] diff --git a/crates/zed/assets/themes/black.toml b/crates/zed/assets/themes/black.toml index ec51391111e67ecb9c8f8e5394cf4ae5fca55da1..a822fa7d3346c1ba2b5aac359ceb1ac940c9a73f 100644 --- a/crates/zed/assets/themes/black.toml +++ b/crates/zed/assets/themes/black.toml @@ -50,3 +50,10 @@ comment = "#6a9955" property = "#4e94ce" variant = "#4fc1ff" constant = "#9cdcfe" + +title = { color = "#9cdcfe", weight = "bold" } +emphasis = "#4ec9b0" +"emphasis.strong" = { color = "#4ec9b0", weight = "bold" } +link_uri = { color = "#6a9955", underline = true } +link_text = { color = "#cb8f77", italic = true } +list_marker = "#4e94ce" diff --git a/crates/zed/assets/themes/dark.toml b/crates/zed/assets/themes/dark.toml index 15850f286ab3c0293b261ae987b5ea4af8259064..9d65a160eb6d1a6ff19c448a19c0231176cd4178 100644 --- a/crates/zed/assets/themes/dark.toml +++ b/crates/zed/assets/themes/dark.toml @@ -50,3 +50,10 @@ comment = "#6a9955" property = "#4e94ce" variant = "#4fc1ff" constant = "#9cdcfe" + +title = { color = "#9cdcfe", weight = "bold" } +emphasis = "#4ec9b0" +"emphasis.strong" = { color = "#4ec9b0", weight = "bold" } +link_uri = { color = "#6a9955", underline = true } +link_text = { color = "#cb8f77", italic = true } +list_marker = "#4e94ce" diff --git a/crates/zed/assets/themes/light.toml b/crates/zed/assets/themes/light.toml index 5a893368c3acc1a5f72cc194edd1595c5d63851e..18134501ece21622abeb5dd5bca0a958e66f7464 100644 --- a/crates/zed/assets/themes/light.toml +++ b/crates/zed/assets/themes/light.toml @@ -49,4 +49,11 @@ number = "#b5cea8" comment = "#6a9955" property = "#4e94ce" variant = "#4fc1ff" -constant = "#9cdcfe" +constant = "#5a9ccc" + +title = { color = "#5a9ccc", weight = "bold" } +emphasis = "#267f29" +"emphasis.strong" = { color = "#267f29", weight = "bold" } +link_uri = { color = "#6a9955", underline = true } +link_text = { color = "#a82121", italic = true } +list_marker = "#4e94ce" diff --git a/crates/zed/languages/markdown/highlights.scm b/crates/zed/languages/markdown/highlights.scm new file mode 100644 index 0000000000000000000000000000000000000000..65ac47ec4bd5537bb5d07301bc6eb9a48124622a --- /dev/null +++ b/crates/zed/languages/markdown/highlights.scm @@ -0,0 +1,24 @@ +(emphasis) @emphasis +(strong_emphasis) @emphasis.strong + +[ + (atx_heading) + (setext_heading) +] @title + +[ + (list_marker_plus) + (list_marker_minus) + (list_marker_star) + (list_marker_dot) + (list_marker_parenthesis) +] @list_marker + +[ + (indented_code_block) + (fenced_code_block) + (code_span) +] @text.literal + +(link_destination) @link_uri +(link_text) @link_text diff --git a/crates/zed/src/language.rs b/crates/zed/src/language.rs index c045804e92d92abf35c6e183e6bdb3b858536358..a84d2cbd40b7a9d16734056e29ce79c18a173bff 100644 --- a/crates/zed/src/language.rs +++ b/crates/zed/src/language.rs @@ -27,8 +27,11 @@ fn rust() -> Language { } fn markdown() -> Language { + let grammar = tree_sitter_markdown::language(); let config = toml::from_slice(&LanguageDir::get("markdown/config.toml").unwrap().data).unwrap(); - Language::new(config, None) + Language::new(config, Some(grammar)) + .with_highlights_query(load_query("markdown/highlights.scm").as_ref()) + .unwrap() } fn load_query(path: &str) -> Cow<'static, str> {