mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
Merge branch 'main' into sergey/z-2308-create-a-proof-of-concept-of-exporting-a-type-from-rust-and
This commit is contained in:
commit
af252888c4
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -51,6 +51,7 @@ jobs:
|
|||||||
rustup set profile minimal
|
rustup set profile minimal
|
||||||
rustup update stable
|
rustup update stable
|
||||||
rustup target add wasm32-wasi
|
rustup target add wasm32-wasi
|
||||||
|
cargo install cargo-nextest
|
||||||
|
|
||||||
- name: Install Node
|
- name: Install Node
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
@ -70,7 +71,7 @@ jobs:
|
|||||||
run: cargo check --workspace
|
run: cargo check --workspace
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --workspace --no-fail-fast
|
run: cargo nextest run --workspace --no-fail-fast
|
||||||
|
|
||||||
- name: Build collab
|
- name: Build collab
|
||||||
run: cargo build -p collab
|
run: cargo build -p collab
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,4 +20,5 @@ DerivedData/
|
|||||||
.swiftpm/config/registries.json
|
.swiftpm/config/registries.json
|
||||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||||
.netrc
|
.netrc
|
||||||
|
.swiftpm
|
||||||
**/*.db
|
**/*.db
|
||||||
|
120
Cargo.lock
generated
120
Cargo.lock
generated
@ -114,6 +114,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"settings",
|
"settings",
|
||||||
|
"smol",
|
||||||
"theme",
|
"theme",
|
||||||
"tiktoken-rs",
|
"tiktoken-rs",
|
||||||
"util",
|
"util",
|
||||||
@ -642,7 +643,7 @@ dependencies = [
|
|||||||
"http",
|
"http",
|
||||||
"http-body",
|
"http-body",
|
||||||
"hyper",
|
"hyper",
|
||||||
"itoa",
|
"itoa 1.0.6",
|
||||||
"matchit",
|
"matchit",
|
||||||
"memchr",
|
"memchr",
|
||||||
"mime",
|
"mime",
|
||||||
@ -3108,7 +3109,7 @@ checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes 1.4.0",
|
"bytes 1.4.0",
|
||||||
"fnv",
|
"fnv",
|
||||||
"itoa",
|
"itoa 1.0.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3167,7 +3168,7 @@ dependencies = [
|
|||||||
"http-body",
|
"http-body",
|
||||||
"httparse",
|
"httparse",
|
||||||
"httpdate",
|
"httpdate",
|
||||||
"itoa",
|
"itoa 1.0.6",
|
||||||
"pin-project-lite 0.2.9",
|
"pin-project-lite 0.2.9",
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -3433,6 +3434,12 @@ dependencies = [
|
|||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "0.4.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
@ -3493,12 +3500,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "json_comments"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "41ee439ee368ba4a77ac70d04f14015415af8600d6c894dc1f11bd79758c57d5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jwt"
|
name = "jwt"
|
||||||
version = "0.16.0"
|
version = "0.16.0"
|
||||||
@ -3612,6 +3613,29 @@ dependencies = [
|
|||||||
"workspace",
|
"workspace",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "language_tools"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"client",
|
||||||
|
"collections",
|
||||||
|
"editor",
|
||||||
|
"env_logger 0.9.3",
|
||||||
|
"futures 0.3.28",
|
||||||
|
"gpui",
|
||||||
|
"language",
|
||||||
|
"lsp",
|
||||||
|
"project",
|
||||||
|
"serde",
|
||||||
|
"settings",
|
||||||
|
"theme",
|
||||||
|
"tree-sitter",
|
||||||
|
"unindent",
|
||||||
|
"util",
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@ -3856,28 +3880,6 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lsp_log"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"client",
|
|
||||||
"collections",
|
|
||||||
"editor",
|
|
||||||
"env_logger 0.9.3",
|
|
||||||
"futures 0.3.28",
|
|
||||||
"gpui",
|
|
||||||
"language",
|
|
||||||
"lsp",
|
|
||||||
"project",
|
|
||||||
"serde",
|
|
||||||
"settings",
|
|
||||||
"theme",
|
|
||||||
"unindent",
|
|
||||||
"util",
|
|
||||||
"workspace",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mach"
|
name = "mach"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@ -5763,7 +5765,7 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
"errno 0.2.8",
|
"errno 0.2.8",
|
||||||
"io-lifetimes 0.5.3",
|
"io-lifetimes 0.5.3",
|
||||||
"itoa",
|
"itoa 1.0.6",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.0.42",
|
"linux-raw-sys 0.0.42",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@ -6195,7 +6197,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
|
checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"itoa",
|
"itoa 1.0.6",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json_lenient"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7d7b9ce5b0a63c6269b9623ed828b39259545a6ec0d8a35d6135ad6af6232add"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"itoa 0.4.8",
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@ -6218,7 +6232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
|
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"form_urlencoded",
|
"form_urlencoded",
|
||||||
"itoa",
|
"itoa 1.0.6",
|
||||||
"ryu",
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@ -6244,7 +6258,7 @@ dependencies = [
|
|||||||
"fs",
|
"fs",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
"gpui",
|
"gpui",
|
||||||
"json_comments",
|
"indoc",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"postage",
|
"postage",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
@ -6253,6 +6267,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_json_lenient",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"sqlez",
|
"sqlez",
|
||||||
"staff_mode",
|
"staff_mode",
|
||||||
@ -6603,7 +6618,7 @@ dependencies = [
|
|||||||
"hkdf",
|
"hkdf",
|
||||||
"hmac 0.12.1",
|
"hmac 0.12.1",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"itoa",
|
"itoa 1.0.6",
|
||||||
"libc",
|
"libc",
|
||||||
"libsqlite3-sys",
|
"libsqlite3-sys",
|
||||||
"log",
|
"log",
|
||||||
@ -6998,18 +7013,6 @@ dependencies = [
|
|||||||
"workspace",
|
"workspace",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "theme_testbench"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"gpui",
|
|
||||||
"project",
|
|
||||||
"settings",
|
|
||||||
"smallvec",
|
|
||||||
"theme",
|
|
||||||
"workspace",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.40"
|
version = "1.0.40"
|
||||||
@ -7089,7 +7092,7 @@ version = "0.3.21"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc"
|
checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa 1.0.6",
|
||||||
"serde",
|
"serde",
|
||||||
"time-core",
|
"time-core",
|
||||||
"time-macros",
|
"time-macros",
|
||||||
@ -7455,8 +7458,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter"
|
name = "tree-sitter"
|
||||||
version = "0.20.9"
|
version = "0.20.10"
|
||||||
source = "git+https://github.com/tree-sitter/tree-sitter?rev=c51896d32dcc11a38e41f36e3deb1a6a9c4f4b14#c51896d32dcc11a38e41f36e3deb1a6a9c4f4b14"
|
source = "git+https://github.com/tree-sitter/tree-sitter?rev=49226023693107fba9a1191136a4f47f38cdca73#49226023693107fba9a1191136a4f47f38cdca73"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"regex",
|
"regex",
|
||||||
@ -7519,6 +7522,15 @@ dependencies = [
|
|||||||
"tree-sitter",
|
"tree-sitter",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tree-sitter-heex"
|
||||||
|
version = "0.0.1"
|
||||||
|
source = "git+https://github.com/phoenixframework/tree-sitter-heex?rev=2e1348c3cf2c9323e87c2744796cf3f3868aa82a#2e1348c3cf2c9323e87c2744796cf3f3868aa82a"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"tree-sitter",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter-html"
|
name = "tree-sitter-html"
|
||||||
version = "0.19.0"
|
version = "0.19.0"
|
||||||
@ -8893,7 +8905,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed"
|
name = "zed"
|
||||||
version = "0.91.0"
|
version = "0.93.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activity_indicator",
|
"activity_indicator",
|
||||||
"ai",
|
"ai",
|
||||||
@ -8937,11 +8949,11 @@ dependencies = [
|
|||||||
"journal",
|
"journal",
|
||||||
"language",
|
"language",
|
||||||
"language_selector",
|
"language_selector",
|
||||||
|
"language_tools",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"lsp",
|
"lsp",
|
||||||
"lsp_log",
|
|
||||||
"node_runtime",
|
"node_runtime",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"outline",
|
"outline",
|
||||||
@ -8972,7 +8984,6 @@ dependencies = [
|
|||||||
"text",
|
"text",
|
||||||
"theme",
|
"theme",
|
||||||
"theme_selector",
|
"theme_selector",
|
||||||
"theme_testbench",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tiny_http",
|
"tiny_http",
|
||||||
"toml",
|
"toml",
|
||||||
@ -8983,6 +8994,7 @@ dependencies = [
|
|||||||
"tree-sitter-elixir",
|
"tree-sitter-elixir",
|
||||||
"tree-sitter-embedded-template",
|
"tree-sitter-embedded-template",
|
||||||
"tree-sitter-go",
|
"tree-sitter-go",
|
||||||
|
"tree-sitter-heex",
|
||||||
"tree-sitter-html",
|
"tree-sitter-html",
|
||||||
"tree-sitter-json 0.20.0",
|
"tree-sitter-json 0.20.0",
|
||||||
"tree-sitter-lua",
|
"tree-sitter-lua",
|
||||||
|
@ -32,10 +32,10 @@ members = [
|
|||||||
"crates/journal",
|
"crates/journal",
|
||||||
"crates/language",
|
"crates/language",
|
||||||
"crates/language_selector",
|
"crates/language_selector",
|
||||||
|
"crates/language_tools",
|
||||||
"crates/live_kit_client",
|
"crates/live_kit_client",
|
||||||
"crates/live_kit_server",
|
"crates/live_kit_server",
|
||||||
"crates/lsp",
|
"crates/lsp",
|
||||||
"crates/lsp_log",
|
|
||||||
"crates/media",
|
"crates/media",
|
||||||
"crates/menu",
|
"crates/menu",
|
||||||
"crates/node_runtime",
|
"crates/node_runtime",
|
||||||
@ -61,7 +61,6 @@ members = [
|
|||||||
"crates/text",
|
"crates/text",
|
||||||
"crates/theme",
|
"crates/theme",
|
||||||
"crates/theme_selector",
|
"crates/theme_selector",
|
||||||
"crates/theme_testbench",
|
|
||||||
"crates/util",
|
"crates/util",
|
||||||
"crates/vim",
|
"crates/vim",
|
||||||
"crates/workspace",
|
"crates/workspace",
|
||||||
@ -99,10 +98,11 @@ tempdir = { version = "0.3.7" }
|
|||||||
thiserror = { version = "1.0.29" }
|
thiserror = { version = "1.0.29" }
|
||||||
time = { version = "0.3", features = ["serde", "serde-well-known"] }
|
time = { version = "0.3", features = ["serde", "serde-well-known"] }
|
||||||
toml = { version = "0.5" }
|
toml = { version = "0.5" }
|
||||||
|
tree-sitter = "0.20"
|
||||||
unindent = { version = "0.1.7" }
|
unindent = { version = "0.1.7" }
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "c51896d32dcc11a38e41f36e3deb1a6a9c4f4b14" }
|
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "49226023693107fba9a1191136a4f47f38cdca73" }
|
||||||
async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" }
|
async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" }
|
||||||
|
|
||||||
# TODO - Remove when a version is released with this PR: https://github.com/servo/core-foundation-rs/pull/457
|
# TODO - Remove when a version is released with this PR: https://github.com/servo/core-foundation-rs/pull/457
|
||||||
|
4
assets/icons/robot_14.svg
Normal file
4
assets/icons/robot_14.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="16" viewBox="0 0 14 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M2.5 4C2.5 2.89531 3.39688 2 4.5 2H9.5C10.6031 2 11.5 2.89531 11.5 4V8C11.5 9.10312 10.6031 10 9.5 10H4.5C3.39688 10 2.5 9.10312 2.5 8V4ZM5 4C4.44687 4 4 4.44687 4 5C4 5.55313 4.44687 6 5 6C5.55313 6 6 5.55313 6 5C6 4.44687 5.55313 4 5 4ZM9 6C9.55313 6 10 5.55313 10 5C10 4.44687 9.55313 4 9 4C8.44687 4 8 4.44687 8 5C8 5.55313 8.44687 6 9 6ZM5 8.5C5.275 8.5 5.5 8.275 5.5 8C5.5 7.725 5.275 7.5 5 7.5C4.725 7.5 4.5 7.725 4.5 8C4.5 8.275 4.725 8.5 5 8.5ZM7 7.5C6.725 7.5 6.5 7.725 6.5 8C6.5 8.275 6.725 8.5 7 8.5C7.275 8.5 7.5 8.275 7.5 8C7.5 7.725 7.275 7.5 7 7.5ZM9 8.5C9.275 8.5 9.5 8.275 9.5 8C9.5 7.725 9.275 7.5 9 7.5C8.725 7.5 8.5 7.725 8.5 8C8.5 8.275 8.725 8.5 9 8.5ZM0 14C0 12.3156 1.34312 11 3 11H11C12.6562 11 14 12.3156 14 14V15C14 15.5531 13.5531 16 13 16H11V14C11 13.4469 10.5531 13 10 13H4C3.44687 13 3 13.4469 3 14V16H1C0.447812 16 0 15.5531 0 15V14Z" fill="#808080"/>
|
||||||
|
<path d="M7.5 2H6.5V0.5C6.5 0.22375 6.725 0 7 0C7.275 0 7.5 0.22375 7.5 0.5V2ZM1.5 4.5V7.5C1.5 7.775 1.27625 8 1 8C0.72375 8 0.5 7.775 0.5 7.5V4.5C0.5 4.225 0.72375 4 1 4C1.27625 4 1.5 4.225 1.5 4.5ZM5.5 16H4.5V14.5C4.5 14.225 4.725 14 5 14C5.275 14 5.5 14.225 5.5 14.5V16ZM7.5 16H6.5V14.5C6.5 14.225 6.725 14 7 14C7.275 14 7.5 14.225 7.5 14.5V16ZM9 14C9.275 14 9.5 14.225 9.5 14.5V16H8.5V14.5C8.5 14.225 8.725 14 9 14ZM13.5 7.5C13.5 7.775 13.275 8 13 8C12.725 8 12.5 7.775 12.5 7.5V4.5C12.5 4.225 12.725 4 13 4C13.275 4 13.5 4.225 13.5 4.5V7.5Z" fill="#808080"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
@ -55,7 +55,40 @@
|
|||||||
"context": "Pane",
|
"context": "Pane",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"alt-cmd-/": "search::ToggleRegex",
|
"alt-cmd-/": "search::ToggleRegex",
|
||||||
"ctrl-0": "project_panel::ToggleFocus"
|
"ctrl-0": "project_panel::ToggleFocus",
|
||||||
|
"cmd-1": [
|
||||||
|
"pane::ActivateItem",
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"cmd-2": [
|
||||||
|
"pane::ActivateItem",
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"cmd-3": [
|
||||||
|
"pane::ActivateItem",
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"cmd-4": [
|
||||||
|
"pane::ActivateItem",
|
||||||
|
3
|
||||||
|
],
|
||||||
|
"cmd-5": [
|
||||||
|
"pane::ActivateItem",
|
||||||
|
4
|
||||||
|
],
|
||||||
|
"cmd-6": [
|
||||||
|
"pane::ActivateItem",
|
||||||
|
5
|
||||||
|
],
|
||||||
|
"cmd-7": [
|
||||||
|
"pane::ActivateItem",
|
||||||
|
6
|
||||||
|
],
|
||||||
|
"cmd-8": [
|
||||||
|
"pane::ActivateItem",
|
||||||
|
7
|
||||||
|
],
|
||||||
|
"cmd-9": "pane::ActivateLastItem"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -200,7 +200,9 @@
|
|||||||
"context": "AssistantEditor > Editor",
|
"context": "AssistantEditor > Editor",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"cmd-enter": "assistant::Assist",
|
"cmd-enter": "assistant::Assist",
|
||||||
"cmd->": "assistant::QuoteSelection"
|
"cmd->": "assistant::QuoteSelection",
|
||||||
|
"shift-enter": "assistant::Split",
|
||||||
|
"ctrl-r": "assistant::CycleMessageRole"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -409,6 +411,7 @@
|
|||||||
"ctrl-shift-k": "editor::DeleteLine",
|
"ctrl-shift-k": "editor::DeleteLine",
|
||||||
"cmd-shift-d": "editor::DuplicateLine",
|
"cmd-shift-d": "editor::DuplicateLine",
|
||||||
"cmd-shift-l": "editor::SplitSelectionIntoLines",
|
"cmd-shift-l": "editor::SplitSelectionIntoLines",
|
||||||
|
"ctrl-j": "editor::JoinLines",
|
||||||
"ctrl-cmd-up": "editor::MoveLineUp",
|
"ctrl-cmd-up": "editor::MoveLineUp",
|
||||||
"ctrl-cmd-down": "editor::MoveLineDown",
|
"ctrl-cmd-down": "editor::MoveLineDown",
|
||||||
"ctrl-alt-backspace": "editor::DeleteToPreviousSubwordStart",
|
"ctrl-alt-backspace": "editor::DeleteToPreviousSubwordStart",
|
||||||
|
@ -25,11 +25,15 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"h": "vim::Left",
|
"h": "vim::Left",
|
||||||
|
"left": "vim::Left",
|
||||||
"backspace": "vim::Backspace",
|
"backspace": "vim::Backspace",
|
||||||
"j": "vim::Down",
|
"j": "vim::Down",
|
||||||
|
"down": "vim::Down",
|
||||||
"enter": "vim::NextLineStart",
|
"enter": "vim::NextLineStart",
|
||||||
"k": "vim::Up",
|
"k": "vim::Up",
|
||||||
|
"up": "vim::Up",
|
||||||
"l": "vim::Right",
|
"l": "vim::Right",
|
||||||
|
"right": "vim::Right",
|
||||||
"$": "vim::EndOfLine",
|
"$": "vim::EndOfLine",
|
||||||
"shift-g": "vim::EndOfDocument",
|
"shift-g": "vim::EndOfDocument",
|
||||||
"w": "vim::NextWordStart",
|
"w": "vim::NextWordStart",
|
||||||
@ -90,6 +94,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"ctrl-o": "pane::GoBack",
|
||||||
|
"ctrl-]": "editor::GoToDefinition",
|
||||||
"escape": "editor::Cancel",
|
"escape": "editor::Cancel",
|
||||||
"0": "vim::StartOfLine", // When no number operator present, use start of line motion
|
"0": "vim::StartOfLine", // When no number operator present, use start of line motion
|
||||||
"1": [
|
"1": [
|
||||||
@ -143,6 +149,7 @@
|
|||||||
"Delete"
|
"Delete"
|
||||||
],
|
],
|
||||||
"shift-d": "vim::DeleteToEndOfLine",
|
"shift-d": "vim::DeleteToEndOfLine",
|
||||||
|
"shift-j": "editor::JoinLines",
|
||||||
"y": [
|
"y": [
|
||||||
"vim::PushOperator",
|
"vim::PushOperator",
|
||||||
"Yank"
|
"Yank"
|
||||||
@ -184,7 +191,6 @@
|
|||||||
"p": "vim::Paste",
|
"p": "vim::Paste",
|
||||||
"u": "editor::Undo",
|
"u": "editor::Undo",
|
||||||
"ctrl-r": "editor::Redo",
|
"ctrl-r": "editor::Redo",
|
||||||
"ctrl-o": "pane::GoBack",
|
|
||||||
"/": [
|
"/": [
|
||||||
"buffer_search::Deploy",
|
"buffer_search::Deploy",
|
||||||
{
|
{
|
||||||
|
@ -108,6 +108,8 @@
|
|||||||
// Whether or not to remove any trailing whitespace from lines of a buffer
|
// Whether or not to remove any trailing whitespace from lines of a buffer
|
||||||
// before saving it.
|
// before saving it.
|
||||||
"remove_trailing_whitespace_on_save": true,
|
"remove_trailing_whitespace_on_save": true,
|
||||||
|
// Whether to start a new line with a comment when a previous line is a comment as well.
|
||||||
|
"extend_comment_on_newline": true,
|
||||||
// Whether or not to ensure there's a single newline at the end of a buffer
|
// Whether or not to ensure there's a single newline at the end of a buffer
|
||||||
// when saving it.
|
// when saving it.
|
||||||
"ensure_final_newline_on_save": true,
|
"ensure_final_newline_on_save": true,
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
// Folder-specific Zed settings
|
// Folder-specific settings
|
||||||
//
|
//
|
||||||
// A subset of Zed's settings can be configured on a per-folder basis.
|
// For a full list of overridable settings, and general information on folder-specific settings,
|
||||||
//
|
// see the documentation: https://docs.zed.dev/configuration/configuring-zed#folder-specific-settings
|
||||||
// For information on how to configure Zed, see the Zed
|
|
||||||
// documentation: https://zed.dev/docs/configuring-zed
|
|
||||||
//
|
|
||||||
// To see all of Zed's default settings without changing your
|
|
||||||
// custom settings, run the `open default settings` command
|
|
||||||
// from the command palette or from `Zed` application menu.
|
|
||||||
{}
|
{}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Folder-specific settings
|
// Zed settings
|
||||||
//
|
//
|
||||||
// For a full list of overridable settings, and general information on folder-specific settings, see the documentation:
|
// For information on how to configure Zed, see the Zed
|
||||||
// https://docs.zed.dev/configuration/configuring-zed#folder-specific-settings
|
// documentation: https://zed.dev/docs/configuring-zed
|
||||||
//
|
//
|
||||||
// To see all of Zed's default settings without changing your
|
// To see all of Zed's default settings without changing your
|
||||||
// custom settings, run the `open default settings` command
|
// custom settings, run the `open default settings` command
|
||||||
|
@ -326,7 +326,7 @@ impl View for ActivityIndicator {
|
|||||||
let mut element = MouseEventHandler::<Self, _>::new(0, cx, |state, cx| {
|
let mut element = MouseEventHandler::<Self, _>::new(0, cx, |state, cx| {
|
||||||
let theme = &theme::current(cx).workspace.status_bar.lsp_status;
|
let theme = &theme::current(cx).workspace.status_bar.lsp_status;
|
||||||
let style = if state.hovered() && on_click.is_some() {
|
let style = if state.hovered() && on_click.is_some() {
|
||||||
theme.hover.as_ref().unwrap_or(&theme.default)
|
theme.hovered.as_ref().unwrap_or(&theme.default)
|
||||||
} else {
|
} else {
|
||||||
&theme.default
|
&theme.default
|
||||||
};
|
};
|
||||||
|
@ -28,6 +28,7 @@ isahc.workspace = true
|
|||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
smol.workspace = true
|
||||||
tiktoken-rs = "0.4"
|
tiktoken-rs = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
|
|
||||||
// Data types for chat completion requests
|
// Data types for chat completion requests
|
||||||
#[derive(Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct OpenAIRequest {
|
struct OpenAIRequest {
|
||||||
model: String,
|
model: String,
|
||||||
messages: Vec<RequestMessage>,
|
messages: Vec<RequestMessage>,
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -49,7 +49,7 @@ impl View for UpdateNotification {
|
|||||||
)
|
)
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<Cancel, _>::new(0, cx, |state, _| {
|
MouseEventHandler::<Cancel, _>::new(0, cx, |state, _| {
|
||||||
let style = theme.dismiss_button.style_for(state, false);
|
let style = theme.dismiss_button.style_for(state);
|
||||||
Svg::new("icons/x_mark_8.svg")
|
Svg::new("icons/x_mark_8.svg")
|
||||||
.with_color(style.color)
|
.with_color(style.color)
|
||||||
.constrained()
|
.constrained()
|
||||||
@ -74,7 +74,7 @@ impl View for UpdateNotification {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.with_child({
|
.with_child({
|
||||||
let style = theme.action_message.style_for(state, false);
|
let style = theme.action_message.style_for(state);
|
||||||
Text::new("View the release notes", style.text.clone())
|
Text::new("View the release notes", style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
|
@ -83,7 +83,7 @@ impl View for Breadcrumbs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MouseEventHandler::<Breadcrumbs, Breadcrumbs>::new(0, cx, |state, _| {
|
MouseEventHandler::<Breadcrumbs, Breadcrumbs>::new(0, cx, |state, _| {
|
||||||
let style = style.style_for(state, false);
|
let style = style.style_for(state);
|
||||||
crumbs.with_style(style.container)
|
crumbs.with_style(style.container)
|
||||||
})
|
})
|
||||||
.on_click(MouseButton::Left, |_, this, cx| {
|
.on_click(MouseButton::Left, |_, this, cx| {
|
||||||
|
@ -39,7 +39,12 @@ use std::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use unindent::Unindent as _;
|
use unindent::Unindent as _;
|
||||||
use workspace::{item::ItemHandle as _, shared_screen::SharedScreen, SplitDirection, Workspace};
|
use workspace::{
|
||||||
|
dock::{test::TestPanel, DockPosition},
|
||||||
|
item::{test::TestItem, ItemHandle as _},
|
||||||
|
shared_screen::SharedScreen,
|
||||||
|
SplitDirection, Workspace,
|
||||||
|
};
|
||||||
|
|
||||||
#[ctor::ctor]
|
#[ctor::ctor]
|
||||||
fn init_logger() {
|
fn init_logger() {
|
||||||
@ -6847,12 +6852,43 @@ async fn test_basic_following(
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Client B activates an external window again, and the previously-opened screen-sharing item
|
// Client B activates a panel, and the previously-opened screen-sharing item gets activated.
|
||||||
// gets activated.
|
let panel = cx_b.add_view(workspace_b.window_id(), |_| {
|
||||||
active_call_b
|
TestPanel::new(DockPosition::Left)
|
||||||
.update(cx_b, |call, cx| call.set_location(None, cx))
|
});
|
||||||
.await
|
workspace_b.update(cx_b, |workspace, cx| {
|
||||||
.unwrap();
|
workspace.add_panel(panel, cx);
|
||||||
|
workspace.toggle_panel_focus::<TestPanel>(cx);
|
||||||
|
});
|
||||||
|
deterministic.run_until_parked();
|
||||||
|
assert_eq!(
|
||||||
|
workspace_a.read_with(cx_a, |workspace, cx| workspace
|
||||||
|
.active_item(cx)
|
||||||
|
.unwrap()
|
||||||
|
.id()),
|
||||||
|
shared_screen.id()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Toggling the focus back to the pane causes client A to return to the multibuffer.
|
||||||
|
workspace_b.update(cx_b, |workspace, cx| {
|
||||||
|
workspace.toggle_panel_focus::<TestPanel>(cx);
|
||||||
|
});
|
||||||
|
deterministic.run_until_parked();
|
||||||
|
workspace_a.read_with(cx_a, |workspace, cx| {
|
||||||
|
assert_eq!(
|
||||||
|
workspace.active_item(cx).unwrap().id(),
|
||||||
|
multibuffer_editor_a.id()
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Client B activates an item that doesn't implement following,
|
||||||
|
// so the previously-opened screen-sharing item gets activated.
|
||||||
|
let unfollowable_item = cx_b.add_view(workspace_b.window_id(), |_| TestItem::new());
|
||||||
|
workspace_b.update(cx_b, |workspace, cx| {
|
||||||
|
workspace.active_pane().update(cx, |pane, cx| {
|
||||||
|
pane.add_item(Box::new(unfollowable_item), true, true, None, cx)
|
||||||
|
})
|
||||||
|
});
|
||||||
deterministic.run_until_parked();
|
deterministic.run_until_parked();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
workspace_a.read_with(cx_a, |workspace, cx| workspace
|
workspace_a.read_with(cx_a, |workspace, cx| workspace
|
||||||
|
@ -299,7 +299,12 @@ impl CollabTitlebarItem {
|
|||||||
pub fn toggle_user_menu(&mut self, _: &ToggleUserMenu, cx: &mut ViewContext<Self>) {
|
pub fn toggle_user_menu(&mut self, _: &ToggleUserMenu, cx: &mut ViewContext<Self>) {
|
||||||
let theme = theme::current(cx).clone();
|
let theme = theme::current(cx).clone();
|
||||||
let avatar_style = theme.workspace.titlebar.leader_avatar.clone();
|
let avatar_style = theme.workspace.titlebar.leader_avatar.clone();
|
||||||
let item_style = theme.context_menu.item.disabled_style().clone();
|
let item_style = theme
|
||||||
|
.context_menu
|
||||||
|
.item
|
||||||
|
.inactive_state()
|
||||||
|
.disabled_style()
|
||||||
|
.clone();
|
||||||
self.user_menu.update(cx, |user_menu, cx| {
|
self.user_menu.update(cx, |user_menu, cx| {
|
||||||
let items = if let Some(user) = self.user_store.read(cx).current_user() {
|
let items = if let Some(user) = self.user_store.read(cx).current_user() {
|
||||||
vec![
|
vec![
|
||||||
@ -361,8 +366,20 @@ impl CollabTitlebarItem {
|
|||||||
.contained()
|
.contained()
|
||||||
.with_style(titlebar.toggle_contacts_badge)
|
.with_style(titlebar.toggle_contacts_badge)
|
||||||
.contained()
|
.contained()
|
||||||
.with_margin_left(titlebar.toggle_contacts_button.default.icon_width)
|
.with_margin_left(
|
||||||
.with_margin_top(titlebar.toggle_contacts_button.default.icon_width)
|
titlebar
|
||||||
|
.toggle_contacts_button
|
||||||
|
.inactive_state()
|
||||||
|
.default
|
||||||
|
.icon_width,
|
||||||
|
)
|
||||||
|
.with_margin_top(
|
||||||
|
titlebar
|
||||||
|
.toggle_contacts_button
|
||||||
|
.inactive_state()
|
||||||
|
.default
|
||||||
|
.icon_width,
|
||||||
|
)
|
||||||
.aligned(),
|
.aligned(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
@ -372,7 +389,8 @@ impl CollabTitlebarItem {
|
|||||||
MouseEventHandler::<ToggleContactsMenu, Self>::new(0, cx, |state, _| {
|
MouseEventHandler::<ToggleContactsMenu, Self>::new(0, cx, |state, _| {
|
||||||
let style = titlebar
|
let style = titlebar
|
||||||
.toggle_contacts_button
|
.toggle_contacts_button
|
||||||
.style_for(state, self.contacts_popover.is_some());
|
.in_state(self.contacts_popover.is_some())
|
||||||
|
.style_for(state);
|
||||||
Svg::new("icons/user_plus_16.svg")
|
Svg::new("icons/user_plus_16.svg")
|
||||||
.with_color(style.color)
|
.with_color(style.color)
|
||||||
.constrained()
|
.constrained()
|
||||||
@ -419,7 +437,7 @@ impl CollabTitlebarItem {
|
|||||||
|
|
||||||
let titlebar = &theme.workspace.titlebar;
|
let titlebar = &theme.workspace.titlebar;
|
||||||
MouseEventHandler::<ToggleScreenSharing, Self>::new(0, cx, |state, _| {
|
MouseEventHandler::<ToggleScreenSharing, Self>::new(0, cx, |state, _| {
|
||||||
let style = titlebar.call_control.style_for(state, false);
|
let style = titlebar.call_control.style_for(state);
|
||||||
Svg::new(icon)
|
Svg::new(icon)
|
||||||
.with_color(style.color)
|
.with_color(style.color)
|
||||||
.constrained()
|
.constrained()
|
||||||
@ -473,7 +491,7 @@ impl CollabTitlebarItem {
|
|||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<ShareUnshare, Self>::new(0, cx, |state, _| {
|
MouseEventHandler::<ShareUnshare, Self>::new(0, cx, |state, _| {
|
||||||
//TODO: Ensure this button has consistent width for both text variations
|
//TODO: Ensure this button has consistent width for both text variations
|
||||||
let style = titlebar.share_button.style_for(state, false);
|
let style = titlebar.share_button.inactive_state().style_for(state);
|
||||||
Label::new(label, style.text.clone())
|
Label::new(label, style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
@ -511,7 +529,7 @@ impl CollabTitlebarItem {
|
|||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<ToggleUserMenu, Self>::new(0, cx, |state, _| {
|
MouseEventHandler::<ToggleUserMenu, Self>::new(0, cx, |state, _| {
|
||||||
let style = titlebar.call_control.style_for(state, false);
|
let style = titlebar.call_control.style_for(state);
|
||||||
Svg::new("icons/ellipsis_14.svg")
|
Svg::new("icons/ellipsis_14.svg")
|
||||||
.with_color(style.color)
|
.with_color(style.color)
|
||||||
.constrained()
|
.constrained()
|
||||||
@ -549,7 +567,7 @@ impl CollabTitlebarItem {
|
|||||||
fn render_sign_in_button(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
fn render_sign_in_button(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||||
let titlebar = &theme.workspace.titlebar;
|
let titlebar = &theme.workspace.titlebar;
|
||||||
MouseEventHandler::<SignIn, Self>::new(0, cx, |state, _| {
|
MouseEventHandler::<SignIn, Self>::new(0, cx, |state, _| {
|
||||||
let style = titlebar.sign_in_prompt.style_for(state, false);
|
let style = titlebar.sign_in_prompt.inactive_state().style_for(state);
|
||||||
Label::new("Sign In", style.text.clone())
|
Label::new("Sign In", style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
|
@ -117,7 +117,8 @@ impl PickerDelegate for ContactFinderDelegate {
|
|||||||
.contact_finder
|
.contact_finder
|
||||||
.picker
|
.picker
|
||||||
.item
|
.item
|
||||||
.style_for(mouse_state, selected);
|
.in_state(selected)
|
||||||
|
.style_for(mouse_state);
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_children(user.avatar.clone().map(|avatar| {
|
.with_children(user.avatar.clone().map(|avatar| {
|
||||||
Image::from_data(avatar)
|
Image::from_data(avatar)
|
||||||
|
@ -774,7 +774,8 @@ impl ContactList {
|
|||||||
.with_style(
|
.with_style(
|
||||||
*theme
|
*theme
|
||||||
.contact_row
|
.contact_row
|
||||||
.style_for(&mut Default::default(), is_selected),
|
.in_state(is_selected)
|
||||||
|
.style_for(&mut Default::default()),
|
||||||
)
|
)
|
||||||
.into_any()
|
.into_any()
|
||||||
}
|
}
|
||||||
@ -797,7 +798,7 @@ impl ContactList {
|
|||||||
.width
|
.width
|
||||||
.or(theme.contact_avatar.height)
|
.or(theme.contact_avatar.height)
|
||||||
.unwrap_or(0.);
|
.unwrap_or(0.);
|
||||||
let row = &theme.project_row.default;
|
let row = &theme.project_row.inactive_state().default;
|
||||||
let tree_branch = theme.tree_branch;
|
let tree_branch = theme.tree_branch;
|
||||||
let line_height = row.name.text.line_height(font_cache);
|
let line_height = row.name.text.line_height(font_cache);
|
||||||
let cap_height = row.name.text.cap_height(font_cache);
|
let cap_height = row.name.text.cap_height(font_cache);
|
||||||
@ -810,8 +811,11 @@ impl ContactList {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MouseEventHandler::<JoinProject, Self>::new(project_id as usize, cx, |mouse_state, _| {
|
MouseEventHandler::<JoinProject, Self>::new(project_id as usize, cx, |mouse_state, _| {
|
||||||
let tree_branch = *tree_branch.style_for(mouse_state, is_selected);
|
let tree_branch = *tree_branch.in_state(is_selected).style_for(mouse_state);
|
||||||
let row = theme.project_row.style_for(mouse_state, is_selected);
|
let row = theme
|
||||||
|
.project_row
|
||||||
|
.in_state(is_selected)
|
||||||
|
.style_for(mouse_state);
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
@ -893,7 +897,7 @@ impl ContactList {
|
|||||||
.width
|
.width
|
||||||
.or(theme.contact_avatar.height)
|
.or(theme.contact_avatar.height)
|
||||||
.unwrap_or(0.);
|
.unwrap_or(0.);
|
||||||
let row = &theme.project_row.default;
|
let row = &theme.project_row.inactive_state().default;
|
||||||
let tree_branch = theme.tree_branch;
|
let tree_branch = theme.tree_branch;
|
||||||
let line_height = row.name.text.line_height(font_cache);
|
let line_height = row.name.text.line_height(font_cache);
|
||||||
let cap_height = row.name.text.cap_height(font_cache);
|
let cap_height = row.name.text.cap_height(font_cache);
|
||||||
@ -904,8 +908,11 @@ impl ContactList {
|
|||||||
peer_id.as_u64() as usize,
|
peer_id.as_u64() as usize,
|
||||||
cx,
|
cx,
|
||||||
|mouse_state, _| {
|
|mouse_state, _| {
|
||||||
let tree_branch = *tree_branch.style_for(mouse_state, is_selected);
|
let tree_branch = *tree_branch.in_state(is_selected).style_for(mouse_state);
|
||||||
let row = theme.project_row.style_for(mouse_state, is_selected);
|
let row = theme
|
||||||
|
.project_row
|
||||||
|
.in_state(is_selected)
|
||||||
|
.style_for(mouse_state);
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
@ -989,7 +996,8 @@ impl ContactList {
|
|||||||
|
|
||||||
let header_style = theme
|
let header_style = theme
|
||||||
.header_row
|
.header_row
|
||||||
.style_for(&mut Default::default(), is_selected);
|
.in_state(is_selected)
|
||||||
|
.style_for(&mut Default::default());
|
||||||
let text = match section {
|
let text = match section {
|
||||||
Section::ActiveCall => "Collaborators",
|
Section::ActiveCall => "Collaborators",
|
||||||
Section::Requests => "Contact Requests",
|
Section::Requests => "Contact Requests",
|
||||||
@ -999,7 +1007,7 @@ impl ContactList {
|
|||||||
let leave_call = if section == Section::ActiveCall {
|
let leave_call = if section == Section::ActiveCall {
|
||||||
Some(
|
Some(
|
||||||
MouseEventHandler::<LeaveCallContactList, Self>::new(0, cx, |state, _| {
|
MouseEventHandler::<LeaveCallContactList, Self>::new(0, cx, |state, _| {
|
||||||
let style = theme.leave_call.style_for(state, false);
|
let style = theme.leave_call.style_for(state);
|
||||||
Label::new("Leave Call", style.text.clone())
|
Label::new("Leave Call", style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
@ -1110,8 +1118,7 @@ impl ContactList {
|
|||||||
contact.user.id as usize,
|
contact.user.id as usize,
|
||||||
cx,
|
cx,
|
||||||
|mouse_state, _| {
|
|mouse_state, _| {
|
||||||
let button_style =
|
let button_style = theme.contact_button.style_for(mouse_state);
|
||||||
theme.contact_button.style_for(mouse_state, false);
|
|
||||||
render_icon_button(button_style, "icons/x_mark_8.svg")
|
render_icon_button(button_style, "icons/x_mark_8.svg")
|
||||||
.aligned()
|
.aligned()
|
||||||
.flex_float()
|
.flex_float()
|
||||||
@ -1146,7 +1153,8 @@ impl ContactList {
|
|||||||
.with_style(
|
.with_style(
|
||||||
*theme
|
*theme
|
||||||
.contact_row
|
.contact_row
|
||||||
.style_for(&mut Default::default(), is_selected),
|
.in_state(is_selected)
|
||||||
|
.style_for(&mut Default::default()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.on_click(MouseButton::Left, move |_, this, cx| {
|
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||||
@ -1204,7 +1212,7 @@ impl ContactList {
|
|||||||
let button_style = if is_contact_request_pending {
|
let button_style = if is_contact_request_pending {
|
||||||
&theme.disabled_button
|
&theme.disabled_button
|
||||||
} else {
|
} else {
|
||||||
theme.contact_button.style_for(mouse_state, false)
|
theme.contact_button.style_for(mouse_state)
|
||||||
};
|
};
|
||||||
render_icon_button(button_style, "icons/x_mark_8.svg").aligned()
|
render_icon_button(button_style, "icons/x_mark_8.svg").aligned()
|
||||||
})
|
})
|
||||||
@ -1227,7 +1235,7 @@ impl ContactList {
|
|||||||
let button_style = if is_contact_request_pending {
|
let button_style = if is_contact_request_pending {
|
||||||
&theme.disabled_button
|
&theme.disabled_button
|
||||||
} else {
|
} else {
|
||||||
theme.contact_button.style_for(mouse_state, false)
|
theme.contact_button.style_for(mouse_state)
|
||||||
};
|
};
|
||||||
render_icon_button(button_style, "icons/check_8.svg")
|
render_icon_button(button_style, "icons/check_8.svg")
|
||||||
.aligned()
|
.aligned()
|
||||||
@ -1250,7 +1258,7 @@ impl ContactList {
|
|||||||
let button_style = if is_contact_request_pending {
|
let button_style = if is_contact_request_pending {
|
||||||
&theme.disabled_button
|
&theme.disabled_button
|
||||||
} else {
|
} else {
|
||||||
theme.contact_button.style_for(mouse_state, false)
|
theme.contact_button.style_for(mouse_state)
|
||||||
};
|
};
|
||||||
render_icon_button(button_style, "icons/x_mark_8.svg")
|
render_icon_button(button_style, "icons/x_mark_8.svg")
|
||||||
.aligned()
|
.aligned()
|
||||||
@ -1277,7 +1285,8 @@ impl ContactList {
|
|||||||
.with_style(
|
.with_style(
|
||||||
*theme
|
*theme
|
||||||
.contact_row
|
.contact_row
|
||||||
.style_for(&mut Default::default(), is_selected),
|
.in_state(is_selected)
|
||||||
|
.style_for(&mut Default::default()),
|
||||||
)
|
)
|
||||||
.into_any()
|
.into_any()
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ where
|
|||||||
)
|
)
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<Dismiss, V>::new(user.id as usize, cx, |state, _| {
|
MouseEventHandler::<Dismiss, V>::new(user.id as usize, cx, |state, _| {
|
||||||
let style = theme.dismiss_button.style_for(state, false);
|
let style = theme.dismiss_button.style_for(state);
|
||||||
Svg::new("icons/x_mark_8.svg")
|
Svg::new("icons/x_mark_8.svg")
|
||||||
.with_color(style.color)
|
.with_color(style.color)
|
||||||
.constrained()
|
.constrained()
|
||||||
@ -93,7 +93,7 @@ where
|
|||||||
.with_children(buttons.into_iter().enumerate().map(
|
.with_children(buttons.into_iter().enumerate().map(
|
||||||
|(ix, (message, handler))| {
|
|(ix, (message, handler))| {
|
||||||
MouseEventHandler::<Button, V>::new(ix, cx, |state, _| {
|
MouseEventHandler::<Button, V>::new(ix, cx, |state, _| {
|
||||||
let button = theme.button.style_for(state, false);
|
let button = theme.button.style_for(state);
|
||||||
Label::new(message, button.text.clone())
|
Label::new(message, button.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(button.container)
|
.with_style(button.container)
|
||||||
|
@ -185,8 +185,8 @@ impl PickerDelegate for CommandPaletteDelegate {
|
|||||||
let mat = &self.matches[ix];
|
let mat = &self.matches[ix];
|
||||||
let command = &self.actions[mat.candidate_id];
|
let command = &self.actions[mat.candidate_id];
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.picker.item.style_for(mouse_state, selected);
|
let style = theme.picker.item.in_state(selected).style_for(mouse_state);
|
||||||
let key_style = &theme.command_palette.key.style_for(mouse_state, selected);
|
let key_style = &theme.command_palette.key.in_state(selected);
|
||||||
let keystroke_spacing = theme.command_palette.keystroke_spacing;
|
let keystroke_spacing = theme.command_palette.keystroke_spacing;
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
|
@ -328,10 +328,8 @@ impl ContextMenu {
|
|||||||
Flex::column().with_children(self.items.iter().enumerate().map(|(ix, item)| {
|
Flex::column().with_children(self.items.iter().enumerate().map(|(ix, item)| {
|
||||||
match item {
|
match item {
|
||||||
ContextMenuItem::Item { label, .. } => {
|
ContextMenuItem::Item { label, .. } => {
|
||||||
let style = style.item.style_for(
|
let style = style.item.in_state(self.selected_index == Some(ix));
|
||||||
&mut Default::default(),
|
let style = style.style_for(&mut Default::default());
|
||||||
Some(ix) == self.selected_index,
|
|
||||||
);
|
|
||||||
|
|
||||||
match label {
|
match label {
|
||||||
ContextMenuItemLabel::String(label) => {
|
ContextMenuItemLabel::String(label) => {
|
||||||
@ -363,10 +361,8 @@ impl ContextMenu {
|
|||||||
.with_children(self.items.iter().enumerate().map(|(ix, item)| {
|
.with_children(self.items.iter().enumerate().map(|(ix, item)| {
|
||||||
match item {
|
match item {
|
||||||
ContextMenuItem::Item { action, .. } => {
|
ContextMenuItem::Item { action, .. } => {
|
||||||
let style = style.item.style_for(
|
let style = style.item.in_state(self.selected_index == Some(ix));
|
||||||
&mut Default::default(),
|
let style = style.style_for(&mut Default::default());
|
||||||
Some(ix) == self.selected_index,
|
|
||||||
);
|
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
ContextMenuItemAction::Action(action) => KeystrokeLabel::new(
|
ContextMenuItemAction::Action(action) => KeystrokeLabel::new(
|
||||||
@ -412,8 +408,8 @@ impl ContextMenu {
|
|||||||
let action = action.clone();
|
let action = action.clone();
|
||||||
let view_id = self.parent_view_id;
|
let view_id = self.parent_view_id;
|
||||||
MouseEventHandler::<MenuItem, ContextMenu>::new(ix, cx, |state, _| {
|
MouseEventHandler::<MenuItem, ContextMenu>::new(ix, cx, |state, _| {
|
||||||
let style =
|
let style = style.item.in_state(self.selected_index == Some(ix));
|
||||||
style.item.style_for(state, Some(ix) == self.selected_index);
|
let style = style.style_for(state);
|
||||||
let keystroke = match &action {
|
let keystroke = match &action {
|
||||||
ContextMenuItemAction::Action(action) => Some(
|
ContextMenuItemAction::Action(action) => Some(
|
||||||
KeystrokeLabel::new(
|
KeystrokeLabel::new(
|
||||||
|
@ -127,16 +127,16 @@ impl CopilotCodeVerification {
|
|||||||
.with_child(
|
.with_child(
|
||||||
Label::new(
|
Label::new(
|
||||||
if copied { "Copied!" } else { "Copy" },
|
if copied { "Copied!" } else { "Copy" },
|
||||||
device_code_style.cta.style_for(state, false).text.clone(),
|
device_code_style.cta.style_for(state).text.clone(),
|
||||||
)
|
)
|
||||||
.aligned()
|
.aligned()
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(*device_code_style.right_container.style_for(state, false))
|
.with_style(*device_code_style.right_container.style_for(state))
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_width(device_code_style.right),
|
.with_width(device_code_style.right),
|
||||||
)
|
)
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(device_code_style.cta.style_for(state, false).container)
|
.with_style(device_code_style.cta.style_for(state).container)
|
||||||
})
|
})
|
||||||
.on_click(gpui::platform::MouseButton::Left, {
|
.on_click(gpui::platform::MouseButton::Left, {
|
||||||
let user_code = data.user_code.clone();
|
let user_code = data.user_code.clone();
|
||||||
|
@ -71,7 +71,8 @@ impl View for CopilotButton {
|
|||||||
.status_bar
|
.status_bar
|
||||||
.panel_buttons
|
.panel_buttons
|
||||||
.button
|
.button
|
||||||
.style_for(state, active);
|
.in_state(active)
|
||||||
|
.style_for(state);
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
@ -255,7 +256,7 @@ impl CopilotButton {
|
|||||||
move |state: &mut MouseState, style: &theme::ContextMenuItem| {
|
move |state: &mut MouseState, style: &theme::ContextMenuItem| {
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(Label::new("Copilot Settings", style.label.clone()))
|
.with_child(Label::new("Copilot Settings", style.label.clone()))
|
||||||
.with_child(theme::ui::icon(icon_style.style_for(state, false)))
|
.with_child(theme::ui::icon(icon_style.style_for(state)))
|
||||||
.align_children_center()
|
.align_children_center()
|
||||||
.into_any()
|
.into_any()
|
||||||
},
|
},
|
||||||
|
@ -430,7 +430,7 @@ impl ProjectDiagnosticsEditor {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.editor.update(cx, |editor, cx| {
|
self.editor.update(cx, |editor, cx| {
|
||||||
editor.remove_blocks(blocks_to_remove, cx);
|
editor.remove_blocks(blocks_to_remove, None, cx);
|
||||||
let block_ids = editor.insert_blocks(
|
let block_ids = editor.insert_blocks(
|
||||||
blocks_to_add.into_iter().map(|block| {
|
blocks_to_add.into_iter().map(|block| {
|
||||||
let (excerpt_id, text_anchor) = block.position;
|
let (excerpt_id, text_anchor) = block.position;
|
||||||
@ -442,6 +442,7 @@ impl ProjectDiagnosticsEditor {
|
|||||||
disposition: block.disposition,
|
disposition: block.disposition,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
Some(Autoscroll::fit()),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1508,7 +1509,8 @@ mod tests {
|
|||||||
let snapshot = editor.snapshot(cx);
|
let snapshot = editor.snapshot(cx);
|
||||||
snapshot
|
snapshot
|
||||||
.blocks_in_range(0..snapshot.max_point().row())
|
.blocks_in_range(0..snapshot.max_point().row())
|
||||||
.filter_map(|(row, block)| {
|
.enumerate()
|
||||||
|
.filter_map(|(ix, (row, block))| {
|
||||||
let name = match block {
|
let name = match block {
|
||||||
TransformBlock::Custom(block) => block
|
TransformBlock::Custom(block) => block
|
||||||
.render(&mut BlockContext {
|
.render(&mut BlockContext {
|
||||||
@ -1519,6 +1521,7 @@ mod tests {
|
|||||||
gutter_width: 0.,
|
gutter_width: 0.,
|
||||||
line_height: 0.,
|
line_height: 0.,
|
||||||
em_width: 0.,
|
em_width: 0.,
|
||||||
|
block_id: ix,
|
||||||
})
|
})
|
||||||
.name()?
|
.name()?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
|
@ -100,7 +100,7 @@ impl View for DiagnosticIndicator {
|
|||||||
.workspace
|
.workspace
|
||||||
.status_bar
|
.status_bar
|
||||||
.diagnostic_summary
|
.diagnostic_summary
|
||||||
.style_for(state, false);
|
.style_for(state);
|
||||||
|
|
||||||
let mut summary_row = Flex::row();
|
let mut summary_row = Flex::row();
|
||||||
if self.summary.error_count > 0 {
|
if self.summary.error_count > 0 {
|
||||||
@ -198,7 +198,7 @@ impl View for DiagnosticIndicator {
|
|||||||
MouseEventHandler::<Message, _>::new(1, cx, |state, _| {
|
MouseEventHandler::<Message, _>::new(1, cx, |state, _| {
|
||||||
Label::new(
|
Label::new(
|
||||||
diagnostic.message.split('\n').next().unwrap().to_string(),
|
diagnostic.message.split('\n').next().unwrap().to_string(),
|
||||||
message_style.style_for(state, false).text.clone(),
|
message_style.style_for(state).text.clone(),
|
||||||
)
|
)
|
||||||
.aligned()
|
.aligned()
|
||||||
.contained()
|
.contained()
|
||||||
|
@ -83,7 +83,7 @@ ctor.workspace = true
|
|||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
unindent.workspace = true
|
unindent.workspace = true
|
||||||
tree-sitter = "0.20"
|
tree-sitter.workspace = true
|
||||||
tree-sitter-rust = "0.20"
|
tree-sitter-rust = "0.20"
|
||||||
tree-sitter-html = "0.19"
|
tree-sitter-html = "0.19"
|
||||||
tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" }
|
tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" }
|
||||||
|
@ -88,6 +88,7 @@ pub struct BlockContext<'a, 'b, 'c> {
|
|||||||
pub gutter_padding: f32,
|
pub gutter_padding: f32,
|
||||||
pub em_width: f32,
|
pub em_width: f32,
|
||||||
pub line_height: f32,
|
pub line_height: f32,
|
||||||
|
pub block_id: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
@ -243,7 +244,7 @@ impl BlockMap {
|
|||||||
// Preserve any old transforms that precede this edit.
|
// Preserve any old transforms that precede this edit.
|
||||||
let old_start = WrapRow(edit.old.start);
|
let old_start = WrapRow(edit.old.start);
|
||||||
let new_start = WrapRow(edit.new.start);
|
let new_start = WrapRow(edit.new.start);
|
||||||
new_transforms.push_tree(cursor.slice(&old_start, Bias::Left, &()), &());
|
new_transforms.append(cursor.slice(&old_start, Bias::Left, &()), &());
|
||||||
if let Some(transform) = cursor.item() {
|
if let Some(transform) = cursor.item() {
|
||||||
if transform.is_isomorphic() && old_start == cursor.end(&()) {
|
if transform.is_isomorphic() && old_start == cursor.end(&()) {
|
||||||
new_transforms.push(transform.clone(), &());
|
new_transforms.push(transform.clone(), &());
|
||||||
@ -425,7 +426,7 @@ impl BlockMap {
|
|||||||
push_isomorphic(&mut new_transforms, extent_after_edit);
|
push_isomorphic(&mut new_transforms, extent_after_edit);
|
||||||
}
|
}
|
||||||
|
|
||||||
new_transforms.push_tree(cursor.suffix(&()), &());
|
new_transforms.append(cursor.suffix(&()), &());
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
new_transforms.summary().input_rows,
|
new_transforms.summary().input_rows,
|
||||||
wrap_snapshot.max_point().row() + 1
|
wrap_snapshot.max_point().row() + 1
|
||||||
|
@ -115,10 +115,10 @@ impl<'a> FoldMapWriter<'a> {
|
|||||||
let mut new_tree = SumTree::new();
|
let mut new_tree = SumTree::new();
|
||||||
let mut cursor = self.0.folds.cursor::<Fold>();
|
let mut cursor = self.0.folds.cursor::<Fold>();
|
||||||
for fold in folds {
|
for fold in folds {
|
||||||
new_tree.push_tree(cursor.slice(&fold, Bias::Right, &buffer), &buffer);
|
new_tree.append(cursor.slice(&fold, Bias::Right, &buffer), &buffer);
|
||||||
new_tree.push(fold, &buffer);
|
new_tree.push(fold, &buffer);
|
||||||
}
|
}
|
||||||
new_tree.push_tree(cursor.suffix(&buffer), &buffer);
|
new_tree.append(cursor.suffix(&buffer), &buffer);
|
||||||
new_tree
|
new_tree
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -165,10 +165,10 @@ impl<'a> FoldMapWriter<'a> {
|
|||||||
let mut cursor = self.0.folds.cursor::<usize>();
|
let mut cursor = self.0.folds.cursor::<usize>();
|
||||||
let mut folds = SumTree::new();
|
let mut folds = SumTree::new();
|
||||||
for fold_ix in fold_ixs_to_delete {
|
for fold_ix in fold_ixs_to_delete {
|
||||||
folds.push_tree(cursor.slice(&fold_ix, Bias::Right, &buffer), &buffer);
|
folds.append(cursor.slice(&fold_ix, Bias::Right, &buffer), &buffer);
|
||||||
cursor.next(&buffer);
|
cursor.next(&buffer);
|
||||||
}
|
}
|
||||||
folds.push_tree(cursor.suffix(&buffer), &buffer);
|
folds.append(cursor.suffix(&buffer), &buffer);
|
||||||
folds
|
folds
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ impl FoldMap {
|
|||||||
cursor.seek(&0, Bias::Right, &());
|
cursor.seek(&0, Bias::Right, &());
|
||||||
|
|
||||||
while let Some(mut edit) = buffer_edits_iter.next() {
|
while let Some(mut edit) = buffer_edits_iter.next() {
|
||||||
new_transforms.push_tree(cursor.slice(&edit.old.start, Bias::Left, &()), &());
|
new_transforms.append(cursor.slice(&edit.old.start, Bias::Left, &()), &());
|
||||||
edit.new.start -= edit.old.start - cursor.start();
|
edit.new.start -= edit.old.start - cursor.start();
|
||||||
edit.old.start = *cursor.start();
|
edit.old.start = *cursor.start();
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ impl FoldMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_transforms.push_tree(cursor.suffix(&()), &());
|
new_transforms.append(cursor.suffix(&()), &());
|
||||||
if new_transforms.is_empty() {
|
if new_transforms.is_empty() {
|
||||||
let text_summary = new_buffer.text_summary();
|
let text_summary = new_buffer.text_summary();
|
||||||
new_transforms.push(
|
new_transforms.push(
|
||||||
|
@ -353,7 +353,7 @@ impl WrapSnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
old_cursor.next(&());
|
old_cursor.next(&());
|
||||||
new_transforms.push_tree(
|
new_transforms.append(
|
||||||
old_cursor.slice(&next_edit.old.start, Bias::Right, &()),
|
old_cursor.slice(&next_edit.old.start, Bias::Right, &()),
|
||||||
&(),
|
&(),
|
||||||
);
|
);
|
||||||
@ -366,7 +366,7 @@ impl WrapSnapshot {
|
|||||||
new_transforms.push_or_extend(Transform::isomorphic(summary));
|
new_transforms.push_or_extend(Transform::isomorphic(summary));
|
||||||
}
|
}
|
||||||
old_cursor.next(&());
|
old_cursor.next(&());
|
||||||
new_transforms.push_tree(old_cursor.suffix(&()), &());
|
new_transforms.append(old_cursor.suffix(&()), &());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,7 +500,7 @@ impl WrapSnapshot {
|
|||||||
new_transforms.push_or_extend(Transform::isomorphic(summary));
|
new_transforms.push_or_extend(Transform::isomorphic(summary));
|
||||||
}
|
}
|
||||||
old_cursor.next(&());
|
old_cursor.next(&());
|
||||||
new_transforms.push_tree(
|
new_transforms.append(
|
||||||
old_cursor.slice(
|
old_cursor.slice(
|
||||||
&TabPoint::new(next_edit.old_rows.start, 0),
|
&TabPoint::new(next_edit.old_rows.start, 0),
|
||||||
Bias::Right,
|
Bias::Right,
|
||||||
@ -517,7 +517,7 @@ impl WrapSnapshot {
|
|||||||
new_transforms.push_or_extend(Transform::isomorphic(summary));
|
new_transforms.push_or_extend(Transform::isomorphic(summary));
|
||||||
}
|
}
|
||||||
old_cursor.next(&());
|
old_cursor.next(&());
|
||||||
new_transforms.push_tree(old_cursor.suffix(&()), &());
|
new_transforms.append(old_cursor.suffix(&()), &());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,11 @@ use copilot::Copilot;
|
|||||||
pub use display_map::DisplayPoint;
|
pub use display_map::DisplayPoint;
|
||||||
use display_map::*;
|
use display_map::*;
|
||||||
pub use editor_settings::EditorSettings;
|
pub use editor_settings::EditorSettings;
|
||||||
pub use element::RenderExcerptHeaderParams;
|
|
||||||
pub use element::{
|
pub use element::{
|
||||||
Cursor, EditorElement, HighlightedRange, HighlightedRangeLine, LineWithInvisibles,
|
Cursor, EditorElement, HighlightedRange, HighlightedRangeLine, LineWithInvisibles,
|
||||||
};
|
};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||||
use gpui::LayoutContext;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
color::Color,
|
color::Color,
|
||||||
@ -208,6 +206,7 @@ actions!(
|
|||||||
DuplicateLine,
|
DuplicateLine,
|
||||||
MoveLineUp,
|
MoveLineUp,
|
||||||
MoveLineDown,
|
MoveLineDown,
|
||||||
|
JoinLines,
|
||||||
Transpose,
|
Transpose,
|
||||||
Cut,
|
Cut,
|
||||||
Copy,
|
Copy,
|
||||||
@ -323,6 +322,7 @@ pub fn init(cx: &mut AppContext) {
|
|||||||
cx.add_action(Editor::indent);
|
cx.add_action(Editor::indent);
|
||||||
cx.add_action(Editor::outdent);
|
cx.add_action(Editor::outdent);
|
||||||
cx.add_action(Editor::delete_line);
|
cx.add_action(Editor::delete_line);
|
||||||
|
cx.add_action(Editor::join_lines);
|
||||||
cx.add_action(Editor::delete_to_previous_word_start);
|
cx.add_action(Editor::delete_to_previous_word_start);
|
||||||
cx.add_action(Editor::delete_to_previous_subword_start);
|
cx.add_action(Editor::delete_to_previous_subword_start);
|
||||||
cx.add_action(Editor::delete_to_next_word_end);
|
cx.add_action(Editor::delete_to_next_word_end);
|
||||||
@ -511,7 +511,6 @@ pub struct Editor {
|
|||||||
mode: EditorMode,
|
mode: EditorMode,
|
||||||
show_gutter: bool,
|
show_gutter: bool,
|
||||||
placeholder_text: Option<Arc<str>>,
|
placeholder_text: Option<Arc<str>>,
|
||||||
render_excerpt_header: Option<element::RenderExcerptHeader>,
|
|
||||||
highlighted_rows: Option<Range<u32>>,
|
highlighted_rows: Option<Range<u32>>,
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
background_highlights: BTreeMap<TypeId, (fn(&Theme) -> Color, Vec<Range<Anchor>>)>,
|
background_highlights: BTreeMap<TypeId, (fn(&Theme) -> Color, Vec<Range<Anchor>>)>,
|
||||||
@ -1317,7 +1316,6 @@ impl Editor {
|
|||||||
mode,
|
mode,
|
||||||
show_gutter: mode == EditorMode::Full,
|
show_gutter: mode == EditorMode::Full,
|
||||||
placeholder_text: None,
|
placeholder_text: None,
|
||||||
render_excerpt_header: None,
|
|
||||||
highlighted_rows: None,
|
highlighted_rows: None,
|
||||||
background_highlights: Default::default(),
|
background_highlights: Default::default(),
|
||||||
nav_history: None,
|
nav_history: None,
|
||||||
@ -2169,8 +2167,8 @@ impl Editor {
|
|||||||
self.transact(cx, |this, cx| {
|
self.transact(cx, |this, cx| {
|
||||||
let (edits, selection_fixup_info): (Vec<_>, Vec<_>) = {
|
let (edits, selection_fixup_info): (Vec<_>, Vec<_>) = {
|
||||||
let selections = this.selections.all::<usize>(cx);
|
let selections = this.selections.all::<usize>(cx);
|
||||||
|
let multi_buffer = this.buffer.read(cx);
|
||||||
let buffer = this.buffer.read(cx).snapshot(cx);
|
let buffer = multi_buffer.snapshot(cx);
|
||||||
selections
|
selections
|
||||||
.iter()
|
.iter()
|
||||||
.map(|selection| {
|
.map(|selection| {
|
||||||
@ -2181,70 +2179,74 @@ impl Editor {
|
|||||||
let end = selection.end;
|
let end = selection.end;
|
||||||
let is_cursor = start == end;
|
let is_cursor = start == end;
|
||||||
let language_scope = buffer.language_scope_at(start);
|
let language_scope = buffer.language_scope_at(start);
|
||||||
let (comment_delimiter, insert_extra_newline) =
|
let (comment_delimiter, insert_extra_newline) = if let Some(language) =
|
||||||
if let Some(language) = &language_scope {
|
&language_scope
|
||||||
let leading_whitespace_len = buffer
|
{
|
||||||
.reversed_chars_at(start)
|
let leading_whitespace_len = buffer
|
||||||
.take_while(|c| c.is_whitespace() && *c != '\n')
|
.reversed_chars_at(start)
|
||||||
.map(|c| c.len_utf8())
|
.take_while(|c| c.is_whitespace() && *c != '\n')
|
||||||
.sum::<usize>();
|
.map(|c| c.len_utf8())
|
||||||
|
.sum::<usize>();
|
||||||
|
|
||||||
let trailing_whitespace_len = buffer
|
let trailing_whitespace_len = buffer
|
||||||
.chars_at(end)
|
.chars_at(end)
|
||||||
.take_while(|c| c.is_whitespace() && *c != '\n')
|
.take_while(|c| c.is_whitespace() && *c != '\n')
|
||||||
.map(|c| c.len_utf8())
|
.map(|c| c.len_utf8())
|
||||||
.sum::<usize>();
|
.sum::<usize>();
|
||||||
|
|
||||||
let insert_extra_newline =
|
let insert_extra_newline =
|
||||||
language.brackets().any(|(pair, enabled)| {
|
language.brackets().any(|(pair, enabled)| {
|
||||||
let pair_start = pair.start.trim_end();
|
let pair_start = pair.start.trim_end();
|
||||||
let pair_end = pair.end.trim_start();
|
let pair_end = pair.end.trim_start();
|
||||||
|
|
||||||
enabled
|
enabled
|
||||||
&& pair.newline
|
&& pair.newline
|
||||||
&& buffer.contains_str_at(
|
&& buffer.contains_str_at(
|
||||||
end + trailing_whitespace_len,
|
end + trailing_whitespace_len,
|
||||||
pair_end,
|
pair_end,
|
||||||
)
|
)
|
||||||
&& buffer.contains_str_at(
|
&& buffer.contains_str_at(
|
||||||
(start - leading_whitespace_len)
|
(start - leading_whitespace_len)
|
||||||
.saturating_sub(pair_start.len()),
|
.saturating_sub(pair_start.len()),
|
||||||
pair_start,
|
pair_start,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
// Comment extension on newline is allowed only for cursor selections
|
// Comment extension on newline is allowed only for cursor selections
|
||||||
let comment_delimiter =
|
let comment_delimiter = language.line_comment_prefix().filter(|_| {
|
||||||
language.line_comment_prefix().filter(|_| is_cursor);
|
let is_comment_extension_enabled =
|
||||||
let comment_delimiter = if let Some(delimiter) = comment_delimiter {
|
multi_buffer.settings_at(0, cx).extend_comment_on_newline;
|
||||||
buffer
|
is_cursor && is_comment_extension_enabled
|
||||||
.buffer_line_for_row(start_point.row)
|
});
|
||||||
.is_some_and(|(snapshot, range)| {
|
let comment_delimiter = if let Some(delimiter) = comment_delimiter {
|
||||||
let mut index_of_first_non_whitespace = 0;
|
buffer
|
||||||
let line_starts_with_comment = snapshot
|
.buffer_line_for_row(start_point.row)
|
||||||
.chars_for_range(range)
|
.is_some_and(|(snapshot, range)| {
|
||||||
.skip_while(|c| {
|
let mut index_of_first_non_whitespace = 0;
|
||||||
let should_skip = c.is_whitespace();
|
let line_starts_with_comment = snapshot
|
||||||
if should_skip {
|
.chars_for_range(range)
|
||||||
index_of_first_non_whitespace += 1;
|
.skip_while(|c| {
|
||||||
}
|
let should_skip = c.is_whitespace();
|
||||||
should_skip
|
if should_skip {
|
||||||
})
|
index_of_first_non_whitespace += 1;
|
||||||
.take(delimiter.len())
|
}
|
||||||
.eq(delimiter.chars());
|
should_skip
|
||||||
let cursor_is_placed_after_comment_marker =
|
})
|
||||||
index_of_first_non_whitespace + delimiter.len()
|
.take(delimiter.len())
|
||||||
<= start_point.column as usize;
|
.eq(delimiter.chars());
|
||||||
line_starts_with_comment
|
let cursor_is_placed_after_comment_marker =
|
||||||
&& cursor_is_placed_after_comment_marker
|
index_of_first_non_whitespace + delimiter.len()
|
||||||
})
|
<= start_point.column as usize;
|
||||||
.then(|| delimiter.clone())
|
line_starts_with_comment
|
||||||
} else {
|
&& cursor_is_placed_after_comment_marker
|
||||||
None
|
})
|
||||||
};
|
.then(|| delimiter.clone())
|
||||||
(comment_delimiter, insert_extra_newline)
|
|
||||||
} else {
|
} else {
|
||||||
(None, false)
|
None
|
||||||
};
|
};
|
||||||
|
(comment_delimiter, insert_extra_newline)
|
||||||
|
} else {
|
||||||
|
(None, false)
|
||||||
|
};
|
||||||
|
|
||||||
let capacity_for_delimiter = comment_delimiter
|
let capacity_for_delimiter = comment_delimiter
|
||||||
.as_deref()
|
.as_deref()
|
||||||
@ -3320,15 +3322,21 @@ impl Editor {
|
|||||||
pub fn render_code_actions_indicator(
|
pub fn render_code_actions_indicator(
|
||||||
&self,
|
&self,
|
||||||
style: &EditorStyle,
|
style: &EditorStyle,
|
||||||
active: bool,
|
is_active: bool,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<AnyElement<Self>> {
|
) -> Option<AnyElement<Self>> {
|
||||||
if self.available_code_actions.is_some() {
|
if self.available_code_actions.is_some() {
|
||||||
enum CodeActions {}
|
enum CodeActions {}
|
||||||
Some(
|
Some(
|
||||||
MouseEventHandler::<CodeActions, _>::new(0, cx, |state, _| {
|
MouseEventHandler::<CodeActions, _>::new(0, cx, |state, _| {
|
||||||
Svg::new("icons/bolt_8.svg")
|
Svg::new("icons/bolt_8.svg").with_color(
|
||||||
.with_color(style.code_actions.indicator.style_for(state, active).color)
|
style
|
||||||
|
.code_actions
|
||||||
|
.indicator
|
||||||
|
.in_state(is_active)
|
||||||
|
.style_for(state)
|
||||||
|
.color,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.with_padding(Padding::uniform(3.))
|
.with_padding(Padding::uniform(3.))
|
||||||
@ -3378,10 +3386,8 @@ impl Editor {
|
|||||||
.with_color(
|
.with_color(
|
||||||
style
|
style
|
||||||
.indicator
|
.indicator
|
||||||
.style_for(
|
.in_state(fold_status == FoldStatus::Folded)
|
||||||
mouse_state,
|
.style_for(mouse_state)
|
||||||
fold_status == FoldStatus::Folded,
|
|
||||||
)
|
|
||||||
.color,
|
.color,
|
||||||
)
|
)
|
||||||
.constrained()
|
.constrained()
|
||||||
@ -3952,6 +3958,60 @@ impl Editor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn join_lines(&mut self, _: &JoinLines, cx: &mut ViewContext<Self>) {
|
||||||
|
let mut row_ranges = Vec::<Range<u32>>::new();
|
||||||
|
for selection in self.selections.all::<Point>(cx) {
|
||||||
|
let start = selection.start.row;
|
||||||
|
let end = if selection.start.row == selection.end.row {
|
||||||
|
selection.start.row + 1
|
||||||
|
} else {
|
||||||
|
selection.end.row
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(last_row_range) = row_ranges.last_mut() {
|
||||||
|
if start <= last_row_range.end {
|
||||||
|
last_row_range.end = end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
row_ranges.push(start..end);
|
||||||
|
}
|
||||||
|
|
||||||
|
let snapshot = self.buffer.read(cx).snapshot(cx);
|
||||||
|
let mut cursor_positions = Vec::new();
|
||||||
|
for row_range in &row_ranges {
|
||||||
|
let anchor = snapshot.anchor_before(Point::new(
|
||||||
|
row_range.end - 1,
|
||||||
|
snapshot.line_len(row_range.end - 1),
|
||||||
|
));
|
||||||
|
cursor_positions.push(anchor.clone()..anchor);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.transact(cx, |this, cx| {
|
||||||
|
for row_range in row_ranges.into_iter().rev() {
|
||||||
|
for row in row_range.rev() {
|
||||||
|
let end_of_line = Point::new(row, snapshot.line_len(row));
|
||||||
|
let indent = snapshot.indent_size_for_line(row + 1);
|
||||||
|
let start_of_next_line = Point::new(row + 1, indent.len);
|
||||||
|
|
||||||
|
let replace = if snapshot.line_len(row + 1) > indent.len {
|
||||||
|
" "
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
|
||||||
|
this.buffer.update(cx, |buffer, cx| {
|
||||||
|
buffer.edit([(end_of_line..start_of_next_line, replace)], None, cx)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
|
s.select_anchor_ranges(cursor_positions)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn duplicate_line(&mut self, _: &DuplicateLine, cx: &mut ViewContext<Self>) {
|
pub fn duplicate_line(&mut self, _: &DuplicateLine, cx: &mut ViewContext<Self>) {
|
||||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||||
let buffer = &display_map.buffer_snapshot;
|
let buffer = &display_map.buffer_snapshot;
|
||||||
@ -5492,7 +5552,7 @@ impl Editor {
|
|||||||
let mut all_selection_lines_are_comments = true;
|
let mut all_selection_lines_are_comments = true;
|
||||||
|
|
||||||
for row in start_row..=end_row {
|
for row in start_row..=end_row {
|
||||||
if snapshot.is_line_blank(row) {
|
if snapshot.is_line_blank(row) && start_row < end_row {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6268,6 +6328,7 @@ impl Editor {
|
|||||||
}),
|
}),
|
||||||
disposition: BlockDisposition::Below,
|
disposition: BlockDisposition::Below,
|
||||||
}],
|
}],
|
||||||
|
Some(Autoscroll::fit()),
|
||||||
cx,
|
cx,
|
||||||
)[0];
|
)[0];
|
||||||
this.pending_rename = Some(RenameState {
|
this.pending_rename = Some(RenameState {
|
||||||
@ -6334,7 +6395,11 @@ impl Editor {
|
|||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<RenameState> {
|
) -> Option<RenameState> {
|
||||||
let rename = self.pending_rename.take()?;
|
let rename = self.pending_rename.take()?;
|
||||||
self.remove_blocks([rename.block_id].into_iter().collect(), cx);
|
self.remove_blocks(
|
||||||
|
[rename.block_id].into_iter().collect(),
|
||||||
|
Some(Autoscroll::fit()),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
self.clear_text_highlights::<Rename>(cx);
|
self.clear_text_highlights::<Rename>(cx);
|
||||||
self.show_local_selections = true;
|
self.show_local_selections = true;
|
||||||
|
|
||||||
@ -6720,29 +6785,43 @@ impl Editor {
|
|||||||
pub fn insert_blocks(
|
pub fn insert_blocks(
|
||||||
&mut self,
|
&mut self,
|
||||||
blocks: impl IntoIterator<Item = BlockProperties<Anchor>>,
|
blocks: impl IntoIterator<Item = BlockProperties<Anchor>>,
|
||||||
|
autoscroll: Option<Autoscroll>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Vec<BlockId> {
|
) -> Vec<BlockId> {
|
||||||
let blocks = self
|
let blocks = self
|
||||||
.display_map
|
.display_map
|
||||||
.update(cx, |display_map, cx| display_map.insert_blocks(blocks, cx));
|
.update(cx, |display_map, cx| display_map.insert_blocks(blocks, cx));
|
||||||
self.request_autoscroll(Autoscroll::fit(), cx);
|
if let Some(autoscroll) = autoscroll {
|
||||||
|
self.request_autoscroll(autoscroll, cx);
|
||||||
|
}
|
||||||
blocks
|
blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace_blocks(
|
pub fn replace_blocks(
|
||||||
&mut self,
|
&mut self,
|
||||||
blocks: HashMap<BlockId, RenderBlock>,
|
blocks: HashMap<BlockId, RenderBlock>,
|
||||||
|
autoscroll: Option<Autoscroll>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
self.display_map
|
self.display_map
|
||||||
.update(cx, |display_map, _| display_map.replace_blocks(blocks));
|
.update(cx, |display_map, _| display_map.replace_blocks(blocks));
|
||||||
self.request_autoscroll(Autoscroll::fit(), cx);
|
if let Some(autoscroll) = autoscroll {
|
||||||
|
self.request_autoscroll(autoscroll, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_blocks(&mut self, block_ids: HashSet<BlockId>, cx: &mut ViewContext<Self>) {
|
pub fn remove_blocks(
|
||||||
|
&mut self,
|
||||||
|
block_ids: HashSet<BlockId>,
|
||||||
|
autoscroll: Option<Autoscroll>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
self.display_map.update(cx, |display_map, cx| {
|
self.display_map.update(cx, |display_map, cx| {
|
||||||
display_map.remove_blocks(block_ids, cx)
|
display_map.remove_blocks(block_ids, cx)
|
||||||
});
|
});
|
||||||
|
if let Some(autoscroll) = autoscroll {
|
||||||
|
self.request_autoscroll(autoscroll, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn longest_row(&self, cx: &mut AppContext) -> u32 {
|
pub fn longest_row(&self, cx: &mut AppContext) -> u32 {
|
||||||
@ -6823,20 +6902,6 @@ impl Editor {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_render_excerpt_header(
|
|
||||||
&mut self,
|
|
||||||
render_excerpt_header: impl 'static
|
|
||||||
+ Fn(
|
|
||||||
&mut Editor,
|
|
||||||
RenderExcerptHeaderParams,
|
|
||||||
&mut LayoutContext<Editor>,
|
|
||||||
) -> AnyElement<Editor>,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) {
|
|
||||||
self.render_excerpt_header = Some(Arc::new(render_excerpt_header));
|
|
||||||
cx.notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reveal_in_finder(&mut self, _: &RevealInFinder, cx: &mut ViewContext<Self>) {
|
pub fn reveal_in_finder(&mut self, _: &RevealInFinder, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
|
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
|
||||||
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {
|
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {
|
||||||
@ -7102,7 +7167,7 @@ impl Editor {
|
|||||||
|
|
||||||
let mut new_selections_by_buffer = HashMap::default();
|
let mut new_selections_by_buffer = HashMap::default();
|
||||||
for selection in editor.selections.all::<usize>(cx) {
|
for selection in editor.selections.all::<usize>(cx) {
|
||||||
for (buffer, mut range) in
|
for (buffer, mut range, _) in
|
||||||
buffer.range_to_buffer_ranges(selection.start..selection.end, cx)
|
buffer.range_to_buffer_ranges(selection.start..selection.end, cx)
|
||||||
{
|
{
|
||||||
if selection.reversed {
|
if selection.reversed {
|
||||||
@ -7272,7 +7337,7 @@ impl Editor {
|
|||||||
|
|
||||||
let vim_mode = cx
|
let vim_mode = cx
|
||||||
.global::<SettingsStore>()
|
.global::<SettingsStore>()
|
||||||
.untyped_user_settings()
|
.raw_user_settings()
|
||||||
.get("vim_mode")
|
.get("vim_mode")
|
||||||
== Some(&serde_json::Value::Bool(true));
|
== Some(&serde_json::Value::Bool(true));
|
||||||
let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
|
let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
|
||||||
@ -7444,6 +7509,7 @@ pub enum Event {
|
|||||||
},
|
},
|
||||||
ScrollPositionChanged {
|
ScrollPositionChanged {
|
||||||
local: bool,
|
local: bool,
|
||||||
|
autoscroll: bool,
|
||||||
},
|
},
|
||||||
Closed,
|
Closed,
|
||||||
}
|
}
|
||||||
@ -7475,12 +7541,8 @@ impl View for Editor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut editor = EditorElement::new(style.clone());
|
|
||||||
if let Some(render_excerpt_header) = self.render_excerpt_header.clone() {
|
|
||||||
editor = editor.with_render_excerpt_header(render_excerpt_header);
|
|
||||||
}
|
|
||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(editor)
|
.with_child(EditorElement::new(style.clone()))
|
||||||
.with_child(ChildView::new(&self.mouse_context_menu, cx))
|
.with_child(ChildView::new(&self.mouse_context_menu, cx))
|
||||||
.into_any()
|
.into_any()
|
||||||
}
|
}
|
||||||
@ -7947,6 +8009,7 @@ impl Deref for EditorStyle {
|
|||||||
|
|
||||||
pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> RenderBlock {
|
pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> RenderBlock {
|
||||||
let mut highlighted_lines = Vec::new();
|
let mut highlighted_lines = Vec::new();
|
||||||
|
|
||||||
for (index, line) in diagnostic.message.lines().enumerate() {
|
for (index, line) in diagnostic.message.lines().enumerate() {
|
||||||
let line = match &diagnostic.source {
|
let line = match &diagnostic.source {
|
||||||
Some(source) if index == 0 => {
|
Some(source) if index == 0 => {
|
||||||
@ -7958,25 +8021,44 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
|
|||||||
};
|
};
|
||||||
highlighted_lines.push(line);
|
highlighted_lines.push(line);
|
||||||
}
|
}
|
||||||
|
let message = diagnostic.message;
|
||||||
Arc::new(move |cx: &mut BlockContext| {
|
Arc::new(move |cx: &mut BlockContext| {
|
||||||
|
let message = message.clone();
|
||||||
let settings = settings::get::<ThemeSettings>(cx);
|
let settings = settings::get::<ThemeSettings>(cx);
|
||||||
|
let tooltip_style = settings.theme.tooltip.clone();
|
||||||
let theme = &settings.theme.editor;
|
let theme = &settings.theme.editor;
|
||||||
let style = diagnostic_style(diagnostic.severity, is_valid, theme);
|
let style = diagnostic_style(diagnostic.severity, is_valid, theme);
|
||||||
let font_size = (style.text_scale_factor * settings.buffer_font_size(cx)).round();
|
let font_size = (style.text_scale_factor * settings.buffer_font_size(cx)).round();
|
||||||
Flex::column()
|
let anchor_x = cx.anchor_x;
|
||||||
.with_children(highlighted_lines.iter().map(|(line, highlights)| {
|
enum BlockContextToolip {}
|
||||||
Label::new(
|
MouseEventHandler::<BlockContext, _>::new(cx.block_id, cx, |_, _| {
|
||||||
line.clone(),
|
Flex::column()
|
||||||
style.message.clone().with_font_size(font_size),
|
.with_children(highlighted_lines.iter().map(|(line, highlights)| {
|
||||||
)
|
Label::new(
|
||||||
.with_highlights(highlights.clone())
|
line.clone(),
|
||||||
.contained()
|
style.message.clone().with_font_size(font_size),
|
||||||
.with_margin_left(cx.anchor_x)
|
)
|
||||||
}))
|
.with_highlights(highlights.clone())
|
||||||
.aligned()
|
.contained()
|
||||||
.left()
|
.with_margin_left(anchor_x)
|
||||||
.into_any()
|
}))
|
||||||
|
.aligned()
|
||||||
|
.left()
|
||||||
|
.into_any()
|
||||||
|
})
|
||||||
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
.on_click(MouseButton::Left, move |_, _, cx| {
|
||||||
|
cx.write_to_clipboard(ClipboardItem::new(message.clone()));
|
||||||
|
})
|
||||||
|
// We really need to rethink this ID system...
|
||||||
|
.with_tooltip::<BlockContextToolip>(
|
||||||
|
cx.block_id,
|
||||||
|
"Copy diagnostic message".to_string(),
|
||||||
|
None,
|
||||||
|
tooltip_style,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.into_any()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::test::{
|
use crate::{
|
||||||
assert_text_with_selections, build_editor, editor_lsp_test_context::EditorLspTestContext,
|
test::{
|
||||||
editor_test_context::EditorTestContext, select_ranges,
|
assert_text_with_selections, build_editor, editor_lsp_test_context::EditorLspTestContext,
|
||||||
|
editor_test_context::EditorTestContext, select_ranges,
|
||||||
|
},
|
||||||
|
JoinLines,
|
||||||
};
|
};
|
||||||
use drag_and_drop::DragAndDrop;
|
use drag_and_drop::DragAndDrop;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
@ -1732,26 +1735,40 @@ async fn test_newline_comments(cx: &mut gpui::TestAppContext) {
|
|||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
));
|
));
|
||||||
|
{
|
||||||
let mut cx = EditorTestContext::new(cx).await;
|
let mut cx = EditorTestContext::new(cx).await;
|
||||||
cx.update_buffer(|buffer, cx| buffer.set_language(Some(language), cx));
|
cx.update_buffer(|buffer, cx| buffer.set_language(Some(language), cx));
|
||||||
cx.set_state(indoc! {"
|
cx.set_state(indoc! {"
|
||||||
// Fooˇ
|
// Fooˇ
|
||||||
"});
|
"});
|
||||||
|
|
||||||
cx.update_editor(|e, cx| e.newline(&Newline, cx));
|
cx.update_editor(|e, cx| e.newline(&Newline, cx));
|
||||||
cx.assert_editor_state(indoc! {"
|
cx.assert_editor_state(indoc! {"
|
||||||
// Foo
|
// Foo
|
||||||
//ˇ
|
//ˇ
|
||||||
"});
|
"});
|
||||||
// Ensure that if cursor is before the comment start, we do not actually insert a comment prefix.
|
// Ensure that if cursor is before the comment start, we do not actually insert a comment prefix.
|
||||||
cx.set_state(indoc! {"
|
cx.set_state(indoc! {"
|
||||||
ˇ// Foo
|
ˇ// Foo
|
||||||
|
"});
|
||||||
|
cx.update_editor(|e, cx| e.newline(&Newline, cx));
|
||||||
|
cx.assert_editor_state(indoc! {"
|
||||||
|
|
||||||
|
ˇ// Foo
|
||||||
|
"});
|
||||||
|
}
|
||||||
|
// Ensure that comment continuations can be disabled.
|
||||||
|
update_test_settings(cx, |settings| {
|
||||||
|
settings.defaults.extend_comment_on_newline = Some(false);
|
||||||
|
});
|
||||||
|
let mut cx = EditorTestContext::new(cx).await;
|
||||||
|
cx.set_state(indoc! {"
|
||||||
|
// Fooˇ
|
||||||
"});
|
"});
|
||||||
cx.update_editor(|e, cx| e.newline(&Newline, cx));
|
cx.update_editor(|e, cx| e.newline(&Newline, cx));
|
||||||
cx.assert_editor_state(indoc! {"
|
cx.assert_editor_state(indoc! {"
|
||||||
|
// Foo
|
||||||
ˇ// Foo
|
ˇ
|
||||||
"});
|
"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2311,6 +2328,137 @@ fn test_delete_line(cx: &mut TestAppContext) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_join_lines_with_single_selection(cx: &mut TestAppContext) {
|
||||||
|
init_test(cx, |_| {});
|
||||||
|
|
||||||
|
cx.add_window(|cx| {
|
||||||
|
let buffer = MultiBuffer::build_simple("aaa\nbbb\nccc\nddd\n\n", cx);
|
||||||
|
let mut editor = build_editor(buffer.clone(), cx);
|
||||||
|
let buffer = buffer.read(cx).as_singleton().unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.ranges::<Point>(cx),
|
||||||
|
&[Point::new(0, 0)..Point::new(0, 0)]
|
||||||
|
);
|
||||||
|
|
||||||
|
// When on single line, replace newline at end by space
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb\nccc\nddd\n\n");
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.ranges::<Point>(cx),
|
||||||
|
&[Point::new(0, 3)..Point::new(0, 3)]
|
||||||
|
);
|
||||||
|
|
||||||
|
// When multiple lines are selected, remove newlines that are spanned by the selection
|
||||||
|
editor.change_selections(None, cx, |s| {
|
||||||
|
s.select_ranges([Point::new(0, 5)..Point::new(2, 2)])
|
||||||
|
});
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb ccc ddd\n\n");
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.ranges::<Point>(cx),
|
||||||
|
&[Point::new(0, 11)..Point::new(0, 11)]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Undo should be transactional
|
||||||
|
editor.undo(&Undo, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb\nccc\nddd\n\n");
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.ranges::<Point>(cx),
|
||||||
|
&[Point::new(0, 5)..Point::new(2, 2)]
|
||||||
|
);
|
||||||
|
|
||||||
|
// When joining an empty line don't insert a space
|
||||||
|
editor.change_selections(None, cx, |s| {
|
||||||
|
s.select_ranges([Point::new(2, 1)..Point::new(2, 2)])
|
||||||
|
});
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb\nccc\nddd\n");
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.ranges::<Point>(cx),
|
||||||
|
[Point::new(2, 3)..Point::new(2, 3)]
|
||||||
|
);
|
||||||
|
|
||||||
|
// We can remove trailing newlines
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb\nccc\nddd");
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.ranges::<Point>(cx),
|
||||||
|
[Point::new(2, 3)..Point::new(2, 3)]
|
||||||
|
);
|
||||||
|
|
||||||
|
// We don't blow up on the last line
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb\nccc\nddd");
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.ranges::<Point>(cx),
|
||||||
|
[Point::new(2, 3)..Point::new(2, 3)]
|
||||||
|
);
|
||||||
|
|
||||||
|
// reset to test indentation
|
||||||
|
editor.buffer.update(cx, |buffer, cx| {
|
||||||
|
buffer.edit(
|
||||||
|
[
|
||||||
|
(Point::new(1, 0)..Point::new(1, 2), " "),
|
||||||
|
(Point::new(2, 0)..Point::new(2, 3), " \n\td"),
|
||||||
|
],
|
||||||
|
None,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
// We remove any leading spaces
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb\n c\n \n\td");
|
||||||
|
editor.change_selections(None, cx, |s| {
|
||||||
|
s.select_ranges([Point::new(0, 1)..Point::new(0, 1)])
|
||||||
|
});
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb c\n \n\td");
|
||||||
|
|
||||||
|
// We don't insert a space for a line containing only spaces
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb c\n\td");
|
||||||
|
|
||||||
|
// We ignore any leading tabs
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb c d");
|
||||||
|
|
||||||
|
editor
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_join_lines_with_multi_selection(cx: &mut TestAppContext) {
|
||||||
|
init_test(cx, |_| {});
|
||||||
|
|
||||||
|
cx.add_window(|cx| {
|
||||||
|
let buffer = MultiBuffer::build_simple("aaa\nbbb\nccc\nddd\n\n", cx);
|
||||||
|
let mut editor = build_editor(buffer.clone(), cx);
|
||||||
|
let buffer = buffer.read(cx).as_singleton().unwrap();
|
||||||
|
|
||||||
|
editor.change_selections(None, cx, |s| {
|
||||||
|
s.select_ranges([
|
||||||
|
Point::new(0, 2)..Point::new(1, 1),
|
||||||
|
Point::new(1, 2)..Point::new(1, 2),
|
||||||
|
Point::new(3, 1)..Point::new(3, 2),
|
||||||
|
])
|
||||||
|
});
|
||||||
|
|
||||||
|
editor.join_lines(&JoinLines, cx);
|
||||||
|
assert_eq!(buffer.read(cx).text(), "aaa bbb ccc\nddd\n");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.ranges::<Point>(cx),
|
||||||
|
[
|
||||||
|
Point::new(0, 7)..Point::new(0, 7),
|
||||||
|
Point::new(1, 3)..Point::new(1, 3)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
editor
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
fn test_duplicate_line(cx: &mut TestAppContext) {
|
fn test_duplicate_line(cx: &mut TestAppContext) {
|
||||||
init_test(cx, |_| {});
|
init_test(cx, |_| {});
|
||||||
@ -2481,6 +2629,7 @@ fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) {
|
|||||||
height: 1,
|
height: 1,
|
||||||
render: Arc::new(|_| Empty::new().into_any()),
|
render: Arc::new(|_| Empty::new().into_any()),
|
||||||
}],
|
}],
|
||||||
|
Some(Autoscroll::fit()),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
editor.change_selections(None, cx, |s| {
|
editor.change_selections(None, cx, |s| {
|
||||||
@ -4930,7 +5079,7 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
|
|||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_toggle_comment(cx: &mut gpui::TestAppContext) {
|
async fn test_toggle_comment(cx: &mut gpui::TestAppContext) {
|
||||||
init_test(cx, |_| {});
|
init_test(cx, |_| {});
|
||||||
|
let mut cx = EditorTestContext::new(cx).await;
|
||||||
let language = Arc::new(Language::new(
|
let language = Arc::new(Language::new(
|
||||||
LanguageConfig {
|
LanguageConfig {
|
||||||
line_comment: Some("// ".into()),
|
line_comment: Some("// ".into()),
|
||||||
@ -4938,77 +5087,95 @@ async fn test_toggle_comment(cx: &mut gpui::TestAppContext) {
|
|||||||
},
|
},
|
||||||
Some(tree_sitter_rust::language()),
|
Some(tree_sitter_rust::language()),
|
||||||
));
|
));
|
||||||
|
cx.update_buffer(|buffer, cx| buffer.set_language(Some(language), cx));
|
||||||
|
|
||||||
let text = "
|
// If multiple selections intersect a line, the line is only toggled once.
|
||||||
|
cx.set_state(indoc! {"
|
||||||
fn a() {
|
fn a() {
|
||||||
//b();
|
«//b();
|
||||||
// c();
|
ˇ»// «c();
|
||||||
// d();
|
//ˇ» d();
|
||||||
}
|
}
|
||||||
"
|
"});
|
||||||
.unindent();
|
|
||||||
|
|
||||||
let buffer = cx.add_model(|cx| Buffer::new(0, text, cx).with_language(language, cx));
|
cx.update_editor(|e, cx| e.toggle_comments(&ToggleComments::default(), cx));
|
||||||
let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx));
|
|
||||||
let (_, view) = cx.add_window(|cx| build_editor(buffer, cx));
|
|
||||||
|
|
||||||
view.update(cx, |editor, cx| {
|
cx.assert_editor_state(indoc! {"
|
||||||
// If multiple selections intersect a line, the line is only
|
fn a() {
|
||||||
// toggled once.
|
«b();
|
||||||
editor.change_selections(None, cx, |s| {
|
c();
|
||||||
s.select_display_ranges([
|
ˇ» d();
|
||||||
DisplayPoint::new(1, 3)..DisplayPoint::new(2, 3),
|
}
|
||||||
DisplayPoint::new(3, 5)..DisplayPoint::new(3, 6),
|
"});
|
||||||
])
|
|
||||||
});
|
|
||||||
editor.toggle_comments(&ToggleComments::default(), cx);
|
|
||||||
assert_eq!(
|
|
||||||
editor.text(cx),
|
|
||||||
"
|
|
||||||
fn a() {
|
|
||||||
b();
|
|
||||||
c();
|
|
||||||
d();
|
|
||||||
}
|
|
||||||
"
|
|
||||||
.unindent()
|
|
||||||
);
|
|
||||||
|
|
||||||
// The comment prefix is inserted at the same column for every line
|
// The comment prefix is inserted at the same column for every line in a
|
||||||
// in a selection.
|
// selection.
|
||||||
editor.change_selections(None, cx, |s| {
|
cx.update_editor(|e, cx| e.toggle_comments(&ToggleComments::default(), cx));
|
||||||
s.select_display_ranges([DisplayPoint::new(1, 3)..DisplayPoint::new(3, 6)])
|
|
||||||
});
|
|
||||||
editor.toggle_comments(&ToggleComments::default(), cx);
|
|
||||||
assert_eq!(
|
|
||||||
editor.text(cx),
|
|
||||||
"
|
|
||||||
fn a() {
|
|
||||||
// b();
|
|
||||||
// c();
|
|
||||||
// d();
|
|
||||||
}
|
|
||||||
"
|
|
||||||
.unindent()
|
|
||||||
);
|
|
||||||
|
|
||||||
// If a selection ends at the beginning of a line, that line is not toggled.
|
cx.assert_editor_state(indoc! {"
|
||||||
editor.change_selections(None, cx, |s| {
|
fn a() {
|
||||||
s.select_display_ranges([DisplayPoint::new(2, 0)..DisplayPoint::new(3, 0)])
|
// «b();
|
||||||
});
|
// c();
|
||||||
editor.toggle_comments(&ToggleComments::default(), cx);
|
ˇ»// d();
|
||||||
assert_eq!(
|
}
|
||||||
editor.text(cx),
|
"});
|
||||||
"
|
|
||||||
fn a() {
|
// If a selection ends at the beginning of a line, that line is not toggled.
|
||||||
// b();
|
cx.set_selections_state(indoc! {"
|
||||||
c();
|
fn a() {
|
||||||
// d();
|
// b();
|
||||||
}
|
«// c();
|
||||||
"
|
ˇ» // d();
|
||||||
.unindent()
|
}
|
||||||
);
|
"});
|
||||||
});
|
|
||||||
|
cx.update_editor(|e, cx| e.toggle_comments(&ToggleComments::default(), cx));
|
||||||
|
|
||||||
|
cx.assert_editor_state(indoc! {"
|
||||||
|
fn a() {
|
||||||
|
// b();
|
||||||
|
«c();
|
||||||
|
ˇ» // d();
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
|
||||||
|
// If a selection span a single line and is empty, the line is toggled.
|
||||||
|
cx.set_state(indoc! {"
|
||||||
|
fn a() {
|
||||||
|
a();
|
||||||
|
b();
|
||||||
|
ˇ
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
|
||||||
|
cx.update_editor(|e, cx| e.toggle_comments(&ToggleComments::default(), cx));
|
||||||
|
|
||||||
|
cx.assert_editor_state(indoc! {"
|
||||||
|
fn a() {
|
||||||
|
a();
|
||||||
|
b();
|
||||||
|
//•ˇ
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
|
||||||
|
// If a selection span multiple lines, empty lines are not toggled.
|
||||||
|
cx.set_state(indoc! {"
|
||||||
|
fn a() {
|
||||||
|
«a();
|
||||||
|
|
||||||
|
c();ˇ»
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
|
||||||
|
cx.update_editor(|e, cx| e.toggle_comments(&ToggleComments::default(), cx));
|
||||||
|
|
||||||
|
cx.assert_editor_state(indoc! {"
|
||||||
|
fn a() {
|
||||||
|
// «a();
|
||||||
|
|
||||||
|
// c();ˇ»
|
||||||
|
}
|
||||||
|
"});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
@ -91,41 +91,17 @@ impl SelectionLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RenderExcerptHeaderParams<'a> {
|
|
||||||
pub id: crate::ExcerptId,
|
|
||||||
pub buffer: &'a language::BufferSnapshot,
|
|
||||||
pub range: &'a crate::ExcerptRange<text::Anchor>,
|
|
||||||
pub starts_new_buffer: bool,
|
|
||||||
pub gutter_padding: f32,
|
|
||||||
pub editor_style: &'a EditorStyle,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type RenderExcerptHeader = Arc<
|
|
||||||
dyn Fn(
|
|
||||||
&mut Editor,
|
|
||||||
RenderExcerptHeaderParams,
|
|
||||||
&mut LayoutContext<Editor>,
|
|
||||||
) -> AnyElement<Editor>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
pub struct EditorElement {
|
pub struct EditorElement {
|
||||||
style: Arc<EditorStyle>,
|
style: Arc<EditorStyle>,
|
||||||
render_excerpt_header: RenderExcerptHeader,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EditorElement {
|
impl EditorElement {
|
||||||
pub fn new(style: EditorStyle) -> Self {
|
pub fn new(style: EditorStyle) -> Self {
|
||||||
Self {
|
Self {
|
||||||
style: Arc::new(style),
|
style: Arc::new(style),
|
||||||
render_excerpt_header: Arc::new(render_excerpt_header),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_render_excerpt_header(mut self, render: RenderExcerptHeader) -> Self {
|
|
||||||
self.render_excerpt_header = render;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn attach_mouse_handlers(
|
fn attach_mouse_handlers(
|
||||||
scene: &mut SceneBuilder,
|
scene: &mut SceneBuilder,
|
||||||
position_map: &Arc<PositionMap>,
|
position_map: &Arc<PositionMap>,
|
||||||
@ -1491,6 +1467,7 @@ impl EditorElement {
|
|||||||
editor: &mut Editor,
|
editor: &mut Editor,
|
||||||
cx: &mut LayoutContext<Editor>,
|
cx: &mut LayoutContext<Editor>,
|
||||||
) -> (f32, Vec<BlockLayout>) {
|
) -> (f32, Vec<BlockLayout>) {
|
||||||
|
let mut block_id = 0;
|
||||||
let scroll_x = snapshot.scroll_anchor.offset.x();
|
let scroll_x = snapshot.scroll_anchor.offset.x();
|
||||||
let (fixed_blocks, non_fixed_blocks) = snapshot
|
let (fixed_blocks, non_fixed_blocks) = snapshot
|
||||||
.blocks_in_range(rows.clone())
|
.blocks_in_range(rows.clone())
|
||||||
@ -1498,7 +1475,7 @@ impl EditorElement {
|
|||||||
TransformBlock::ExcerptHeader { .. } => false,
|
TransformBlock::ExcerptHeader { .. } => false,
|
||||||
TransformBlock::Custom(block) => block.style() == BlockStyle::Fixed,
|
TransformBlock::Custom(block) => block.style() == BlockStyle::Fixed,
|
||||||
});
|
});
|
||||||
let mut render_block = |block: &TransformBlock, width: f32| {
|
let mut render_block = |block: &TransformBlock, width: f32, block_id: usize| {
|
||||||
let mut element = match block {
|
let mut element = match block {
|
||||||
TransformBlock::Custom(block) => {
|
TransformBlock::Custom(block) => {
|
||||||
let align_to = block
|
let align_to = block
|
||||||
@ -1523,6 +1500,7 @@ impl EditorElement {
|
|||||||
scroll_x,
|
scroll_x,
|
||||||
gutter_width,
|
gutter_width,
|
||||||
em_width,
|
em_width,
|
||||||
|
block_id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
TransformBlock::ExcerptHeader {
|
TransformBlock::ExcerptHeader {
|
||||||
@ -1531,18 +1509,117 @@ impl EditorElement {
|
|||||||
range,
|
range,
|
||||||
starts_new_buffer,
|
starts_new_buffer,
|
||||||
..
|
..
|
||||||
} => (self.render_excerpt_header)(
|
} => {
|
||||||
editor,
|
let tooltip_style = theme::current(cx).tooltip.clone();
|
||||||
RenderExcerptHeaderParams {
|
let include_root = editor
|
||||||
id: *id,
|
.project
|
||||||
buffer,
|
.as_ref()
|
||||||
range,
|
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
|
||||||
starts_new_buffer: *starts_new_buffer,
|
.unwrap_or_default();
|
||||||
gutter_padding,
|
let jump_icon = project::File::from_dyn(buffer.file()).map(|file| {
|
||||||
editor_style: style,
|
let jump_path = ProjectPath {
|
||||||
},
|
worktree_id: file.worktree_id(cx),
|
||||||
cx,
|
path: file.path.clone(),
|
||||||
),
|
};
|
||||||
|
let jump_anchor = range
|
||||||
|
.primary
|
||||||
|
.as_ref()
|
||||||
|
.map_or(range.context.start, |primary| primary.start);
|
||||||
|
let jump_position = language::ToPoint::to_point(&jump_anchor, buffer);
|
||||||
|
|
||||||
|
enum JumpIcon {}
|
||||||
|
MouseEventHandler::<JumpIcon, _>::new((*id).into(), cx, |state, _| {
|
||||||
|
let style = style.jump_icon.style_for(state);
|
||||||
|
Svg::new("icons/arrow_up_right_8.svg")
|
||||||
|
.with_color(style.color)
|
||||||
|
.constrained()
|
||||||
|
.with_width(style.icon_width)
|
||||||
|
.aligned()
|
||||||
|
.contained()
|
||||||
|
.with_style(style.container)
|
||||||
|
.constrained()
|
||||||
|
.with_width(style.button_width)
|
||||||
|
.with_height(style.button_width)
|
||||||
|
})
|
||||||
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
.on_click(MouseButton::Left, move |_, editor, cx| {
|
||||||
|
if let Some(workspace) = editor
|
||||||
|
.workspace
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|(workspace, _)| workspace.upgrade(cx))
|
||||||
|
{
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
Editor::jump(
|
||||||
|
workspace,
|
||||||
|
jump_path.clone(),
|
||||||
|
jump_position,
|
||||||
|
jump_anchor,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.with_tooltip::<JumpIcon>(
|
||||||
|
(*id).into(),
|
||||||
|
"Jump to Buffer".to_string(),
|
||||||
|
Some(Box::new(crate::OpenExcerpts)),
|
||||||
|
tooltip_style.clone(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.aligned()
|
||||||
|
.flex_float()
|
||||||
|
});
|
||||||
|
|
||||||
|
if *starts_new_buffer {
|
||||||
|
let editor_font_size = style.text.font_size;
|
||||||
|
let style = &style.diagnostic_path_header;
|
||||||
|
let font_size = (style.text_scale_factor * editor_font_size).round();
|
||||||
|
|
||||||
|
let path = buffer.resolve_file_path(cx, include_root);
|
||||||
|
let mut filename = None;
|
||||||
|
let mut parent_path = None;
|
||||||
|
// Can't use .and_then() because `.file_name()` and `.parent()` return references :(
|
||||||
|
if let Some(path) = path {
|
||||||
|
filename = path.file_name().map(|f| f.to_string_lossy().to_string());
|
||||||
|
parent_path =
|
||||||
|
path.parent().map(|p| p.to_string_lossy().to_string() + "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
Flex::row()
|
||||||
|
.with_child(
|
||||||
|
Label::new(
|
||||||
|
filename.unwrap_or_else(|| "untitled".to_string()),
|
||||||
|
style.filename.text.clone().with_font_size(font_size),
|
||||||
|
)
|
||||||
|
.contained()
|
||||||
|
.with_style(style.filename.container)
|
||||||
|
.aligned(),
|
||||||
|
)
|
||||||
|
.with_children(parent_path.map(|path| {
|
||||||
|
Label::new(path, style.path.text.clone().with_font_size(font_size))
|
||||||
|
.contained()
|
||||||
|
.with_style(style.path.container)
|
||||||
|
.aligned()
|
||||||
|
}))
|
||||||
|
.with_children(jump_icon)
|
||||||
|
.contained()
|
||||||
|
.with_style(style.container)
|
||||||
|
.with_padding_left(gutter_padding)
|
||||||
|
.with_padding_right(gutter_padding)
|
||||||
|
.expanded()
|
||||||
|
.into_any_named("path header block")
|
||||||
|
} else {
|
||||||
|
let text_style = style.text.clone();
|
||||||
|
Flex::row()
|
||||||
|
.with_child(Label::new("⋯", text_style))
|
||||||
|
.with_children(jump_icon)
|
||||||
|
.contained()
|
||||||
|
.with_padding_left(gutter_padding)
|
||||||
|
.with_padding_right(gutter_padding)
|
||||||
|
.expanded()
|
||||||
|
.into_any_named("collapsed context")
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
element.layout(
|
element.layout(
|
||||||
@ -1559,7 +1636,8 @@ impl EditorElement {
|
|||||||
let mut fixed_block_max_width = 0f32;
|
let mut fixed_block_max_width = 0f32;
|
||||||
let mut blocks = Vec::new();
|
let mut blocks = Vec::new();
|
||||||
for (row, block) in fixed_blocks {
|
for (row, block) in fixed_blocks {
|
||||||
let element = render_block(block, f32::INFINITY);
|
let element = render_block(block, f32::INFINITY, block_id);
|
||||||
|
block_id += 1;
|
||||||
fixed_block_max_width = fixed_block_max_width.max(element.size().x() + em_width);
|
fixed_block_max_width = fixed_block_max_width.max(element.size().x() + em_width);
|
||||||
blocks.push(BlockLayout {
|
blocks.push(BlockLayout {
|
||||||
row,
|
row,
|
||||||
@ -1579,7 +1657,8 @@ impl EditorElement {
|
|||||||
.max(gutter_width + scroll_width),
|
.max(gutter_width + scroll_width),
|
||||||
BlockStyle::Fixed => unreachable!(),
|
BlockStyle::Fixed => unreachable!(),
|
||||||
};
|
};
|
||||||
let element = render_block(block, width);
|
let element = render_block(block, width, block_id);
|
||||||
|
block_id += 1;
|
||||||
blocks.push(BlockLayout {
|
blocks.push(BlockLayout {
|
||||||
row,
|
row,
|
||||||
element,
|
element,
|
||||||
@ -2015,7 +2094,7 @@ impl Element<Editor> for EditorElement {
|
|||||||
.folds
|
.folds
|
||||||
.ellipses
|
.ellipses
|
||||||
.background
|
.background
|
||||||
.style_for(&mut cx.mouse_state::<FoldMarkers>(id as usize), false)
|
.style_for(&mut cx.mouse_state::<FoldMarkers>(id as usize))
|
||||||
.color;
|
.color;
|
||||||
|
|
||||||
(id, fold, color)
|
(id, fold, color)
|
||||||
@ -2679,121 +2758,6 @@ impl HighlightedRange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_excerpt_header(
|
|
||||||
editor: &mut Editor,
|
|
||||||
RenderExcerptHeaderParams {
|
|
||||||
id,
|
|
||||||
buffer,
|
|
||||||
range,
|
|
||||||
starts_new_buffer,
|
|
||||||
gutter_padding,
|
|
||||||
editor_style,
|
|
||||||
}: RenderExcerptHeaderParams,
|
|
||||||
cx: &mut LayoutContext<Editor>,
|
|
||||||
) -> AnyElement<Editor> {
|
|
||||||
let tooltip_style = theme::current(cx).tooltip.clone();
|
|
||||||
let include_root = editor
|
|
||||||
.project
|
|
||||||
.as_ref()
|
|
||||||
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
|
|
||||||
.unwrap_or_default();
|
|
||||||
let jump_icon = project::File::from_dyn(buffer.file()).map(|file| {
|
|
||||||
let jump_path = ProjectPath {
|
|
||||||
worktree_id: file.worktree_id(cx),
|
|
||||||
path: file.path.clone(),
|
|
||||||
};
|
|
||||||
let jump_anchor = range
|
|
||||||
.primary
|
|
||||||
.as_ref()
|
|
||||||
.map_or(range.context.start, |primary| primary.start);
|
|
||||||
let jump_position = language::ToPoint::to_point(&jump_anchor, buffer);
|
|
||||||
|
|
||||||
enum JumpIcon {}
|
|
||||||
MouseEventHandler::<JumpIcon, _>::new(id.into(), cx, |state, _| {
|
|
||||||
let style = editor_style.jump_icon.style_for(state, false);
|
|
||||||
Svg::new("icons/arrow_up_right_8.svg")
|
|
||||||
.with_color(style.color)
|
|
||||||
.constrained()
|
|
||||||
.with_width(style.icon_width)
|
|
||||||
.aligned()
|
|
||||||
.contained()
|
|
||||||
.with_style(style.container)
|
|
||||||
.constrained()
|
|
||||||
.with_width(style.button_width)
|
|
||||||
.with_height(style.button_width)
|
|
||||||
})
|
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
|
||||||
.on_click(MouseButton::Left, move |_, editor, cx| {
|
|
||||||
if let Some(workspace) = editor
|
|
||||||
.workspace
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|(workspace, _)| workspace.upgrade(cx))
|
|
||||||
{
|
|
||||||
workspace.update(cx, |workspace, cx| {
|
|
||||||
Editor::jump(workspace, jump_path.clone(), jump_position, jump_anchor, cx);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.with_tooltip::<JumpIcon>(
|
|
||||||
id.into(),
|
|
||||||
"Jump to Buffer".to_string(),
|
|
||||||
Some(Box::new(crate::OpenExcerpts)),
|
|
||||||
tooltip_style.clone(),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
.aligned()
|
|
||||||
.flex_float()
|
|
||||||
});
|
|
||||||
|
|
||||||
if starts_new_buffer {
|
|
||||||
let style = &editor_style.diagnostic_path_header;
|
|
||||||
let font_size = (style.text_scale_factor * editor_style.text.font_size).round();
|
|
||||||
|
|
||||||
let path = buffer.resolve_file_path(cx, include_root);
|
|
||||||
let mut filename = None;
|
|
||||||
let mut parent_path = None;
|
|
||||||
// Can't use .and_then() because `.file_name()` and `.parent()` return references :(
|
|
||||||
if let Some(path) = path {
|
|
||||||
filename = path.file_name().map(|f| f.to_string_lossy().to_string());
|
|
||||||
parent_path = path.parent().map(|p| p.to_string_lossy().to_string() + "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
Flex::row()
|
|
||||||
.with_child(
|
|
||||||
Label::new(
|
|
||||||
filename.unwrap_or_else(|| "untitled".to_string()),
|
|
||||||
style.filename.text.clone().with_font_size(font_size),
|
|
||||||
)
|
|
||||||
.contained()
|
|
||||||
.with_style(style.filename.container)
|
|
||||||
.aligned(),
|
|
||||||
)
|
|
||||||
.with_children(parent_path.map(|path| {
|
|
||||||
Label::new(path, style.path.text.clone().with_font_size(font_size))
|
|
||||||
.contained()
|
|
||||||
.with_style(style.path.container)
|
|
||||||
.aligned()
|
|
||||||
}))
|
|
||||||
.with_children(jump_icon)
|
|
||||||
.contained()
|
|
||||||
.with_style(style.container)
|
|
||||||
.with_padding_left(gutter_padding)
|
|
||||||
.with_padding_right(gutter_padding)
|
|
||||||
.expanded()
|
|
||||||
.into_any_named("path header block")
|
|
||||||
} else {
|
|
||||||
let text_style = editor_style.text.clone();
|
|
||||||
Flex::row()
|
|
||||||
.with_child(Label::new("⋯", text_style))
|
|
||||||
.with_children(jump_icon)
|
|
||||||
.contained()
|
|
||||||
.with_padding_left(gutter_padding)
|
|
||||||
.with_padding_right(gutter_padding)
|
|
||||||
.expanded()
|
|
||||||
.into_any_named("collapsed context")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn position_to_display_point(
|
fn position_to_display_point(
|
||||||
position: Vector2F,
|
position: Vector2F,
|
||||||
text_bounds: RectF,
|
text_bounds: RectF,
|
||||||
@ -2923,6 +2887,7 @@ mod tests {
|
|||||||
position: Anchor::min(),
|
position: Anchor::min(),
|
||||||
render: Arc::new(|_| Empty::new().into_any()),
|
render: Arc::new(|_| Empty::new().into_any()),
|
||||||
}],
|
}],
|
||||||
|
None,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ impl FollowableItem for Editor {
|
|||||||
match event {
|
match event {
|
||||||
Event::Edited => true,
|
Event::Edited => true,
|
||||||
Event::SelectionsChanged { local } => *local,
|
Event::SelectionsChanged { local } => *local,
|
||||||
Event::ScrollPositionChanged { local } => *local,
|
Event::ScrollPositionChanged { local, .. } => *local,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1010,7 +1010,7 @@ impl MultiBuffer {
|
|||||||
|
|
||||||
let suffix = cursor.suffix(&());
|
let suffix = cursor.suffix(&());
|
||||||
let changed_trailing_excerpt = suffix.is_empty();
|
let changed_trailing_excerpt = suffix.is_empty();
|
||||||
new_excerpts.push_tree(suffix, &());
|
new_excerpts.append(suffix, &());
|
||||||
drop(cursor);
|
drop(cursor);
|
||||||
snapshot.excerpts = new_excerpts;
|
snapshot.excerpts = new_excerpts;
|
||||||
snapshot.excerpt_ids = new_excerpt_ids;
|
snapshot.excerpt_ids = new_excerpt_ids;
|
||||||
@ -1118,7 +1118,7 @@ impl MultiBuffer {
|
|||||||
&self,
|
&self,
|
||||||
point: T,
|
point: T,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> Option<(ModelHandle<Buffer>, usize)> {
|
) -> Option<(ModelHandle<Buffer>, usize, ExcerptId)> {
|
||||||
let snapshot = self.read(cx);
|
let snapshot = self.read(cx);
|
||||||
let offset = point.to_offset(&snapshot);
|
let offset = point.to_offset(&snapshot);
|
||||||
let mut cursor = snapshot.excerpts.cursor::<usize>();
|
let mut cursor = snapshot.excerpts.cursor::<usize>();
|
||||||
@ -1132,7 +1132,7 @@ impl MultiBuffer {
|
|||||||
let buffer_point = excerpt_start + offset - *cursor.start();
|
let buffer_point = excerpt_start + offset - *cursor.start();
|
||||||
let buffer = self.buffers.borrow()[&excerpt.buffer_id].buffer.clone();
|
let buffer = self.buffers.borrow()[&excerpt.buffer_id].buffer.clone();
|
||||||
|
|
||||||
(buffer, buffer_point)
|
(buffer, buffer_point, excerpt.id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1140,7 +1140,7 @@ impl MultiBuffer {
|
|||||||
&self,
|
&self,
|
||||||
range: Range<T>,
|
range: Range<T>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> Vec<(ModelHandle<Buffer>, Range<usize>)> {
|
) -> Vec<(ModelHandle<Buffer>, Range<usize>, ExcerptId)> {
|
||||||
let snapshot = self.read(cx);
|
let snapshot = self.read(cx);
|
||||||
let start = range.start.to_offset(&snapshot);
|
let start = range.start.to_offset(&snapshot);
|
||||||
let end = range.end.to_offset(&snapshot);
|
let end = range.end.to_offset(&snapshot);
|
||||||
@ -1165,7 +1165,7 @@ impl MultiBuffer {
|
|||||||
let start = excerpt_start + (cmp::max(start, *cursor.start()) - *cursor.start());
|
let start = excerpt_start + (cmp::max(start, *cursor.start()) - *cursor.start());
|
||||||
let end = excerpt_start + (cmp::min(end, end_before_newline) - *cursor.start());
|
let end = excerpt_start + (cmp::min(end, end_before_newline) - *cursor.start());
|
||||||
let buffer = self.buffers.borrow()[&excerpt.buffer_id].buffer.clone();
|
let buffer = self.buffers.borrow()[&excerpt.buffer_id].buffer.clone();
|
||||||
result.push((buffer, start..end));
|
result.push((buffer, start..end, excerpt.id));
|
||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1193,7 +1193,7 @@ impl MultiBuffer {
|
|||||||
while let Some(excerpt_id) = excerpt_ids.next() {
|
while let Some(excerpt_id) = excerpt_ids.next() {
|
||||||
// Seek to the next excerpt to remove, preserving any preceding excerpts.
|
// Seek to the next excerpt to remove, preserving any preceding excerpts.
|
||||||
let locator = snapshot.excerpt_locator_for_id(excerpt_id);
|
let locator = snapshot.excerpt_locator_for_id(excerpt_id);
|
||||||
new_excerpts.push_tree(cursor.slice(&Some(locator), Bias::Left, &()), &());
|
new_excerpts.append(cursor.slice(&Some(locator), Bias::Left, &()), &());
|
||||||
|
|
||||||
if let Some(mut excerpt) = cursor.item() {
|
if let Some(mut excerpt) = cursor.item() {
|
||||||
if excerpt.id != excerpt_id {
|
if excerpt.id != excerpt_id {
|
||||||
@ -1245,7 +1245,7 @@ impl MultiBuffer {
|
|||||||
}
|
}
|
||||||
let suffix = cursor.suffix(&());
|
let suffix = cursor.suffix(&());
|
||||||
let changed_trailing_excerpt = suffix.is_empty();
|
let changed_trailing_excerpt = suffix.is_empty();
|
||||||
new_excerpts.push_tree(suffix, &());
|
new_excerpts.append(suffix, &());
|
||||||
drop(cursor);
|
drop(cursor);
|
||||||
snapshot.excerpts = new_excerpts;
|
snapshot.excerpts = new_excerpts;
|
||||||
|
|
||||||
@ -1387,7 +1387,7 @@ impl MultiBuffer {
|
|||||||
cx: &'a AppContext,
|
cx: &'a AppContext,
|
||||||
) -> Option<Arc<Language>> {
|
) -> Option<Arc<Language>> {
|
||||||
self.point_to_buffer_offset(point, cx)
|
self.point_to_buffer_offset(point, cx)
|
||||||
.and_then(|(buffer, offset)| buffer.read(cx).language_at(offset))
|
.and_then(|(buffer, offset, _)| buffer.read(cx).language_at(offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn settings_at<'a, T: ToOffset>(
|
pub fn settings_at<'a, T: ToOffset>(
|
||||||
@ -1397,7 +1397,7 @@ impl MultiBuffer {
|
|||||||
) -> &'a LanguageSettings {
|
) -> &'a LanguageSettings {
|
||||||
let mut language = None;
|
let mut language = None;
|
||||||
let mut file = None;
|
let mut file = None;
|
||||||
if let Some((buffer, offset)) = self.point_to_buffer_offset(point, cx) {
|
if let Some((buffer, offset, _)) = self.point_to_buffer_offset(point, cx) {
|
||||||
let buffer = buffer.read(cx);
|
let buffer = buffer.read(cx);
|
||||||
language = buffer.language_at(offset);
|
language = buffer.language_at(offset);
|
||||||
file = buffer.file();
|
file = buffer.file();
|
||||||
@ -1509,7 +1509,7 @@ impl MultiBuffer {
|
|||||||
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, usize)>();
|
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, usize)>();
|
||||||
|
|
||||||
for (locator, buffer, buffer_edited) in excerpts_to_edit {
|
for (locator, buffer, buffer_edited) in excerpts_to_edit {
|
||||||
new_excerpts.push_tree(cursor.slice(&Some(locator), Bias::Left, &()), &());
|
new_excerpts.append(cursor.slice(&Some(locator), Bias::Left, &()), &());
|
||||||
let old_excerpt = cursor.item().unwrap();
|
let old_excerpt = cursor.item().unwrap();
|
||||||
let buffer = buffer.read(cx);
|
let buffer = buffer.read(cx);
|
||||||
let buffer_id = buffer.remote_id();
|
let buffer_id = buffer.remote_id();
|
||||||
@ -1549,7 +1549,7 @@ impl MultiBuffer {
|
|||||||
new_excerpts.push(new_excerpt, &());
|
new_excerpts.push(new_excerpt, &());
|
||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
}
|
}
|
||||||
new_excerpts.push_tree(cursor.suffix(&()), &());
|
new_excerpts.append(cursor.suffix(&()), &());
|
||||||
|
|
||||||
drop(cursor);
|
drop(cursor);
|
||||||
snapshot.excerpts = new_excerpts;
|
snapshot.excerpts = new_excerpts;
|
||||||
@ -5196,7 +5196,7 @@ mod tests {
|
|||||||
.range_to_buffer_ranges(start_ix..end_ix, cx);
|
.range_to_buffer_ranges(start_ix..end_ix, cx);
|
||||||
let excerpted_buffers_text = excerpted_buffer_ranges
|
let excerpted_buffers_text = excerpted_buffer_ranges
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(buffer, buffer_range)| {
|
.map(|(buffer, buffer_range, _)| {
|
||||||
buffer
|
buffer
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.text_for_range(buffer_range.clone())
|
.text_for_range(buffer_range.clone())
|
||||||
|
@ -173,6 +173,7 @@ impl ScrollManager {
|
|||||||
scroll_position: Vector2F,
|
scroll_position: Vector2F,
|
||||||
map: &DisplaySnapshot,
|
map: &DisplaySnapshot,
|
||||||
local: bool,
|
local: bool,
|
||||||
|
autoscroll: bool,
|
||||||
workspace_id: Option<i64>,
|
workspace_id: Option<i64>,
|
||||||
cx: &mut ViewContext<Editor>,
|
cx: &mut ViewContext<Editor>,
|
||||||
) {
|
) {
|
||||||
@ -203,7 +204,7 @@ impl ScrollManager {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
self.set_anchor(new_anchor, top_row, local, workspace_id, cx);
|
self.set_anchor(new_anchor, top_row, local, autoscroll, workspace_id, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_anchor(
|
fn set_anchor(
|
||||||
@ -211,11 +212,12 @@ impl ScrollManager {
|
|||||||
anchor: ScrollAnchor,
|
anchor: ScrollAnchor,
|
||||||
top_row: u32,
|
top_row: u32,
|
||||||
local: bool,
|
local: bool,
|
||||||
|
autoscroll: bool,
|
||||||
workspace_id: Option<i64>,
|
workspace_id: Option<i64>,
|
||||||
cx: &mut ViewContext<Editor>,
|
cx: &mut ViewContext<Editor>,
|
||||||
) {
|
) {
|
||||||
self.anchor = anchor;
|
self.anchor = anchor;
|
||||||
cx.emit(Event::ScrollPositionChanged { local });
|
cx.emit(Event::ScrollPositionChanged { local, autoscroll });
|
||||||
self.show_scrollbar(cx);
|
self.show_scrollbar(cx);
|
||||||
self.autoscroll_request.take();
|
self.autoscroll_request.take();
|
||||||
if let Some(workspace_id) = workspace_id {
|
if let Some(workspace_id) = workspace_id {
|
||||||
@ -296,21 +298,28 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_scroll_position(&mut self, scroll_position: Vector2F, cx: &mut ViewContext<Self>) {
|
pub fn set_scroll_position(&mut self, scroll_position: Vector2F, cx: &mut ViewContext<Self>) {
|
||||||
self.set_scroll_position_internal(scroll_position, true, cx);
|
self.set_scroll_position_internal(scroll_position, true, false, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_scroll_position_internal(
|
pub(crate) fn set_scroll_position_internal(
|
||||||
&mut self,
|
&mut self,
|
||||||
scroll_position: Vector2F,
|
scroll_position: Vector2F,
|
||||||
local: bool,
|
local: bool,
|
||||||
|
autoscroll: bool,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
let map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
let map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||||
|
|
||||||
hide_hover(self, cx);
|
hide_hover(self, cx);
|
||||||
let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
|
let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
|
||||||
self.scroll_manager
|
self.scroll_manager.set_scroll_position(
|
||||||
.set_scroll_position(scroll_position, &map, local, workspace_id, cx);
|
scroll_position,
|
||||||
|
&map,
|
||||||
|
local,
|
||||||
|
autoscroll,
|
||||||
|
workspace_id,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> Vector2F {
|
pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> Vector2F {
|
||||||
@ -326,7 +335,7 @@ impl Editor {
|
|||||||
.to_point(&self.buffer().read(cx).snapshot(cx))
|
.to_point(&self.buffer().read(cx).snapshot(cx))
|
||||||
.row;
|
.row;
|
||||||
self.scroll_manager
|
self.scroll_manager
|
||||||
.set_anchor(scroll_anchor, top_row, true, workspace_id, cx);
|
.set_anchor(scroll_anchor, top_row, true, false, workspace_id, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_scroll_anchor_remote(
|
pub(crate) fn set_scroll_anchor_remote(
|
||||||
@ -341,7 +350,7 @@ impl Editor {
|
|||||||
.to_point(&self.buffer().read(cx).snapshot(cx))
|
.to_point(&self.buffer().read(cx).snapshot(cx))
|
||||||
.row;
|
.row;
|
||||||
self.scroll_manager
|
self.scroll_manager
|
||||||
.set_anchor(scroll_anchor, top_row, false, workspace_id, cx);
|
.set_anchor(scroll_anchor, top_row, false, false, workspace_id, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scroll_screen(&mut self, amount: &ScrollAmount, cx: &mut ViewContext<Self>) {
|
pub fn scroll_screen(&mut self, amount: &ScrollAmount, cx: &mut ViewContext<Self>) {
|
||||||
|
@ -136,23 +136,23 @@ impl Editor {
|
|||||||
|
|
||||||
if target_top < start_row {
|
if target_top < start_row {
|
||||||
scroll_position.set_y(target_top);
|
scroll_position.set_y(target_top);
|
||||||
self.set_scroll_position_internal(scroll_position, local, cx);
|
self.set_scroll_position_internal(scroll_position, local, true, cx);
|
||||||
} else if target_bottom >= end_row {
|
} else if target_bottom >= end_row {
|
||||||
scroll_position.set_y(target_bottom - visible_lines);
|
scroll_position.set_y(target_bottom - visible_lines);
|
||||||
self.set_scroll_position_internal(scroll_position, local, cx);
|
self.set_scroll_position_internal(scroll_position, local, true, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AutoscrollStrategy::Center => {
|
AutoscrollStrategy::Center => {
|
||||||
scroll_position.set_y((first_cursor_top - margin).max(0.0));
|
scroll_position.set_y((first_cursor_top - margin).max(0.0));
|
||||||
self.set_scroll_position_internal(scroll_position, local, cx);
|
self.set_scroll_position_internal(scroll_position, local, true, cx);
|
||||||
}
|
}
|
||||||
AutoscrollStrategy::Top => {
|
AutoscrollStrategy::Top => {
|
||||||
scroll_position.set_y((first_cursor_top).max(0.0));
|
scroll_position.set_y((first_cursor_top).max(0.0));
|
||||||
self.set_scroll_position_internal(scroll_position, local, cx);
|
self.set_scroll_position_internal(scroll_position, local, true, cx);
|
||||||
}
|
}
|
||||||
AutoscrollStrategy::Bottom => {
|
AutoscrollStrategy::Bottom => {
|
||||||
scroll_position.set_y((last_cursor_bottom - visible_lines).max(0.0));
|
scroll_position.set_y((last_cursor_bottom - visible_lines).max(0.0));
|
||||||
self.set_scroll_position_internal(scroll_position, local, cx);
|
self.set_scroll_position_internal(scroll_position, local, true, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,8 @@ impl View for DeployFeedbackButton {
|
|||||||
.status_bar
|
.status_bar
|
||||||
.panel_buttons
|
.panel_buttons
|
||||||
.button
|
.button
|
||||||
.style_for(state, active);
|
.in_state(active)
|
||||||
|
.style_for(state);
|
||||||
|
|
||||||
Svg::new("icons/feedback_16.svg")
|
Svg::new("icons/feedback_16.svg")
|
||||||
.with_color(style.icon_color)
|
.with_color(style.icon_color)
|
||||||
|
@ -48,7 +48,7 @@ impl View for SubmitFeedbackButton {
|
|||||||
let theme = theme::current(cx).clone();
|
let theme = theme::current(cx).clone();
|
||||||
enum SubmitFeedbackButton {}
|
enum SubmitFeedbackButton {}
|
||||||
MouseEventHandler::<SubmitFeedbackButton, Self>::new(0, cx, |state, _| {
|
MouseEventHandler::<SubmitFeedbackButton, Self>::new(0, cx, |state, _| {
|
||||||
let style = theme.feedback.submit_button.style_for(state, false);
|
let style = theme.feedback.submit_button.style_for(state);
|
||||||
Label::new("Submit as Markdown", style.text.clone())
|
Label::new("Submit as Markdown", style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
|
@ -546,7 +546,7 @@ impl PickerDelegate for FileFinderDelegate {
|
|||||||
.get(ix)
|
.get(ix)
|
||||||
.expect("Invalid matches state: no element for index {ix}");
|
.expect("Invalid matches state: no element for index {ix}");
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.picker.item.style_for(mouse_state, selected);
|
let style = theme.picker.item.in_state(selected).style_for(mouse_state);
|
||||||
let (file_name, file_name_positions, full_path, full_path_positions) =
|
let (file_name, file_name_positions, full_path, full_path_positions) =
|
||||||
self.labels_for_match(path_match, cx, ix);
|
self.labels_for_match(path_match, cx, ix);
|
||||||
Flex::column()
|
Flex::column()
|
||||||
|
@ -445,7 +445,7 @@ type WindowBoundsCallback = Box<dyn FnMut(WindowBounds, Uuid, &mut WindowContext
|
|||||||
type KeystrokeCallback =
|
type KeystrokeCallback =
|
||||||
Box<dyn FnMut(&Keystroke, &MatchResult, Option<&Box<dyn Action>>, &mut WindowContext) -> bool>;
|
Box<dyn FnMut(&Keystroke, &MatchResult, Option<&Box<dyn Action>>, &mut WindowContext) -> bool>;
|
||||||
type ActiveLabeledTasksCallback = Box<dyn FnMut(&mut AppContext) -> bool>;
|
type ActiveLabeledTasksCallback = Box<dyn FnMut(&mut AppContext) -> bool>;
|
||||||
type DeserializeActionCallback = fn(json: &str) -> anyhow::Result<Box<dyn Action>>;
|
type DeserializeActionCallback = fn(json: serde_json::Value) -> anyhow::Result<Box<dyn Action>>;
|
||||||
type WindowShouldCloseSubscriptionCallback = Box<dyn FnMut(&mut AppContext) -> bool>;
|
type WindowShouldCloseSubscriptionCallback = Box<dyn FnMut(&mut AppContext) -> bool>;
|
||||||
|
|
||||||
pub struct AppContext {
|
pub struct AppContext {
|
||||||
@ -624,14 +624,14 @@ impl AppContext {
|
|||||||
pub fn deserialize_action(
|
pub fn deserialize_action(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
argument: Option<&str>,
|
argument: Option<serde_json::Value>,
|
||||||
) -> Result<Box<dyn Action>> {
|
) -> Result<Box<dyn Action>> {
|
||||||
let callback = self
|
let callback = self
|
||||||
.action_deserializers
|
.action_deserializers
|
||||||
.get(name)
|
.get(name)
|
||||||
.ok_or_else(|| anyhow!("unknown action {}", name))?
|
.ok_or_else(|| anyhow!("unknown action {}", name))?
|
||||||
.1;
|
.1;
|
||||||
callback(argument.unwrap_or("{}"))
|
callback(argument.unwrap_or_else(|| serde_json::Value::Object(Default::default())))
|
||||||
.with_context(|| format!("invalid data for action {}", name))
|
.with_context(|| format!("invalid data for action {}", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5573,7 +5573,7 @@ mod tests {
|
|||||||
let action1 = cx
|
let action1 = cx
|
||||||
.deserialize_action(
|
.deserialize_action(
|
||||||
"test::something::ComplexAction",
|
"test::something::ComplexAction",
|
||||||
Some(r#"{"arg": "a", "count": 5}"#),
|
Some(serde_json::from_str(r#"{"arg": "a", "count": 5}"#).unwrap()),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let action2 = cx
|
let action2 = cx
|
||||||
|
@ -11,7 +11,7 @@ pub trait Action: 'static {
|
|||||||
fn qualified_name() -> &'static str
|
fn qualified_name() -> &'static str
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
fn from_json_str(json: &str) -> anyhow::Result<Box<dyn Action>>
|
fn from_json_str(json: serde_json::Value) -> anyhow::Result<Box<dyn Action>>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ macro_rules! actions {
|
|||||||
$crate::__impl_action! {
|
$crate::__impl_action! {
|
||||||
$namespace,
|
$namespace,
|
||||||
$name,
|
$name,
|
||||||
fn from_json_str(_: &str) -> $crate::anyhow::Result<Box<dyn $crate::Action>> {
|
fn from_json_str(_: $crate::serde_json::Value) -> $crate::anyhow::Result<Box<dyn $crate::Action>> {
|
||||||
Ok(Box::new(Self))
|
Ok(Box::new(Self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,8 +58,8 @@ macro_rules! impl_actions {
|
|||||||
$crate::__impl_action! {
|
$crate::__impl_action! {
|
||||||
$namespace,
|
$namespace,
|
||||||
$name,
|
$name,
|
||||||
fn from_json_str(json: &str) -> $crate::anyhow::Result<Box<dyn $crate::Action>> {
|
fn from_json_str(json: $crate::serde_json::Value) -> $crate::anyhow::Result<Box<dyn $crate::Action>> {
|
||||||
Ok(Box::new($crate::serde_json::from_str::<Self>(json)?))
|
Ok(Box::new($crate::serde_json::from_value::<Self>(json)?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
@ -394,7 +394,7 @@ impl<'a> WindowContext<'a> {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter_map(move |(name, (type_id, deserialize))| {
|
.filter_map(move |(name, (type_id, deserialize))| {
|
||||||
if let Some(action_depth) = handler_depths_by_action_type.get(type_id).copied() {
|
if let Some(action_depth) = handler_depths_by_action_type.get(type_id).copied() {
|
||||||
let action = deserialize("{}").ok()?;
|
let action = deserialize(serde_json::Value::Object(Default::default())).ok()?;
|
||||||
let bindings = self
|
let bindings = self
|
||||||
.keystroke_matcher
|
.keystroke_matcher
|
||||||
.bindings_for_action_type(*type_id)
|
.bindings_for_action_type(*type_id)
|
||||||
|
@ -211,7 +211,7 @@ impl<V: View> Element<V> for List<V> {
|
|||||||
let mut cursor = old_items.cursor::<Count>();
|
let mut cursor = old_items.cursor::<Count>();
|
||||||
|
|
||||||
if state.rendered_range.start < new_rendered_range.start {
|
if state.rendered_range.start < new_rendered_range.start {
|
||||||
new_items.push_tree(
|
new_items.append(
|
||||||
cursor.slice(&Count(state.rendered_range.start), Bias::Right, &()),
|
cursor.slice(&Count(state.rendered_range.start), Bias::Right, &()),
|
||||||
&(),
|
&(),
|
||||||
);
|
);
|
||||||
@ -221,7 +221,7 @@ impl<V: View> Element<V> for List<V> {
|
|||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new_items.push_tree(
|
new_items.append(
|
||||||
cursor.slice(&Count(new_rendered_range.start), Bias::Right, &()),
|
cursor.slice(&Count(new_rendered_range.start), Bias::Right, &()),
|
||||||
&(),
|
&(),
|
||||||
);
|
);
|
||||||
@ -230,7 +230,7 @@ impl<V: View> Element<V> for List<V> {
|
|||||||
cursor.seek(&Count(new_rendered_range.end), Bias::Right, &());
|
cursor.seek(&Count(new_rendered_range.end), Bias::Right, &());
|
||||||
|
|
||||||
if new_rendered_range.end < state.rendered_range.start {
|
if new_rendered_range.end < state.rendered_range.start {
|
||||||
new_items.push_tree(
|
new_items.append(
|
||||||
cursor.slice(&Count(state.rendered_range.start), Bias::Right, &()),
|
cursor.slice(&Count(state.rendered_range.start), Bias::Right, &()),
|
||||||
&(),
|
&(),
|
||||||
);
|
);
|
||||||
@ -240,7 +240,7 @@ impl<V: View> Element<V> for List<V> {
|
|||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
}
|
}
|
||||||
|
|
||||||
new_items.push_tree(cursor.suffix(&()), &());
|
new_items.append(cursor.suffix(&()), &());
|
||||||
|
|
||||||
state.items = new_items;
|
state.items = new_items;
|
||||||
state.rendered_range = new_rendered_range;
|
state.rendered_range = new_rendered_range;
|
||||||
@ -413,7 +413,7 @@ impl<V: View> ListState<V> {
|
|||||||
old_heights.seek_forward(&Count(old_range.end), Bias::Right, &());
|
old_heights.seek_forward(&Count(old_range.end), Bias::Right, &());
|
||||||
|
|
||||||
new_heights.extend((0..count).map(|_| ListItem::Unrendered), &());
|
new_heights.extend((0..count).map(|_| ListItem::Unrendered), &());
|
||||||
new_heights.push_tree(old_heights.suffix(&()), &());
|
new_heights.append(old_heights.suffix(&()), &());
|
||||||
drop(old_heights);
|
drop(old_heights);
|
||||||
state.items = new_heights;
|
state.items = new_heights;
|
||||||
}
|
}
|
||||||
|
@ -786,7 +786,7 @@ impl platform::Platform for MacPlatform {
|
|||||||
|
|
||||||
fn set_cursor_style(&self, style: CursorStyle) {
|
fn set_cursor_style(&self, style: CursorStyle) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let cursor: id = match style {
|
let new_cursor: id = match style {
|
||||||
CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor],
|
CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor],
|
||||||
CursorStyle::ResizeLeftRight => {
|
CursorStyle::ResizeLeftRight => {
|
||||||
msg_send![class!(NSCursor), resizeLeftRightCursor]
|
msg_send![class!(NSCursor), resizeLeftRightCursor]
|
||||||
@ -795,7 +795,11 @@ impl platform::Platform for MacPlatform {
|
|||||||
CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor],
|
CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor],
|
||||||
CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor],
|
CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor],
|
||||||
};
|
};
|
||||||
let _: () = msg_send![cursor, set];
|
|
||||||
|
let old_cursor: id = msg_send![class!(NSCursor), currentCursor];
|
||||||
|
if new_cursor != old_cursor {
|
||||||
|
let _: () = msg_send![new_cursor, set];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ serde_json.workspace = true
|
|||||||
similar = "1.3"
|
similar = "1.3"
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
tree-sitter = "0.20"
|
tree-sitter.workspace = true
|
||||||
tree-sitter-rust = { version = "*", optional = true }
|
tree-sitter-rust = { version = "*", optional = true }
|
||||||
tree-sitter-typescript = { version = "*", optional = true }
|
tree-sitter-typescript = { version = "*", optional = true }
|
||||||
unicase = "2.6"
|
unicase = "2.6"
|
||||||
@ -72,6 +72,8 @@ ctor.workspace = true
|
|||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
indoc.workspace = true
|
indoc.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
|
unindent.workspace = true
|
||||||
|
|
||||||
tree-sitter-embedded-template = "*"
|
tree-sitter-embedded-template = "*"
|
||||||
tree-sitter-html = "*"
|
tree-sitter-html = "*"
|
||||||
tree-sitter-javascript = "*"
|
tree-sitter-javascript = "*"
|
||||||
@ -81,4 +83,3 @@ tree-sitter-rust = "*"
|
|||||||
tree-sitter-python = "*"
|
tree-sitter-python = "*"
|
||||||
tree-sitter-typescript = "*"
|
tree-sitter-typescript = "*"
|
||||||
tree-sitter-ruby = "*"
|
tree-sitter-ruby = "*"
|
||||||
unindent.workspace = true
|
|
||||||
|
@ -8,7 +8,8 @@ use crate::{
|
|||||||
language_settings::{language_settings, LanguageSettings},
|
language_settings::{language_settings, LanguageSettings},
|
||||||
outline::OutlineItem,
|
outline::OutlineItem,
|
||||||
syntax_map::{
|
syntax_map::{
|
||||||
SyntaxMap, SyntaxMapCapture, SyntaxMapCaptures, SyntaxSnapshot, ToTreeSitterPoint,
|
SyntaxLayerInfo, SyntaxMap, SyntaxMapCapture, SyntaxMapCaptures, SyntaxSnapshot,
|
||||||
|
ToTreeSitterPoint,
|
||||||
},
|
},
|
||||||
CodeLabel, LanguageScope, Outline,
|
CodeLabel, LanguageScope, Outline,
|
||||||
};
|
};
|
||||||
@ -2116,12 +2117,20 @@ impl BufferSnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn language_at<D: ToOffset>(&self, position: D) -> Option<&Arc<Language>> {
|
pub fn syntax_layers(&self) -> impl Iterator<Item = SyntaxLayerInfo> + '_ {
|
||||||
|
self.syntax.layers_for_range(0..self.len(), &self.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn syntax_layer_at<D: ToOffset>(&self, position: D) -> Option<SyntaxLayerInfo> {
|
||||||
let offset = position.to_offset(self);
|
let offset = position.to_offset(self);
|
||||||
self.syntax
|
self.syntax
|
||||||
.layers_for_range(offset..offset, &self.text)
|
.layers_for_range(offset..offset, &self.text)
|
||||||
.filter(|l| l.node.end_byte() > offset)
|
.filter(|l| l.node().end_byte() > offset)
|
||||||
.last()
|
.last()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn language_at<D: ToOffset>(&self, position: D) -> Option<&Arc<Language>> {
|
||||||
|
self.syntax_layer_at(position)
|
||||||
.map(|info| info.language)
|
.map(|info| info.language)
|
||||||
.or(self.language.as_ref())
|
.or(self.language.as_ref())
|
||||||
}
|
}
|
||||||
@ -2140,7 +2149,7 @@ impl BufferSnapshot {
|
|||||||
if let Some(layer_info) = self
|
if let Some(layer_info) = self
|
||||||
.syntax
|
.syntax
|
||||||
.layers_for_range(offset..offset, &self.text)
|
.layers_for_range(offset..offset, &self.text)
|
||||||
.filter(|l| l.node.end_byte() > offset)
|
.filter(|l| l.node().end_byte() > offset)
|
||||||
.last()
|
.last()
|
||||||
{
|
{
|
||||||
Some(LanguageScope {
|
Some(LanguageScope {
|
||||||
@ -2188,7 +2197,7 @@ impl BufferSnapshot {
|
|||||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||||
let mut result: Option<Range<usize>> = None;
|
let mut result: Option<Range<usize>> = None;
|
||||||
'outer: for layer in self.syntax.layers_for_range(range.clone(), &self.text) {
|
'outer: for layer in self.syntax.layers_for_range(range.clone(), &self.text) {
|
||||||
let mut cursor = layer.node.walk();
|
let mut cursor = layer.node().walk();
|
||||||
|
|
||||||
// Descend to the first leaf that touches the start of the range,
|
// Descend to the first leaf that touches the start of the range,
|
||||||
// and if the range is non-empty, extends beyond the start.
|
// and if the range is non-empty, extends beyond the start.
|
||||||
|
@ -2242,7 +2242,7 @@ fn get_tree_sexp(buffer: &ModelHandle<Buffer>, cx: &gpui::TestAppContext) -> Str
|
|||||||
buffer.read_with(cx, |buffer, _| {
|
buffer.read_with(cx, |buffer, _| {
|
||||||
let snapshot = buffer.snapshot();
|
let snapshot = buffer.snapshot();
|
||||||
let layers = snapshot.syntax.layers(buffer.as_text_snapshot());
|
let layers = snapshot.syntax.layers(buffer.as_text_snapshot());
|
||||||
layers[0].node.to_sexp()
|
layers[0].node().to_sexp()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ use futures::{
|
|||||||
future::{BoxFuture, Shared},
|
future::{BoxFuture, Shared},
|
||||||
FutureExt, TryFutureExt as _,
|
FutureExt, TryFutureExt as _,
|
||||||
};
|
};
|
||||||
use gpui::{executor::Background, AppContext, Task};
|
use gpui::{executor::Background, AppContext, AsyncAppContext, Task};
|
||||||
use highlight_map::HighlightMap;
|
use highlight_map::HighlightMap;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use lsp::CodeActionKind;
|
use lsp::CodeActionKind;
|
||||||
@ -57,6 +57,7 @@ pub use buffer::*;
|
|||||||
pub use diagnostic_set::DiagnosticEntry;
|
pub use diagnostic_set::DiagnosticEntry;
|
||||||
pub use lsp::LanguageServerId;
|
pub use lsp::LanguageServerId;
|
||||||
pub use outline::{Outline, OutlineItem};
|
pub use outline::{Outline, OutlineItem};
|
||||||
|
pub use syntax_map::{OwnedSyntaxLayerInfo, SyntaxLayerInfo};
|
||||||
pub use tree_sitter::{Parser, Tree};
|
pub use tree_sitter::{Parser, Tree};
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
@ -124,27 +125,46 @@ impl CachedLspAdapter {
|
|||||||
|
|
||||||
pub async fn fetch_latest_server_version(
|
pub async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
http: Arc<dyn HttpClient>,
|
delegate: &dyn LspAdapterDelegate,
|
||||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||||
self.adapter.fetch_latest_server_version(http).await
|
self.adapter.fetch_latest_server_version(delegate).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn will_fetch_server(
|
||||||
|
&self,
|
||||||
|
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||||
|
cx: &mut AsyncAppContext,
|
||||||
|
) -> Option<Task<Result<()>>> {
|
||||||
|
self.adapter.will_fetch_server(delegate, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn will_start_server(
|
||||||
|
&self,
|
||||||
|
delegate: &Arc<dyn LspAdapterDelegate>,
|
||||||
|
cx: &mut AsyncAppContext,
|
||||||
|
) -> Option<Task<Result<()>>> {
|
||||||
|
self.adapter.will_start_server(delegate, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_server_binary(
|
pub async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
version: Box<dyn 'static + Send + Any>,
|
version: Box<dyn 'static + Send + Any>,
|
||||||
http: Arc<dyn HttpClient>,
|
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
|
delegate: &dyn LspAdapterDelegate,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
self.adapter
|
self.adapter
|
||||||
.fetch_server_binary(version, http, container_dir)
|
.fetch_server_binary(version, container_dir, delegate)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cached_server_binary(
|
pub async fn cached_server_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
|
delegate: &dyn LspAdapterDelegate,
|
||||||
) -> Option<LanguageServerBinary> {
|
) -> Option<LanguageServerBinary> {
|
||||||
self.adapter.cached_server_binary(container_dir).await
|
self.adapter
|
||||||
|
.cached_server_binary(container_dir, delegate)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
|
pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
|
||||||
@ -186,23 +206,48 @@ impl CachedLspAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait LspAdapterDelegate: Send + Sync {
|
||||||
|
fn show_notification(&self, message: &str, cx: &mut AppContext);
|
||||||
|
fn http_client(&self) -> Arc<dyn HttpClient>;
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait LspAdapter: 'static + Send + Sync {
|
pub trait LspAdapter: 'static + Send + Sync {
|
||||||
async fn name(&self) -> LanguageServerName;
|
async fn name(&self) -> LanguageServerName;
|
||||||
|
|
||||||
async fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
http: Arc<dyn HttpClient>,
|
delegate: &dyn LspAdapterDelegate,
|
||||||
) -> Result<Box<dyn 'static + Send + Any>>;
|
) -> Result<Box<dyn 'static + Send + Any>>;
|
||||||
|
|
||||||
|
fn will_fetch_server(
|
||||||
|
&self,
|
||||||
|
_: &Arc<dyn LspAdapterDelegate>,
|
||||||
|
_: &mut AsyncAppContext,
|
||||||
|
) -> Option<Task<Result<()>>> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn will_start_server(
|
||||||
|
&self,
|
||||||
|
_: &Arc<dyn LspAdapterDelegate>,
|
||||||
|
_: &mut AsyncAppContext,
|
||||||
|
) -> Option<Task<Result<()>>> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
async fn fetch_server_binary(
|
async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
version: Box<dyn 'static + Send + Any>,
|
version: Box<dyn 'static + Send + Any>,
|
||||||
http: Arc<dyn HttpClient>,
|
|
||||||
container_dir: PathBuf,
|
container_dir: PathBuf,
|
||||||
|
delegate: &dyn LspAdapterDelegate,
|
||||||
) -> Result<LanguageServerBinary>;
|
) -> Result<LanguageServerBinary>;
|
||||||
|
|
||||||
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<LanguageServerBinary>;
|
async fn cached_server_binary(
|
||||||
|
&self,
|
||||||
|
container_dir: PathBuf,
|
||||||
|
delegate: &dyn LspAdapterDelegate,
|
||||||
|
) -> Option<LanguageServerBinary>;
|
||||||
|
|
||||||
async fn process_diagnostics(&self, _: &mut lsp::PublishDiagnosticsParams) {}
|
async fn process_diagnostics(&self, _: &mut lsp::PublishDiagnosticsParams) {}
|
||||||
|
|
||||||
@ -512,10 +557,7 @@ pub struct LanguageRegistry {
|
|||||||
login_shell_env_loaded: Shared<Task<()>>,
|
login_shell_env_loaded: Shared<Task<()>>,
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
lsp_binary_paths: Mutex<
|
lsp_binary_paths: Mutex<
|
||||||
HashMap<
|
HashMap<LanguageServerName, Shared<Task<Result<LanguageServerBinary, Arc<anyhow::Error>>>>>,
|
||||||
LanguageServerName,
|
|
||||||
Shared<BoxFuture<'static, Result<LanguageServerBinary, Arc<anyhow::Error>>>>,
|
|
||||||
>,
|
|
||||||
>,
|
>,
|
||||||
executor: Option<Arc<Background>>,
|
executor: Option<Arc<Background>>,
|
||||||
}
|
}
|
||||||
@ -811,7 +853,7 @@ impl LanguageRegistry {
|
|||||||
language: Arc<Language>,
|
language: Arc<Language>,
|
||||||
adapter: Arc<CachedLspAdapter>,
|
adapter: Arc<CachedLspAdapter>,
|
||||||
root_path: Arc<Path>,
|
root_path: Arc<Path>,
|
||||||
http_client: Arc<dyn HttpClient>,
|
delegate: Arc<dyn LspAdapterDelegate>,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) -> Option<PendingLanguageServer> {
|
) -> Option<PendingLanguageServer> {
|
||||||
let server_id = self.state.write().next_language_server_id();
|
let server_id = self.state.write().next_language_server_id();
|
||||||
@ -859,35 +901,40 @@ impl LanguageRegistry {
|
|||||||
.log_err()?;
|
.log_err()?;
|
||||||
let this = self.clone();
|
let this = self.clone();
|
||||||
let language = language.clone();
|
let language = language.clone();
|
||||||
let http_client = http_client.clone();
|
|
||||||
let download_dir = download_dir.clone();
|
let download_dir = download_dir.clone();
|
||||||
let root_path = root_path.clone();
|
let root_path = root_path.clone();
|
||||||
let adapter = adapter.clone();
|
let adapter = adapter.clone();
|
||||||
let lsp_binary_statuses = self.lsp_binary_statuses_tx.clone();
|
let lsp_binary_statuses = self.lsp_binary_statuses_tx.clone();
|
||||||
let login_shell_env_loaded = self.login_shell_env_loaded.clone();
|
let login_shell_env_loaded = self.login_shell_env_loaded.clone();
|
||||||
|
|
||||||
let task = cx.spawn(|cx| async move {
|
let task = cx.spawn(|mut cx| async move {
|
||||||
login_shell_env_loaded.await;
|
login_shell_env_loaded.await;
|
||||||
|
|
||||||
let mut lock = this.lsp_binary_paths.lock();
|
let entry = this
|
||||||
let entry = lock
|
.lsp_binary_paths
|
||||||
|
.lock()
|
||||||
.entry(adapter.name.clone())
|
.entry(adapter.name.clone())
|
||||||
.or_insert_with(|| {
|
.or_insert_with(|| {
|
||||||
get_binary(
|
cx.spawn(|cx| {
|
||||||
adapter.clone(),
|
get_binary(
|
||||||
language.clone(),
|
adapter.clone(),
|
||||||
http_client,
|
language.clone(),
|
||||||
download_dir,
|
delegate.clone(),
|
||||||
lsp_binary_statuses,
|
download_dir,
|
||||||
)
|
lsp_binary_statuses,
|
||||||
.map_err(Arc::new)
|
cx,
|
||||||
.boxed()
|
)
|
||||||
|
.map_err(Arc::new)
|
||||||
|
})
|
||||||
.shared()
|
.shared()
|
||||||
})
|
})
|
||||||
.clone();
|
.clone();
|
||||||
drop(lock);
|
|
||||||
let binary = entry.clone().map_err(|e| anyhow!(e)).await?;
|
let binary = entry.clone().map_err(|e| anyhow!(e)).await?;
|
||||||
|
|
||||||
|
if let Some(task) = adapter.will_start_server(&delegate, &mut cx) {
|
||||||
|
task.await?;
|
||||||
|
}
|
||||||
|
|
||||||
let server = lsp::LanguageServer::new(
|
let server = lsp::LanguageServer::new(
|
||||||
server_id,
|
server_id,
|
||||||
&binary.path,
|
&binary.path,
|
||||||
@ -957,9 +1004,10 @@ impl Default for LanguageRegistry {
|
|||||||
async fn get_binary(
|
async fn get_binary(
|
||||||
adapter: Arc<CachedLspAdapter>,
|
adapter: Arc<CachedLspAdapter>,
|
||||||
language: Arc<Language>,
|
language: Arc<Language>,
|
||||||
http_client: Arc<dyn HttpClient>,
|
delegate: Arc<dyn LspAdapterDelegate>,
|
||||||
download_dir: Arc<Path>,
|
download_dir: Arc<Path>,
|
||||||
statuses: async_broadcast::Sender<(Arc<Language>, LanguageServerBinaryStatus)>,
|
statuses: async_broadcast::Sender<(Arc<Language>, LanguageServerBinaryStatus)>,
|
||||||
|
mut cx: AsyncAppContext,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
let container_dir = download_dir.join(adapter.name.0.as_ref());
|
let container_dir = download_dir.join(adapter.name.0.as_ref());
|
||||||
if !container_dir.exists() {
|
if !container_dir.exists() {
|
||||||
@ -968,17 +1016,24 @@ async fn get_binary(
|
|||||||
.context("failed to create container directory")?;
|
.context("failed to create container directory")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(task) = adapter.will_fetch_server(&delegate, &mut cx) {
|
||||||
|
task.await?;
|
||||||
|
}
|
||||||
|
|
||||||
let binary = fetch_latest_binary(
|
let binary = fetch_latest_binary(
|
||||||
adapter.clone(),
|
adapter.clone(),
|
||||||
language.clone(),
|
language.clone(),
|
||||||
http_client,
|
delegate.as_ref(),
|
||||||
&container_dir,
|
&container_dir,
|
||||||
statuses.clone(),
|
statuses.clone(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Err(error) = binary.as_ref() {
|
if let Err(error) = binary.as_ref() {
|
||||||
if let Some(cached) = adapter.cached_server_binary(container_dir).await {
|
if let Some(cached) = adapter
|
||||||
|
.cached_server_binary(container_dir, delegate.as_ref())
|
||||||
|
.await
|
||||||
|
{
|
||||||
statuses
|
statuses
|
||||||
.broadcast((language.clone(), LanguageServerBinaryStatus::Cached))
|
.broadcast((language.clone(), LanguageServerBinaryStatus::Cached))
|
||||||
.await?;
|
.await?;
|
||||||
@ -1000,7 +1055,7 @@ async fn get_binary(
|
|||||||
async fn fetch_latest_binary(
|
async fn fetch_latest_binary(
|
||||||
adapter: Arc<CachedLspAdapter>,
|
adapter: Arc<CachedLspAdapter>,
|
||||||
language: Arc<Language>,
|
language: Arc<Language>,
|
||||||
http_client: Arc<dyn HttpClient>,
|
delegate: &dyn LspAdapterDelegate,
|
||||||
container_dir: &Path,
|
container_dir: &Path,
|
||||||
lsp_binary_statuses_tx: async_broadcast::Sender<(Arc<Language>, LanguageServerBinaryStatus)>,
|
lsp_binary_statuses_tx: async_broadcast::Sender<(Arc<Language>, LanguageServerBinaryStatus)>,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
@ -1011,14 +1066,12 @@ async fn fetch_latest_binary(
|
|||||||
LanguageServerBinaryStatus::CheckingForUpdate,
|
LanguageServerBinaryStatus::CheckingForUpdate,
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
let version_info = adapter
|
let version_info = adapter.fetch_latest_server_version(delegate).await?;
|
||||||
.fetch_latest_server_version(http_client.clone())
|
|
||||||
.await?;
|
|
||||||
lsp_binary_statuses_tx
|
lsp_binary_statuses_tx
|
||||||
.broadcast((language.clone(), LanguageServerBinaryStatus::Downloading))
|
.broadcast((language.clone(), LanguageServerBinaryStatus::Downloading))
|
||||||
.await?;
|
.await?;
|
||||||
let binary = adapter
|
let binary = adapter
|
||||||
.fetch_server_binary(version_info, http_client, container_dir.to_path_buf())
|
.fetch_server_binary(version_info, container_dir.to_path_buf(), delegate)
|
||||||
.await?;
|
.await?;
|
||||||
lsp_binary_statuses_tx
|
lsp_binary_statuses_tx
|
||||||
.broadcast((language.clone(), LanguageServerBinaryStatus::Downloaded))
|
.broadcast((language.clone(), LanguageServerBinaryStatus::Downloaded))
|
||||||
@ -1542,7 +1595,7 @@ impl LspAdapter for Arc<FakeLspAdapter> {
|
|||||||
|
|
||||||
async fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
_: Arc<dyn HttpClient>,
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
@ -1550,13 +1603,17 @@ impl LspAdapter for Arc<FakeLspAdapter> {
|
|||||||
async fn fetch_server_binary(
|
async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
_: Box<dyn 'static + Send + Any>,
|
_: Box<dyn 'static + Send + Any>,
|
||||||
_: Arc<dyn HttpClient>,
|
|
||||||
_: PathBuf,
|
_: PathBuf,
|
||||||
|
_: &dyn LspAdapterDelegate,
|
||||||
) -> Result<LanguageServerBinary> {
|
) -> Result<LanguageServerBinary> {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cached_server_binary(&self, _: PathBuf) -> Option<LanguageServerBinary> {
|
async fn cached_server_binary(
|
||||||
|
&self,
|
||||||
|
_: PathBuf,
|
||||||
|
_: &dyn LspAdapterDelegate,
|
||||||
|
) -> Option<LanguageServerBinary> {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ pub struct LanguageSettings {
|
|||||||
pub enable_language_server: bool,
|
pub enable_language_server: bool,
|
||||||
pub show_copilot_suggestions: bool,
|
pub show_copilot_suggestions: bool,
|
||||||
pub show_whitespaces: ShowWhitespaceSetting,
|
pub show_whitespaces: ShowWhitespaceSetting,
|
||||||
|
pub extend_comment_on_newline: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
@ -95,6 +96,8 @@ pub struct LanguageSettingsContent {
|
|||||||
pub show_copilot_suggestions: Option<bool>,
|
pub show_copilot_suggestions: Option<bool>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub show_whitespaces: Option<ShowWhitespaceSetting>,
|
pub show_whitespaces: Option<ShowWhitespaceSetting>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub extend_comment_on_newline: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||||
@ -340,7 +343,10 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
|
|||||||
src.show_copilot_suggestions,
|
src.show_copilot_suggestions,
|
||||||
);
|
);
|
||||||
merge(&mut settings.show_whitespaces, src.show_whitespaces);
|
merge(&mut settings.show_whitespaces, src.show_whitespaces);
|
||||||
|
merge(
|
||||||
|
&mut settings.extend_comment_on_newline,
|
||||||
|
src.extend_comment_on_newline,
|
||||||
|
);
|
||||||
fn merge<T>(target: &mut T, value: Option<T>) {
|
fn merge<T>(target: &mut T, value: Option<T>) {
|
||||||
if let Some(value) = value {
|
if let Some(value) = value {
|
||||||
*target = value;
|
*target = value;
|
||||||
|
File diff suppressed because it is too large
Load Diff
1199
crates/language/src/syntax_map/syntax_map_tests.rs
Normal file
1199
crates/language/src/syntax_map/syntax_map_tests.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -55,7 +55,7 @@ impl View for ActiveBufferLanguage {
|
|||||||
|
|
||||||
MouseEventHandler::<Self, Self>::new(0, cx, |state, cx| {
|
MouseEventHandler::<Self, Self>::new(0, cx, |state, cx| {
|
||||||
let theme = &theme::current(cx).workspace.status_bar;
|
let theme = &theme::current(cx).workspace.status_bar;
|
||||||
let style = theme.active_language.style_for(state, false);
|
let style = theme.active_language.style_for(state);
|
||||||
Label::new(active_language_text, style.text.clone())
|
Label::new(active_language_text, style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
|
@ -180,7 +180,7 @@ impl PickerDelegate for LanguageSelectorDelegate {
|
|||||||
) -> AnyElement<Picker<Self>> {
|
) -> AnyElement<Picker<Self>> {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let mat = &self.matches[ix];
|
let mat = &self.matches[ix];
|
||||||
let style = theme.picker.item.style_for(mouse_state, selected);
|
let style = theme.picker.item.in_state(selected).style_for(mouse_state);
|
||||||
let buffer_language_name = self.buffer.read(cx).language().map(|l| l.name());
|
let buffer_language_name = self.buffer.read(cx).language().map(|l| l.name());
|
||||||
let mut label = mat.string.clone();
|
let mut label = mat.string.clone();
|
||||||
if buffer_language_name.as_deref() == Some(mat.string.as_str()) {
|
if buffer_language_name.as_deref() == Some(mat.string.as_str()) {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lsp_log"
|
name = "language_tools"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "src/lsp_log.rs"
|
path = "src/language_tools.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -22,6 +22,7 @@ lsp = { path = "../lsp" }
|
|||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
tree-sitter.workspace = true
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
client = { path = "../client", features = ["test-support"] }
|
client = { path = "../client", features = ["test-support"] }
|
15
crates/language_tools/src/language_tools.rs
Normal file
15
crates/language_tools/src/language_tools.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
mod lsp_log;
|
||||||
|
mod syntax_tree_view;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod lsp_log_tests;
|
||||||
|
|
||||||
|
use gpui::AppContext;
|
||||||
|
|
||||||
|
pub use lsp_log::{LogStore, LspLogToolbarItemView, LspLogView};
|
||||||
|
pub use syntax_tree_view::{SyntaxTreeToolbarItemView, SyntaxTreeView};
|
||||||
|
|
||||||
|
pub fn init(cx: &mut AppContext) {
|
||||||
|
lsp_log::init(cx);
|
||||||
|
syntax_tree_view::init(cx);
|
||||||
|
}
|
@ -1,6 +1,3 @@
|
|||||||
#[cfg(test)]
|
|
||||||
mod lsp_log_tests;
|
|
||||||
|
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use editor::Editor;
|
use editor::Editor;
|
||||||
use futures::{channel::mpsc, StreamExt};
|
use futures::{channel::mpsc, StreamExt};
|
||||||
@ -27,7 +24,7 @@ use workspace::{
|
|||||||
const SEND_LINE: &str = "// Send:\n";
|
const SEND_LINE: &str = "// Send:\n";
|
||||||
const RECEIVE_LINE: &str = "// Receive:\n";
|
const RECEIVE_LINE: &str = "// Receive:\n";
|
||||||
|
|
||||||
struct LogStore {
|
pub struct LogStore {
|
||||||
projects: HashMap<WeakModelHandle<Project>, ProjectState>,
|
projects: HashMap<WeakModelHandle<Project>, ProjectState>,
|
||||||
io_tx: mpsc::UnboundedSender<(WeakModelHandle<Project>, LanguageServerId, bool, String)>,
|
io_tx: mpsc::UnboundedSender<(WeakModelHandle<Project>, LanguageServerId, bool, String)>,
|
||||||
}
|
}
|
||||||
@ -49,10 +46,10 @@ struct LanguageServerRpcState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct LspLogView {
|
pub struct LspLogView {
|
||||||
|
pub(crate) editor: ViewHandle<Editor>,
|
||||||
log_store: ModelHandle<LogStore>,
|
log_store: ModelHandle<LogStore>,
|
||||||
current_server_id: Option<LanguageServerId>,
|
current_server_id: Option<LanguageServerId>,
|
||||||
is_showing_rpc_trace: bool,
|
is_showing_rpc_trace: bool,
|
||||||
editor: ViewHandle<Editor>,
|
|
||||||
project: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,16 +65,16 @@ enum MessageKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
struct LogMenuItem {
|
pub(crate) struct LogMenuItem {
|
||||||
server_id: LanguageServerId,
|
pub server_id: LanguageServerId,
|
||||||
server_name: LanguageServerName,
|
pub server_name: LanguageServerName,
|
||||||
worktree: ModelHandle<Worktree>,
|
pub worktree: ModelHandle<Worktree>,
|
||||||
rpc_trace_enabled: bool,
|
pub rpc_trace_enabled: bool,
|
||||||
rpc_trace_selected: bool,
|
pub rpc_trace_selected: bool,
|
||||||
logs_selected: bool,
|
pub logs_selected: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
actions!(log, [OpenLanguageServerLogs]);
|
actions!(debug, [OpenLanguageServerLogs]);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
let log_store = cx.add_model(|cx| LogStore::new(cx));
|
let log_store = cx.add_model(|cx| LogStore::new(cx));
|
||||||
@ -114,7 +111,7 @@ pub fn init(cx: &mut AppContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LogStore {
|
impl LogStore {
|
||||||
fn new(cx: &mut ModelContext<Self>) -> Self {
|
pub fn new(cx: &mut ModelContext<Self>) -> Self {
|
||||||
let (io_tx, mut io_rx) = mpsc::unbounded();
|
let (io_tx, mut io_rx) = mpsc::unbounded();
|
||||||
let this = Self {
|
let this = Self {
|
||||||
projects: HashMap::default(),
|
projects: HashMap::default(),
|
||||||
@ -320,7 +317,7 @@ impl LogStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LspLogView {
|
impl LspLogView {
|
||||||
fn new(
|
pub fn new(
|
||||||
project: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
log_store: ModelHandle<LogStore>,
|
log_store: ModelHandle<LogStore>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
@ -360,7 +357,7 @@ impl LspLogView {
|
|||||||
editor
|
editor
|
||||||
}
|
}
|
||||||
|
|
||||||
fn menu_items<'a>(&'a self, cx: &'a AppContext) -> Option<Vec<LogMenuItem>> {
|
pub(crate) fn menu_items<'a>(&'a self, cx: &'a AppContext) -> Option<Vec<LogMenuItem>> {
|
||||||
let log_store = self.log_store.read(cx);
|
let log_store = self.log_store.read(cx);
|
||||||
let state = log_store.projects.get(&self.project.downgrade())?;
|
let state = log_store.projects.get(&self.project.downgrade())?;
|
||||||
let mut rows = self
|
let mut rows = self
|
||||||
@ -544,12 +541,7 @@ impl View for LspLogToolbarItemView {
|
|||||||
let theme = theme::current(cx).clone();
|
let theme = theme::current(cx).clone();
|
||||||
let Some(log_view) = self.log_view.as_ref() else { return Empty::new().into_any() };
|
let Some(log_view) = self.log_view.as_ref() else { return Empty::new().into_any() };
|
||||||
let log_view = log_view.read(cx);
|
let log_view = log_view.read(cx);
|
||||||
|
let menu_rows = log_view.menu_items(cx).unwrap_or_default();
|
||||||
let menu_rows = self
|
|
||||||
.log_view
|
|
||||||
.as_ref()
|
|
||||||
.and_then(|view| view.read(cx).menu_items(cx))
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let current_server_id = log_view.current_server_id;
|
let current_server_id = log_view.current_server_id;
|
||||||
let current_server = current_server_id.and_then(|current_server_id| {
|
let current_server = current_server_id.and_then(|current_server_id| {
|
||||||
@ -586,7 +578,7 @@ impl View for LspLogToolbarItemView {
|
|||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(theme.lsp_log_menu.container)
|
.with_style(theme.toolbar_dropdown_menu.container)
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_width(400.)
|
.with_width(400.)
|
||||||
.with_height(400.)
|
.with_height(400.)
|
||||||
@ -596,6 +588,7 @@ impl View for LspLogToolbarItemView {
|
|||||||
cx.notify()
|
cx.notify()
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
.with_hoverable(true)
|
||||||
.with_fit_mode(OverlayFitMode::SwitchAnchor)
|
.with_fit_mode(OverlayFitMode::SwitchAnchor)
|
||||||
.with_anchor_corner(AnchorCorner::TopLeft)
|
.with_anchor_corner(AnchorCorner::TopLeft)
|
||||||
.with_z_index(999)
|
.with_z_index(999)
|
||||||
@ -688,7 +681,7 @@ impl LspLogToolbarItemView {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| "No server selected".into());
|
.unwrap_or_else(|| "No server selected".into());
|
||||||
let style = theme.lsp_log_menu.header.style_for(state, false);
|
let style = theme.toolbar_dropdown_menu.header.style_for(state);
|
||||||
Label::new(label, style.text.clone())
|
Label::new(label, style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
@ -714,7 +707,7 @@ impl LspLogToolbarItemView {
|
|||||||
|
|
||||||
Flex::column()
|
Flex::column()
|
||||||
.with_child({
|
.with_child({
|
||||||
let style = &theme.lsp_log_menu.server;
|
let style = &theme.toolbar_dropdown_menu.section_header;
|
||||||
Label::new(
|
Label::new(
|
||||||
format!("{} ({})", name.0, worktree.read(cx).root_name()),
|
format!("{} ({})", name.0, worktree.read(cx).root_name()),
|
||||||
style.text.clone(),
|
style.text.clone(),
|
||||||
@ -722,16 +715,20 @@ impl LspLogToolbarItemView {
|
|||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_height(theme.lsp_log_menu.row_height)
|
.with_height(theme.toolbar_dropdown_menu.row_height)
|
||||||
})
|
})
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<ActivateLog, _>::new(id.0, cx, move |state, _| {
|
MouseEventHandler::<ActivateLog, _>::new(id.0, cx, move |state, _| {
|
||||||
let style = theme.lsp_log_menu.item.style_for(state, logs_selected);
|
let style = theme
|
||||||
|
.toolbar_dropdown_menu
|
||||||
|
.item
|
||||||
|
.in_state(logs_selected)
|
||||||
|
.style_for(state);
|
||||||
Label::new(SERVER_LOGS, style.text.clone())
|
Label::new(SERVER_LOGS, style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_height(theme.lsp_log_menu.row_height)
|
.with_height(theme.toolbar_dropdown_menu.row_height)
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.on_click(MouseButton::Left, move |_, view, cx| {
|
.on_click(MouseButton::Left, move |_, view, cx| {
|
||||||
@ -740,12 +737,16 @@ impl LspLogToolbarItemView {
|
|||||||
)
|
)
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<ActivateRpcTrace, _>::new(id.0, cx, move |state, cx| {
|
MouseEventHandler::<ActivateRpcTrace, _>::new(id.0, cx, move |state, cx| {
|
||||||
let style = theme.lsp_log_menu.item.style_for(state, rpc_trace_selected);
|
let style = theme
|
||||||
|
.toolbar_dropdown_menu
|
||||||
|
.item
|
||||||
|
.in_state(rpc_trace_selected)
|
||||||
|
.style_for(state);
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
Label::new(RPC_MESSAGES, style.text.clone())
|
Label::new(RPC_MESSAGES, style.text.clone())
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_height(theme.lsp_log_menu.row_height),
|
.with_height(theme.toolbar_dropdown_menu.row_height),
|
||||||
)
|
)
|
||||||
.with_child(
|
.with_child(
|
||||||
ui::checkbox_with_label::<Self, _, Self, _>(
|
ui::checkbox_with_label::<Self, _, Self, _>(
|
||||||
@ -764,7 +765,7 @@ impl LspLogToolbarItemView {
|
|||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_height(theme.lsp_log_menu.row_height)
|
.with_height(theme.toolbar_dropdown_menu.row_height)
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.on_click(MouseButton::Left, move |_, view, cx| {
|
.on_click(MouseButton::Left, move |_, view, cx| {
|
@ -1,7 +1,12 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::lsp_log::LogMenuItem;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use futures::StreamExt;
|
||||||
use gpui::{serde_json::json, TestAppContext};
|
use gpui::{serde_json::json, TestAppContext};
|
||||||
use language::{tree_sitter_rust, FakeLspAdapter, Language, LanguageConfig};
|
use language::{tree_sitter_rust, FakeLspAdapter, Language, LanguageConfig, LanguageServerName};
|
||||||
use project::FakeFs;
|
use project::{FakeFs, Project};
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
676
crates/language_tools/src/syntax_tree_view.rs
Normal file
676
crates/language_tools/src/syntax_tree_view.rs
Normal file
@ -0,0 +1,676 @@
|
|||||||
|
use editor::{scroll::autoscroll::Autoscroll, Anchor, Editor, ExcerptId};
|
||||||
|
use gpui::{
|
||||||
|
actions,
|
||||||
|
elements::{
|
||||||
|
AnchorCorner, Empty, Flex, Label, MouseEventHandler, Overlay, OverlayFitMode,
|
||||||
|
ParentElement, ScrollTarget, Stack, UniformList, UniformListState,
|
||||||
|
},
|
||||||
|
fonts::TextStyle,
|
||||||
|
platform::{CursorStyle, MouseButton},
|
||||||
|
AppContext, Element, Entity, ModelHandle, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||||
|
};
|
||||||
|
use language::{Buffer, OwnedSyntaxLayerInfo, SyntaxLayerInfo};
|
||||||
|
use std::{mem, ops::Range, sync::Arc};
|
||||||
|
use theme::{Theme, ThemeSettings};
|
||||||
|
use tree_sitter::{Node, TreeCursor};
|
||||||
|
use workspace::{
|
||||||
|
item::{Item, ItemHandle},
|
||||||
|
ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||||
|
};
|
||||||
|
|
||||||
|
actions!(debug, [OpenSyntaxTreeView]);
|
||||||
|
|
||||||
|
pub fn init(cx: &mut AppContext) {
|
||||||
|
cx.add_action(
|
||||||
|
move |workspace: &mut Workspace, _: &OpenSyntaxTreeView, cx: _| {
|
||||||
|
let active_item = workspace.active_item(cx);
|
||||||
|
let workspace_handle = workspace.weak_handle();
|
||||||
|
let syntax_tree_view =
|
||||||
|
cx.add_view(|cx| SyntaxTreeView::new(workspace_handle, active_item, cx));
|
||||||
|
workspace.add_item(Box::new(syntax_tree_view), cx);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SyntaxTreeView {
|
||||||
|
workspace_handle: WeakViewHandle<Workspace>,
|
||||||
|
editor: Option<EditorState>,
|
||||||
|
mouse_y: Option<f32>,
|
||||||
|
line_height: Option<f32>,
|
||||||
|
list_state: UniformListState,
|
||||||
|
selected_descendant_ix: Option<usize>,
|
||||||
|
hovered_descendant_ix: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SyntaxTreeToolbarItemView {
|
||||||
|
tree_view: Option<ViewHandle<SyntaxTreeView>>,
|
||||||
|
subscription: Option<gpui::Subscription>,
|
||||||
|
menu_open: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct EditorState {
|
||||||
|
editor: ViewHandle<Editor>,
|
||||||
|
active_buffer: Option<BufferState>,
|
||||||
|
_subscription: gpui::Subscription,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct BufferState {
|
||||||
|
buffer: ModelHandle<Buffer>,
|
||||||
|
excerpt_id: ExcerptId,
|
||||||
|
active_layer: Option<OwnedSyntaxLayerInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SyntaxTreeView {
|
||||||
|
pub fn new(
|
||||||
|
workspace_handle: WeakViewHandle<Workspace>,
|
||||||
|
active_item: Option<Box<dyn ItemHandle>>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> Self {
|
||||||
|
let mut this = Self {
|
||||||
|
workspace_handle: workspace_handle.clone(),
|
||||||
|
list_state: UniformListState::default(),
|
||||||
|
editor: None,
|
||||||
|
mouse_y: None,
|
||||||
|
line_height: None,
|
||||||
|
hovered_descendant_ix: None,
|
||||||
|
selected_descendant_ix: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.workspace_updated(active_item, cx);
|
||||||
|
cx.observe(
|
||||||
|
&workspace_handle.upgrade(cx).unwrap(),
|
||||||
|
|this, workspace, cx| {
|
||||||
|
this.workspace_updated(workspace.read(cx).active_item(cx), cx);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
|
fn workspace_updated(
|
||||||
|
&mut self,
|
||||||
|
active_item: Option<Box<dyn ItemHandle>>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) {
|
||||||
|
if let Some(item) = active_item {
|
||||||
|
if item.id() != cx.view_id() {
|
||||||
|
if let Some(editor) = item.act_as::<Editor>(cx) {
|
||||||
|
self.set_editor(editor, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_editor(&mut self, editor: ViewHandle<Editor>, cx: &mut ViewContext<Self>) {
|
||||||
|
if let Some(state) = &self.editor {
|
||||||
|
if state.editor == editor {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editor.update(cx, |editor, cx| {
|
||||||
|
editor.clear_background_highlights::<Self>(cx)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let subscription = cx.subscribe(&editor, |this, _, event, cx| {
|
||||||
|
let did_reparse = match event {
|
||||||
|
editor::Event::Reparsed => true,
|
||||||
|
editor::Event::SelectionsChanged { .. } => false,
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
this.editor_updated(did_reparse, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.editor = Some(EditorState {
|
||||||
|
editor,
|
||||||
|
_subscription: subscription,
|
||||||
|
active_buffer: None,
|
||||||
|
});
|
||||||
|
self.editor_updated(true, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn editor_updated(&mut self, did_reparse: bool, cx: &mut ViewContext<Self>) -> Option<()> {
|
||||||
|
// Find which excerpt the cursor is in, and the position within that excerpted buffer.
|
||||||
|
let editor_state = self.editor.as_mut()?;
|
||||||
|
let editor = &editor_state.editor.read(cx);
|
||||||
|
let selection_range = editor.selections.last::<usize>(cx).range();
|
||||||
|
let multibuffer = editor.buffer().read(cx);
|
||||||
|
let (buffer, range, excerpt_id) = multibuffer
|
||||||
|
.range_to_buffer_ranges(selection_range, cx)
|
||||||
|
.pop()?;
|
||||||
|
|
||||||
|
// If the cursor has moved into a different excerpt, retrieve a new syntax layer
|
||||||
|
// from that buffer.
|
||||||
|
let buffer_state = editor_state
|
||||||
|
.active_buffer
|
||||||
|
.get_or_insert_with(|| BufferState {
|
||||||
|
buffer: buffer.clone(),
|
||||||
|
excerpt_id,
|
||||||
|
active_layer: None,
|
||||||
|
});
|
||||||
|
let mut prev_layer = None;
|
||||||
|
if did_reparse {
|
||||||
|
prev_layer = buffer_state.active_layer.take();
|
||||||
|
}
|
||||||
|
if buffer_state.buffer != buffer || buffer_state.excerpt_id != buffer_state.excerpt_id {
|
||||||
|
buffer_state.buffer = buffer.clone();
|
||||||
|
buffer_state.excerpt_id = excerpt_id;
|
||||||
|
buffer_state.active_layer = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let layer = match &mut buffer_state.active_layer {
|
||||||
|
Some(layer) => layer,
|
||||||
|
None => {
|
||||||
|
let snapshot = buffer.read(cx).snapshot();
|
||||||
|
let layer = if let Some(prev_layer) = prev_layer {
|
||||||
|
let prev_range = prev_layer.node().byte_range();
|
||||||
|
snapshot
|
||||||
|
.syntax_layers()
|
||||||
|
.filter(|layer| layer.language == &prev_layer.language)
|
||||||
|
.min_by_key(|layer| {
|
||||||
|
let range = layer.node().byte_range();
|
||||||
|
((range.start as i64) - (prev_range.start as i64)).abs()
|
||||||
|
+ ((range.end as i64) - (prev_range.end as i64)).abs()
|
||||||
|
})?
|
||||||
|
} else {
|
||||||
|
snapshot.syntax_layers().next()?
|
||||||
|
};
|
||||||
|
buffer_state.active_layer.insert(layer.to_owned())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Within the active layer, find the syntax node under the cursor,
|
||||||
|
// and scroll to it.
|
||||||
|
let mut cursor = layer.node().walk();
|
||||||
|
while cursor.goto_first_child_for_byte(range.start).is_some() {
|
||||||
|
if !range.is_empty() && cursor.node().end_byte() == range.start {
|
||||||
|
cursor.goto_next_sibling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ascend to the smallest ancestor that contains the range.
|
||||||
|
loop {
|
||||||
|
let node_range = cursor.node().byte_range();
|
||||||
|
if node_range.start <= range.start && node_range.end >= range.end {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if !cursor.goto_parent() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let descendant_ix = cursor.descendant_index();
|
||||||
|
self.selected_descendant_ix = Some(descendant_ix);
|
||||||
|
self.list_state.scroll_to(ScrollTarget::Show(descendant_ix));
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_click(&mut self, y: f32, cx: &mut ViewContext<SyntaxTreeView>) -> Option<()> {
|
||||||
|
let line_height = self.line_height?;
|
||||||
|
let ix = ((self.list_state.scroll_top() + y) / line_height) as usize;
|
||||||
|
|
||||||
|
self.update_editor_with_range_for_descendant_ix(ix, cx, |editor, mut range, cx| {
|
||||||
|
// Put the cursor at the beginning of the node.
|
||||||
|
mem::swap(&mut range.start, &mut range.end);
|
||||||
|
|
||||||
|
editor.change_selections(Some(Autoscroll::newest()), cx, |selections| {
|
||||||
|
selections.select_ranges(vec![range]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hover_state_changed(&mut self, cx: &mut ViewContext<SyntaxTreeView>) {
|
||||||
|
if let Some((y, line_height)) = self.mouse_y.zip(self.line_height) {
|
||||||
|
let ix = ((self.list_state.scroll_top() + y) / line_height) as usize;
|
||||||
|
if self.hovered_descendant_ix != Some(ix) {
|
||||||
|
self.hovered_descendant_ix = Some(ix);
|
||||||
|
self.update_editor_with_range_for_descendant_ix(ix, cx, |editor, range, cx| {
|
||||||
|
editor.clear_background_highlights::<Self>(cx);
|
||||||
|
editor.highlight_background::<Self>(
|
||||||
|
vec![range],
|
||||||
|
|theme| theme.editor.document_highlight_write_background,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_editor_with_range_for_descendant_ix(
|
||||||
|
&self,
|
||||||
|
descendant_ix: usize,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
mut f: impl FnMut(&mut Editor, Range<Anchor>, &mut ViewContext<Editor>),
|
||||||
|
) -> Option<()> {
|
||||||
|
let editor_state = self.editor.as_ref()?;
|
||||||
|
let buffer_state = editor_state.active_buffer.as_ref()?;
|
||||||
|
let layer = buffer_state.active_layer.as_ref()?;
|
||||||
|
|
||||||
|
// Find the node.
|
||||||
|
let mut cursor = layer.node().walk();
|
||||||
|
cursor.goto_descendant(descendant_ix);
|
||||||
|
let node = cursor.node();
|
||||||
|
let range = node.byte_range();
|
||||||
|
|
||||||
|
// Build a text anchor range.
|
||||||
|
let buffer = buffer_state.buffer.read(cx);
|
||||||
|
let range = buffer.anchor_before(range.start)..buffer.anchor_after(range.end);
|
||||||
|
|
||||||
|
// Build a multibuffer anchor range.
|
||||||
|
let multibuffer = editor_state.editor.read(cx).buffer();
|
||||||
|
let multibuffer = multibuffer.read(cx).snapshot(cx);
|
||||||
|
let excerpt_id = buffer_state.excerpt_id;
|
||||||
|
let range = multibuffer.anchor_in_excerpt(excerpt_id, range.start)
|
||||||
|
..multibuffer.anchor_in_excerpt(excerpt_id, range.end);
|
||||||
|
|
||||||
|
// Update the editor with the anchor range.
|
||||||
|
editor_state.editor.update(cx, |editor, cx| {
|
||||||
|
f(editor, range, cx);
|
||||||
|
});
|
||||||
|
Some(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_node(
|
||||||
|
cursor: &TreeCursor,
|
||||||
|
depth: u32,
|
||||||
|
selected: bool,
|
||||||
|
hovered: bool,
|
||||||
|
list_hovered: bool,
|
||||||
|
style: &TextStyle,
|
||||||
|
editor_theme: &theme::Editor,
|
||||||
|
cx: &AppContext,
|
||||||
|
) -> gpui::AnyElement<SyntaxTreeView> {
|
||||||
|
let node = cursor.node();
|
||||||
|
let mut range_style = style.clone();
|
||||||
|
let em_width = style.em_width(cx.font_cache());
|
||||||
|
let gutter_padding = (em_width * editor_theme.gutter_padding_factor).round();
|
||||||
|
|
||||||
|
range_style.color = editor_theme.line_number;
|
||||||
|
|
||||||
|
let mut anonymous_node_style = style.clone();
|
||||||
|
let string_color = editor_theme
|
||||||
|
.syntax
|
||||||
|
.highlights
|
||||||
|
.iter()
|
||||||
|
.find_map(|(name, style)| (name == "string").then(|| style.color)?);
|
||||||
|
let property_color = editor_theme
|
||||||
|
.syntax
|
||||||
|
.highlights
|
||||||
|
.iter()
|
||||||
|
.find_map(|(name, style)| (name == "property").then(|| style.color)?);
|
||||||
|
if let Some(color) = string_color {
|
||||||
|
anonymous_node_style.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut row = Flex::row();
|
||||||
|
if let Some(field_name) = cursor.field_name() {
|
||||||
|
let mut field_style = style.clone();
|
||||||
|
if let Some(color) = property_color {
|
||||||
|
field_style.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
row.add_children([
|
||||||
|
Label::new(field_name, field_style),
|
||||||
|
Label::new(": ", style.clone()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return row
|
||||||
|
.with_child(
|
||||||
|
if node.is_named() {
|
||||||
|
Label::new(node.kind(), style.clone())
|
||||||
|
} else {
|
||||||
|
Label::new(format!("\"{}\"", node.kind()), anonymous_node_style)
|
||||||
|
}
|
||||||
|
.contained()
|
||||||
|
.with_margin_right(em_width),
|
||||||
|
)
|
||||||
|
.with_child(Label::new(format_node_range(node), range_style))
|
||||||
|
.contained()
|
||||||
|
.with_background_color(if selected {
|
||||||
|
editor_theme.selection.selection
|
||||||
|
} else if hovered && list_hovered {
|
||||||
|
editor_theme.active_line_background
|
||||||
|
} else {
|
||||||
|
Default::default()
|
||||||
|
})
|
||||||
|
.with_padding_left(gutter_padding + depth as f32 * 18.0)
|
||||||
|
.into_any();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity for SyntaxTreeView {
|
||||||
|
type Event = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl View for SyntaxTreeView {
|
||||||
|
fn ui_name() -> &'static str {
|
||||||
|
"SyntaxTreeView"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut gpui::ViewContext<'_, '_, Self>) -> gpui::AnyElement<Self> {
|
||||||
|
let settings = settings::get::<ThemeSettings>(cx);
|
||||||
|
let font_family_id = settings.buffer_font_family;
|
||||||
|
let font_family_name = cx.font_cache().family_name(font_family_id).unwrap();
|
||||||
|
let font_properties = Default::default();
|
||||||
|
let font_id = cx
|
||||||
|
.font_cache()
|
||||||
|
.select_font(font_family_id, &font_properties)
|
||||||
|
.unwrap();
|
||||||
|
let font_size = settings.buffer_font_size(cx);
|
||||||
|
|
||||||
|
let editor_theme = settings.theme.editor.clone();
|
||||||
|
let style = TextStyle {
|
||||||
|
color: editor_theme.text_color,
|
||||||
|
font_family_name,
|
||||||
|
font_family_id,
|
||||||
|
font_id,
|
||||||
|
font_size,
|
||||||
|
font_properties: Default::default(),
|
||||||
|
underline: Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let line_height = cx.font_cache().line_height(font_size);
|
||||||
|
if Some(line_height) != self.line_height {
|
||||||
|
self.line_height = Some(line_height);
|
||||||
|
self.hover_state_changed(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(layer) = self
|
||||||
|
.editor
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|editor| editor.active_buffer.as_ref())
|
||||||
|
.and_then(|buffer| buffer.active_layer.as_ref())
|
||||||
|
{
|
||||||
|
let layer = layer.clone();
|
||||||
|
let theme = editor_theme.clone();
|
||||||
|
return MouseEventHandler::<Self, Self>::new(0, cx, move |state, cx| {
|
||||||
|
let list_hovered = state.hovered();
|
||||||
|
UniformList::new(
|
||||||
|
self.list_state.clone(),
|
||||||
|
layer.node().descendant_count(),
|
||||||
|
cx,
|
||||||
|
move |this, range, items, cx| {
|
||||||
|
let mut cursor = layer.node().walk();
|
||||||
|
let mut descendant_ix = range.start as usize;
|
||||||
|
cursor.goto_descendant(descendant_ix);
|
||||||
|
let mut depth = cursor.depth();
|
||||||
|
let mut visited_children = false;
|
||||||
|
while descendant_ix < range.end {
|
||||||
|
if visited_children {
|
||||||
|
if cursor.goto_next_sibling() {
|
||||||
|
visited_children = false;
|
||||||
|
} else if cursor.goto_parent() {
|
||||||
|
depth -= 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
items.push(Self::render_node(
|
||||||
|
&cursor,
|
||||||
|
depth,
|
||||||
|
Some(descendant_ix) == this.selected_descendant_ix,
|
||||||
|
Some(descendant_ix) == this.hovered_descendant_ix,
|
||||||
|
list_hovered,
|
||||||
|
&style,
|
||||||
|
&theme,
|
||||||
|
cx,
|
||||||
|
));
|
||||||
|
descendant_ix += 1;
|
||||||
|
if cursor.goto_first_child() {
|
||||||
|
depth += 1;
|
||||||
|
} else {
|
||||||
|
visited_children = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.on_move(move |event, this, cx| {
|
||||||
|
let y = event.position.y() - event.region.origin_y();
|
||||||
|
this.mouse_y = Some(y);
|
||||||
|
this.hover_state_changed(cx);
|
||||||
|
})
|
||||||
|
.on_click(MouseButton::Left, move |event, this, cx| {
|
||||||
|
let y = event.position.y() - event.region.origin_y();
|
||||||
|
this.handle_click(y, cx);
|
||||||
|
})
|
||||||
|
.contained()
|
||||||
|
.with_background_color(editor_theme.background)
|
||||||
|
.into_any();
|
||||||
|
}
|
||||||
|
|
||||||
|
Empty::new().into_any()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Item for SyntaxTreeView {
|
||||||
|
fn tab_content<V: View>(
|
||||||
|
&self,
|
||||||
|
_: Option<usize>,
|
||||||
|
style: &theme::Tab,
|
||||||
|
_: &AppContext,
|
||||||
|
) -> gpui::AnyElement<V> {
|
||||||
|
Label::new("Syntax Tree", style.label.clone()).into_any()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_on_split(
|
||||||
|
&self,
|
||||||
|
_workspace_id: workspace::WorkspaceId,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> Option<Self>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
let mut clone = Self::new(self.workspace_handle.clone(), None, cx);
|
||||||
|
if let Some(editor) = &self.editor {
|
||||||
|
clone.set_editor(editor.editor.clone(), cx)
|
||||||
|
}
|
||||||
|
Some(clone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SyntaxTreeToolbarItemView {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
menu_open: false,
|
||||||
|
tree_view: None,
|
||||||
|
subscription: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_menu(
|
||||||
|
&mut self,
|
||||||
|
cx: &mut ViewContext<'_, '_, Self>,
|
||||||
|
) -> Option<gpui::AnyElement<Self>> {
|
||||||
|
let theme = theme::current(cx).clone();
|
||||||
|
let tree_view = self.tree_view.as_ref()?;
|
||||||
|
let tree_view = tree_view.read(cx);
|
||||||
|
|
||||||
|
let editor_state = tree_view.editor.as_ref()?;
|
||||||
|
let buffer_state = editor_state.active_buffer.as_ref()?;
|
||||||
|
let active_layer = buffer_state.active_layer.clone()?;
|
||||||
|
let active_buffer = buffer_state.buffer.read(cx).snapshot();
|
||||||
|
|
||||||
|
enum Menu {}
|
||||||
|
|
||||||
|
Some(
|
||||||
|
Stack::new()
|
||||||
|
.with_child(Self::render_header(&theme, &active_layer, cx))
|
||||||
|
.with_children(self.menu_open.then(|| {
|
||||||
|
Overlay::new(
|
||||||
|
MouseEventHandler::<Menu, _>::new(0, cx, move |_, cx| {
|
||||||
|
Flex::column()
|
||||||
|
.with_children(active_buffer.syntax_layers().enumerate().map(
|
||||||
|
|(ix, layer)| {
|
||||||
|
Self::render_menu_item(&theme, &active_layer, layer, ix, cx)
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.contained()
|
||||||
|
.with_style(theme.toolbar_dropdown_menu.container)
|
||||||
|
.constrained()
|
||||||
|
.with_width(400.)
|
||||||
|
.with_height(400.)
|
||||||
|
})
|
||||||
|
.on_down_out(MouseButton::Left, |_, this, cx| {
|
||||||
|
this.menu_open = false;
|
||||||
|
cx.notify()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.with_hoverable(true)
|
||||||
|
.with_fit_mode(OverlayFitMode::SwitchAnchor)
|
||||||
|
.with_anchor_corner(AnchorCorner::TopLeft)
|
||||||
|
.with_z_index(999)
|
||||||
|
.aligned()
|
||||||
|
.bottom()
|
||||||
|
.left()
|
||||||
|
}))
|
||||||
|
.aligned()
|
||||||
|
.left()
|
||||||
|
.clipped()
|
||||||
|
.into_any(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle_menu(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
self.menu_open = !self.menu_open;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_layer(&mut self, layer_ix: usize, cx: &mut ViewContext<Self>) -> Option<()> {
|
||||||
|
let tree_view = self.tree_view.as_ref()?;
|
||||||
|
tree_view.update(cx, |view, cx| {
|
||||||
|
let editor_state = view.editor.as_mut()?;
|
||||||
|
let buffer_state = editor_state.active_buffer.as_mut()?;
|
||||||
|
let snapshot = buffer_state.buffer.read(cx).snapshot();
|
||||||
|
let layer = snapshot.syntax_layers().nth(layer_ix)?;
|
||||||
|
buffer_state.active_layer = Some(layer.to_owned());
|
||||||
|
view.selected_descendant_ix = None;
|
||||||
|
self.menu_open = false;
|
||||||
|
cx.notify();
|
||||||
|
Some(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_header(
|
||||||
|
theme: &Arc<Theme>,
|
||||||
|
active_layer: &OwnedSyntaxLayerInfo,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> impl Element<Self> {
|
||||||
|
enum ToggleMenu {}
|
||||||
|
MouseEventHandler::<ToggleMenu, Self>::new(0, cx, move |state, _| {
|
||||||
|
let style = theme.toolbar_dropdown_menu.header.style_for(state);
|
||||||
|
Flex::row()
|
||||||
|
.with_child(
|
||||||
|
Label::new(active_layer.language.name().to_string(), style.text.clone())
|
||||||
|
.contained()
|
||||||
|
.with_margin_right(style.secondary_text_spacing),
|
||||||
|
)
|
||||||
|
.with_child(Label::new(
|
||||||
|
format_node_range(active_layer.node()),
|
||||||
|
style
|
||||||
|
.secondary_text
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| style.text.clone()),
|
||||||
|
))
|
||||||
|
.contained()
|
||||||
|
.with_style(style.container)
|
||||||
|
})
|
||||||
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
.on_click(MouseButton::Left, move |_, view, cx| {
|
||||||
|
view.toggle_menu(cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_menu_item(
|
||||||
|
theme: &Arc<Theme>,
|
||||||
|
active_layer: &OwnedSyntaxLayerInfo,
|
||||||
|
layer: SyntaxLayerInfo,
|
||||||
|
layer_ix: usize,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> impl Element<Self> {
|
||||||
|
enum ActivateLayer {}
|
||||||
|
MouseEventHandler::<ActivateLayer, _>::new(layer_ix, cx, move |state, _| {
|
||||||
|
let is_selected = layer.node() == active_layer.node();
|
||||||
|
let style = theme
|
||||||
|
.toolbar_dropdown_menu
|
||||||
|
.item
|
||||||
|
.in_state(is_selected)
|
||||||
|
.style_for(state);
|
||||||
|
Flex::row()
|
||||||
|
.with_child(
|
||||||
|
Label::new(layer.language.name().to_string(), style.text.clone())
|
||||||
|
.contained()
|
||||||
|
.with_margin_right(style.secondary_text_spacing),
|
||||||
|
)
|
||||||
|
.with_child(Label::new(
|
||||||
|
format_node_range(layer.node()),
|
||||||
|
style
|
||||||
|
.secondary_text
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| style.text.clone()),
|
||||||
|
))
|
||||||
|
.contained()
|
||||||
|
.with_style(style.container)
|
||||||
|
})
|
||||||
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
|
.on_click(MouseButton::Left, move |_, view, cx| {
|
||||||
|
view.select_layer(layer_ix, cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_node_range(node: Node) -> String {
|
||||||
|
let start = node.start_position();
|
||||||
|
let end = node.end_position();
|
||||||
|
format!(
|
||||||
|
"[{}:{} - {}:{}]",
|
||||||
|
start.row + 1,
|
||||||
|
start.column + 1,
|
||||||
|
end.row + 1,
|
||||||
|
end.column + 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity for SyntaxTreeToolbarItemView {
|
||||||
|
type Event = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl View for SyntaxTreeToolbarItemView {
|
||||||
|
fn ui_name() -> &'static str {
|
||||||
|
"SyntaxTreeToolbarItemView"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<'_, '_, Self>) -> gpui::AnyElement<Self> {
|
||||||
|
self.render_menu(cx)
|
||||||
|
.unwrap_or_else(|| Empty::new().into_any())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToolbarItemView for SyntaxTreeToolbarItemView {
|
||||||
|
fn set_active_pane_item(
|
||||||
|
&mut self,
|
||||||
|
active_pane_item: Option<&dyn ItemHandle>,
|
||||||
|
cx: &mut ViewContext<Self>,
|
||||||
|
) -> workspace::ToolbarItemLocation {
|
||||||
|
self.menu_open = false;
|
||||||
|
if let Some(item) = active_pane_item {
|
||||||
|
if let Some(view) = item.downcast::<SyntaxTreeView>() {
|
||||||
|
self.tree_view = Some(view.clone());
|
||||||
|
self.subscription = Some(cx.observe(&view, |_, _, cx| cx.notify()));
|
||||||
|
return ToolbarItemLocation::PrimaryLeft {
|
||||||
|
flex: Some((1., false)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.tree_view = None;
|
||||||
|
self.subscription = None;
|
||||||
|
ToolbarItemLocation::Hidden
|
||||||
|
}
|
||||||
|
}
|
@ -6,17 +6,23 @@ import ScreenCaptureKit
|
|||||||
class LKRoomDelegate: RoomDelegate {
|
class LKRoomDelegate: RoomDelegate {
|
||||||
var data: UnsafeRawPointer
|
var data: UnsafeRawPointer
|
||||||
var onDidDisconnect: @convention(c) (UnsafeRawPointer) -> Void
|
var onDidDisconnect: @convention(c) (UnsafeRawPointer) -> Void
|
||||||
|
var onDidSubscribeToRemoteAudioTrack: @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void
|
||||||
|
var onDidUnsubscribeFromRemoteAudioTrack: @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void
|
||||||
var onDidSubscribeToRemoteVideoTrack: @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void
|
var onDidSubscribeToRemoteVideoTrack: @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void
|
||||||
var onDidUnsubscribeFromRemoteVideoTrack: @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void
|
var onDidUnsubscribeFromRemoteVideoTrack: @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void
|
||||||
|
|
||||||
init(
|
init(
|
||||||
data: UnsafeRawPointer,
|
data: UnsafeRawPointer,
|
||||||
onDidDisconnect: @escaping @convention(c) (UnsafeRawPointer) -> Void,
|
onDidDisconnect: @escaping @convention(c) (UnsafeRawPointer) -> Void,
|
||||||
|
onDidSubscribeToRemoteAudioTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
||||||
|
onDidUnsubscribeFromRemoteAudioTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void,
|
||||||
onDidSubscribeToRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
onDidSubscribeToRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
||||||
onDidUnsubscribeFromRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void)
|
onDidUnsubscribeFromRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void)
|
||||||
{
|
{
|
||||||
self.data = data
|
self.data = data
|
||||||
self.onDidDisconnect = onDidDisconnect
|
self.onDidDisconnect = onDidDisconnect
|
||||||
|
self.onDidSubscribeToRemoteAudioTrack = onDidSubscribeToRemoteAudioTrack
|
||||||
|
self.onDidUnsubscribeFromRemoteAudioTrack = onDidUnsubscribeFromRemoteAudioTrack
|
||||||
self.onDidSubscribeToRemoteVideoTrack = onDidSubscribeToRemoteVideoTrack
|
self.onDidSubscribeToRemoteVideoTrack = onDidSubscribeToRemoteVideoTrack
|
||||||
self.onDidUnsubscribeFromRemoteVideoTrack = onDidUnsubscribeFromRemoteVideoTrack
|
self.onDidUnsubscribeFromRemoteVideoTrack = onDidUnsubscribeFromRemoteVideoTrack
|
||||||
}
|
}
|
||||||
@ -30,12 +36,16 @@ class LKRoomDelegate: RoomDelegate {
|
|||||||
func room(_ room: Room, participant: RemoteParticipant, didSubscribe publication: RemoteTrackPublication, track: Track) {
|
func room(_ room: Room, participant: RemoteParticipant, didSubscribe publication: RemoteTrackPublication, track: Track) {
|
||||||
if track.kind == .video {
|
if track.kind == .video {
|
||||||
self.onDidSubscribeToRemoteVideoTrack(self.data, participant.identity as CFString, track.sid! as CFString, Unmanaged.passUnretained(track).toOpaque())
|
self.onDidSubscribeToRemoteVideoTrack(self.data, participant.identity as CFString, track.sid! as CFString, Unmanaged.passUnretained(track).toOpaque())
|
||||||
|
} else if track.kind == .audio {
|
||||||
|
self.onDidSubscribeToRemoteAudioTrack(self.data, participant.identity as CFString, track.sid! as CFString, Unmanaged.passUnretained(track).toOpaque())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func room(_ room: Room, participant: RemoteParticipant, didUnsubscribe publication: RemoteTrackPublication, track: Track) {
|
func room(_ room: Room, participant: RemoteParticipant, didUnsubscribe publication: RemoteTrackPublication, track: Track) {
|
||||||
if track.kind == .video {
|
if track.kind == .video {
|
||||||
self.onDidUnsubscribeFromRemoteVideoTrack(self.data, participant.identity as CFString, track.sid! as CFString)
|
self.onDidUnsubscribeFromRemoteVideoTrack(self.data, participant.identity as CFString, track.sid! as CFString)
|
||||||
|
} else if track.kind == .audio {
|
||||||
|
self.onDidUnsubscribeFromRemoteAudioTrack(self.data, participant.identity as CFString, track.sid! as CFString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,12 +87,16 @@ class LKVideoRenderer: NSObject, VideoRenderer {
|
|||||||
public func LKRoomDelegateCreate(
|
public func LKRoomDelegateCreate(
|
||||||
data: UnsafeRawPointer,
|
data: UnsafeRawPointer,
|
||||||
onDidDisconnect: @escaping @convention(c) (UnsafeRawPointer) -> Void,
|
onDidDisconnect: @escaping @convention(c) (UnsafeRawPointer) -> Void,
|
||||||
|
onDidSubscribeToRemoteAudioTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
||||||
|
onDidUnsubscribeFromRemoteAudioTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void,
|
||||||
onDidSubscribeToRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
onDidSubscribeToRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
||||||
onDidUnsubscribeFromRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void
|
onDidUnsubscribeFromRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void
|
||||||
) -> UnsafeMutableRawPointer {
|
) -> UnsafeMutableRawPointer {
|
||||||
let delegate = LKRoomDelegate(
|
let delegate = LKRoomDelegate(
|
||||||
data: data,
|
data: data,
|
||||||
onDidDisconnect: onDidDisconnect,
|
onDidDisconnect: onDidDisconnect,
|
||||||
|
onDidSubscribeToRemoteAudioTrack: onDidSubscribeToRemoteAudioTrack,
|
||||||
|
onDidUnsubscribeFromRemoteAudioTrack: onDidUnsubscribeFromRemoteAudioTrack,
|
||||||
onDidSubscribeToRemoteVideoTrack: onDidSubscribeToRemoteVideoTrack,
|
onDidSubscribeToRemoteVideoTrack: onDidSubscribeToRemoteVideoTrack,
|
||||||
onDidUnsubscribeFromRemoteVideoTrack: onDidUnsubscribeFromRemoteVideoTrack
|
onDidUnsubscribeFromRemoteVideoTrack: onDidUnsubscribeFromRemoteVideoTrack
|
||||||
)
|
)
|
||||||
@ -123,6 +137,18 @@ public func LKRoomPublishVideoTrack(room: UnsafeRawPointer, track: UnsafeRawPoin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@_cdecl("LKRoomPublishAudioTrack")
|
||||||
|
public func LKRoomPublishAudioTrack(room: UnsafeRawPointer, track: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, UnsafeMutableRawPointer?, CFString?) -> Void, callback_data: UnsafeRawPointer) {
|
||||||
|
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
||||||
|
let track = Unmanaged<LocalAudioTrack>.fromOpaque(track).takeUnretainedValue()
|
||||||
|
room.localParticipant?.publishAudioTrack(track: track).then { publication in
|
||||||
|
callback(callback_data, Unmanaged.passRetained(publication).toOpaque(), nil)
|
||||||
|
}.catch { error in
|
||||||
|
callback(callback_data, nil, error.localizedDescription as CFString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@_cdecl("LKRoomUnpublishTrack")
|
@_cdecl("LKRoomUnpublishTrack")
|
||||||
public func LKRoomUnpublishTrack(room: UnsafeRawPointer, publication: UnsafeRawPointer) {
|
public func LKRoomUnpublishTrack(room: UnsafeRawPointer, publication: UnsafeRawPointer) {
|
||||||
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
||||||
@ -130,6 +156,20 @@ public func LKRoomUnpublishTrack(room: UnsafeRawPointer, publication: UnsafeRawP
|
|||||||
let _ = room.localParticipant?.unpublish(publication: publication)
|
let _ = room.localParticipant?.unpublish(publication: publication)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@_cdecl("LKRoomAudioTracksForRemoteParticipant")
|
||||||
|
public func LKRoomAudioTracksForRemoteParticipant(room: UnsafeRawPointer, participantId: CFString) -> CFArray? {
|
||||||
|
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
||||||
|
|
||||||
|
for (_, participant) in room.remoteParticipants {
|
||||||
|
if participant.identity == participantId as String {
|
||||||
|
return participant.audioTracks.compactMap { $0.track as? RemoteAudioTrack } as CFArray?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@_cdecl("LKRoomVideoTracksForRemoteParticipant")
|
@_cdecl("LKRoomVideoTracksForRemoteParticipant")
|
||||||
public func LKRoomVideoTracksForRemoteParticipant(room: UnsafeRawPointer, participantId: CFString) -> CFArray? {
|
public func LKRoomVideoTracksForRemoteParticipant(room: UnsafeRawPointer, participantId: CFString) -> CFArray? {
|
||||||
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
||||||
@ -143,6 +183,17 @@ public func LKRoomVideoTracksForRemoteParticipant(room: UnsafeRawPointer, partic
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@_cdecl("LKLocalAudioTrackCreateTrack")
|
||||||
|
public func LKLocalAudioTrackCreateTrack() -> UnsafeMutableRawPointer {
|
||||||
|
let track = LocalAudioTrack.createTrack(options: AudioCaptureOptions(
|
||||||
|
echoCancellation: true,
|
||||||
|
noiseSuppression: true
|
||||||
|
))
|
||||||
|
|
||||||
|
return Unmanaged.passRetained(track).toOpaque()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@_cdecl("LKCreateScreenShareTrackForDisplay")
|
@_cdecl("LKCreateScreenShareTrackForDisplay")
|
||||||
public func LKCreateScreenShareTrackForDisplay(display: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer {
|
public func LKCreateScreenShareTrackForDisplay(display: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer {
|
||||||
let display = Unmanaged<MacOSDisplay>.fromOpaque(display).takeUnretainedValue()
|
let display = Unmanaged<MacOSDisplay>.fromOpaque(display).takeUnretainedValue()
|
||||||
@ -150,6 +201,19 @@ public func LKCreateScreenShareTrackForDisplay(display: UnsafeMutableRawPointer)
|
|||||||
return Unmanaged.passRetained(track).toOpaque()
|
return Unmanaged.passRetained(track).toOpaque()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@_cdecl("LKRemoteAudioTrackStart")
|
||||||
|
public func LKRemoteAudioTrackStart(track: UnsafeRawPointer, onStart: @escaping @convention(c) (UnsafeRawPointer, Bool) -> Void, callbackData: UnsafeRawPointer) {
|
||||||
|
let track = Unmanaged<Track>.fromOpaque(track).takeUnretainedValue() as! RemoteAudioTrack
|
||||||
|
|
||||||
|
track.start().then { success in
|
||||||
|
onStart(callbackData, success)
|
||||||
|
}
|
||||||
|
.catch { _ in
|
||||||
|
onStart(callbackData, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@_cdecl("LKVideoRendererCreate")
|
@_cdecl("LKVideoRendererCreate")
|
||||||
public func LKVideoRendererCreate(data: UnsafeRawPointer, onFrame: @escaping @convention(c) (UnsafeRawPointer, CVPixelBuffer) -> Bool, onDrop: @escaping @convention(c) (UnsafeRawPointer) -> Void) -> UnsafeMutableRawPointer {
|
public func LKVideoRendererCreate(data: UnsafeRawPointer, onFrame: @escaping @convention(c) (UnsafeRawPointer, CVPixelBuffer) -> Bool, onDrop: @escaping @convention(c) (UnsafeRawPointer) -> Void) -> UnsafeMutableRawPointer {
|
||||||
Unmanaged.passRetained(LKVideoRenderer(data: data, onFrame: onFrame, onDrop: onDrop)).toOpaque()
|
Unmanaged.passRetained(LKVideoRenderer(data: data, onFrame: onFrame, onDrop: onDrop)).toOpaque()
|
||||||
@ -169,6 +233,12 @@ public func LKRemoteVideoTrackGetSid(track: UnsafeRawPointer) -> CFString {
|
|||||||
return track.sid! as CFString
|
return track.sid! as CFString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@_cdecl("LKRemoteAudioTrackGetSid")
|
||||||
|
public func LKRemoteAudioTrackGetSid(track: UnsafeRawPointer) -> CFString {
|
||||||
|
let track = Unmanaged<RemoteAudioTrack>.fromOpaque(track).takeUnretainedValue()
|
||||||
|
return track.sid! as CFString
|
||||||
|
}
|
||||||
|
|
||||||
@_cdecl("LKDisplaySources")
|
@_cdecl("LKDisplaySources")
|
||||||
public func LKDisplaySources(data: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, CFArray?, CFString?) -> Void) {
|
public func LKDisplaySources(data: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, CFArray?, CFString?) -> Void) {
|
||||||
MacOSScreenCapturer.sources(for: .display, includeCurrentApplication: false, preferredMethod: .legacy).then { displaySources in
|
MacOSScreenCapturer.sources(for: .display, includeCurrentApplication: false, preferredMethod: .legacy).then { displaySources in
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use gpui::{actions, keymap_matcher::Binding, Menu, MenuItem};
|
use gpui::{actions, keymap_matcher::Binding, Menu, MenuItem};
|
||||||
use live_kit_client::{LocalVideoTrack, RemoteVideoTrackUpdate, Room};
|
use live_kit_client::{
|
||||||
|
LocalAudioTrack, LocalVideoTrack, RemoteAudioTrackUpdate, RemoteVideoTrackUpdate, Room,
|
||||||
|
};
|
||||||
use live_kit_server::token::{self, VideoGrant};
|
use live_kit_server::token::{self, VideoGrant};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use simplelog::SimpleLogger;
|
use simplelog::SimpleLogger;
|
||||||
@ -11,6 +15,12 @@ fn main() {
|
|||||||
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||||
|
|
||||||
gpui::App::new(()).unwrap().run(|cx| {
|
gpui::App::new(()).unwrap().run(|cx| {
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
println!("USING TEST LIVEKIT");
|
||||||
|
|
||||||
|
#[cfg(not(any(test, feature = "test-support")))]
|
||||||
|
println!("USING REAL LIVEKIT");
|
||||||
|
|
||||||
cx.platform().activate(true);
|
cx.platform().activate(true);
|
||||||
cx.add_global_action(quit);
|
cx.add_global_action(quit);
|
||||||
|
|
||||||
@ -49,16 +59,14 @@ fn main() {
|
|||||||
let room_b = Room::new();
|
let room_b = Room::new();
|
||||||
room_b.connect(&live_kit_url, &user2_token).await.unwrap();
|
room_b.connect(&live_kit_url, &user2_token).await.unwrap();
|
||||||
|
|
||||||
let mut track_changes = room_b.remote_video_track_updates();
|
let mut audio_track_updates = room_b.remote_audio_track_updates();
|
||||||
|
let audio_track = LocalAudioTrack::create();
|
||||||
|
let audio_track_publication = room_a.publish_audio_track(&audio_track).await.unwrap();
|
||||||
|
|
||||||
let displays = room_a.display_sources().await.unwrap();
|
if let RemoteAudioTrackUpdate::Subscribed(track) =
|
||||||
let display = displays.into_iter().next().unwrap();
|
audio_track_updates.next().await.unwrap()
|
||||||
|
{
|
||||||
let track_a = LocalVideoTrack::screen_share_for_display(&display);
|
let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
||||||
let track_a_publication = room_a.publish_video_track(&track_a).await.unwrap();
|
|
||||||
|
|
||||||
if let RemoteVideoTrackUpdate::Subscribed(track) = track_changes.next().await.unwrap() {
|
|
||||||
let remote_tracks = room_b.remote_video_tracks("test-participant-1");
|
|
||||||
assert_eq!(remote_tracks.len(), 1);
|
assert_eq!(remote_tracks.len(), 1);
|
||||||
assert_eq!(remote_tracks[0].publisher_id(), "test-participant-1");
|
assert_eq!(remote_tracks[0].publisher_id(), "test-participant-1");
|
||||||
assert_eq!(track.publisher_id(), "test-participant-1");
|
assert_eq!(track.publisher_id(), "test-participant-1");
|
||||||
@ -66,18 +74,60 @@ fn main() {
|
|||||||
panic!("unexpected message");
|
panic!("unexpected message");
|
||||||
}
|
}
|
||||||
|
|
||||||
let remote_track = room_b
|
println!("Pausing for 5 seconds to test audio, make some noise!");
|
||||||
|
let timer = cx.background().timer(Duration::from_secs(5));
|
||||||
|
timer.await;
|
||||||
|
|
||||||
|
let remote_audio_track = room_b
|
||||||
|
.remote_audio_tracks("test-participant-1")
|
||||||
|
.pop()
|
||||||
|
.unwrap();
|
||||||
|
room_a.unpublish_track(audio_track_publication);
|
||||||
|
if let RemoteAudioTrackUpdate::Unsubscribed {
|
||||||
|
publisher_id,
|
||||||
|
track_id,
|
||||||
|
} = audio_track_updates.next().await.unwrap()
|
||||||
|
{
|
||||||
|
assert_eq!(publisher_id, "test-participant-1");
|
||||||
|
assert_eq!(remote_audio_track.sid(), track_id);
|
||||||
|
assert_eq!(room_b.remote_audio_tracks("test-participant-1").len(), 0);
|
||||||
|
} else {
|
||||||
|
panic!("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut video_track_updates = room_b.remote_video_track_updates();
|
||||||
|
let displays = room_a.display_sources().await.unwrap();
|
||||||
|
let display = displays.into_iter().next().unwrap();
|
||||||
|
|
||||||
|
let local_video_track = LocalVideoTrack::screen_share_for_display(&display);
|
||||||
|
let local_video_track_publication = room_a
|
||||||
|
.publish_video_track(&local_video_track)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if let RemoteVideoTrackUpdate::Subscribed(track) =
|
||||||
|
video_track_updates.next().await.unwrap()
|
||||||
|
{
|
||||||
|
let remote_video_tracks = room_b.remote_video_tracks("test-participant-1");
|
||||||
|
assert_eq!(remote_video_tracks.len(), 1);
|
||||||
|
assert_eq!(remote_video_tracks[0].publisher_id(), "test-participant-1");
|
||||||
|
assert_eq!(track.publisher_id(), "test-participant-1");
|
||||||
|
} else {
|
||||||
|
panic!("unexpected message");
|
||||||
|
}
|
||||||
|
|
||||||
|
let remote_video_track = room_b
|
||||||
.remote_video_tracks("test-participant-1")
|
.remote_video_tracks("test-participant-1")
|
||||||
.pop()
|
.pop()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
room_a.unpublish_track(track_a_publication);
|
room_a.unpublish_track(local_video_track_publication);
|
||||||
if let RemoteVideoTrackUpdate::Unsubscribed {
|
if let RemoteVideoTrackUpdate::Unsubscribed {
|
||||||
publisher_id,
|
publisher_id,
|
||||||
track_id,
|
track_id,
|
||||||
} = track_changes.next().await.unwrap()
|
} = video_track_updates.next().await.unwrap()
|
||||||
{
|
{
|
||||||
assert_eq!(publisher_id, "test-participant-1");
|
assert_eq!(publisher_id, "test-participant-1");
|
||||||
assert_eq!(remote_track.sid(), track_id);
|
assert_eq!(remote_video_track.sid(), track_id);
|
||||||
assert_eq!(room_b.remote_video_tracks("test-participant-1").len(), 0);
|
assert_eq!(room_b.remote_video_tracks("test-participant-1").len(), 0);
|
||||||
} else {
|
} else {
|
||||||
panic!("unexpected message");
|
panic!("unexpected message");
|
||||||
|
@ -4,7 +4,7 @@ pub mod prod;
|
|||||||
pub use prod::*;
|
pub use prod::*;
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
mod test;
|
pub mod test;
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub use test::*;
|
pub use test::*;
|
||||||
|
@ -21,6 +21,17 @@ extern "C" {
|
|||||||
fn LKRoomDelegateCreate(
|
fn LKRoomDelegateCreate(
|
||||||
callback_data: *mut c_void,
|
callback_data: *mut c_void,
|
||||||
on_did_disconnect: extern "C" fn(callback_data: *mut c_void),
|
on_did_disconnect: extern "C" fn(callback_data: *mut c_void),
|
||||||
|
on_did_subscribe_to_remote_audio_track: extern "C" fn(
|
||||||
|
callback_data: *mut c_void,
|
||||||
|
publisher_id: CFStringRef,
|
||||||
|
track_id: CFStringRef,
|
||||||
|
remote_track: *const c_void,
|
||||||
|
),
|
||||||
|
on_did_unsubscribe_from_remote_audio_track: extern "C" fn(
|
||||||
|
callback_data: *mut c_void,
|
||||||
|
publisher_id: CFStringRef,
|
||||||
|
track_id: CFStringRef,
|
||||||
|
),
|
||||||
on_did_subscribe_to_remote_video_track: extern "C" fn(
|
on_did_subscribe_to_remote_video_track: extern "C" fn(
|
||||||
callback_data: *mut c_void,
|
callback_data: *mut c_void,
|
||||||
publisher_id: CFStringRef,
|
publisher_id: CFStringRef,
|
||||||
@ -49,7 +60,18 @@ extern "C" {
|
|||||||
callback: extern "C" fn(*mut c_void, *mut c_void, CFStringRef),
|
callback: extern "C" fn(*mut c_void, *mut c_void, CFStringRef),
|
||||||
callback_data: *mut c_void,
|
callback_data: *mut c_void,
|
||||||
);
|
);
|
||||||
|
fn LKRoomPublishAudioTrack(
|
||||||
|
room: *const c_void,
|
||||||
|
track: *const c_void,
|
||||||
|
callback: extern "C" fn(*mut c_void, *mut c_void, CFStringRef),
|
||||||
|
callback_data: *mut c_void,
|
||||||
|
);
|
||||||
fn LKRoomUnpublishTrack(room: *const c_void, publication: *const c_void);
|
fn LKRoomUnpublishTrack(room: *const c_void, publication: *const c_void);
|
||||||
|
fn LKRoomAudioTracksForRemoteParticipant(
|
||||||
|
room: *const c_void,
|
||||||
|
participant_id: CFStringRef,
|
||||||
|
) -> CFArrayRef;
|
||||||
|
|
||||||
fn LKRoomVideoTracksForRemoteParticipant(
|
fn LKRoomVideoTracksForRemoteParticipant(
|
||||||
room: *const c_void,
|
room: *const c_void,
|
||||||
participant_id: CFStringRef,
|
participant_id: CFStringRef,
|
||||||
@ -61,6 +83,13 @@ extern "C" {
|
|||||||
on_drop: extern "C" fn(callback_data: *mut c_void),
|
on_drop: extern "C" fn(callback_data: *mut c_void),
|
||||||
) -> *const c_void;
|
) -> *const c_void;
|
||||||
|
|
||||||
|
fn LKRemoteAudioTrackGetSid(track: *const c_void) -> CFStringRef;
|
||||||
|
// fn LKRemoteAudioTrackStart(
|
||||||
|
// track: *const c_void,
|
||||||
|
// callback: extern "C" fn(*mut c_void, bool),
|
||||||
|
// callback_data: *mut c_void
|
||||||
|
// );
|
||||||
|
|
||||||
fn LKVideoTrackAddRenderer(track: *const c_void, renderer: *const c_void);
|
fn LKVideoTrackAddRenderer(track: *const c_void, renderer: *const c_void);
|
||||||
fn LKRemoteVideoTrackGetSid(track: *const c_void) -> CFStringRef;
|
fn LKRemoteVideoTrackGetSid(track: *const c_void) -> CFStringRef;
|
||||||
|
|
||||||
@ -73,6 +102,7 @@ extern "C" {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
fn LKCreateScreenShareTrackForDisplay(display: *const c_void) -> *const c_void;
|
fn LKCreateScreenShareTrackForDisplay(display: *const c_void) -> *const c_void;
|
||||||
|
fn LKLocalAudioTrackCreateTrack() -> *const c_void;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Sid = String;
|
pub type Sid = String;
|
||||||
@ -89,6 +119,7 @@ pub struct Room {
|
|||||||
watch::Sender<ConnectionState>,
|
watch::Sender<ConnectionState>,
|
||||||
watch::Receiver<ConnectionState>,
|
watch::Receiver<ConnectionState>,
|
||||||
)>,
|
)>,
|
||||||
|
remote_audio_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteAudioTrackUpdate>>>,
|
||||||
remote_video_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteVideoTrackUpdate>>>,
|
remote_video_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteVideoTrackUpdate>>>,
|
||||||
_delegate: RoomDelegate,
|
_delegate: RoomDelegate,
|
||||||
}
|
}
|
||||||
@ -100,6 +131,7 @@ impl Room {
|
|||||||
Self {
|
Self {
|
||||||
native_room: unsafe { LKRoomCreate(delegate.native_delegate) },
|
native_room: unsafe { LKRoomCreate(delegate.native_delegate) },
|
||||||
connection: Mutex::new(watch::channel_with(ConnectionState::Disconnected)),
|
connection: Mutex::new(watch::channel_with(ConnectionState::Disconnected)),
|
||||||
|
remote_audio_track_subscribers: Default::default(),
|
||||||
remote_video_track_subscribers: Default::default(),
|
remote_video_track_subscribers: Default::default(),
|
||||||
_delegate: delegate,
|
_delegate: delegate,
|
||||||
}
|
}
|
||||||
@ -191,6 +223,32 @@ impl Room {
|
|||||||
async { rx.await.unwrap().context("error publishing video track") }
|
async { rx.await.unwrap().context("error publishing video track") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn publish_audio_track(
|
||||||
|
self: &Arc<Self>,
|
||||||
|
track: &LocalAudioTrack,
|
||||||
|
) -> impl Future<Output = Result<LocalTrackPublication>> {
|
||||||
|
let (tx, rx) = oneshot::channel::<Result<LocalTrackPublication>>();
|
||||||
|
extern "C" fn callback(tx: *mut c_void, publication: *mut c_void, error: CFStringRef) {
|
||||||
|
let tx =
|
||||||
|
unsafe { Box::from_raw(tx as *mut oneshot::Sender<Result<LocalTrackPublication>>) };
|
||||||
|
if error.is_null() {
|
||||||
|
let _ = tx.send(Ok(LocalTrackPublication(publication)));
|
||||||
|
} else {
|
||||||
|
let error = unsafe { CFString::wrap_under_get_rule(error).to_string() };
|
||||||
|
let _ = tx.send(Err(anyhow!(error)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
LKRoomPublishAudioTrack(
|
||||||
|
self.native_room,
|
||||||
|
track.0,
|
||||||
|
callback,
|
||||||
|
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
async { rx.await.unwrap().context("error publishing video track") }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn unpublish_track(&self, publication: LocalTrackPublication) {
|
pub fn unpublish_track(&self, publication: LocalTrackPublication) {
|
||||||
unsafe {
|
unsafe {
|
||||||
LKRoomUnpublishTrack(self.native_room, publication.0);
|
LKRoomUnpublishTrack(self.native_room, publication.0);
|
||||||
@ -226,12 +284,65 @@ impl Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remote_audio_tracks(&self, participant_id: &str) -> Vec<Arc<RemoteAudioTrack>> {
|
||||||
|
unsafe {
|
||||||
|
let tracks = LKRoomAudioTracksForRemoteParticipant(
|
||||||
|
self.native_room,
|
||||||
|
CFString::new(participant_id).as_concrete_TypeRef(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if tracks.is_null() {
|
||||||
|
Vec::new()
|
||||||
|
} else {
|
||||||
|
let tracks = CFArray::wrap_under_get_rule(tracks);
|
||||||
|
tracks
|
||||||
|
.into_iter()
|
||||||
|
.map(|native_track| {
|
||||||
|
let native_track = *native_track;
|
||||||
|
let id =
|
||||||
|
CFString::wrap_under_get_rule(LKRemoteAudioTrackGetSid(native_track))
|
||||||
|
.to_string();
|
||||||
|
Arc::new(RemoteAudioTrack::new(
|
||||||
|
native_track,
|
||||||
|
id,
|
||||||
|
participant_id.into(),
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remote_audio_track_updates(&self) -> mpsc::UnboundedReceiver<RemoteAudioTrackUpdate> {
|
||||||
|
let (tx, rx) = mpsc::unbounded();
|
||||||
|
self.remote_audio_track_subscribers.lock().push(tx);
|
||||||
|
rx
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remote_video_track_updates(&self) -> mpsc::UnboundedReceiver<RemoteVideoTrackUpdate> {
|
pub fn remote_video_track_updates(&self) -> mpsc::UnboundedReceiver<RemoteVideoTrackUpdate> {
|
||||||
let (tx, rx) = mpsc::unbounded();
|
let (tx, rx) = mpsc::unbounded();
|
||||||
self.remote_video_track_subscribers.lock().push(tx);
|
self.remote_video_track_subscribers.lock().push(tx);
|
||||||
rx
|
rx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn did_subscribe_to_remote_audio_track(&self, track: RemoteAudioTrack) {
|
||||||
|
let track = Arc::new(track);
|
||||||
|
self.remote_audio_track_subscribers.lock().retain(|tx| {
|
||||||
|
tx.unbounded_send(RemoteAudioTrackUpdate::Subscribed(track.clone()))
|
||||||
|
.is_ok()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn did_unsubscribe_from_remote_audio_track(&self, publisher_id: String, track_id: String) {
|
||||||
|
self.remote_audio_track_subscribers.lock().retain(|tx| {
|
||||||
|
tx.unbounded_send(RemoteAudioTrackUpdate::Unsubscribed {
|
||||||
|
publisher_id: publisher_id.clone(),
|
||||||
|
track_id: track_id.clone(),
|
||||||
|
})
|
||||||
|
.is_ok()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn did_subscribe_to_remote_video_track(&self, track: RemoteVideoTrack) {
|
fn did_subscribe_to_remote_video_track(&self, track: RemoteVideoTrack) {
|
||||||
let track = Arc::new(track);
|
let track = Arc::new(track);
|
||||||
self.remote_video_track_subscribers.lock().retain(|tx| {
|
self.remote_video_track_subscribers.lock().retain(|tx| {
|
||||||
@ -294,6 +405,8 @@ impl RoomDelegate {
|
|||||||
LKRoomDelegateCreate(
|
LKRoomDelegateCreate(
|
||||||
weak_room as *mut c_void,
|
weak_room as *mut c_void,
|
||||||
Self::on_did_disconnect,
|
Self::on_did_disconnect,
|
||||||
|
Self::on_did_subscribe_to_remote_audio_track,
|
||||||
|
Self::on_did_unsubscribe_from_remote_audio_track,
|
||||||
Self::on_did_subscribe_to_remote_video_track,
|
Self::on_did_subscribe_to_remote_video_track,
|
||||||
Self::on_did_unsubscribe_from_remote_video_track,
|
Self::on_did_unsubscribe_from_remote_video_track,
|
||||||
)
|
)
|
||||||
@ -312,6 +425,36 @@ impl RoomDelegate {
|
|||||||
let _ = Weak::into_raw(room);
|
let _ = Weak::into_raw(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" fn on_did_subscribe_to_remote_audio_track(
|
||||||
|
room: *mut c_void,
|
||||||
|
publisher_id: CFStringRef,
|
||||||
|
track_id: CFStringRef,
|
||||||
|
track: *const c_void,
|
||||||
|
) {
|
||||||
|
let room = unsafe { Weak::from_raw(room as *mut Room) };
|
||||||
|
let publisher_id = unsafe { CFString::wrap_under_get_rule(publisher_id).to_string() };
|
||||||
|
let track_id = unsafe { CFString::wrap_under_get_rule(track_id).to_string() };
|
||||||
|
let track = RemoteAudioTrack::new(track, track_id, publisher_id);
|
||||||
|
if let Some(room) = room.upgrade() {
|
||||||
|
room.did_subscribe_to_remote_audio_track(track);
|
||||||
|
}
|
||||||
|
let _ = Weak::into_raw(room);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" fn on_did_unsubscribe_from_remote_audio_track(
|
||||||
|
room: *mut c_void,
|
||||||
|
publisher_id: CFStringRef,
|
||||||
|
track_id: CFStringRef,
|
||||||
|
) {
|
||||||
|
let room = unsafe { Weak::from_raw(room as *mut Room) };
|
||||||
|
let publisher_id = unsafe { CFString::wrap_under_get_rule(publisher_id).to_string() };
|
||||||
|
let track_id = unsafe { CFString::wrap_under_get_rule(track_id).to_string() };
|
||||||
|
if let Some(room) = room.upgrade() {
|
||||||
|
room.did_unsubscribe_from_remote_audio_track(publisher_id, track_id);
|
||||||
|
}
|
||||||
|
let _ = Weak::into_raw(room);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" fn on_did_subscribe_to_remote_video_track(
|
extern "C" fn on_did_subscribe_to_remote_video_track(
|
||||||
room: *mut c_void,
|
room: *mut c_void,
|
||||||
publisher_id: CFStringRef,
|
publisher_id: CFStringRef,
|
||||||
@ -352,6 +495,20 @@ impl Drop for RoomDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct LocalAudioTrack(*const c_void);
|
||||||
|
|
||||||
|
impl LocalAudioTrack {
|
||||||
|
pub fn create() -> Self {
|
||||||
|
Self(unsafe { LKLocalAudioTrackCreateTrack() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for LocalAudioTrack {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe { CFRelease(self.0) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct LocalVideoTrack(*const c_void);
|
pub struct LocalVideoTrack(*const c_void);
|
||||||
|
|
||||||
impl LocalVideoTrack {
|
impl LocalVideoTrack {
|
||||||
@ -374,6 +531,34 @@ impl Drop for LocalTrackPublication {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct RemoteAudioTrack {
|
||||||
|
_native_track: *const c_void,
|
||||||
|
sid: Sid,
|
||||||
|
publisher_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RemoteAudioTrack {
|
||||||
|
fn new(native_track: *const c_void, sid: Sid, publisher_id: String) -> Self {
|
||||||
|
unsafe {
|
||||||
|
CFRetain(native_track);
|
||||||
|
}
|
||||||
|
Self {
|
||||||
|
_native_track: native_track,
|
||||||
|
sid,
|
||||||
|
publisher_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sid(&self) -> &str {
|
||||||
|
&self.sid
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn publisher_id(&self) -> &str {
|
||||||
|
&self.publisher_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RemoteVideoTrack {
|
pub struct RemoteVideoTrack {
|
||||||
native_track: *const c_void,
|
native_track: *const c_void,
|
||||||
@ -453,6 +638,11 @@ pub enum RemoteVideoTrackUpdate {
|
|||||||
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum RemoteAudioTrackUpdate {
|
||||||
|
Subscribed(Arc<RemoteAudioTrack>),
|
||||||
|
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
||||||
|
}
|
||||||
|
|
||||||
pub struct MacOSDisplay(*const c_void);
|
pub struct MacOSDisplay(*const c_void);
|
||||||
|
|
||||||
impl MacOSDisplay {
|
impl MacOSDisplay {
|
||||||
|
@ -67,7 +67,7 @@ impl TestServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_room(&self, room: String) -> Result<()> {
|
pub async fn create_room(&self, room: String) -> Result<()> {
|
||||||
self.background.simulate_random_delay().await;
|
self.background.simulate_random_delay().await;
|
||||||
let mut server_rooms = self.rooms.lock();
|
let mut server_rooms = self.rooms.lock();
|
||||||
if server_rooms.contains_key(&room) {
|
if server_rooms.contains_key(&room) {
|
||||||
@ -104,7 +104,7 @@ impl TestServer {
|
|||||||
room_name
|
room_name
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
for track in &room.tracks {
|
for track in &room.video_tracks {
|
||||||
client_room
|
client_room
|
||||||
.0
|
.0
|
||||||
.lock()
|
.lock()
|
||||||
@ -182,7 +182,7 @@ impl TestServer {
|
|||||||
frames_rx: local_track.frames_rx.clone(),
|
frames_rx: local_track.frames_rx.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
room.tracks.push(track.clone());
|
room.video_tracks.push(track.clone());
|
||||||
|
|
||||||
for (id, client_room) in &room.client_rooms {
|
for (id, client_room) in &room.client_rooms {
|
||||||
if *id != identity {
|
if *id != identity {
|
||||||
@ -199,6 +199,43 @@ impl TestServer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn publish_audio_track(
|
||||||
|
&self,
|
||||||
|
token: String,
|
||||||
|
_local_track: &LocalAudioTrack,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.background.simulate_random_delay().await;
|
||||||
|
let claims = live_kit_server::token::validate(&token, &self.secret_key)?;
|
||||||
|
let identity = claims.sub.unwrap().to_string();
|
||||||
|
let room_name = claims.video.room.unwrap();
|
||||||
|
|
||||||
|
let mut server_rooms = self.rooms.lock();
|
||||||
|
let room = server_rooms
|
||||||
|
.get_mut(&*room_name)
|
||||||
|
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
|
||||||
|
|
||||||
|
let track = Arc::new(RemoteAudioTrack {
|
||||||
|
sid: nanoid::nanoid!(17),
|
||||||
|
publisher_id: identity.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
room.audio_tracks.push(track.clone());
|
||||||
|
|
||||||
|
for (id, client_room) in &room.client_rooms {
|
||||||
|
if *id != identity {
|
||||||
|
let _ = client_room
|
||||||
|
.0
|
||||||
|
.lock()
|
||||||
|
.audio_track_updates
|
||||||
|
.0
|
||||||
|
.try_broadcast(RemoteAudioTrackUpdate::Subscribed(track.clone()))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn video_tracks(&self, token: String) -> Result<Vec<Arc<RemoteVideoTrack>>> {
|
fn video_tracks(&self, token: String) -> Result<Vec<Arc<RemoteVideoTrack>>> {
|
||||||
let claims = live_kit_server::token::validate(&token, &self.secret_key)?;
|
let claims = live_kit_server::token::validate(&token, &self.secret_key)?;
|
||||||
let room_name = claims.video.room.unwrap();
|
let room_name = claims.video.room.unwrap();
|
||||||
@ -207,14 +244,26 @@ impl TestServer {
|
|||||||
let room = server_rooms
|
let room = server_rooms
|
||||||
.get_mut(&*room_name)
|
.get_mut(&*room_name)
|
||||||
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
|
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
|
||||||
Ok(room.tracks.clone())
|
Ok(room.video_tracks.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn audio_tracks(&self, token: String) -> Result<Vec<Arc<RemoteAudioTrack>>> {
|
||||||
|
let claims = live_kit_server::token::validate(&token, &self.secret_key)?;
|
||||||
|
let room_name = claims.video.room.unwrap();
|
||||||
|
|
||||||
|
let mut server_rooms = self.rooms.lock();
|
||||||
|
let room = server_rooms
|
||||||
|
.get_mut(&*room_name)
|
||||||
|
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
|
||||||
|
Ok(room.audio_tracks.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TestServerRoom {
|
struct TestServerRoom {
|
||||||
client_rooms: HashMap<Sid, Arc<Room>>,
|
client_rooms: HashMap<Sid, Arc<Room>>,
|
||||||
tracks: Vec<Arc<RemoteVideoTrack>>,
|
video_tracks: Vec<Arc<RemoteVideoTrack>>,
|
||||||
|
audio_tracks: Vec<Arc<RemoteAudioTrack>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestServerRoom {}
|
impl TestServerRoom {}
|
||||||
@ -266,6 +315,10 @@ struct RoomState {
|
|||||||
watch::Receiver<ConnectionState>,
|
watch::Receiver<ConnectionState>,
|
||||||
),
|
),
|
||||||
display_sources: Vec<MacOSDisplay>,
|
display_sources: Vec<MacOSDisplay>,
|
||||||
|
audio_track_updates: (
|
||||||
|
async_broadcast::Sender<RemoteAudioTrackUpdate>,
|
||||||
|
async_broadcast::Receiver<RemoteAudioTrackUpdate>,
|
||||||
|
),
|
||||||
video_track_updates: (
|
video_track_updates: (
|
||||||
async_broadcast::Sender<RemoteVideoTrackUpdate>,
|
async_broadcast::Sender<RemoteVideoTrackUpdate>,
|
||||||
async_broadcast::Receiver<RemoteVideoTrackUpdate>,
|
async_broadcast::Receiver<RemoteVideoTrackUpdate>,
|
||||||
@ -286,6 +339,7 @@ impl Room {
|
|||||||
connection: watch::channel_with(ConnectionState::Disconnected),
|
connection: watch::channel_with(ConnectionState::Disconnected),
|
||||||
display_sources: Default::default(),
|
display_sources: Default::default(),
|
||||||
video_track_updates: async_broadcast::broadcast(128),
|
video_track_updates: async_broadcast::broadcast(128),
|
||||||
|
audio_track_updates: async_broadcast::broadcast(128),
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,8 +381,34 @@ impl Room {
|
|||||||
Ok(LocalTrackPublication)
|
Ok(LocalTrackPublication)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn publish_audio_track(
|
||||||
|
self: &Arc<Self>,
|
||||||
|
track: &LocalAudioTrack,
|
||||||
|
) -> impl Future<Output = Result<LocalTrackPublication>> {
|
||||||
|
let this = self.clone();
|
||||||
|
let track = track.clone();
|
||||||
|
async move {
|
||||||
|
this.test_server()
|
||||||
|
.publish_audio_track(this.token(), &track)
|
||||||
|
.await?;
|
||||||
|
Ok(LocalTrackPublication)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn unpublish_track(&self, _: LocalTrackPublication) {}
|
pub fn unpublish_track(&self, _publication: LocalTrackPublication) {}
|
||||||
|
|
||||||
|
pub fn remote_audio_tracks(&self, publisher_id: &str) -> Vec<Arc<RemoteAudioTrack>> {
|
||||||
|
if !self.is_connected() {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.test_server()
|
||||||
|
.audio_tracks(self.token())
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.filter(|track| track.publisher_id() == publisher_id)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remote_video_tracks(&self, publisher_id: &str) -> Vec<Arc<RemoteVideoTrack>> {
|
pub fn remote_video_tracks(&self, publisher_id: &str) -> Vec<Arc<RemoteVideoTrack>> {
|
||||||
if !self.is_connected() {
|
if !self.is_connected() {
|
||||||
@ -343,6 +423,10 @@ impl Room {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remote_audio_track_updates(&self) -> impl Stream<Item = RemoteAudioTrackUpdate> {
|
||||||
|
self.0.lock().audio_track_updates.1.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remote_video_track_updates(&self) -> impl Stream<Item = RemoteVideoTrackUpdate> {
|
pub fn remote_video_track_updates(&self) -> impl Stream<Item = RemoteVideoTrackUpdate> {
|
||||||
self.0.lock().video_track_updates.1.clone()
|
self.0.lock().video_track_updates.1.clone()
|
||||||
}
|
}
|
||||||
@ -404,6 +488,15 @@ impl LocalVideoTrack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct LocalAudioTrack;
|
||||||
|
|
||||||
|
impl LocalAudioTrack {
|
||||||
|
pub fn create() -> Self {
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RemoteVideoTrack {
|
pub struct RemoteVideoTrack {
|
||||||
sid: Sid,
|
sid: Sid,
|
||||||
publisher_id: Sid,
|
publisher_id: Sid,
|
||||||
@ -424,12 +517,33 @@ impl RemoteVideoTrack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RemoteAudioTrack {
|
||||||
|
sid: Sid,
|
||||||
|
publisher_id: Sid,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RemoteAudioTrack {
|
||||||
|
pub fn sid(&self) -> &str {
|
||||||
|
&self.sid
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn publisher_id(&self) -> &str {
|
||||||
|
&self.publisher_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum RemoteVideoTrackUpdate {
|
pub enum RemoteVideoTrackUpdate {
|
||||||
Subscribed(Arc<RemoteVideoTrack>),
|
Subscribed(Arc<RemoteVideoTrack>),
|
||||||
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum RemoteAudioTrackUpdate {
|
||||||
|
Subscribed(Arc<RemoteAudioTrack>),
|
||||||
|
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct MacOSDisplay {
|
pub struct MacOSDisplay {
|
||||||
frames: (
|
frames: (
|
||||||
|
@ -33,7 +33,7 @@ const JSON_RPC_VERSION: &str = "2.0";
|
|||||||
const CONTENT_LEN_HEADER: &str = "Content-Length: ";
|
const CONTENT_LEN_HEADER: &str = "Content-Length: ";
|
||||||
|
|
||||||
type NotificationHandler = Box<dyn Send + FnMut(Option<usize>, &str, AsyncAppContext)>;
|
type NotificationHandler = Box<dyn Send + FnMut(Option<usize>, &str, AsyncAppContext)>;
|
||||||
type ResponseHandler = Box<dyn Send + FnOnce(Result<&str, Error>)>;
|
type ResponseHandler = Box<dyn Send + FnOnce(Result<String, Error>)>;
|
||||||
type IoHandler = Box<dyn Send + FnMut(bool, &str)>;
|
type IoHandler = Box<dyn Send + FnMut(bool, &str)>;
|
||||||
|
|
||||||
pub struct LanguageServer {
|
pub struct LanguageServer {
|
||||||
@ -103,14 +103,14 @@ struct Notification<'a, T> {
|
|||||||
params: T,
|
params: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
struct AnyNotification<'a> {
|
struct AnyNotification<'a> {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
id: Option<usize>,
|
id: Option<usize>,
|
||||||
#[serde(borrow)]
|
#[serde(borrow)]
|
||||||
method: &'a str,
|
method: &'a str,
|
||||||
#[serde(borrow)]
|
#[serde(borrow, default)]
|
||||||
params: &'a RawValue,
|
params: Option<&'a RawValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@ -157,9 +157,12 @@ impl LanguageServer {
|
|||||||
"unhandled notification {}:\n{}",
|
"unhandled notification {}:\n{}",
|
||||||
notification.method,
|
notification.method,
|
||||||
serde_json::to_string_pretty(
|
serde_json::to_string_pretty(
|
||||||
&Value::from_str(notification.params.get()).unwrap()
|
¬ification
|
||||||
|
.params
|
||||||
|
.and_then(|params| Value::from_str(params.get()).ok())
|
||||||
|
.unwrap_or(Value::Null)
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -279,7 +282,11 @@ impl LanguageServer {
|
|||||||
|
|
||||||
if let Ok(msg) = serde_json::from_slice::<AnyNotification>(&buffer) {
|
if let Ok(msg) = serde_json::from_slice::<AnyNotification>(&buffer) {
|
||||||
if let Some(handler) = notification_handlers.lock().get_mut(msg.method) {
|
if let Some(handler) = notification_handlers.lock().get_mut(msg.method) {
|
||||||
handler(msg.id, msg.params.get(), cx.clone());
|
handler(
|
||||||
|
msg.id,
|
||||||
|
&msg.params.map(|params| params.get()).unwrap_or("null"),
|
||||||
|
cx.clone(),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
on_unhandled_notification(msg);
|
on_unhandled_notification(msg);
|
||||||
}
|
}
|
||||||
@ -295,9 +302,9 @@ impl LanguageServer {
|
|||||||
if let Some(error) = error {
|
if let Some(error) = error {
|
||||||
handler(Err(error));
|
handler(Err(error));
|
||||||
} else if let Some(result) = result {
|
} else if let Some(result) = result {
|
||||||
handler(Ok(result.get()));
|
handler(Ok(result.get().into()));
|
||||||
} else {
|
} else {
|
||||||
handler(Ok("null"));
|
handler(Ok("null".into()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -450,11 +457,13 @@ impl LanguageServer {
|
|||||||
let response_handlers = self.response_handlers.clone();
|
let response_handlers = self.response_handlers.clone();
|
||||||
let next_id = AtomicUsize::new(self.next_id.load(SeqCst));
|
let next_id = AtomicUsize::new(self.next_id.load(SeqCst));
|
||||||
let outbound_tx = self.outbound_tx.clone();
|
let outbound_tx = self.outbound_tx.clone();
|
||||||
|
let executor = self.executor.clone();
|
||||||
let mut output_done = self.output_done_rx.lock().take().unwrap();
|
let mut output_done = self.output_done_rx.lock().take().unwrap();
|
||||||
let shutdown_request = Self::request_internal::<request::Shutdown>(
|
let shutdown_request = Self::request_internal::<request::Shutdown>(
|
||||||
&next_id,
|
&next_id,
|
||||||
&response_handlers,
|
&response_handlers,
|
||||||
&outbound_tx,
|
&outbound_tx,
|
||||||
|
&executor,
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
let exit = Self::notify_internal::<notification::Exit>(&outbound_tx, ());
|
let exit = Self::notify_internal::<notification::Exit>(&outbound_tx, ());
|
||||||
@ -651,6 +660,7 @@ impl LanguageServer {
|
|||||||
&self.next_id,
|
&self.next_id,
|
||||||
&self.response_handlers,
|
&self.response_handlers,
|
||||||
&self.outbound_tx,
|
&self.outbound_tx,
|
||||||
|
&self.executor,
|
||||||
params,
|
params,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -659,6 +669,7 @@ impl LanguageServer {
|
|||||||
next_id: &AtomicUsize,
|
next_id: &AtomicUsize,
|
||||||
response_handlers: &Mutex<Option<HashMap<usize, ResponseHandler>>>,
|
response_handlers: &Mutex<Option<HashMap<usize, ResponseHandler>>>,
|
||||||
outbound_tx: &channel::Sender<String>,
|
outbound_tx: &channel::Sender<String>,
|
||||||
|
executor: &Arc<executor::Background>,
|
||||||
params: T::Params,
|
params: T::Params,
|
||||||
) -> impl 'static + Future<Output = Result<T::Result>>
|
) -> impl 'static + Future<Output = Result<T::Result>>
|
||||||
where
|
where
|
||||||
@ -679,15 +690,20 @@ impl LanguageServer {
|
|||||||
.as_mut()
|
.as_mut()
|
||||||
.ok_or_else(|| anyhow!("server shut down"))
|
.ok_or_else(|| anyhow!("server shut down"))
|
||||||
.map(|handlers| {
|
.map(|handlers| {
|
||||||
|
let executor = executor.clone();
|
||||||
handlers.insert(
|
handlers.insert(
|
||||||
id,
|
id,
|
||||||
Box::new(move |result| {
|
Box::new(move |result| {
|
||||||
let response = match result {
|
executor
|
||||||
Ok(response) => serde_json::from_str(response)
|
.spawn(async move {
|
||||||
.context("failed to deserialize response"),
|
let response = match result {
|
||||||
Err(error) => Err(anyhow!("{}", error.message)),
|
Ok(response) => serde_json::from_str(&response)
|
||||||
};
|
.context("failed to deserialize response"),
|
||||||
let _ = tx.send(response);
|
Err(error) => Err(anyhow!("{}", error.message)),
|
||||||
|
};
|
||||||
|
let _ = tx.send(response);
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -828,7 +844,13 @@ impl LanguageServer {
|
|||||||
cx,
|
cx,
|
||||||
move |msg| {
|
move |msg| {
|
||||||
notifications_tx
|
notifications_tx
|
||||||
.try_send((msg.method.to_string(), msg.params.get().to_string()))
|
.try_send((
|
||||||
|
msg.method.to_string(),
|
||||||
|
msg.params
|
||||||
|
.map(|raw_value| raw_value.get())
|
||||||
|
.unwrap_or("null")
|
||||||
|
.to_string(),
|
||||||
|
))
|
||||||
.ok();
|
.ok();
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
|
@ -204,7 +204,7 @@ impl PickerDelegate for OutlineViewDelegate {
|
|||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> AnyElement<Picker<Self>> {
|
) -> AnyElement<Picker<Self>> {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.picker.item.style_for(mouse_state, selected);
|
let style = theme.picker.item.in_state(selected).style_for(mouse_state);
|
||||||
let string_match = &self.matches[ix];
|
let string_match = &self.matches[ix];
|
||||||
let outline_item = &self.outline.items[string_match.candidate_id];
|
let outline_item = &self.outline.items[string_match.candidate_id];
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ pub mod worktree;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod project_tests;
|
mod project_tests;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod worktree_tests;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use client::{proto, Client, TypedEnvelope, UserStore};
|
use client::{proto, Client, TypedEnvelope, UserStore};
|
||||||
@ -36,9 +38,9 @@ use language::{
|
|||||||
},
|
},
|
||||||
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, CachedLspAdapter, CodeAction, CodeLabel,
|
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, CachedLspAdapter, CodeAction, CodeLabel,
|
||||||
Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Diff, Event as BufferEvent, File as _,
|
Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Diff, Event as BufferEvent, File as _,
|
||||||
Language, LanguageRegistry, LanguageServerName, LocalFile, OffsetRangeExt, Operation, Patch,
|
Language, LanguageRegistry, LanguageServerName, LocalFile, LspAdapterDelegate, OffsetRangeExt,
|
||||||
PendingLanguageServer, PointUtf16, TextBufferSnapshot, ToOffset, ToPointUtf16, Transaction,
|
Operation, Patch, PendingLanguageServer, PointUtf16, TextBufferSnapshot, ToOffset,
|
||||||
Unclipped,
|
ToPointUtf16, Transaction, Unclipped,
|
||||||
};
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
use lsp::{
|
use lsp::{
|
||||||
@ -73,8 +75,8 @@ use std::{
|
|||||||
};
|
};
|
||||||
use terminals::Terminals;
|
use terminals::Terminals;
|
||||||
use util::{
|
use util::{
|
||||||
debug_panic, defer, merge_json_value_into, paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc,
|
debug_panic, defer, http::HttpClient, merge_json_value_into,
|
||||||
ResultExt, TryFutureExt as _,
|
paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use fs::*;
|
pub use fs::*;
|
||||||
@ -250,6 +252,7 @@ pub enum Event {
|
|||||||
LanguageServerAdded(LanguageServerId),
|
LanguageServerAdded(LanguageServerId),
|
||||||
LanguageServerRemoved(LanguageServerId),
|
LanguageServerRemoved(LanguageServerId),
|
||||||
LanguageServerLog(LanguageServerId, String),
|
LanguageServerLog(LanguageServerId, String),
|
||||||
|
Notification(String),
|
||||||
ActiveEntryChanged(Option<ProjectEntryId>),
|
ActiveEntryChanged(Option<ProjectEntryId>),
|
||||||
WorktreeAdded,
|
WorktreeAdded,
|
||||||
WorktreeRemoved(WorktreeId),
|
WorktreeRemoved(WorktreeId),
|
||||||
@ -433,6 +436,11 @@ pub enum FormatTrigger {
|
|||||||
Manual,
|
Manual,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ProjectLspAdapterDelegate {
|
||||||
|
project: ModelHandle<Project>,
|
||||||
|
http_client: Arc<dyn HttpClient>,
|
||||||
|
}
|
||||||
|
|
||||||
impl FormatTrigger {
|
impl FormatTrigger {
|
||||||
fn from_proto(value: i32) -> FormatTrigger {
|
fn from_proto(value: i32) -> FormatTrigger {
|
||||||
match value {
|
match value {
|
||||||
@ -2405,7 +2413,7 @@ impl Project {
|
|||||||
language.clone(),
|
language.clone(),
|
||||||
adapter.clone(),
|
adapter.clone(),
|
||||||
worktree_path.clone(),
|
worktree_path.clone(),
|
||||||
self.client.http_client(),
|
ProjectLspAdapterDelegate::new(self, cx),
|
||||||
cx,
|
cx,
|
||||||
) {
|
) {
|
||||||
Some(pending_server) => pending_server,
|
Some(pending_server) => pending_server,
|
||||||
@ -7186,6 +7194,26 @@ impl<P: AsRef<Path>> From<(WorktreeId, P)> for ProjectPath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ProjectLspAdapterDelegate {
|
||||||
|
fn new(project: &Project, cx: &ModelContext<Project>) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
project: cx.handle(),
|
||||||
|
http_client: project.client.http_client(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LspAdapterDelegate for ProjectLspAdapterDelegate {
|
||||||
|
fn show_notification(&self, message: &str, cx: &mut AppContext) {
|
||||||
|
self.project
|
||||||
|
.update(cx, |_, cx| cx.emit(Event::Notification(message.to_owned())));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn http_client(&self) -> Arc<dyn HttpClient> {
|
||||||
|
self.http_client.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn split_operations(
|
fn split_operations(
|
||||||
mut operations: Vec<proto::Operation>,
|
mut operations: Vec<proto::Operation>,
|
||||||
) -> impl Iterator<Item = Vec<proto::Operation>> {
|
) -> impl Iterator<Item = Vec<proto::Operation>> {
|
||||||
|
File diff suppressed because it is too large
Load Diff
1523
crates/project/src/worktree_tests.rs
Normal file
1523
crates/project/src/worktree_tests.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -1253,7 +1253,10 @@ impl ProjectPanel {
|
|||||||
let show_editor = details.is_editing && !details.is_processing;
|
let show_editor = details.is_editing && !details.is_processing;
|
||||||
|
|
||||||
MouseEventHandler::<Self, _>::new(entry_id.to_usize(), cx, |state, cx| {
|
MouseEventHandler::<Self, _>::new(entry_id.to_usize(), cx, |state, cx| {
|
||||||
let mut style = entry_style.style_for(state, details.is_selected).clone();
|
let mut style = entry_style
|
||||||
|
.in_state(details.is_selected)
|
||||||
|
.style_for(state)
|
||||||
|
.clone();
|
||||||
|
|
||||||
if cx
|
if cx
|
||||||
.global::<DragAndDrop<Workspace>>()
|
.global::<DragAndDrop<Workspace>>()
|
||||||
@ -1264,7 +1267,7 @@ impl ProjectPanel {
|
|||||||
.filter(|destination| details.path.starts_with(destination))
|
.filter(|destination| details.path.starts_with(destination))
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
style = entry_style.active.clone().unwrap();
|
style = entry_style.active_state().default.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
let row_container_style = if show_editor {
|
let row_container_style = if show_editor {
|
||||||
@ -1405,9 +1408,11 @@ impl View for ProjectPanel {
|
|||||||
let button_style = theme.open_project_button.clone();
|
let button_style = theme.open_project_button.clone();
|
||||||
let context_menu_item_style = theme::current(cx).context_menu.item.clone();
|
let context_menu_item_style = theme::current(cx).context_menu.item.clone();
|
||||||
move |state, cx| {
|
move |state, cx| {
|
||||||
let button_style = button_style.style_for(state, false).clone();
|
let button_style = button_style.style_for(state).clone();
|
||||||
let context_menu_item =
|
let context_menu_item = context_menu_item_style
|
||||||
context_menu_item_style.style_for(state, true).clone();
|
.active_state()
|
||||||
|
.style_for(state)
|
||||||
|
.clone();
|
||||||
|
|
||||||
theme::ui::keystroke_label(
|
theme::ui::keystroke_label(
|
||||||
"Open a project",
|
"Open a project",
|
||||||
|
@ -196,7 +196,7 @@ impl PickerDelegate for ProjectSymbolsDelegate {
|
|||||||
) -> AnyElement<Picker<Self>> {
|
) -> AnyElement<Picker<Self>> {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = &theme.picker.item;
|
let style = &theme.picker.item;
|
||||||
let current_style = style.style_for(mouse_state, selected);
|
let current_style = style.in_state(selected).style_for(mouse_state);
|
||||||
|
|
||||||
let string_match = &self.matches[ix];
|
let string_match = &self.matches[ix];
|
||||||
let symbol = &self.symbols[string_match.candidate_id];
|
let symbol = &self.symbols[string_match.candidate_id];
|
||||||
@ -229,7 +229,10 @@ impl PickerDelegate for ProjectSymbolsDelegate {
|
|||||||
.with_child(
|
.with_child(
|
||||||
// Avoid styling the path differently when it is selected, since
|
// Avoid styling the path differently when it is selected, since
|
||||||
// the symbol's syntax highlighting doesn't change when selected.
|
// the symbol's syntax highlighting doesn't change when selected.
|
||||||
Label::new(path.to_string(), style.default.label.clone()),
|
Label::new(
|
||||||
|
path.to_string(),
|
||||||
|
style.inactive_state().default.label.clone(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(current_style.container)
|
.with_style(current_style.container)
|
||||||
|
@ -173,7 +173,7 @@ impl PickerDelegate for RecentProjectsDelegate {
|
|||||||
cx: &gpui::AppContext,
|
cx: &gpui::AppContext,
|
||||||
) -> AnyElement<Picker<Self>> {
|
) -> AnyElement<Picker<Self>> {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.picker.item.style_for(mouse_state, selected);
|
let style = theme.picker.item.in_state(selected).style_for(mouse_state);
|
||||||
|
|
||||||
let string_match = &self.matches[ix];
|
let string_match = &self.matches[ix];
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ impl Rope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.chunks.push_tree(chunks.suffix(&()), &());
|
self.chunks.append(chunks.suffix(&()), &());
|
||||||
self.check_invariants();
|
self.check_invariants();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +328,11 @@ impl BufferSearchBar {
|
|||||||
Some(
|
Some(
|
||||||
MouseEventHandler::<Self, _>::new(option as usize, cx, |state, cx| {
|
MouseEventHandler::<Self, _>::new(option as usize, cx, |state, cx| {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.search.option_button.style_for(state, is_active);
|
let style = theme
|
||||||
|
.search
|
||||||
|
.option_button
|
||||||
|
.in_state(is_active)
|
||||||
|
.style_for(state);
|
||||||
Label::new(icon, style.text.clone())
|
Label::new(icon, style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
@ -371,7 +375,7 @@ impl BufferSearchBar {
|
|||||||
enum NavButton {}
|
enum NavButton {}
|
||||||
MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| {
|
MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.search.option_button.style_for(state, false);
|
let style = theme.search.option_button.inactive_state().style_for(state);
|
||||||
Label::new(icon, style.text.clone())
|
Label::new(icon, style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
@ -403,7 +407,7 @@ impl BufferSearchBar {
|
|||||||
|
|
||||||
enum CloseButton {}
|
enum CloseButton {}
|
||||||
MouseEventHandler::<CloseButton, _>::new(0, cx, |state, _| {
|
MouseEventHandler::<CloseButton, _>::new(0, cx, |state, _| {
|
||||||
let style = theme.dismiss_button.style_for(state, false);
|
let style = theme.dismiss_button.style_for(state);
|
||||||
Svg::new("icons/x_mark_8.svg")
|
Svg::new("icons/x_mark_8.svg")
|
||||||
.with_color(style.color)
|
.with_color(style.color)
|
||||||
.constrained()
|
.constrained()
|
||||||
|
@ -896,7 +896,7 @@ impl ProjectSearchBar {
|
|||||||
enum NavButton {}
|
enum NavButton {}
|
||||||
MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| {
|
MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.search.option_button.style_for(state, false);
|
let style = theme.search.option_button.inactive_state().style_for(state);
|
||||||
Label::new(icon, style.text.clone())
|
Label::new(icon, style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
@ -927,7 +927,11 @@ impl ProjectSearchBar {
|
|||||||
let is_active = self.is_option_enabled(option, cx);
|
let is_active = self.is_option_enabled(option, cx);
|
||||||
MouseEventHandler::<Self, _>::new(option as usize, cx, |state, cx| {
|
MouseEventHandler::<Self, _>::new(option as usize, cx, |state, cx| {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.search.option_button.style_for(state, is_active);
|
let style = theme
|
||||||
|
.search
|
||||||
|
.option_button
|
||||||
|
.in_state(is_active)
|
||||||
|
.style_for(state);
|
||||||
Label::new(icon, style.text.clone())
|
Label::new(icon, style.text.clone())
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
|
@ -21,7 +21,7 @@ util = { path = "../util" }
|
|||||||
|
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
json_comments = "0.2"
|
serde_json_lenient = {version = "0.1", features = ["preserve_order", "raw_value"]}
|
||||||
lazy_static.workspace = true
|
lazy_static.workspace = true
|
||||||
postage.workspace = true
|
postage.workspace = true
|
||||||
rust-embed.workspace = true
|
rust-embed.workspace = true
|
||||||
@ -31,12 +31,12 @@ serde_derive.workspace = true
|
|||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
toml.workspace = true
|
toml.workspace = true
|
||||||
tree-sitter = "*"
|
tree-sitter.workspace = true
|
||||||
tree-sitter-json = "*"
|
tree-sitter-json = "*"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
gpui = { path = "../gpui", features = ["test-support"] }
|
gpui = { path = "../gpui", features = ["test-support"] }
|
||||||
fs = { path = "../fs", features = ["test-support"] }
|
fs = { path = "../fs", features = ["test-support"] }
|
||||||
|
indoc.workspace = true
|
||||||
pretty_assertions = "1.3.0"
|
pretty_assertions = "1.3.0"
|
||||||
unindent.workspace = true
|
unindent.workspace = true
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{settings_store::parse_json_with_comments, SettingsAssets};
|
use crate::{settings_store::parse_json_with_comments, SettingsAssets};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use collections::BTreeMap;
|
use collections::BTreeMap;
|
||||||
use gpui::{keymap_matcher::Binding, AppContext};
|
use gpui::{keymap_matcher::Binding, AppContext};
|
||||||
use schemars::{
|
use schemars::{
|
||||||
@ -7,7 +7,7 @@ use schemars::{
|
|||||||
schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation}, JsonSchema,
|
schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation}, JsonSchema,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::{value::RawValue, Value};
|
use serde_json::Value;
|
||||||
use util::{asset_str, ResultExt};
|
use util::{asset_str, ResultExt};
|
||||||
|
|
||||||
#[derive(Deserialize, Default, Clone, JsonSchema)]
|
#[derive(Deserialize, Default, Clone, JsonSchema)]
|
||||||
@ -23,7 +23,7 @@ pub struct KeymapBlock {
|
|||||||
|
|
||||||
#[derive(Deserialize, Default, Clone)]
|
#[derive(Deserialize, Default, Clone)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct KeymapAction(Box<RawValue>);
|
pub struct KeymapAction(Value);
|
||||||
|
|
||||||
impl JsonSchema for KeymapAction {
|
impl JsonSchema for KeymapAction {
|
||||||
fn schema_name() -> String {
|
fn schema_name() -> String {
|
||||||
@ -36,11 +36,12 @@ impl JsonSchema for KeymapAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct ActionWithData(Box<str>, Box<RawValue>);
|
struct ActionWithData(Box<str>, Value);
|
||||||
|
|
||||||
impl KeymapFile {
|
impl KeymapFile {
|
||||||
pub fn load_asset(asset_path: &str, cx: &mut AppContext) -> Result<()> {
|
pub fn load_asset(asset_path: &str, cx: &mut AppContext) -> Result<()> {
|
||||||
let content = asset_str::<SettingsAssets>(asset_path);
|
let content = asset_str::<SettingsAssets>(asset_path);
|
||||||
|
|
||||||
Self::parse(content.as_ref())?.add_to_cx(cx)
|
Self::parse(content.as_ref())?.add_to_cx(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,18 +54,27 @@ impl KeymapFile {
|
|||||||
let bindings = bindings
|
let bindings = bindings
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|(keystroke, action)| {
|
.filter_map(|(keystroke, action)| {
|
||||||
let action = action.0.get();
|
let action = action.0;
|
||||||
|
|
||||||
// This is a workaround for a limitation in serde: serde-rs/json#497
|
// This is a workaround for a limitation in serde: serde-rs/json#497
|
||||||
// We want to deserialize the action data as a `RawValue` so that we can
|
// We want to deserialize the action data as a `RawValue` so that we can
|
||||||
// deserialize the action itself dynamically directly from the JSON
|
// deserialize the action itself dynamically directly from the JSON
|
||||||
// string. But `RawValue` currently does not work inside of an untagged enum.
|
// string. But `RawValue` currently does not work inside of an untagged enum.
|
||||||
if action.starts_with('[') {
|
if let Value::Array(items) = action {
|
||||||
let ActionWithData(name, data) = serde_json::from_str(action).log_err()?;
|
let Ok([name, data]): Result<[serde_json::Value; 2], _> = items.try_into() else {
|
||||||
cx.deserialize_action(&name, Some(data.get()))
|
return Some(Err(anyhow!("Expected array of length 2")));
|
||||||
|
};
|
||||||
|
let serde_json::Value::String(name) = name else {
|
||||||
|
return Some(Err(anyhow!("Expected first item in array to be a string.")))
|
||||||
|
};
|
||||||
|
cx.deserialize_action(
|
||||||
|
&name,
|
||||||
|
Some(data),
|
||||||
|
)
|
||||||
|
} else if let Value::String(name) = action {
|
||||||
|
cx.deserialize_action(&name, None)
|
||||||
} else {
|
} else {
|
||||||
let name = serde_json::from_str(action).log_err()?;
|
return Some(Err(anyhow!("Expected two-element array, got {:?}", action)));
|
||||||
cx.deserialize_action(name, None)
|
|
||||||
}
|
}
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
@ -117,3 +127,24 @@ impl KeymapFile {
|
|||||||
serde_json::to_value(root_schema).unwrap()
|
serde_json::to_value(root_schema).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::KeymapFile;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_deserialize_keymap_with_trailing_comma() {
|
||||||
|
let json = indoc::indoc! {"[
|
||||||
|
// Standard macOS bindings
|
||||||
|
{
|
||||||
|
\"bindings\": {
|
||||||
|
\"up\": \"menu::SelectPrev\",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"
|
||||||
|
|
||||||
|
};
|
||||||
|
KeymapFile::parse(json).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -86,9 +86,9 @@ pub struct SettingsJsonSchemaParams<'a> {
|
|||||||
/// A set of strongly-typed setting values defined via multiple JSON files.
|
/// A set of strongly-typed setting values defined via multiple JSON files.
|
||||||
pub struct SettingsStore {
|
pub struct SettingsStore {
|
||||||
setting_values: HashMap<TypeId, Box<dyn AnySettingValue>>,
|
setting_values: HashMap<TypeId, Box<dyn AnySettingValue>>,
|
||||||
default_deserialized_settings: serde_json::Value,
|
raw_default_settings: serde_json::Value,
|
||||||
user_deserialized_settings: serde_json::Value,
|
raw_user_settings: serde_json::Value,
|
||||||
local_deserialized_settings: BTreeMap<(usize, Arc<Path>), serde_json::Value>,
|
raw_local_settings: BTreeMap<(usize, Arc<Path>), serde_json::Value>,
|
||||||
tab_size_callback: Option<(TypeId, Box<dyn Fn(&dyn Any) -> Option<usize>>)>,
|
tab_size_callback: Option<(TypeId, Box<dyn Fn(&dyn Any) -> Option<usize>>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,9 +96,9 @@ impl Default for SettingsStore {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
SettingsStore {
|
SettingsStore {
|
||||||
setting_values: Default::default(),
|
setting_values: Default::default(),
|
||||||
default_deserialized_settings: serde_json::json!({}),
|
raw_default_settings: serde_json::json!({}),
|
||||||
user_deserialized_settings: serde_json::json!({}),
|
raw_user_settings: serde_json::json!({}),
|
||||||
local_deserialized_settings: Default::default(),
|
raw_local_settings: Default::default(),
|
||||||
tab_size_callback: Default::default(),
|
tab_size_callback: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,13 +148,13 @@ impl SettingsStore {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
if let Some(default_settings) = setting_value
|
if let Some(default_settings) = setting_value
|
||||||
.deserialize_setting(&self.default_deserialized_settings)
|
.deserialize_setting(&self.raw_default_settings)
|
||||||
.log_err()
|
.log_err()
|
||||||
{
|
{
|
||||||
let mut user_values_stack = Vec::new();
|
let mut user_values_stack = Vec::new();
|
||||||
|
|
||||||
if let Some(user_settings) = setting_value
|
if let Some(user_settings) = setting_value
|
||||||
.deserialize_setting(&self.user_deserialized_settings)
|
.deserialize_setting(&self.raw_user_settings)
|
||||||
.log_err()
|
.log_err()
|
||||||
{
|
{
|
||||||
user_values_stack = vec![user_settings];
|
user_values_stack = vec![user_settings];
|
||||||
@ -196,8 +196,8 @@ impl SettingsStore {
|
|||||||
///
|
///
|
||||||
/// This is only for debugging and reporting. For user-facing functionality,
|
/// This is only for debugging and reporting. For user-facing functionality,
|
||||||
/// use the typed setting interface.
|
/// use the typed setting interface.
|
||||||
pub fn untyped_user_settings(&self) -> &serde_json::Value {
|
pub fn raw_user_settings(&self) -> &serde_json::Value {
|
||||||
&self.user_deserialized_settings
|
&self.raw_user_settings
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
@ -219,7 +219,7 @@ impl SettingsStore {
|
|||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
update: impl FnOnce(&mut T::FileContent),
|
update: impl FnOnce(&mut T::FileContent),
|
||||||
) {
|
) {
|
||||||
let old_text = serde_json::to_string(&self.user_deserialized_settings).unwrap();
|
let old_text = serde_json::to_string(&self.raw_user_settings).unwrap();
|
||||||
let new_text = self.new_text_for_update::<T>(old_text, update);
|
let new_text = self.new_text_for_update::<T>(old_text, update);
|
||||||
self.set_user_settings(&new_text, cx).unwrap();
|
self.set_user_settings(&new_text, cx).unwrap();
|
||||||
}
|
}
|
||||||
@ -248,25 +248,19 @@ impl SettingsStore {
|
|||||||
) -> Vec<(Range<usize>, String)> {
|
) -> Vec<(Range<usize>, String)> {
|
||||||
let setting_type_id = TypeId::of::<T>();
|
let setting_type_id = TypeId::of::<T>();
|
||||||
|
|
||||||
let old_content = self
|
let setting = self
|
||||||
.setting_values
|
.setting_values
|
||||||
.get(&setting_type_id)
|
.get(&setting_type_id)
|
||||||
.unwrap_or_else(|| panic!("unregistered setting type {}", type_name::<T>()))
|
.unwrap_or_else(|| panic!("unregistered setting type {}", type_name::<T>()));
|
||||||
.deserialize_setting(&self.user_deserialized_settings)
|
let raw_settings = parse_json_with_comments::<serde_json::Value>(text).unwrap_or_default();
|
||||||
.unwrap_or_else(|e| {
|
let old_content = match setting.deserialize_setting(&raw_settings) {
|
||||||
panic!(
|
Ok(content) => content.0.downcast::<T::FileContent>().unwrap(),
|
||||||
"could not deserialize setting type {} from user settings: {}",
|
Err(_) => Box::new(T::FileContent::default()),
|
||||||
type_name::<T>(),
|
};
|
||||||
e
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.0
|
|
||||||
.downcast::<T::FileContent>()
|
|
||||||
.unwrap();
|
|
||||||
let mut new_content = old_content.clone();
|
let mut new_content = old_content.clone();
|
||||||
update(&mut new_content);
|
update(&mut new_content);
|
||||||
|
|
||||||
let old_value = &serde_json::to_value(&old_content).unwrap();
|
let old_value = serde_json::to_value(&old_content).unwrap();
|
||||||
let new_value = serde_json::to_value(new_content).unwrap();
|
let new_value = serde_json::to_value(new_content).unwrap();
|
||||||
|
|
||||||
let mut key_path = Vec::new();
|
let mut key_path = Vec::new();
|
||||||
@ -323,7 +317,7 @@ impl SettingsStore {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let settings: serde_json::Value = parse_json_with_comments(default_settings_content)?;
|
let settings: serde_json::Value = parse_json_with_comments(default_settings_content)?;
|
||||||
if settings.is_object() {
|
if settings.is_object() {
|
||||||
self.default_deserialized_settings = settings;
|
self.raw_default_settings = settings;
|
||||||
self.recompute_values(None, cx)?;
|
self.recompute_values(None, cx)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@ -339,7 +333,7 @@ impl SettingsStore {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let settings: serde_json::Value = parse_json_with_comments(user_settings_content)?;
|
let settings: serde_json::Value = parse_json_with_comments(user_settings_content)?;
|
||||||
if settings.is_object() {
|
if settings.is_object() {
|
||||||
self.user_deserialized_settings = settings;
|
self.raw_user_settings = settings;
|
||||||
self.recompute_values(None, cx)?;
|
self.recompute_values(None, cx)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@ -356,11 +350,10 @@ impl SettingsStore {
|
|||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if let Some(content) = settings_content {
|
if let Some(content) = settings_content {
|
||||||
self.local_deserialized_settings
|
self.raw_local_settings
|
||||||
.insert((root_id, path.clone()), parse_json_with_comments(content)?);
|
.insert((root_id, path.clone()), parse_json_with_comments(content)?);
|
||||||
} else {
|
} else {
|
||||||
self.local_deserialized_settings
|
self.raw_local_settings.remove(&(root_id, path.clone()));
|
||||||
.remove(&(root_id, path.clone()));
|
|
||||||
}
|
}
|
||||||
self.recompute_values(Some((root_id, &path)), cx)?;
|
self.recompute_values(Some((root_id, &path)), cx)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -368,14 +361,13 @@ impl SettingsStore {
|
|||||||
|
|
||||||
/// Add or remove a set of local settings via a JSON string.
|
/// Add or remove a set of local settings via a JSON string.
|
||||||
pub fn clear_local_settings(&mut self, root_id: usize, cx: &AppContext) -> Result<()> {
|
pub fn clear_local_settings(&mut self, root_id: usize, cx: &AppContext) -> Result<()> {
|
||||||
self.local_deserialized_settings
|
self.raw_local_settings.retain(|k, _| k.0 != root_id);
|
||||||
.retain(|k, _| k.0 != root_id);
|
|
||||||
self.recompute_values(Some((root_id, "".as_ref())), cx)?;
|
self.recompute_values(Some((root_id, "".as_ref())), cx)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_settings(&self, root_id: usize) -> impl '_ + Iterator<Item = (Arc<Path>, String)> {
|
pub fn local_settings(&self, root_id: usize) -> impl '_ + Iterator<Item = (Arc<Path>, String)> {
|
||||||
self.local_deserialized_settings
|
self.raw_local_settings
|
||||||
.range((root_id, Path::new("").into())..(root_id + 1, Path::new("").into()))
|
.range((root_id, Path::new("").into())..(root_id + 1, Path::new("").into()))
|
||||||
.map(|((_, path), content)| (path.clone(), serde_json::to_string(content).unwrap()))
|
.map(|((_, path), content)| (path.clone(), serde_json::to_string(content).unwrap()))
|
||||||
}
|
}
|
||||||
@ -466,14 +458,13 @@ impl SettingsStore {
|
|||||||
let mut user_settings_stack = Vec::<DeserializedSetting>::new();
|
let mut user_settings_stack = Vec::<DeserializedSetting>::new();
|
||||||
let mut paths_stack = Vec::<Option<(usize, &Path)>>::new();
|
let mut paths_stack = Vec::<Option<(usize, &Path)>>::new();
|
||||||
for setting_value in self.setting_values.values_mut() {
|
for setting_value in self.setting_values.values_mut() {
|
||||||
let default_settings =
|
let default_settings = setting_value.deserialize_setting(&self.raw_default_settings)?;
|
||||||
setting_value.deserialize_setting(&self.default_deserialized_settings)?;
|
|
||||||
|
|
||||||
user_settings_stack.clear();
|
user_settings_stack.clear();
|
||||||
paths_stack.clear();
|
paths_stack.clear();
|
||||||
|
|
||||||
if let Some(user_settings) = setting_value
|
if let Some(user_settings) = setting_value
|
||||||
.deserialize_setting(&self.user_deserialized_settings)
|
.deserialize_setting(&self.raw_user_settings)
|
||||||
.log_err()
|
.log_err()
|
||||||
{
|
{
|
||||||
user_settings_stack.push(user_settings);
|
user_settings_stack.push(user_settings);
|
||||||
@ -491,7 +482,7 @@ impl SettingsStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reload the local values for the setting.
|
// Reload the local values for the setting.
|
||||||
for ((root_id, path), local_settings) in &self.local_deserialized_settings {
|
for ((root_id, path), local_settings) in &self.raw_local_settings {
|
||||||
// Build a stack of all of the local values for that setting.
|
// Build a stack of all of the local values for that setting.
|
||||||
while let Some(prev_entry) = paths_stack.last() {
|
while let Some(prev_entry) = paths_stack.last() {
|
||||||
if let Some((prev_root_id, prev_path)) = prev_entry {
|
if let Some((prev_root_id, prev_path)) = prev_entry {
|
||||||
@ -542,9 +533,9 @@ impl Debug for SettingsStore {
|
|||||||
.map(|value| value.setting_type_name())
|
.map(|value| value.setting_type_name())
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
.field("default_settings", &self.default_deserialized_settings)
|
.field("default_settings", &self.raw_default_settings)
|
||||||
.field("user_settings", &self.user_deserialized_settings)
|
.field("user_settings", &self.raw_user_settings)
|
||||||
.field("local_settings", &self.local_deserialized_settings)
|
.field("local_settings", &self.raw_local_settings)
|
||||||
.finish_non_exhaustive()
|
.finish_non_exhaustive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -843,11 +834,8 @@ fn to_pretty_json(value: &impl Serialize, indent_size: usize, indent_prefix_len:
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_json_with_comments<T: DeserializeOwned>(content: &str) -> Result<T> {
|
pub fn parse_json_with_comments<T: DeserializeOwned>(content: &str) -> Result<T> {
|
||||||
Ok(serde_json::from_reader(
|
Ok(serde_json_lenient::from_str(content)?)
|
||||||
json_comments::CommentSettings::c_style().strip_comments(content.as_bytes()),
|
|
||||||
)?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -669,7 +669,7 @@ impl<'a, T: Item> SeekAggregate<'a, T> for () {
|
|||||||
impl<'a, T: Item> SeekAggregate<'a, T> for SliceSeekAggregate<T> {
|
impl<'a, T: Item> SeekAggregate<'a, T> for SliceSeekAggregate<T> {
|
||||||
fn begin_leaf(&mut self) {}
|
fn begin_leaf(&mut self) {}
|
||||||
fn end_leaf(&mut self, cx: &<T::Summary as Summary>::Context) {
|
fn end_leaf(&mut self, cx: &<T::Summary as Summary>::Context) {
|
||||||
self.tree.push_tree(
|
self.tree.append(
|
||||||
SumTree(Arc::new(Node::Leaf {
|
SumTree(Arc::new(Node::Leaf {
|
||||||
summary: mem::take(&mut self.leaf_summary),
|
summary: mem::take(&mut self.leaf_summary),
|
||||||
items: mem::take(&mut self.leaf_items),
|
items: mem::take(&mut self.leaf_items),
|
||||||
@ -689,7 +689,7 @@ impl<'a, T: Item> SeekAggregate<'a, T> for SliceSeekAggregate<T> {
|
|||||||
_: &T::Summary,
|
_: &T::Summary,
|
||||||
cx: &<T::Summary as Summary>::Context,
|
cx: &<T::Summary as Summary>::Context,
|
||||||
) {
|
) {
|
||||||
self.tree.push_tree(tree.clone(), cx);
|
self.tree.append(tree.clone(), cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ impl<T: Item> SumTree<T> {
|
|||||||
|
|
||||||
for item in iter {
|
for item in iter {
|
||||||
if leaf.is_some() && leaf.as_ref().unwrap().items().len() == 2 * TREE_BASE {
|
if leaf.is_some() && leaf.as_ref().unwrap().items().len() == 2 * TREE_BASE {
|
||||||
self.push_tree(SumTree(Arc::new(leaf.take().unwrap())), cx);
|
self.append(SumTree(Arc::new(leaf.take().unwrap())), cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if leaf.is_none() {
|
if leaf.is_none() {
|
||||||
@ -295,13 +295,13 @@ impl<T: Item> SumTree<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if leaf.is_some() {
|
if leaf.is_some() {
|
||||||
self.push_tree(SumTree(Arc::new(leaf.take().unwrap())), cx);
|
self.append(SumTree(Arc::new(leaf.take().unwrap())), cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push(&mut self, item: T, cx: &<T::Summary as Summary>::Context) {
|
pub fn push(&mut self, item: T, cx: &<T::Summary as Summary>::Context) {
|
||||||
let summary = item.summary();
|
let summary = item.summary();
|
||||||
self.push_tree(
|
self.append(
|
||||||
SumTree(Arc::new(Node::Leaf {
|
SumTree(Arc::new(Node::Leaf {
|
||||||
summary: summary.clone(),
|
summary: summary.clone(),
|
||||||
items: ArrayVec::from_iter(Some(item)),
|
items: ArrayVec::from_iter(Some(item)),
|
||||||
@ -311,11 +311,11 @@ impl<T: Item> SumTree<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_tree(&mut self, other: Self, cx: &<T::Summary as Summary>::Context) {
|
pub fn append(&mut self, other: Self, cx: &<T::Summary as Summary>::Context) {
|
||||||
if !other.0.is_leaf() || !other.0.items().is_empty() {
|
if !other.0.is_leaf() || !other.0.items().is_empty() {
|
||||||
if self.0.height() < other.0.height() {
|
if self.0.height() < other.0.height() {
|
||||||
for tree in other.0.child_trees() {
|
for tree in other.0.child_trees() {
|
||||||
self.push_tree(tree.clone(), cx);
|
self.append(tree.clone(), cx);
|
||||||
}
|
}
|
||||||
} else if let Some(split_tree) = self.push_tree_recursive(other, cx) {
|
} else if let Some(split_tree) = self.push_tree_recursive(other, cx) {
|
||||||
*self = Self::from_child_trees(self.clone(), split_tree, cx);
|
*self = Self::from_child_trees(self.clone(), split_tree, cx);
|
||||||
@ -512,7 +512,7 @@ impl<T: KeyedItem> SumTree<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
new_tree.push(item, cx);
|
new_tree.push(item, cx);
|
||||||
new_tree.push_tree(cursor.suffix(cx), cx);
|
new_tree.append(cursor.suffix(cx), cx);
|
||||||
new_tree
|
new_tree
|
||||||
};
|
};
|
||||||
replaced
|
replaced
|
||||||
@ -529,7 +529,7 @@ impl<T: KeyedItem> SumTree<T> {
|
|||||||
cursor.next(cx);
|
cursor.next(cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new_tree.push_tree(cursor.suffix(cx), cx);
|
new_tree.append(cursor.suffix(cx), cx);
|
||||||
new_tree
|
new_tree
|
||||||
};
|
};
|
||||||
removed
|
removed
|
||||||
@ -563,7 +563,7 @@ impl<T: KeyedItem> SumTree<T> {
|
|||||||
{
|
{
|
||||||
new_tree.extend(buffered_items.drain(..), cx);
|
new_tree.extend(buffered_items.drain(..), cx);
|
||||||
let slice = cursor.slice(&new_key, Bias::Left, cx);
|
let slice = cursor.slice(&new_key, Bias::Left, cx);
|
||||||
new_tree.push_tree(slice, cx);
|
new_tree.append(slice, cx);
|
||||||
old_item = cursor.item();
|
old_item = cursor.item();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,7 +583,7 @@ impl<T: KeyedItem> SumTree<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_tree.extend(buffered_items, cx);
|
new_tree.extend(buffered_items, cx);
|
||||||
new_tree.push_tree(cursor.suffix(cx), cx);
|
new_tree.append(cursor.suffix(cx), cx);
|
||||||
new_tree
|
new_tree
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -719,7 +719,7 @@ mod tests {
|
|||||||
let mut tree2 = SumTree::new();
|
let mut tree2 = SumTree::new();
|
||||||
tree2.extend(50..100, &());
|
tree2.extend(50..100, &());
|
||||||
|
|
||||||
tree1.push_tree(tree2, &());
|
tree1.append(tree2, &());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tree1.items(&()),
|
tree1.items(&()),
|
||||||
(0..20).chain(50..100).collect::<Vec<u8>>()
|
(0..20).chain(50..100).collect::<Vec<u8>>()
|
||||||
@ -766,7 +766,7 @@ mod tests {
|
|||||||
let mut new_tree = cursor.slice(&Count(splice_start), Bias::Right, &());
|
let mut new_tree = cursor.slice(&Count(splice_start), Bias::Right, &());
|
||||||
new_tree.extend(new_items, &());
|
new_tree.extend(new_items, &());
|
||||||
cursor.seek(&Count(splice_end), Bias::Right, &());
|
cursor.seek(&Count(splice_end), Bias::Right, &());
|
||||||
new_tree.push_tree(cursor.slice(&tree_end, Bias::Right, &()), &());
|
new_tree.append(cursor.slice(&tree_end, Bias::Right, &()), &());
|
||||||
new_tree
|
new_tree
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ impl<K: Clone + Debug + Default + Ord, V: Clone + Debug> TreeMap<K, V> {
|
|||||||
removed = Some(cursor.item().unwrap().value.clone());
|
removed = Some(cursor.item().unwrap().value.clone());
|
||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
}
|
}
|
||||||
new_tree.push_tree(cursor.suffix(&()), &());
|
new_tree.append(cursor.suffix(&()), &());
|
||||||
drop(cursor);
|
drop(cursor);
|
||||||
self.0 = new_tree;
|
self.0 = new_tree;
|
||||||
removed
|
removed
|
||||||
@ -79,7 +79,7 @@ impl<K: Clone + Debug + Default + Ord, V: Clone + Debug> TreeMap<K, V> {
|
|||||||
let mut cursor = self.0.cursor::<MapKeyRef<'_, K>>();
|
let mut cursor = self.0.cursor::<MapKeyRef<'_, K>>();
|
||||||
let mut new_tree = cursor.slice(&start, Bias::Left, &());
|
let mut new_tree = cursor.slice(&start, Bias::Left, &());
|
||||||
cursor.seek(&end, Bias::Left, &());
|
cursor.seek(&end, Bias::Left, &());
|
||||||
new_tree.push_tree(cursor.suffix(&()), &());
|
new_tree.append(cursor.suffix(&()), &());
|
||||||
drop(cursor);
|
drop(cursor);
|
||||||
self.0 = new_tree;
|
self.0 = new_tree;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ impl<K: Clone + Debug + Default + Ord, V: Clone + Debug> TreeMap<K, V> {
|
|||||||
new_tree.push(updated, &());
|
new_tree.push(updated, &());
|
||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
}
|
}
|
||||||
new_tree.push_tree(cursor.suffix(&()), &());
|
new_tree.append(cursor.suffix(&()), &());
|
||||||
drop(cursor);
|
drop(cursor);
|
||||||
self.0 = new_tree;
|
self.0 = new_tree;
|
||||||
result
|
result
|
||||||
|
@ -600,7 +600,7 @@ impl Buffer {
|
|||||||
let mut old_fragments = self.fragments.cursor::<FragmentTextSummary>();
|
let mut old_fragments = self.fragments.cursor::<FragmentTextSummary>();
|
||||||
let mut new_fragments =
|
let mut new_fragments =
|
||||||
old_fragments.slice(&edits.peek().unwrap().0.start, Bias::Right, &None);
|
old_fragments.slice(&edits.peek().unwrap().0.start, Bias::Right, &None);
|
||||||
new_ropes.push_tree(new_fragments.summary().text);
|
new_ropes.append(new_fragments.summary().text);
|
||||||
|
|
||||||
let mut fragment_start = old_fragments.start().visible;
|
let mut fragment_start = old_fragments.start().visible;
|
||||||
for (range, new_text) in edits {
|
for (range, new_text) in edits {
|
||||||
@ -625,8 +625,8 @@ impl Buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let slice = old_fragments.slice(&range.start, Bias::Right, &None);
|
let slice = old_fragments.slice(&range.start, Bias::Right, &None);
|
||||||
new_ropes.push_tree(slice.summary().text);
|
new_ropes.append(slice.summary().text);
|
||||||
new_fragments.push_tree(slice, &None);
|
new_fragments.append(slice, &None);
|
||||||
fragment_start = old_fragments.start().visible;
|
fragment_start = old_fragments.start().visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,8 +728,8 @@ impl Buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let suffix = old_fragments.suffix(&None);
|
let suffix = old_fragments.suffix(&None);
|
||||||
new_ropes.push_tree(suffix.summary().text);
|
new_ropes.append(suffix.summary().text);
|
||||||
new_fragments.push_tree(suffix, &None);
|
new_fragments.append(suffix, &None);
|
||||||
let (visible_text, deleted_text) = new_ropes.finish();
|
let (visible_text, deleted_text) = new_ropes.finish();
|
||||||
drop(old_fragments);
|
drop(old_fragments);
|
||||||
|
|
||||||
@ -828,7 +828,7 @@ impl Buffer {
|
|||||||
Bias::Left,
|
Bias::Left,
|
||||||
&cx,
|
&cx,
|
||||||
);
|
);
|
||||||
new_ropes.push_tree(new_fragments.summary().text);
|
new_ropes.append(new_fragments.summary().text);
|
||||||
|
|
||||||
let mut fragment_start = old_fragments.start().0.full_offset();
|
let mut fragment_start = old_fragments.start().0.full_offset();
|
||||||
for (range, new_text) in edits {
|
for (range, new_text) in edits {
|
||||||
@ -854,8 +854,8 @@ impl Buffer {
|
|||||||
|
|
||||||
let slice =
|
let slice =
|
||||||
old_fragments.slice(&VersionedFullOffset::Offset(range.start), Bias::Left, &cx);
|
old_fragments.slice(&VersionedFullOffset::Offset(range.start), Bias::Left, &cx);
|
||||||
new_ropes.push_tree(slice.summary().text);
|
new_ropes.append(slice.summary().text);
|
||||||
new_fragments.push_tree(slice, &None);
|
new_fragments.append(slice, &None);
|
||||||
fragment_start = old_fragments.start().0.full_offset();
|
fragment_start = old_fragments.start().0.full_offset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -986,8 +986,8 @@ impl Buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let suffix = old_fragments.suffix(&cx);
|
let suffix = old_fragments.suffix(&cx);
|
||||||
new_ropes.push_tree(suffix.summary().text);
|
new_ropes.append(suffix.summary().text);
|
||||||
new_fragments.push_tree(suffix, &None);
|
new_fragments.append(suffix, &None);
|
||||||
let (visible_text, deleted_text) = new_ropes.finish();
|
let (visible_text, deleted_text) = new_ropes.finish();
|
||||||
drop(old_fragments);
|
drop(old_fragments);
|
||||||
|
|
||||||
@ -1056,8 +1056,8 @@ impl Buffer {
|
|||||||
|
|
||||||
for fragment_id in self.fragment_ids_for_edits(undo.counts.keys()) {
|
for fragment_id in self.fragment_ids_for_edits(undo.counts.keys()) {
|
||||||
let preceding_fragments = old_fragments.slice(&Some(fragment_id), Bias::Left, &None);
|
let preceding_fragments = old_fragments.slice(&Some(fragment_id), Bias::Left, &None);
|
||||||
new_ropes.push_tree(preceding_fragments.summary().text);
|
new_ropes.append(preceding_fragments.summary().text);
|
||||||
new_fragments.push_tree(preceding_fragments, &None);
|
new_fragments.append(preceding_fragments, &None);
|
||||||
|
|
||||||
if let Some(fragment) = old_fragments.item() {
|
if let Some(fragment) = old_fragments.item() {
|
||||||
let mut fragment = fragment.clone();
|
let mut fragment = fragment.clone();
|
||||||
@ -1087,8 +1087,8 @@ impl Buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let suffix = old_fragments.suffix(&None);
|
let suffix = old_fragments.suffix(&None);
|
||||||
new_ropes.push_tree(suffix.summary().text);
|
new_ropes.append(suffix.summary().text);
|
||||||
new_fragments.push_tree(suffix, &None);
|
new_fragments.append(suffix, &None);
|
||||||
|
|
||||||
drop(old_fragments);
|
drop(old_fragments);
|
||||||
let (visible_text, deleted_text) = new_ropes.finish();
|
let (visible_text, deleted_text) = new_ropes.finish();
|
||||||
@ -2070,7 +2070,7 @@ impl<'a> RopeBuilder<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_tree(&mut self, len: FragmentTextSummary) {
|
fn append(&mut self, len: FragmentTextSummary) {
|
||||||
self.push(len.visible, true, true);
|
self.push(len.visible, true, true);
|
||||||
self.push(len.deleted, false, false);
|
self.push(len.deleted, false, false);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ pub struct Theme {
|
|||||||
pub context_menu: ContextMenu,
|
pub context_menu: ContextMenu,
|
||||||
pub contacts_popover: ContactsPopover,
|
pub contacts_popover: ContactsPopover,
|
||||||
pub contact_list: ContactList,
|
pub contact_list: ContactList,
|
||||||
pub lsp_log_menu: LspLogMenu,
|
pub toolbar_dropdown_menu: DropdownMenu,
|
||||||
pub copilot: Copilot,
|
pub copilot: Copilot,
|
||||||
pub contact_finder: ContactFinder,
|
pub contact_finder: ContactFinder,
|
||||||
pub project_panel: ProjectPanel,
|
pub project_panel: ProjectPanel,
|
||||||
@ -129,12 +129,12 @@ pub struct Titlebar {
|
|||||||
pub leader_avatar: AvatarStyle,
|
pub leader_avatar: AvatarStyle,
|
||||||
pub follower_avatar: AvatarStyle,
|
pub follower_avatar: AvatarStyle,
|
||||||
pub inactive_avatar_grayscale: bool,
|
pub inactive_avatar_grayscale: bool,
|
||||||
pub sign_in_prompt: Interactive<ContainedText>,
|
pub sign_in_prompt: Toggleable<Interactive<ContainedText>>,
|
||||||
pub outdated_warning: ContainedText,
|
pub outdated_warning: ContainedText,
|
||||||
pub share_button: Interactive<ContainedText>,
|
pub share_button: Toggleable<Interactive<ContainedText>>,
|
||||||
pub call_control: Interactive<IconButton>,
|
pub call_control: Interactive<IconButton>,
|
||||||
pub toggle_contacts_button: Interactive<IconButton>,
|
pub toggle_contacts_button: Toggleable<Interactive<IconButton>>,
|
||||||
pub user_menu_button: Interactive<IconButton>,
|
pub user_menu_button: Toggleable<Interactive<IconButton>>,
|
||||||
pub toggle_contacts_badge: ContainerStyle,
|
pub toggle_contacts_badge: ContainerStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,12 +205,12 @@ pub struct ContactList {
|
|||||||
pub user_query_editor: FieldEditor,
|
pub user_query_editor: FieldEditor,
|
||||||
pub user_query_editor_height: f32,
|
pub user_query_editor_height: f32,
|
||||||
pub add_contact_button: IconButton,
|
pub add_contact_button: IconButton,
|
||||||
pub header_row: Interactive<ContainedText>,
|
pub header_row: Toggleable<Interactive<ContainedText>>,
|
||||||
pub leave_call: Interactive<ContainedText>,
|
pub leave_call: Interactive<ContainedText>,
|
||||||
pub contact_row: Interactive<ContainerStyle>,
|
pub contact_row: Toggleable<Interactive<ContainerStyle>>,
|
||||||
pub row_height: f32,
|
pub row_height: f32,
|
||||||
pub project_row: Interactive<ProjectRow>,
|
pub project_row: Toggleable<Interactive<ProjectRow>>,
|
||||||
pub tree_branch: Interactive<TreeBranch>,
|
pub tree_branch: Toggleable<Interactive<TreeBranch>>,
|
||||||
pub contact_avatar: ImageStyle,
|
pub contact_avatar: ImageStyle,
|
||||||
pub contact_status_free: ContainerStyle,
|
pub contact_status_free: ContainerStyle,
|
||||||
pub contact_status_busy: ContainerStyle,
|
pub contact_status_busy: ContainerStyle,
|
||||||
@ -247,20 +247,31 @@ pub struct ContactFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Default, JsonSchema)]
|
#[derive(Deserialize, Default, JsonSchema)]
|
||||||
pub struct LspLogMenu {
|
pub struct DropdownMenu {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub container: ContainerStyle,
|
pub container: ContainerStyle,
|
||||||
pub header: Interactive<ContainedText>,
|
pub header: Interactive<DropdownMenuItem>,
|
||||||
pub server: ContainedText,
|
pub section_header: ContainedText,
|
||||||
pub item: Interactive<ContainedText>,
|
pub item: Toggleable<Interactive<DropdownMenuItem>>,
|
||||||
pub row_height: f32,
|
pub row_height: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Default, JsonSchema)]
|
||||||
|
pub struct DropdownMenuItem {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub container: ContainerStyle,
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub text: TextStyle,
|
||||||
|
pub secondary_text: Option<TextStyle>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub secondary_text_spacing: f32,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
||||||
pub struct TabBar {
|
pub struct TabBar {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub container: ContainerStyle,
|
pub container: ContainerStyle,
|
||||||
pub pane_button: Interactive<IconButton>,
|
pub pane_button: Toggleable<Interactive<IconButton>>,
|
||||||
pub pane_button_container: ContainerStyle,
|
pub pane_button_container: ContainerStyle,
|
||||||
pub active_pane: TabStyles,
|
pub active_pane: TabStyles,
|
||||||
pub inactive_pane: TabStyles,
|
pub inactive_pane: TabStyles,
|
||||||
@ -349,7 +360,7 @@ pub struct Search {
|
|||||||
pub include_exclude_editor: FindEditor,
|
pub include_exclude_editor: FindEditor,
|
||||||
pub invalid_include_exclude_editor: ContainerStyle,
|
pub invalid_include_exclude_editor: ContainerStyle,
|
||||||
pub include_exclude_inputs: ContainedText,
|
pub include_exclude_inputs: ContainedText,
|
||||||
pub option_button: Interactive<ContainedText>,
|
pub option_button: Toggleable<Interactive<ContainedText>>,
|
||||||
pub match_background: Color,
|
pub match_background: Color,
|
||||||
pub match_index: ContainedText,
|
pub match_index: ContainedText,
|
||||||
pub results_status: TextStyle,
|
pub results_status: TextStyle,
|
||||||
@ -385,7 +396,7 @@ pub struct StatusBarPanelButtons {
|
|||||||
pub group_left: ContainerStyle,
|
pub group_left: ContainerStyle,
|
||||||
pub group_bottom: ContainerStyle,
|
pub group_bottom: ContainerStyle,
|
||||||
pub group_right: ContainerStyle,
|
pub group_right: ContainerStyle,
|
||||||
pub button: Interactive<PanelButton>,
|
pub button: Toggleable<Interactive<PanelButton>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Default, JsonSchema)]
|
#[derive(Deserialize, Default, JsonSchema)]
|
||||||
@ -434,10 +445,10 @@ pub struct PanelButton {
|
|||||||
pub struct ProjectPanel {
|
pub struct ProjectPanel {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub container: ContainerStyle,
|
pub container: ContainerStyle,
|
||||||
pub entry: Interactive<ProjectPanelEntry>,
|
pub entry: Toggleable<Interactive<ProjectPanelEntry>>,
|
||||||
pub dragged_entry: ProjectPanelEntry,
|
pub dragged_entry: ProjectPanelEntry,
|
||||||
pub ignored_entry: Interactive<ProjectPanelEntry>,
|
pub ignored_entry: Toggleable<Interactive<ProjectPanelEntry>>,
|
||||||
pub cut_entry: Interactive<ProjectPanelEntry>,
|
pub cut_entry: Toggleable<Interactive<ProjectPanelEntry>>,
|
||||||
pub filename_editor: FieldEditor,
|
pub filename_editor: FieldEditor,
|
||||||
pub indent_width: f32,
|
pub indent_width: f32,
|
||||||
pub open_project_button: Interactive<ContainedText>,
|
pub open_project_button: Interactive<ContainedText>,
|
||||||
@ -471,7 +482,7 @@ pub struct GitProjectStatus {
|
|||||||
pub struct ContextMenu {
|
pub struct ContextMenu {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub container: ContainerStyle,
|
pub container: ContainerStyle,
|
||||||
pub item: Interactive<ContextMenuItem>,
|
pub item: Toggleable<Interactive<ContextMenuItem>>,
|
||||||
pub keystroke_margin: f32,
|
pub keystroke_margin: f32,
|
||||||
pub separator: ContainerStyle,
|
pub separator: ContainerStyle,
|
||||||
}
|
}
|
||||||
@ -488,7 +499,7 @@ pub struct ContextMenuItem {
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize, Default, JsonSchema)]
|
#[derive(Debug, Deserialize, Default, JsonSchema)]
|
||||||
pub struct CommandPalette {
|
pub struct CommandPalette {
|
||||||
pub key: Interactive<ContainedLabel>,
|
pub key: Toggleable<ContainedLabel>,
|
||||||
pub keystroke_spacing: f32,
|
pub keystroke_spacing: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +566,7 @@ pub struct Picker {
|
|||||||
pub input_editor: FieldEditor,
|
pub input_editor: FieldEditor,
|
||||||
pub empty_input_editor: FieldEditor,
|
pub empty_input_editor: FieldEditor,
|
||||||
pub no_matches: ContainedLabel,
|
pub no_matches: ContainedLabel,
|
||||||
pub item: Interactive<ContainedLabel>,
|
pub item: Toggleable<Interactive<ContainedLabel>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
|
#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
|
||||||
@ -761,13 +772,13 @@ pub struct InteractiveColor {
|
|||||||
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
||||||
pub struct CodeActions {
|
pub struct CodeActions {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub indicator: Interactive<InteractiveColor>,
|
pub indicator: Toggleable<Interactive<InteractiveColor>>,
|
||||||
pub vertical_scale: f32,
|
pub vertical_scale: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
#[derive(Clone, Deserialize, Default, JsonSchema)]
|
||||||
pub struct Folds {
|
pub struct Folds {
|
||||||
pub indicator: Interactive<InteractiveColor>,
|
pub indicator: Toggleable<Interactive<InteractiveColor>>,
|
||||||
pub ellipses: FoldEllipses,
|
pub ellipses: FoldEllipses,
|
||||||
pub fold_background: Color,
|
pub fold_background: Color,
|
||||||
pub icon_margin_scale: f32,
|
pub icon_margin_scale: f32,
|
||||||
@ -795,38 +806,46 @@ pub struct DiffStyle {
|
|||||||
#[derive(Debug, Default, Clone, Copy, JsonSchema)]
|
#[derive(Debug, Default, Clone, Copy, JsonSchema)]
|
||||||
pub struct Interactive<T> {
|
pub struct Interactive<T> {
|
||||||
pub default: T,
|
pub default: T,
|
||||||
pub hover: Option<T>,
|
pub hovered: Option<T>,
|
||||||
pub hover_and_active: Option<T>,
|
|
||||||
pub clicked: Option<T>,
|
pub clicked: Option<T>,
|
||||||
pub click_and_active: Option<T>,
|
|
||||||
pub active: Option<T>,
|
|
||||||
pub disabled: Option<T>,
|
pub disabled: Option<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Interactive<T> {
|
#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
|
||||||
pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
|
pub struct Toggleable<T> {
|
||||||
|
active: T,
|
||||||
|
inactive: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Toggleable<T> {
|
||||||
|
pub fn new(active: T, inactive: T) -> Self {
|
||||||
|
Self { active, inactive }
|
||||||
|
}
|
||||||
|
pub fn in_state(&self, active: bool) -> &T {
|
||||||
if active {
|
if active {
|
||||||
if state.hovered() {
|
&self.active
|
||||||
self.hover_and_active
|
} else {
|
||||||
.as_ref()
|
&self.inactive
|
||||||
.unwrap_or(self.active.as_ref().unwrap_or(&self.default))
|
}
|
||||||
} else if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some()
|
}
|
||||||
{
|
pub fn active_state(&self) -> &T {
|
||||||
self.click_and_active
|
self.in_state(true)
|
||||||
.as_ref()
|
}
|
||||||
.unwrap_or(self.active.as_ref().unwrap_or(&self.default))
|
pub fn inactive_state(&self) -> &T {
|
||||||
} else {
|
self.in_state(false)
|
||||||
self.active.as_ref().unwrap_or(&self.default)
|
}
|
||||||
}
|
}
|
||||||
} else if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
|
|
||||||
|
impl<T> Interactive<T> {
|
||||||
|
pub fn style_for(&self, state: &mut MouseState) -> &T {
|
||||||
|
if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
|
||||||
self.clicked.as_ref().unwrap()
|
self.clicked.as_ref().unwrap()
|
||||||
} else if state.hovered() {
|
} else if state.hovered() {
|
||||||
self.hover.as_ref().unwrap_or(&self.default)
|
self.hovered.as_ref().unwrap_or(&self.default)
|
||||||
} else {
|
} else {
|
||||||
&self.default
|
&self.default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disabled_style(&self) -> &T {
|
pub fn disabled_style(&self) -> &T {
|
||||||
self.disabled.as_ref().unwrap_or(&self.default)
|
self.disabled.as_ref().unwrap_or(&self.default)
|
||||||
}
|
}
|
||||||
@ -839,13 +858,9 @@ impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
|
|||||||
{
|
{
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Helper {
|
struct Helper {
|
||||||
#[serde(flatten)]
|
|
||||||
default: Value,
|
default: Value,
|
||||||
hover: Option<Value>,
|
hovered: Option<Value>,
|
||||||
hover_and_active: Option<Value>,
|
|
||||||
clicked: Option<Value>,
|
clicked: Option<Value>,
|
||||||
click_and_active: Option<Value>,
|
|
||||||
active: Option<Value>,
|
|
||||||
disabled: Option<Value>,
|
disabled: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -870,21 +885,15 @@ impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let hover = deserialize_state(json.hover)?;
|
let hovered = deserialize_state(json.hovered)?;
|
||||||
let hover_and_active = deserialize_state(json.hover_and_active)?;
|
|
||||||
let clicked = deserialize_state(json.clicked)?;
|
let clicked = deserialize_state(json.clicked)?;
|
||||||
let click_and_active = deserialize_state(json.click_and_active)?;
|
|
||||||
let active = deserialize_state(json.active)?;
|
|
||||||
let disabled = deserialize_state(json.disabled)?;
|
let disabled = deserialize_state(json.disabled)?;
|
||||||
let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
|
let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
|
||||||
|
|
||||||
Ok(Interactive {
|
Ok(Interactive {
|
||||||
default,
|
default,
|
||||||
hover,
|
hovered,
|
||||||
hover_and_active,
|
|
||||||
clicked,
|
clicked,
|
||||||
click_and_active,
|
|
||||||
active,
|
|
||||||
disabled,
|
disabled,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ where
|
|||||||
F: Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
|
F: Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
|
||||||
{
|
{
|
||||||
MouseEventHandler::<Tag, V>::new(0, cx, |state, _| {
|
MouseEventHandler::<Tag, V>::new(0, cx, |state, _| {
|
||||||
let style = style.style_for(state, false);
|
let style = style.style_for(state);
|
||||||
Label::new(label, style.text.to_owned())
|
Label::new(label, style.text.to_owned())
|
||||||
.aligned()
|
.aligned()
|
||||||
.contained()
|
.contained()
|
||||||
@ -221,13 +221,13 @@ where
|
|||||||
title,
|
title,
|
||||||
style
|
style
|
||||||
.title_text
|
.title_text
|
||||||
.style_for(&mut MouseState::default(), false)
|
.style_for(&mut MouseState::default())
|
||||||
.clone(),
|
.clone(),
|
||||||
))
|
))
|
||||||
.with_child(
|
.with_child(
|
||||||
// FIXME: Get a better tag type
|
// FIXME: Get a better tag type
|
||||||
MouseEventHandler::<Tag, V>::new(999999, cx, |state, _cx| {
|
MouseEventHandler::<Tag, V>::new(999999, cx, |state, _cx| {
|
||||||
let style = style.close_icon.style_for(state, false);
|
let style = style.close_icon.style_for(state);
|
||||||
icon(style)
|
icon(style)
|
||||||
})
|
})
|
||||||
.on_click(platform::MouseButton::Left, move |_, _, cx| {
|
.on_click(platform::MouseButton::Left, move |_, _, cx| {
|
||||||
|
@ -208,7 +208,7 @@ impl PickerDelegate for ThemeSelectorDelegate {
|
|||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> AnyElement<Picker<Self>> {
|
) -> AnyElement<Picker<Self>> {
|
||||||
let theme = theme::current(cx);
|
let theme = theme::current(cx);
|
||||||
let style = theme.picker.item.style_for(mouse_state, selected);
|
let style = theme.picker.item.in_state(selected).style_for(mouse_state);
|
||||||
|
|
||||||
let theme_match = &self.matches[ix];
|
let theme_match = &self.matches[ix];
|
||||||
Label::new(theme_match.string.clone(), style.label.clone())
|
Label::new(theme_match.string.clone(), style.label.clone())
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "theme_testbench"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
path = "src/theme_testbench.rs"
|
|
||||||
doctest = false
|
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
gpui = { path = "../gpui" }
|
|
||||||
theme = { path = "../theme" }
|
|
||||||
settings = { path = "../settings" }
|
|
||||||
workspace = { path = "../workspace" }
|
|
||||||
project = { path = "../project" }
|
|
||||||
|
|
||||||
smallvec.workspace = true
|
|
@ -1,300 +0,0 @@
|
|||||||
use gpui::{
|
|
||||||
actions,
|
|
||||||
color::Color,
|
|
||||||
elements::{
|
|
||||||
AnyElement, Canvas, Container, ContainerStyle, Flex, Label, Margin, MouseEventHandler,
|
|
||||||
Padding, ParentElement,
|
|
||||||
},
|
|
||||||
fonts::TextStyle,
|
|
||||||
AppContext, Border, Element, Entity, ModelHandle, Quad, Task, View, ViewContext, ViewHandle,
|
|
||||||
WeakViewHandle,
|
|
||||||
};
|
|
||||||
use project::Project;
|
|
||||||
use theme::{ColorScheme, Layer, Style, StyleSet, ThemeSettings};
|
|
||||||
use workspace::{item::Item, register_deserializable_item, Pane, Workspace};
|
|
||||||
|
|
||||||
actions!(theme, [DeployThemeTestbench]);
|
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
|
||||||
cx.add_action(ThemeTestbench::deploy);
|
|
||||||
|
|
||||||
register_deserializable_item::<ThemeTestbench>(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ThemeTestbench {}
|
|
||||||
|
|
||||||
impl ThemeTestbench {
|
|
||||||
pub fn deploy(
|
|
||||||
workspace: &mut Workspace,
|
|
||||||
_: &DeployThemeTestbench,
|
|
||||||
cx: &mut ViewContext<Workspace>,
|
|
||||||
) {
|
|
||||||
let view = cx.add_view(|_| ThemeTestbench {});
|
|
||||||
workspace.add_item(Box::new(view), cx);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_ramps(color_scheme: &ColorScheme) -> Flex<Self> {
|
|
||||||
fn display_ramp(ramp: &Vec<Color>) -> AnyElement<ThemeTestbench> {
|
|
||||||
Flex::row()
|
|
||||||
.with_children(ramp.iter().cloned().map(|color| {
|
|
||||||
Canvas::new(move |scene, bounds, _, _, _| {
|
|
||||||
scene.push_quad(Quad {
|
|
||||||
bounds,
|
|
||||||
background: Some(color),
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.flex(1.0, false)
|
|
||||||
}))
|
|
||||||
.flex(1.0, false)
|
|
||||||
.into_any()
|
|
||||||
}
|
|
||||||
|
|
||||||
Flex::column()
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.neutral))
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.red))
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.orange))
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.yellow))
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.green))
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.cyan))
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.blue))
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.violet))
|
|
||||||
.with_child(display_ramp(&color_scheme.ramps.magenta))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_layer(
|
|
||||||
layer_index: usize,
|
|
||||||
layer: &Layer,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) -> Container<Self> {
|
|
||||||
Flex::column()
|
|
||||||
.with_child(
|
|
||||||
Self::render_button_set(0, layer_index, "base", &layer.base, cx).flex(1., false),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Self::render_button_set(1, layer_index, "variant", &layer.variant, cx)
|
|
||||||
.flex(1., false),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Self::render_button_set(2, layer_index, "on", &layer.on, cx).flex(1., false),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Self::render_button_set(3, layer_index, "accent", &layer.accent, cx)
|
|
||||||
.flex(1., false),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Self::render_button_set(4, layer_index, "positive", &layer.positive, cx)
|
|
||||||
.flex(1., false),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Self::render_button_set(5, layer_index, "warning", &layer.warning, cx)
|
|
||||||
.flex(1., false),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Self::render_button_set(6, layer_index, "negative", &layer.negative, cx)
|
|
||||||
.flex(1., false),
|
|
||||||
)
|
|
||||||
.contained()
|
|
||||||
.with_style(ContainerStyle {
|
|
||||||
margin: Margin {
|
|
||||||
top: 10.,
|
|
||||||
bottom: 10.,
|
|
||||||
left: 10.,
|
|
||||||
right: 10.,
|
|
||||||
},
|
|
||||||
background_color: Some(layer.base.default.background),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_button_set(
|
|
||||||
set_index: usize,
|
|
||||||
layer_index: usize,
|
|
||||||
set_name: &'static str,
|
|
||||||
style_set: &StyleSet,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) -> Flex<Self> {
|
|
||||||
Flex::row()
|
|
||||||
.with_child(Self::render_button(
|
|
||||||
set_index * 6,
|
|
||||||
layer_index,
|
|
||||||
set_name,
|
|
||||||
&style_set,
|
|
||||||
None,
|
|
||||||
cx,
|
|
||||||
))
|
|
||||||
.with_child(Self::render_button(
|
|
||||||
set_index * 6 + 1,
|
|
||||||
layer_index,
|
|
||||||
"hovered",
|
|
||||||
&style_set,
|
|
||||||
Some(|style_set| &style_set.hovered),
|
|
||||||
cx,
|
|
||||||
))
|
|
||||||
.with_child(Self::render_button(
|
|
||||||
set_index * 6 + 2,
|
|
||||||
layer_index,
|
|
||||||
"pressed",
|
|
||||||
&style_set,
|
|
||||||
Some(|style_set| &style_set.pressed),
|
|
||||||
cx,
|
|
||||||
))
|
|
||||||
.with_child(Self::render_button(
|
|
||||||
set_index * 6 + 3,
|
|
||||||
layer_index,
|
|
||||||
"active",
|
|
||||||
&style_set,
|
|
||||||
Some(|style_set| &style_set.active),
|
|
||||||
cx,
|
|
||||||
))
|
|
||||||
.with_child(Self::render_button(
|
|
||||||
set_index * 6 + 4,
|
|
||||||
layer_index,
|
|
||||||
"disabled",
|
|
||||||
&style_set,
|
|
||||||
Some(|style_set| &style_set.disabled),
|
|
||||||
cx,
|
|
||||||
))
|
|
||||||
.with_child(Self::render_button(
|
|
||||||
set_index * 6 + 5,
|
|
||||||
layer_index,
|
|
||||||
"inverted",
|
|
||||||
&style_set,
|
|
||||||
Some(|style_set| &style_set.inverted),
|
|
||||||
cx,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_button(
|
|
||||||
button_index: usize,
|
|
||||||
layer_index: usize,
|
|
||||||
text: &'static str,
|
|
||||||
style_set: &StyleSet,
|
|
||||||
style_override: Option<fn(&StyleSet) -> &Style>,
|
|
||||||
cx: &mut ViewContext<Self>,
|
|
||||||
) -> AnyElement<Self> {
|
|
||||||
enum TestBenchButton {}
|
|
||||||
MouseEventHandler::<TestBenchButton, _>::new(layer_index + button_index, cx, |state, cx| {
|
|
||||||
let style = if let Some(style_override) = style_override {
|
|
||||||
style_override(&style_set)
|
|
||||||
} else if state.clicked().is_some() {
|
|
||||||
&style_set.pressed
|
|
||||||
} else if state.hovered() {
|
|
||||||
&style_set.hovered
|
|
||||||
} else {
|
|
||||||
&style_set.default
|
|
||||||
};
|
|
||||||
|
|
||||||
Self::render_label(text.to_string(), style, cx)
|
|
||||||
.contained()
|
|
||||||
.with_style(ContainerStyle {
|
|
||||||
margin: Margin {
|
|
||||||
top: 4.,
|
|
||||||
bottom: 4.,
|
|
||||||
left: 4.,
|
|
||||||
right: 4.,
|
|
||||||
},
|
|
||||||
padding: Padding {
|
|
||||||
top: 4.,
|
|
||||||
bottom: 4.,
|
|
||||||
left: 4.,
|
|
||||||
right: 4.,
|
|
||||||
},
|
|
||||||
background_color: Some(style.background),
|
|
||||||
border: Border {
|
|
||||||
width: 1.,
|
|
||||||
color: style.border,
|
|
||||||
overlay: false,
|
|
||||||
top: true,
|
|
||||||
bottom: true,
|
|
||||||
left: true,
|
|
||||||
right: true,
|
|
||||||
},
|
|
||||||
corner_radius: 2.,
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.flex(1., true)
|
|
||||||
.into_any()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_label(text: String, style: &Style, cx: &mut ViewContext<Self>) -> Label {
|
|
||||||
let settings = settings::get::<ThemeSettings>(cx);
|
|
||||||
let font_cache = cx.font_cache();
|
|
||||||
let family_id = settings.buffer_font_family;
|
|
||||||
let font_size = settings.buffer_font_size(cx);
|
|
||||||
let font_id = font_cache
|
|
||||||
.select_font(family_id, &Default::default())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let text_style = TextStyle {
|
|
||||||
color: style.foreground,
|
|
||||||
font_family_id: family_id,
|
|
||||||
font_family_name: font_cache.family_name(family_id).unwrap(),
|
|
||||||
font_id,
|
|
||||||
font_size,
|
|
||||||
font_properties: Default::default(),
|
|
||||||
underline: Default::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Label::new(text, text_style)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Entity for ThemeTestbench {
|
|
||||||
type Event = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
impl View for ThemeTestbench {
|
|
||||||
fn ui_name() -> &'static str {
|
|
||||||
"ThemeTestbench"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> AnyElement<Self> {
|
|
||||||
let color_scheme = &theme::current(cx).clone().color_scheme;
|
|
||||||
|
|
||||||
Flex::row()
|
|
||||||
.with_child(
|
|
||||||
Self::render_ramps(color_scheme)
|
|
||||||
.contained()
|
|
||||||
.with_margin_right(10.)
|
|
||||||
.flex(0.1, false),
|
|
||||||
)
|
|
||||||
.with_child(
|
|
||||||
Flex::column()
|
|
||||||
.with_child(Self::render_layer(100, &color_scheme.lowest, cx).flex(1., true))
|
|
||||||
.with_child(Self::render_layer(200, &color_scheme.middle, cx).flex(1., true))
|
|
||||||
.with_child(Self::render_layer(300, &color_scheme.highest, cx).flex(1., true))
|
|
||||||
.flex(1., false),
|
|
||||||
)
|
|
||||||
.into_any()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Item for ThemeTestbench {
|
|
||||||
fn tab_content<T: View>(
|
|
||||||
&self,
|
|
||||||
_: Option<usize>,
|
|
||||||
style: &theme::Tab,
|
|
||||||
_: &AppContext,
|
|
||||||
) -> AnyElement<T> {
|
|
||||||
Label::new("Theme Testbench", style.label.clone())
|
|
||||||
.aligned()
|
|
||||||
.contained()
|
|
||||||
.into_any()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn serialized_item_kind() -> Option<&'static str> {
|
|
||||||
Some("ThemeTestBench")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn deserialize(
|
|
||||||
_project: ModelHandle<Project>,
|
|
||||||
_workspace: WeakViewHandle<Workspace>,
|
|
||||||
_workspace_id: workspace::WorkspaceId,
|
|
||||||
_item_id: workspace::ItemId,
|
|
||||||
cx: &mut ViewContext<Pane>,
|
|
||||||
) -> Task<gpui::anyhow::Result<ViewHandle<Self>>> {
|
|
||||||
Task::ready(Ok(cx.add_view(|_| Self {})))
|
|
||||||
}
|
|
||||||
}
|
|
@ -98,3 +98,14 @@ async fn test_buffer_search(cx: &mut gpui::TestAppContext) {
|
|||||||
assert_eq!(bar.query_editor.read(cx).text(cx), "jumps");
|
assert_eq!(bar.query_editor.read(cx).text(cx), "jumps");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_count_down(cx: &mut gpui::TestAppContext) {
|
||||||
|
let mut cx = VimTestContext::new(cx, true).await;
|
||||||
|
|
||||||
|
cx.set_state(indoc! {"aˇa\nbb\ncc\ndd\nee"}, Mode::Normal);
|
||||||
|
cx.simulate_keystrokes(["2", "down"]);
|
||||||
|
cx.assert_editor_state("aa\nbb\ncˇc\ndd\nee");
|
||||||
|
cx.simulate_keystrokes(["9", "down"]);
|
||||||
|
cx.assert_editor_state("aa\nbb\ncc\ndd\neˇe");
|
||||||
|
}
|
||||||
|
@ -141,7 +141,7 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
|
|||||||
) -> gpui::AnyElement<Picker<Self>> {
|
) -> gpui::AnyElement<Picker<Self>> {
|
||||||
let theme = &theme::current(cx);
|
let theme = &theme::current(cx);
|
||||||
let keymap_match = &self.matches[ix];
|
let keymap_match = &self.matches[ix];
|
||||||
let style = theme.picker.item.style_for(mouse_state, selected);
|
let style = theme.picker.item.in_state(selected).style_for(mouse_state);
|
||||||
|
|
||||||
Label::new(keymap_match.string.clone(), style.label.clone())
|
Label::new(keymap_match.string.clone(), style.label.clone())
|
||||||
.with_highlights(keymap_match.positions.clone())
|
.with_highlights(keymap_match.positions.clone())
|
||||||
|
@ -498,7 +498,9 @@ impl View for PanelButtons {
|
|||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
|
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
|
||||||
let style = button_style.style_for(state, is_active);
|
let style = button_style.in_state(is_active);
|
||||||
|
|
||||||
|
let style = style.style_for(state);
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
Svg::new(view.icon_path(cx))
|
Svg::new(view.icon_path(cx))
|
||||||
@ -598,8 +600,8 @@ impl StatusItemView for PanelButtons {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub(crate) mod test {
|
pub mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use gpui::{ViewContext, WindowContext};
|
use gpui::{ViewContext, WindowContext};
|
||||||
|
|
||||||
|
@ -710,8 +710,8 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub(crate) mod test {
|
pub mod test {
|
||||||
use super::{Item, ItemEvent};
|
use super::{Item, ItemEvent};
|
||||||
use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
@ -291,7 +291,7 @@ pub mod simple_message_notification {
|
|||||||
)
|
)
|
||||||
.with_child(
|
.with_child(
|
||||||
MouseEventHandler::<Cancel, _>::new(0, cx, |state, _| {
|
MouseEventHandler::<Cancel, _>::new(0, cx, |state, _| {
|
||||||
let style = theme.dismiss_button.style_for(state, false);
|
let style = theme.dismiss_button.style_for(state);
|
||||||
Svg::new("icons/x_mark_8.svg")
|
Svg::new("icons/x_mark_8.svg")
|
||||||
.with_color(style.color)
|
.with_color(style.color)
|
||||||
.constrained()
|
.constrained()
|
||||||
@ -323,7 +323,7 @@ pub mod simple_message_notification {
|
|||||||
0,
|
0,
|
||||||
cx,
|
cx,
|
||||||
|state, _| {
|
|state, _| {
|
||||||
let style = theme.action_message.style_for(state, false);
|
let style = theme.action_message.style_for(state);
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
|
@ -1410,7 +1410,7 @@ impl Pane {
|
|||||||
pub fn render_tab_bar_button<F: 'static + Fn(&mut Pane, &mut EventContext<Pane>)>(
|
pub fn render_tab_bar_button<F: 'static + Fn(&mut Pane, &mut EventContext<Pane>)>(
|
||||||
index: usize,
|
index: usize,
|
||||||
icon: &'static str,
|
icon: &'static str,
|
||||||
active: bool,
|
is_active: bool,
|
||||||
tooltip: Option<(String, Option<Box<dyn Action>>)>,
|
tooltip: Option<(String, Option<Box<dyn Action>>)>,
|
||||||
cx: &mut ViewContext<Pane>,
|
cx: &mut ViewContext<Pane>,
|
||||||
on_click: F,
|
on_click: F,
|
||||||
@ -1420,7 +1420,7 @@ impl Pane {
|
|||||||
|
|
||||||
let mut button = MouseEventHandler::<TabBarButton, _>::new(index, cx, |mouse_state, cx| {
|
let mut button = MouseEventHandler::<TabBarButton, _>::new(index, cx, |mouse_state, cx| {
|
||||||
let theme = &settings::get::<ThemeSettings>(cx).theme.workspace.tab_bar;
|
let theme = &settings::get::<ThemeSettings>(cx).theme.workspace.tab_bar;
|
||||||
let style = theme.pane_button.style_for(mouse_state, active);
|
let style = theme.pane_button.in_state(is_active).style_for(mouse_state);
|
||||||
Svg::new(icon)
|
Svg::new(icon)
|
||||||
.with_color(style.color)
|
.with_color(style.color)
|
||||||
.constrained()
|
.constrained()
|
||||||
|
@ -162,6 +162,12 @@ define_connection! {
|
|||||||
ALTER TABLE workspaces ADD COLUMN right_dock_active_panel TEXT;
|
ALTER TABLE workspaces ADD COLUMN right_dock_active_panel TEXT;
|
||||||
ALTER TABLE workspaces ADD COLUMN bottom_dock_visible INTEGER; //bool
|
ALTER TABLE workspaces ADD COLUMN bottom_dock_visible INTEGER; //bool
|
||||||
ALTER TABLE workspaces ADD COLUMN bottom_dock_active_panel TEXT;
|
ALTER TABLE workspaces ADD COLUMN bottom_dock_active_panel TEXT;
|
||||||
|
),
|
||||||
|
// Add panel zoom persistence
|
||||||
|
sql!(
|
||||||
|
ALTER TABLE workspaces ADD COLUMN left_dock_zoom INTEGER; //bool
|
||||||
|
ALTER TABLE workspaces ADD COLUMN right_dock_zoom INTEGER; //bool
|
||||||
|
ALTER TABLE workspaces ADD COLUMN bottom_dock_zoom INTEGER; //bool
|
||||||
)];
|
)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,10 +202,13 @@ impl WorkspaceDb {
|
|||||||
display,
|
display,
|
||||||
left_dock_visible,
|
left_dock_visible,
|
||||||
left_dock_active_panel,
|
left_dock_active_panel,
|
||||||
|
left_dock_zoom,
|
||||||
right_dock_visible,
|
right_dock_visible,
|
||||||
right_dock_active_panel,
|
right_dock_active_panel,
|
||||||
|
right_dock_zoom,
|
||||||
bottom_dock_visible,
|
bottom_dock_visible,
|
||||||
bottom_dock_active_panel
|
bottom_dock_active_panel,
|
||||||
|
bottom_dock_zoom
|
||||||
FROM workspaces
|
FROM workspaces
|
||||||
WHERE workspace_location = ?
|
WHERE workspace_location = ?
|
||||||
})
|
})
|
||||||
@ -244,22 +253,28 @@ impl WorkspaceDb {
|
|||||||
workspace_location,
|
workspace_location,
|
||||||
left_dock_visible,
|
left_dock_visible,
|
||||||
left_dock_active_panel,
|
left_dock_active_panel,
|
||||||
|
left_dock_zoom,
|
||||||
right_dock_visible,
|
right_dock_visible,
|
||||||
right_dock_active_panel,
|
right_dock_active_panel,
|
||||||
|
right_dock_zoom,
|
||||||
bottom_dock_visible,
|
bottom_dock_visible,
|
||||||
bottom_dock_active_panel,
|
bottom_dock_active_panel,
|
||||||
|
bottom_dock_zoom,
|
||||||
timestamp
|
timestamp
|
||||||
)
|
)
|
||||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, CURRENT_TIMESTAMP)
|
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, CURRENT_TIMESTAMP)
|
||||||
ON CONFLICT DO
|
ON CONFLICT DO
|
||||||
UPDATE SET
|
UPDATE SET
|
||||||
workspace_location = ?2,
|
workspace_location = ?2,
|
||||||
left_dock_visible = ?3,
|
left_dock_visible = ?3,
|
||||||
left_dock_active_panel = ?4,
|
left_dock_active_panel = ?4,
|
||||||
right_dock_visible = ?5,
|
left_dock_zoom = ?5,
|
||||||
right_dock_active_panel = ?6,
|
right_dock_visible = ?6,
|
||||||
bottom_dock_visible = ?7,
|
right_dock_active_panel = ?7,
|
||||||
bottom_dock_active_panel = ?8,
|
right_dock_zoom = ?8,
|
||||||
|
bottom_dock_visible = ?9,
|
||||||
|
bottom_dock_active_panel = ?10,
|
||||||
|
bottom_dock_zoom = ?11,
|
||||||
timestamp = CURRENT_TIMESTAMP
|
timestamp = CURRENT_TIMESTAMP
|
||||||
))?((workspace.id, &workspace.location, workspace.docks))
|
))?((workspace.id, &workspace.location, workspace.docks))
|
||||||
.context("Updating workspace")?;
|
.context("Updating workspace")?;
|
||||||
|
@ -100,16 +100,19 @@ impl Bind for DockStructure {
|
|||||||
pub struct DockData {
|
pub struct DockData {
|
||||||
pub(crate) visible: bool,
|
pub(crate) visible: bool,
|
||||||
pub(crate) active_panel: Option<String>,
|
pub(crate) active_panel: Option<String>,
|
||||||
|
pub(crate) zoom: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Column for DockData {
|
impl Column for DockData {
|
||||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||||
let (visible, next_index) = Option::<bool>::column(statement, start_index)?;
|
let (visible, next_index) = Option::<bool>::column(statement, start_index)?;
|
||||||
let (active_panel, next_index) = Option::<String>::column(statement, next_index)?;
|
let (active_panel, next_index) = Option::<String>::column(statement, next_index)?;
|
||||||
|
let (zoom, next_index) = Option::<bool>::column(statement, next_index)?;
|
||||||
Ok((
|
Ok((
|
||||||
DockData {
|
DockData {
|
||||||
visible: visible.unwrap_or(false),
|
visible: visible.unwrap_or(false),
|
||||||
active_panel,
|
active_panel,
|
||||||
|
zoom: zoom.unwrap_or(false),
|
||||||
},
|
},
|
||||||
next_index,
|
next_index,
|
||||||
))
|
))
|
||||||
@ -119,7 +122,8 @@ impl Column for DockData {
|
|||||||
impl Bind for DockData {
|
impl Bind for DockData {
|
||||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||||
let next_index = statement.bind(&self.visible, start_index)?;
|
let next_index = statement.bind(&self.visible, start_index)?;
|
||||||
statement.bind(&self.active_panel, next_index)
|
let next_index = statement.bind(&self.active_panel, next_index)?;
|
||||||
|
statement.bind(&self.zoom, next_index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>
|
|||||||
) -> AnyElement<Toolbar> {
|
) -> AnyElement<Toolbar> {
|
||||||
MouseEventHandler::<A, _>::new(0, cx, |state, _| {
|
MouseEventHandler::<A, _>::new(0, cx, |state, _| {
|
||||||
let style = if enabled {
|
let style = if enabled {
|
||||||
style.style_for(state, false)
|
style.style_for(state)
|
||||||
} else {
|
} else {
|
||||||
style.disabled_style()
|
style.disabled_style()
|
||||||
};
|
};
|
||||||
|
@ -140,9 +140,11 @@ pub struct OpenPaths {
|
|||||||
#[derive(Clone, Deserialize, PartialEq)]
|
#[derive(Clone, Deserialize, PartialEq)]
|
||||||
pub struct ActivatePane(pub usize);
|
pub struct ActivatePane(pub usize);
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
pub struct Toast {
|
pub struct Toast {
|
||||||
id: usize,
|
id: usize,
|
||||||
msg: Cow<'static, str>,
|
msg: Cow<'static, str>,
|
||||||
|
#[serde(skip)]
|
||||||
on_click: Option<(Cow<'static, str>, Arc<dyn Fn(&mut WindowContext)>)>,
|
on_click: Option<(Cow<'static, str>, Arc<dyn Fn(&mut WindowContext)>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,9 +185,9 @@ impl Clone for Toast {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type WorkspaceId = i64;
|
impl_actions!(workspace, [ActivatePane, Toast]);
|
||||||
|
|
||||||
impl_actions!(workspace, [ActivatePane]);
|
pub type WorkspaceId = i64;
|
||||||
|
|
||||||
pub fn init_settings(cx: &mut AppContext) {
|
pub fn init_settings(cx: &mut AppContext) {
|
||||||
settings::register::<WorkspaceSettings>(cx);
|
settings::register::<WorkspaceSettings>(cx);
|
||||||
@ -553,6 +555,10 @@ impl Workspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project::Event::Notification(message) => this.show_notification(0, cx, |cx| {
|
||||||
|
cx.add_view(|_| MessageNotification::new(message.clone()))
|
||||||
|
}),
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
cx.notify()
|
cx.notify()
|
||||||
@ -919,6 +925,7 @@ impl Workspace {
|
|||||||
this.zoomed = None;
|
this.zoomed = None;
|
||||||
this.zoomed_position = None;
|
this.zoomed_position = None;
|
||||||
}
|
}
|
||||||
|
this.update_active_view_for_followers(cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1598,9 +1605,7 @@ impl Workspace {
|
|||||||
focus_center = true;
|
focus_center = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if active_panel.is_zoomed(cx) {
|
cx.focus(active_panel.as_any());
|
||||||
cx.focus(active_panel.as_any());
|
|
||||||
}
|
|
||||||
reveal_dock = true;
|
reveal_dock = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1946,18 +1951,7 @@ impl Workspace {
|
|||||||
self.zoomed = None;
|
self.zoomed = None;
|
||||||
}
|
}
|
||||||
self.zoomed_position = None;
|
self.zoomed_position = None;
|
||||||
|
self.update_active_view_for_followers(cx);
|
||||||
self.update_followers(
|
|
||||||
proto::update_followers::Variant::UpdateActiveView(proto::UpdateActiveView {
|
|
||||||
id: self.active_item(cx).and_then(|item| {
|
|
||||||
item.to_followable_item_handle(cx)?
|
|
||||||
.remote_id(&self.app_state.client, cx)
|
|
||||||
.map(|id| id.to_proto())
|
|
||||||
}),
|
|
||||||
leader_id: self.leader_for_pane(&pane),
|
|
||||||
}),
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
@ -2646,6 +2640,30 @@ impl Workspace {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_active_view_for_followers(&self, cx: &AppContext) {
|
||||||
|
if self.active_pane.read(cx).has_focus() {
|
||||||
|
self.update_followers(
|
||||||
|
proto::update_followers::Variant::UpdateActiveView(proto::UpdateActiveView {
|
||||||
|
id: self.active_item(cx).and_then(|item| {
|
||||||
|
item.to_followable_item_handle(cx)?
|
||||||
|
.remote_id(&self.app_state.client, cx)
|
||||||
|
.map(|id| id.to_proto())
|
||||||
|
}),
|
||||||
|
leader_id: self.leader_for_pane(&self.active_pane),
|
||||||
|
}),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
self.update_followers(
|
||||||
|
proto::update_followers::Variant::UpdateActiveView(proto::UpdateActiveView {
|
||||||
|
id: None,
|
||||||
|
leader_id: None,
|
||||||
|
}),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update_followers(
|
fn update_followers(
|
||||||
&self,
|
&self,
|
||||||
update: proto::update_followers::Variant,
|
update: proto::update_followers::Variant,
|
||||||
@ -2693,12 +2711,10 @@ impl Workspace {
|
|||||||
.and_then(|id| state.items_by_leader_view_id.get(&id))
|
.and_then(|id| state.items_by_leader_view_id.get(&id))
|
||||||
{
|
{
|
||||||
items_to_activate.push((pane.clone(), item.boxed_clone()));
|
items_to_activate.push((pane.clone(), item.boxed_clone()));
|
||||||
} else {
|
} else if let Some(shared_screen) =
|
||||||
if let Some(shared_screen) =
|
self.shared_screen_for_peer(leader_id, pane, cx)
|
||||||
self.shared_screen_for_peer(leader_id, pane, cx)
|
{
|
||||||
{
|
items_to_activate.push((pane.clone(), Box::new(shared_screen)));
|
||||||
items_to_activate.push((pane.clone(), Box::new(shared_screen)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2838,7 +2854,7 @@ impl Workspace {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_workspace(&self, cx: &AppContext) {
|
fn serialize_workspace(&self, cx: &ViewContext<Self>) {
|
||||||
fn serialize_pane_handle(
|
fn serialize_pane_handle(
|
||||||
pane_handle: &ViewHandle<Pane>,
|
pane_handle: &ViewHandle<Pane>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
@ -2881,7 +2897,7 @@ impl Workspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_serialized_docks(this: &Workspace, cx: &AppContext) -> DockStructure {
|
fn build_serialized_docks(this: &Workspace, cx: &ViewContext<Workspace>) -> DockStructure {
|
||||||
let left_dock = this.left_dock.read(cx);
|
let left_dock = this.left_dock.read(cx);
|
||||||
let left_visible = left_dock.is_open();
|
let left_visible = left_dock.is_open();
|
||||||
let left_active_panel = left_dock.visible_panel().and_then(|panel| {
|
let left_active_panel = left_dock.visible_panel().and_then(|panel| {
|
||||||
@ -2890,6 +2906,10 @@ impl Workspace {
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
let left_dock_zoom = left_dock
|
||||||
|
.visible_panel()
|
||||||
|
.map(|panel| panel.is_zoomed(cx))
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
let right_dock = this.right_dock.read(cx);
|
let right_dock = this.right_dock.read(cx);
|
||||||
let right_visible = right_dock.is_open();
|
let right_visible = right_dock.is_open();
|
||||||
@ -2899,6 +2919,10 @@ impl Workspace {
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
let right_dock_zoom = right_dock
|
||||||
|
.visible_panel()
|
||||||
|
.map(|panel| panel.is_zoomed(cx))
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
let bottom_dock = this.bottom_dock.read(cx);
|
let bottom_dock = this.bottom_dock.read(cx);
|
||||||
let bottom_visible = bottom_dock.is_open();
|
let bottom_visible = bottom_dock.is_open();
|
||||||
@ -2908,19 +2932,26 @@ impl Workspace {
|
|||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
let bottom_dock_zoom = bottom_dock
|
||||||
|
.visible_panel()
|
||||||
|
.map(|panel| panel.is_zoomed(cx))
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
DockStructure {
|
DockStructure {
|
||||||
left: DockData {
|
left: DockData {
|
||||||
visible: left_visible,
|
visible: left_visible,
|
||||||
active_panel: left_active_panel,
|
active_panel: left_active_panel,
|
||||||
|
zoom: left_dock_zoom,
|
||||||
},
|
},
|
||||||
right: DockData {
|
right: DockData {
|
||||||
visible: right_visible,
|
visible: right_visible,
|
||||||
active_panel: right_active_panel,
|
active_panel: right_active_panel,
|
||||||
|
zoom: right_dock_zoom,
|
||||||
},
|
},
|
||||||
bottom: DockData {
|
bottom: DockData {
|
||||||
visible: bottom_visible,
|
visible: bottom_visible,
|
||||||
active_panel: bottom_active_panel,
|
active_panel: bottom_active_panel,
|
||||||
|
zoom: bottom_dock_zoom,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3033,14 +3064,31 @@ impl Workspace {
|
|||||||
dock.activate_panel(ix, cx);
|
dock.activate_panel(ix, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dock.active_panel()
|
||||||
|
.map(|panel| {
|
||||||
|
panel.set_zoomed(docks.left.zoom, cx)
|
||||||
|
});
|
||||||
|
if docks.left.visible && docks.left.zoom {
|
||||||
|
cx.focus_self()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
// TODO: I think the bug is that setting zoom or active undoes the bottom zoom or something
|
||||||
workspace.right_dock.update(cx, |dock, cx| {
|
workspace.right_dock.update(cx, |dock, cx| {
|
||||||
dock.set_open(docks.right.visible, cx);
|
dock.set_open(docks.right.visible, cx);
|
||||||
if let Some(active_panel) = docks.right.active_panel {
|
if let Some(active_panel) = docks.right.active_panel {
|
||||||
if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) {
|
if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) {
|
||||||
dock.activate_panel(ix, cx);
|
dock.activate_panel(ix, cx);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dock.active_panel()
|
||||||
|
.map(|panel| {
|
||||||
|
panel.set_zoomed(docks.right.zoom, cx)
|
||||||
|
});
|
||||||
|
|
||||||
|
if docks.right.visible && docks.right.zoom {
|
||||||
|
cx.focus_self()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
workspace.bottom_dock.update(cx, |dock, cx| {
|
workspace.bottom_dock.update(cx, |dock, cx| {
|
||||||
dock.set_open(docks.bottom.visible, cx);
|
dock.set_open(docks.bottom.visible, cx);
|
||||||
@ -3049,8 +3097,18 @@ impl Workspace {
|
|||||||
dock.activate_panel(ix, cx);
|
dock.activate_panel(ix, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dock.active_panel()
|
||||||
|
.map(|panel| {
|
||||||
|
panel.set_zoomed(docks.bottom.zoom, cx)
|
||||||
|
});
|
||||||
|
|
||||||
|
if docks.bottom.visible && docks.bottom.zoom {
|
||||||
|
cx.focus_self()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@ -4413,7 +4471,7 @@ mod tests {
|
|||||||
workspace.read_with(cx, |workspace, cx| {
|
workspace.read_with(cx, |workspace, cx| {
|
||||||
assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
assert!(!panel.is_zoomed(cx));
|
assert!(!panel.is_zoomed(cx));
|
||||||
assert!(!panel.has_focus(cx));
|
assert!(panel.has_focus(cx));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Focus and zoom panel
|
// Focus and zoom panel
|
||||||
@ -4488,7 +4546,7 @@ mod tests {
|
|||||||
workspace.read_with(cx, |workspace, cx| {
|
workspace.read_with(cx, |workspace, cx| {
|
||||||
let pane = pane.read(cx);
|
let pane = pane.read(cx);
|
||||||
assert!(!pane.is_zoomed());
|
assert!(!pane.is_zoomed());
|
||||||
assert!(pane.has_focus());
|
assert!(!pane.has_focus());
|
||||||
assert!(workspace.right_dock().read(cx).is_open());
|
assert!(workspace.right_dock().read(cx).is_open());
|
||||||
assert!(workspace.zoomed.is_none());
|
assert!(workspace.zoomed.is_none());
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
|
|||||||
description = "The fast, collaborative code editor."
|
description = "The fast, collaborative code editor."
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
name = "zed"
|
name = "zed"
|
||||||
version = "0.91.0"
|
version = "0.93.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
@ -45,11 +45,11 @@ journal = { path = "../journal" }
|
|||||||
language = { path = "../language" }
|
language = { path = "../language" }
|
||||||
language_selector = { path = "../language_selector" }
|
language_selector = { path = "../language_selector" }
|
||||||
lsp = { path = "../lsp" }
|
lsp = { path = "../lsp" }
|
||||||
lsp_log = { path = "../lsp_log" }
|
language_tools = { path = "../language_tools" }
|
||||||
node_runtime = { path = "../node_runtime" }
|
node_runtime = { path = "../node_runtime" }
|
||||||
ai = { path = "../ai" }
|
ai = { path = "../ai" }
|
||||||
outline = { path = "../outline" }
|
outline = { path = "../outline" }
|
||||||
plugin_runtime = { path = "../plugin_runtime" }
|
plugin_runtime = { path = "../plugin_runtime",optional = true }
|
||||||
project = { path = "../project" }
|
project = { path = "../project" }
|
||||||
project_panel = { path = "../project_panel" }
|
project_panel = { path = "../project_panel" }
|
||||||
project_symbols = { path = "../project_symbols" }
|
project_symbols = { path = "../project_symbols" }
|
||||||
@ -62,7 +62,6 @@ text = { path = "../text" }
|
|||||||
terminal_view = { path = "../terminal_view" }
|
terminal_view = { path = "../terminal_view" }
|
||||||
theme = { path = "../theme" }
|
theme = { path = "../theme" }
|
||||||
theme_selector = { path = "../theme_selector" }
|
theme_selector = { path = "../theme_selector" }
|
||||||
theme_testbench = { path = "../theme_testbench" }
|
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
vim = { path = "../vim" }
|
vim = { path = "../vim" }
|
||||||
workspace = { path = "../workspace" }
|
workspace = { path = "../workspace" }
|
||||||
@ -102,13 +101,14 @@ tempdir.workspace = true
|
|||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
tiny_http = "0.8"
|
tiny_http = "0.8"
|
||||||
toml.workspace = true
|
toml.workspace = true
|
||||||
tree-sitter = "0.20"
|
tree-sitter.workspace = true
|
||||||
tree-sitter-c = "0.20.1"
|
tree-sitter-c = "0.20.1"
|
||||||
tree-sitter-cpp = "0.20.0"
|
tree-sitter-cpp = "0.20.0"
|
||||||
tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" }
|
tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" }
|
||||||
tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" }
|
tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" }
|
||||||
tree-sitter-embedded-template = "0.20.0"
|
tree-sitter-embedded-template = "0.20.0"
|
||||||
tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "aeb2f33b366fd78d5789ff104956ce23508b85db" }
|
tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "aeb2f33b366fd78d5789ff104956ce23508b85db" }
|
||||||
|
tree-sitter-heex = { git = "https://github.com/phoenixframework/tree-sitter-heex", rev = "2e1348c3cf2c9323e87c2744796cf3f3868aa82a" }
|
||||||
tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "40a81c01a40ac48744e0c8ccabbaba1920441199" }
|
tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "40a81c01a40ac48744e0c8ccabbaba1920441199" }
|
||||||
tree-sitter-rust = "0.20.3"
|
tree-sitter-rust = "0.20.3"
|
||||||
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
||||||
@ -146,15 +146,19 @@ icon = ["resources/app-icon-preview@2x.png", "resources/app-icon-preview.png"]
|
|||||||
identifier = "dev.zed.Zed-Dev"
|
identifier = "dev.zed.Zed-Dev"
|
||||||
name = "Zed Dev"
|
name = "Zed Dev"
|
||||||
osx_minimum_system_version = "10.15.7"
|
osx_minimum_system_version = "10.15.7"
|
||||||
|
osx_info_plist_exts = ["resources/info/*"]
|
||||||
|
|
||||||
[package.metadata.bundle-preview]
|
[package.metadata.bundle-preview]
|
||||||
icon = ["resources/app-icon-preview@2x.png", "resources/app-icon-preview.png"]
|
icon = ["resources/app-icon-preview@2x.png", "resources/app-icon-preview.png"]
|
||||||
identifier = "dev.zed.Zed-Preview"
|
identifier = "dev.zed.Zed-Preview"
|
||||||
name = "Zed Preview"
|
name = "Zed Preview"
|
||||||
osx_minimum_system_version = "10.15.7"
|
osx_minimum_system_version = "10.15.7"
|
||||||
|
osx_info_plist_exts = ["resources/info/*"]
|
||||||
|
|
||||||
|
|
||||||
[package.metadata.bundle-stable]
|
[package.metadata.bundle-stable]
|
||||||
icon = ["resources/app-icon@2x.png", "resources/app-icon.png"]
|
icon = ["resources/app-icon@2x.png", "resources/app-icon.png"]
|
||||||
identifier = "dev.zed.Zed"
|
identifier = "dev.zed.Zed"
|
||||||
name = "Zed"
|
name = "Zed"
|
||||||
osx_minimum_system_version = "10.15.7"
|
osx_minimum_system_version = "10.15.7"
|
||||||
|
osx_info_plist_exts = ["resources/info/*"]
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user