Unified · Split
| @@ -148,8 +148,8 @@ jobs: · 147 unmodified lines | |||
| 148 | - name: Create app bundle | 148 | - name: Create app bundle |
| 149 | run: script/bundle | 149 | run: script/bundle |
| 150 | 150 | ||
| 151 | - name: Upload app bundle to workflow run if main branch or specifi label | 151 | - name: Upload app bundle to workflow run if main branch or specific label |
| 152 | uses: actions/upload-artifact@v2 | 152 | uses: actions/upload-artifact@v3 |
| 153 | if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }} | 153 | if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }} |
| 154 | with: | 154 | with: |
| 155 | name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.dmg | 155 | name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.dmg |
| @@ -1243,9 +1243,9 @@ dependencies = [ · 1242 unmodified lines | |||
| 1243 | 1243 | ||
| 1244 | [[package]] | 1244 | [[package]] |
| 1245 | name = "clap" | 1245 | name = "clap" |
| 1246 | version = "4.3.14" | 1246 | version = "4.3.15" |
| 1247 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1247 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1248 | checksum = "98330784c494e49850cb23b8e2afcca13587d2500b2e3f1f78ae20248059c9be" | 1248 | checksum = "8f644d0dac522c8b05ddc39aaaccc5b136d5dc4ff216610c5641e3be5becf56c" |
| 1249 | dependencies = [ | 1249 | dependencies = [ |
| 1250 | "clap_builder", | 1250 | "clap_builder", |
| 1251 | "clap_derive 4.3.12", | 1251 | "clap_derive 4.3.12", |
| @@ -1254,9 +1254,9 @@ dependencies = [ · 2 unmodified lines | |||
| 1254 | 1254 | ||
| 1255 | [[package]] | 1255 | [[package]] |
| 1256 | name = "clap_builder" | 1256 | name = "clap_builder" |
| 1257 | version = "4.3.14" | 1257 | version = "4.3.15" |
| 1258 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1258 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1259 | checksum = "e182eb5f2562a67dda37e2c57af64d720a9e010c5e860ed87c056586aeafa52e" | 1259 | checksum = "af410122b9778e024f9e0fb35682cc09cc3f85cad5e8d3ba8f47a9702df6e73d" |
| 1260 | dependencies = [ | 1260 | dependencies = [ |
| 1261 | "anstream", | 1261 | "anstream", |
| 1262 | "anstyle", | 1262 | "anstyle", |
| @@ -2253,7 +2253,6 @@ dependencies = [ · 990 unmodified lines | |||
| 2253 | "theme", | 2253 | "theme", |
| 2254 | "tree-sitter", | 2254 | "tree-sitter", |
| 2255 | "tree-sitter-html", | 2255 | "tree-sitter-html", |
| 2256 | "tree-sitter-javascript", | ||
| 2257 | "tree-sitter-rust", | 2256 | "tree-sitter-rust", |
| 2258 | "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", | 2257 | "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", |
| 2259 | "unindent", | 2258 | "unindent", |
| @@ -3750,15 +3749,16 @@ dependencies = [ · 1490 unmodified lines | |||
| 3750 | "text", | 3749 | "text", |
| 3751 | "theme", | 3750 | "theme", |
| 3752 | "tree-sitter", | 3751 | "tree-sitter", |
| 3752 | "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=4ba9dab6e2602960d95b2b625f3386c27e08084e)", | ||
| 3753 | "tree-sitter-embedded-template", | 3753 | "tree-sitter-embedded-template", |
| 3754 | "tree-sitter-heex", | ||
| 3754 | "tree-sitter-html", | 3755 | "tree-sitter-html", |
| 3755 | "tree-sitter-javascript", | 3756 | "tree-sitter-json 0.20.0", |
| 3756 | "tree-sitter-json 0.19.0", | ||
| 3757 | "tree-sitter-markdown", | 3757 | "tree-sitter-markdown", |
| 3758 | "tree-sitter-python", | 3758 | "tree-sitter-python", |
| 3759 | "tree-sitter-ruby", | 3759 | "tree-sitter-ruby", |
| 3760 | "tree-sitter-rust", | 3760 | "tree-sitter-rust", |
| 3761 | "tree-sitter-typescript 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)", | 3761 | "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", |
| 3762 | "unicase", | 3762 | "unicase", |
| 3763 | "unindent", | 3763 | "unindent", |
| 3764 | "util", | 3764 | "util", |
| @@ -8083,16 +8083,6 @@ dependencies = [ · 4318 unmodified lines | |||
| 8083 | "tree-sitter", | 8083 | "tree-sitter", |
| 8084 | ] | 8084 | ] |
| 8085 | 8085 | ||
| 8086 | [[package]] | ||
| 8087 | name = "tree-sitter-javascript" | ||
| 8088 | version = "0.20.0" | ||
| 8089 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 8090 | checksum = "2490fab08630b2c8943c320f7b63473cbf65511c8d83aec551beb9b4375906ed" | ||
| 8091 | dependencies = [ | ||
| 8092 | "cc", | ||
| 8093 | "tree-sitter", | ||
| 8094 | ] | ||
| 8095 | |||
| 8096 | [[package]] | 8086 | [[package]] |
| 8097 | name = "tree-sitter-json" | 8087 | name = "tree-sitter-json" |
| 8098 | version = "0.19.0" | 8088 | version = "0.19.0" |
| @@ -8131,6 +8121,15 @@ dependencies = [ · 32 unmodified lines | |||
| 8131 | "tree-sitter", | 8121 | "tree-sitter", |
| 8132 | ] | 8122 | ] |
| 8133 | 8123 | ||
| 8124 | [[package]] | ||
| 8125 | name = "tree-sitter-php" | ||
| 8126 | version = "0.19.1" | ||
| 8127 | source = "git+https://github.com/tree-sitter/tree-sitter-php?rev=d43130fd1525301e9826f420c5393a4d169819fc#d43130fd1525301e9826f420c5393a4d169819fc" | ||
| 8128 | dependencies = [ | ||
| 8129 | "cc", | ||
| 8130 | "tree-sitter", | ||
| 8131 | ] | ||
| 8132 | |||
| 8134 | [[package]] | 8133 | [[package]] |
| 8135 | name = "tree-sitter-python" | 8134 | name = "tree-sitter-python" |
| 8136 | version = "0.20.2" | 8135 | version = "0.20.2" |
| @@ -8179,6 +8178,15 @@ dependencies = [ · 42 unmodified lines | |||
| 8179 | "tree-sitter", | 8178 | "tree-sitter", |
| 8180 | ] | 8179 | ] |
| 8181 | 8180 | ||
| 8181 | [[package]] | ||
| 8182 | name = "tree-sitter-svelte" | ||
| 8183 | version = "0.10.2" | ||
| 8184 | source = "git+https://github.com/Himujjal/tree-sitter-svelte?rev=697bb515471871e85ff799ea57a76298a71a9cca#697bb515471871e85ff799ea57a76298a71a9cca" | ||
| 8185 | dependencies = [ | ||
| 8186 | "cc", | ||
| 8187 | "tree-sitter", | ||
| 8188 | ] | ||
| 8189 | |||
| 8182 | [[package]] | 8190 | [[package]] |
| 8183 | name = "tree-sitter-toml" | 8191 | name = "tree-sitter-toml" |
| 8184 | version = "0.5.1" | 8192 | version = "0.5.1" |
| @@ -9449,7 +9457,7 @@ name = "xtask" · 1264 unmodified lines | |||
| 9449 | version = "0.1.0" | 9457 | version = "0.1.0" |
| 9450 | dependencies = [ | 9458 | dependencies = [ |
| 9451 | "anyhow", | 9459 | "anyhow", |
| 9452 | "clap 4.3.14", | 9460 | "clap 4.3.15", |
| 9453 | "schemars", | 9461 | "schemars", |
| 9454 | "serde_json", | 9462 | "serde_json", |
| 9455 | "theme", | 9463 | "theme", |
| @@ -9580,11 +9588,13 @@ dependencies = [ · 124 unmodified lines | |||
| 9580 | "tree-sitter-json 0.20.0", | 9588 | "tree-sitter-json 0.20.0", |
| 9581 | "tree-sitter-lua", | 9589 | "tree-sitter-lua", |
| 9582 | "tree-sitter-markdown", | 9590 | "tree-sitter-markdown", |
| 9591 | "tree-sitter-php", | ||
| 9583 | "tree-sitter-python", | 9592 | "tree-sitter-python", |
| 9584 | "tree-sitter-racket", | 9593 | "tree-sitter-racket", |
| 9585 | "tree-sitter-ruby", | 9594 | "tree-sitter-ruby", |
| 9586 | "tree-sitter-rust", | 9595 | "tree-sitter-rust", |
| 9587 | "tree-sitter-scheme", | 9596 | "tree-sitter-scheme", |
| 9597 | "tree-sitter-svelte", | ||
| 9588 | "tree-sitter-toml 0.5.1", | 9598 | "tree-sitter-toml 0.5.1", |
| 9589 | "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", | 9599 | "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", |
| 9590 | "tree-sitter-yaml", | 9600 | "tree-sitter-yaml", |
| @@ -107,6 +107,28 @@ tree-sitter = "0.20" · 106 unmodified lines | |||
| 107 | unindent = { version = "0.1.7" } | 107 | unindent = { version = "0.1.7" } |
| 108 | pretty_assertions = "1.3.0" | 108 | pretty_assertions = "1.3.0" |
| 109 | 109 | ||
| 110 | tree-sitter-c = "0.20.1" | ||
| 111 | tree-sitter-cpp = "0.20.0" | ||
| 112 | tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } | ||
| 113 | tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" } | ||
| 114 | tree-sitter-embedded-template = "0.20.0" | ||
| 115 | tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "aeb2f33b366fd78d5789ff104956ce23508b85db" } | ||
| 116 | tree-sitter-heex = { git = "https://github.com/phoenixframework/tree-sitter-heex", rev = "2e1348c3cf2c9323e87c2744796cf3f3868aa82a" } | ||
| 117 | tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "40a81c01a40ac48744e0c8ccabbaba1920441199" } | ||
| 118 | tree-sitter-rust = "0.20.3" | ||
| 119 | tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" } | ||
| 120 | tree-sitter-php = { git = "https://github.com/tree-sitter/tree-sitter-php", rev = "d43130fd1525301e9826f420c5393a4d169819fc" } | ||
| 121 | tree-sitter-python = "0.20.2" | ||
| 122 | tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" } | ||
| 123 | tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" } | ||
| 124 | tree-sitter-ruby = "0.20.0" | ||
| 125 | tree-sitter-html = "0.19.0" | ||
| 126 | tree-sitter-scheme = { git = "https://github.com/6cdh/tree-sitter-scheme", rev = "af0fd1fa452cb2562dc7b5c8a8c55551c39273b9"} | ||
| 127 | tree-sitter-svelte = { git = "https://github.com/Himujjal/tree-sitter-svelte", rev = "697bb515471871e85ff799ea57a76298a71a9cca"} | ||
| 128 | tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a"} | ||
| 129 | tree-sitter-yaml = { git = "https://github.com/zed-industries/tree-sitter-yaml", rev = "f545a41f57502e1b5ddf2a6668896c1b0620f930"} | ||
| 130 | tree-sitter-lua = "0.0.14" | ||
| 131 | |||
| 110 | [patch.crates-io] | 132 | [patch.crates-io] |
| 111 | tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "49226023693107fba9a1191136a4f47f38cdca73" } | 133 | tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "49226023693107fba9a1191136a4f47f38cdca73" } |
| 112 | async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" } | 134 | async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" } |
| @@ -9,6 +9,7 @@ · 8 unmodified lines | |||
| 9 | "context": "Editor", | 9 | "context": "Editor", |
| 10 | "bindings": { | 10 | "bindings": { |
| 11 | "cmd-b": "editor::GoToDefinition", | 11 | "cmd-b": "editor::GoToDefinition", |
| 12 | "alt-cmd-b": "editor::GoToDefinitionSplit", | ||
| 12 | "cmd-<": "editor::ScrollCursorCenter", | 13 | "cmd-<": "editor::ScrollCursorCenter", |
| 13 | "cmd-g": [ | 14 | "cmd-g": [ |
| 14 | "editor::SelectNext", | 15 | "editor::SelectNext", |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | |||
| 13 | "cmd-up": "menu::SelectFirst", | 13 | "cmd-up": "menu::SelectFirst", |
| 14 | "cmd-down": "menu::SelectLast", | 14 | "cmd-down": "menu::SelectLast", |
| 15 | "enter": "menu::Confirm", | 15 | "enter": "menu::Confirm", |
| 16 | "cmd-enter": "menu::SecondaryConfirm", | ||
| 16 | "escape": "menu::Cancel", | 17 | "escape": "menu::Cancel", |
| 17 | "ctrl-c": "menu::Cancel", | 18 | "ctrl-c": "menu::Cancel", |
| 18 | "cmd-{": "pane::ActivatePrevItem", | 19 | "cmd-{": "pane::ActivatePrevItem", |
| @@ -194,8 +195,8 @@ · 175 unmodified lines | |||
| 194 | { | 195 | { |
| 195 | "context": "Editor && mode == auto_height", | 196 | "context": "Editor && mode == auto_height", |
| 196 | "bindings": { | 197 | "bindings": { |
| 197 | "alt-enter": "editor::Newline", | 198 | "shift-enter": "editor::Newline", |
| 198 | "cmd-alt-enter": "editor::NewlineBelow" | 199 | "cmd-shift-enter": "editor::NewlineBelow" |
| 199 | } | 200 | } |
| 200 | }, | 201 | }, |
| 201 | { | 202 | { |
| @@ -221,7 +222,8 @@ · 19 unmodified lines | |||
| 221 | "escape": "buffer_search::Dismiss", | 222 | "escape": "buffer_search::Dismiss", |
| 222 | "tab": "buffer_search::FocusEditor", | 223 | "tab": "buffer_search::FocusEditor", |
| 223 | "enter": "search::SelectNextMatch", | 224 | "enter": "search::SelectNextMatch", |
| 224 | "shift-enter": "search::SelectPrevMatch" | 225 | "shift-enter": "search::SelectPrevMatch", |
| 226 | "alt-enter": "search::SelectAllMatches" | ||
| 225 | } | 227 | } |
| 226 | }, | 228 | }, |
| 227 | { | 229 | { |
| @@ -242,6 +244,7 @@ · 14 unmodified lines | |||
| 242 | "cmd-f": "project_search::ToggleFocus", | 244 | "cmd-f": "project_search::ToggleFocus", |
| 243 | "cmd-g": "search::SelectNextMatch", | 245 | "cmd-g": "search::SelectNextMatch", |
| 244 | "cmd-shift-g": "search::SelectPrevMatch", | 246 | "cmd-shift-g": "search::SelectPrevMatch", |
| 247 | "alt-enter": "search::SelectAllMatches", | ||
| 245 | "alt-cmd-c": "search::ToggleCaseSensitive", | 248 | "alt-cmd-c": "search::ToggleCaseSensitive", |
| 246 | "alt-cmd-w": "search::ToggleWholeWord", | 249 | "alt-cmd-w": "search::ToggleWholeWord", |
| 247 | "alt-cmd-r": "search::ToggleRegex" | 250 | "alt-cmd-r": "search::ToggleRegex" |
| @@ -296,7 +299,9 @@ · 48 unmodified lines | |||
| 296 | "shift-f8": "editor::GoToPrevDiagnostic", | 299 | "shift-f8": "editor::GoToPrevDiagnostic", |
| 297 | "f2": "editor::Rename", | 300 | "f2": "editor::Rename", |
| 298 | "f12": "editor::GoToDefinition", | 301 | "f12": "editor::GoToDefinition", |
| 302 | "alt-f12": "editor::GoToDefinitionSplit", | ||
| 299 | "cmd-f12": "editor::GoToTypeDefinition", | 303 | "cmd-f12": "editor::GoToTypeDefinition", |
| 304 | "alt-cmd-f12": "editor::GoToTypeDefinitionSplit", | ||
| 300 | "alt-shift-f12": "editor::FindAllReferences", | 305 | "alt-shift-f12": "editor::FindAllReferences", |
| 301 | "ctrl-m": "editor::MoveToEnclosingBracket", | 306 | "ctrl-m": "editor::MoveToEnclosingBracket", |
| 302 | "alt-cmd-[": "editor::Fold", | 307 | "alt-cmd-[": "editor::Fold", |
| @@ -46,8 +46,9 @@ · 45 unmodified lines | |||
| 46 | "alt-f7": "editor::FindAllReferences", | 46 | "alt-f7": "editor::FindAllReferences", |
| 47 | "cmd-alt-f7": "editor::FindAllReferences", | 47 | "cmd-alt-f7": "editor::FindAllReferences", |
| 48 | "cmd-b": "editor::GoToDefinition", | 48 | "cmd-b": "editor::GoToDefinition", |
| 49 | "cmd-alt-b": "editor::GoToDefinition", | 49 | "cmd-alt-b": "editor::GoToDefinitionSplit", |
| 50 | "cmd-shift-b": "editor::GoToTypeDefinition", | 50 | "cmd-shift-b": "editor::GoToTypeDefinition", |
| 51 | "cmd-alt-shift-b": "editor::GoToTypeDefinitionSplit", | ||
| 51 | "alt-enter": "editor::ToggleCodeActions", | 52 | "alt-enter": "editor::ToggleCodeActions", |
| 52 | "f2": "editor::GoToDiagnostic", | 53 | "f2": "editor::GoToDiagnostic", |
| 53 | "cmd-f2": "editor::GoToPrevDiagnostic", | 54 | "cmd-f2": "editor::GoToPrevDiagnostic", |
| @@ -20,6 +20,7 @@ · 19 unmodified lines | |||
| 20 | "cmd-shift-a": "editor::SelectLargerSyntaxNode", | 20 | "cmd-shift-a": "editor::SelectLargerSyntaxNode", |
| 21 | "shift-f12": "editor::FindAllReferences", | 21 | "shift-f12": "editor::FindAllReferences", |
| 22 | "alt-cmd-down": "editor::GoToDefinition", | 22 | "alt-cmd-down": "editor::GoToDefinition", |
| 23 | "ctrl-alt-cmd-down": "editor::GoToDefinitionSplit", | ||
| 23 | "alt-shift-cmd-down": "editor::FindAllReferences", | 24 | "alt-shift-cmd-down": "editor::FindAllReferences", |
| 24 | "ctrl-.": "editor::GoToHunk", | 25 | "ctrl-.": "editor::GoToHunk", |
| 25 | "ctrl-,": "editor::GoToPrevHunk", | 26 | "ctrl-,": "editor::GoToPrevHunk", |
| @@ -12,6 +12,7 @@ · 11 unmodified lines | |||
| 12 | "cmd-l": "go_to_line::Toggle", | 12 | "cmd-l": "go_to_line::Toggle", |
| 13 | "ctrl-shift-d": "editor::DuplicateLine", | 13 | "ctrl-shift-d": "editor::DuplicateLine", |
| 14 | "cmd-b": "editor::GoToDefinition", | 14 | "cmd-b": "editor::GoToDefinition", |
| 15 | "alt-cmd-b": "editor::GoToDefinition", | ||
| 15 | "cmd-j": "editor::ScrollCursorCenter", | 16 | "cmd-j": "editor::ScrollCursorCenter", |
| 16 | "cmd-shift-l": "editor::SelectLine", | 17 | "cmd-shift-l": "editor::SelectLine", |
| 17 | "cmd-shift-t": "outline::Toggle", | 18 | "cmd-shift-t": "outline::Toggle", |
| @@ -99,6 +99,10 @@ · 98 unmodified lines | |||
| 99 | "vim::SwitchMode", | 99 | "vim::SwitchMode", |
| 100 | "Normal" | 100 | "Normal" |
| 101 | ], | 101 | ], |
| 102 | "ctrl+[": [ | ||
| 103 | "vim::SwitchMode", | ||
| 104 | "Normal" | ||
| 105 | ], | ||
| 102 | "0": "vim::StartOfLine", // When no number operator present, use start of line motion | 106 | "0": "vim::StartOfLine", // When no number operator present, use start of line motion |
| 103 | "1": [ | 107 | "1": [ |
| 104 | "vim::Number", | 108 | "vim::Number", |
| @@ -234,10 +238,6 @@ · 129 unmodified lines | |||
| 234 | "h": "editor::Hover", | 238 | "h": "editor::Hover", |
| 235 | "t": "pane::ActivateNextItem", | 239 | "t": "pane::ActivateNextItem", |
| 236 | "shift-t": "pane::ActivatePrevItem", | 240 | "shift-t": "pane::ActivatePrevItem", |
| 237 | "escape": [ | ||
| 238 | "vim::SwitchMode", | ||
| 239 | "Normal" | ||
| 240 | ], | ||
| 241 | "d": "editor::GoToDefinition" | 241 | "d": "editor::GoToDefinition" |
| 242 | } | 242 | } |
| 243 | }, | 243 | }, |
| @@ -265,10 +265,6 @@ · 21 unmodified lines | |||
| 265 | "t": "editor::ScrollCursorTop", | 265 | "t": "editor::ScrollCursorTop", |
| 266 | "z": "editor::ScrollCursorCenter", | 266 | "z": "editor::ScrollCursorCenter", |
| 267 | "b": "editor::ScrollCursorBottom", | 267 | "b": "editor::ScrollCursorBottom", |
| 268 | "escape": [ | ||
| 269 | "vim::SwitchMode", | ||
| 270 | "Normal" | ||
| 271 | ] | ||
| 272 | } | 268 | } |
| 273 | }, | 269 | }, |
| 274 | { | 270 | { |
| @@ -322,7 +318,8 @@ · 47 unmodified lines | |||
| 322 | "context": "Editor && vim_mode == insert", | 318 | "context": "Editor && vim_mode == insert", |
| 323 | "bindings": { | 319 | "bindings": { |
| 324 | "escape": "vim::NormalBefore", | 320 | "escape": "vim::NormalBefore", |
| 325 | "ctrl-c": "vim::NormalBefore" | 321 | "ctrl-c": "vim::NormalBefore", |
| 322 | "ctrl-[": "vim::NormalBefore", | ||
| 326 | } | 323 | } |
| 327 | }, | 324 | }, |
| 328 | { | 325 | { |
| @@ -333,6 +330,10 @@ · 4 unmodified lines | |||
| 333 | "escape": [ | 330 | "escape": [ |
| 334 | "vim::SwitchMode", | 331 | "vim::SwitchMode", |
| 335 | "Normal" | 332 | "Normal" |
| 333 | ], | ||
| 334 | "ctrl+[": [ | ||
| 335 | "vim::SwitchMode", | ||
| 336 | "Normal" | ||
| 336 | ] | 337 | ] |
| 337 | } | 338 | } |
| 338 | } | 339 | } |
| @@ -24,6 +24,17 @@ · 23 unmodified lines | |||
| 24 | }, | 24 | }, |
| 25 | // The default font size for text in the editor | 25 | // The default font size for text in the editor |
| 26 | "buffer_font_size": 15, | 26 | "buffer_font_size": 15, |
| 27 | // Set the buffer's line height. | ||
| 28 | // May take 3 values: | ||
| 29 | // 1. Use a line height that's comfortable for reading (1.618) | ||
| 30 | // "line_height": "comfortable" | ||
| 31 | // 2. Use a standard line height, (1.3) | ||
| 32 | // "line_height": "standard", | ||
| 33 | // 3. Use a custom line height | ||
| 34 | // "line_height": { | ||
| 35 | // "custom": 2 | ||
| 36 | // }, | ||
| 37 | "buffer_line_height": "comfortable", | ||
| 27 | // The factor to grow the active pane by. Defaults to 1.0 | 38 | // The factor to grow the active pane by. Defaults to 1.0 |
| 28 | // which gives the same size as all other panes. | 39 | // which gives the same size as all other panes. |
| 29 | "active_pane_magnification": 1.0, | 40 | "active_pane_magnification": 1.0, |
| @@ -117,6 +128,13 @@ · 87 unmodified lines | |||
| 117 | // 4. Save when idle for a certain amount of time: | 128 | // 4. Save when idle for a certain amount of time: |
| 118 | // "autosave": { "after_delay": {"milliseconds": 500} }, | 129 | // "autosave": { "after_delay": {"milliseconds": 500} }, |
| 119 | "autosave": "off", | 130 | "autosave": "off", |
| 131 | // Settings related to the editor's tabs | ||
| 132 | "tabs": { | ||
| 133 | // Show git status colors in the editor tabs. | ||
| 134 | "git_status": false, | ||
| 135 | // Position of the close button on the editor tabs. | ||
| 136 | "close_position": "right" | ||
| 137 | }, | ||
| 120 | // Whether or not to remove any trailing whitespace from lines of a buffer | 138 | // Whether or not to remove any trailing whitespace from lines of a buffer |
| 121 | // before saving it. | 139 | // before saving it. |
| 122 | "remove_trailing_whitespace_on_save": true, | 140 | "remove_trailing_whitespace_on_save": true, |
| @@ -282,7 +300,6 @@ · 159 unmodified lines | |||
| 282 | // "line_height": { | 300 | // "line_height": { |
| 283 | // "custom": 2 | 301 | // "custom": 2 |
| 284 | // }, | 302 | // }, |
| 285 | // | ||
| 286 | "line_height": "comfortable" | 303 | "line_height": "comfortable" |
| 287 | // Set the terminal's font size. If this option is not included, | 304 | // Set the terminal's font size. If this option is not included, |
| 288 | // the terminal will default to matching the buffer's font size. | 305 | // the terminal will default to matching the buffer's font size. |
| @@ -7217,7 +7217,7 @@ async fn test_peers_following_each_other( · 7216 unmodified lines | |||
| 7217 | 7217 | ||
| 7218 | // Clients A and B follow each other in split panes | 7218 | // Clients A and B follow each other in split panes |
| 7219 | workspace_a.update(cx_a, |workspace, cx| { | 7219 | workspace_a.update(cx_a, |workspace, cx| { |
| 7220 | workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); | 7220 | workspace.split_and_clone(workspace.active_pane().clone(), SplitDirection::Right, cx); |
| 7221 | }); | 7221 | }); |
| 7222 | workspace_a | 7222 | workspace_a |
| 7223 | .update(cx_a, |workspace, cx| { | 7223 | .update(cx_a, |workspace, cx| { |
| @@ -7228,7 +7228,7 @@ async fn test_peers_following_each_other( · 4 unmodified lines | |||
| 7228 | .await | 7228 | .await |
| 7229 | .unwrap(); | 7229 | .unwrap(); |
| 7230 | workspace_b.update(cx_b, |workspace, cx| { | 7230 | workspace_b.update(cx_b, |workspace, cx| { |
| 7231 | workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); | 7231 | workspace.split_and_clone(workspace.active_pane().clone(), SplitDirection::Right, cx); |
| 7232 | }); | 7232 | }); |
| 7233 | workspace_b | 7233 | workspace_b |
| 7234 | .update(cx_b, |workspace, cx| { | 7234 | .update(cx_b, |workspace, cx| { |
| @@ -7455,7 +7455,7 @@ async fn test_auto_unfollowing( · 220 unmodified lines | |||
| 7455 | 7455 | ||
| 7456 | // When client B activates a different pane, it continues following client A in the original pane. | 7456 | // When client B activates a different pane, it continues following client A in the original pane. |
| 7457 | workspace_b.update(cx_b, |workspace, cx| { | 7457 | workspace_b.update(cx_b, |workspace, cx| { |
| 7458 | workspace.split_pane(pane_b.clone(), SplitDirection::Right, cx) | 7458 | workspace.split_and_clone(pane_b.clone(), SplitDirection::Right, cx) |
| 7459 | }); | 7459 | }); |
| 7460 | assert_eq!( | 7460 | assert_eq!( |
| 7461 | workspace_b.read_with(cx_b, |workspace, _| workspace.leader_for_pane(&pane_b)), | 7461 | workspace_b.read_with(cx_b, |workspace, _| workspace.leader_for_pane(&pane_b)), |
| @@ -67,7 +67,7 @@ impl PickerDelegate for ContactFinderDelegate { · 66 unmodified lines | |||
| 67 | }) | 67 | }) |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | fn confirm(&mut self, cx: &mut ViewContext<Picker<Self>>) { | 70 | fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) { |
| 71 | if let Some(user) = self.potential_contacts.get(self.selected_index) { | 71 | if let Some(user) = self.potential_contacts.get(self.selected_index) { |
| 72 | let user_store = self.user_store.read(cx); | 72 | let user_store = self.user_store.read(cx); |
| 73 | match user_store.contact_request_status(user) { | 73 | match user_store.contact_request_status(user) { |
| @@ -160,7 +160,7 @@ impl PickerDelegate for CommandPaletteDelegate { · 159 unmodified lines | |||
| 160 | 160 | ||
| 161 | fn dismissed(&mut self, _cx: &mut ViewContext<Picker<Self>>) {} | 161 | fn dismissed(&mut self, _cx: &mut ViewContext<Picker<Self>>) {} |
| 162 | 162 | ||
| 163 | fn confirm(&mut self, cx: &mut ViewContext<Picker<Self>>) { | 163 | fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) { |
| 164 | if !self.matches.is_empty() { | 164 | if !self.matches.is_empty() { |
| 165 | let window_id = cx.window_id(); | 165 | let window_id = cx.window_id(); |
| 166 | let focused_view_id = self.focused_view_id; | 166 | let focused_view_id = self.focused_view_id; |
| @@ -7,7 +7,6 @@ use anyhow::Context; · 6 unmodified lines | |||
| 7 | use gpui::AppContext; | 7 | use gpui::AppContext; |
| 8 | pub use indoc::indoc; | 8 | pub use indoc::indoc; |
| 9 | pub use lazy_static; | 9 | pub use lazy_static; |
| 10 | use parking_lot::{Mutex, RwLock}; | ||
| 11 | pub use smol; | 10 | pub use smol; |
| 12 | pub use sqlez; | 11 | pub use sqlez; |
| 13 | pub use sqlez_macros; | 12 | pub use sqlez_macros; |
| @@ -17,11 +16,9 @@ pub use util::paths::DB_DIR; · 3 unmodified lines | |||
| 17 | use sqlez::domain::Migrator; | 16 | use sqlez::domain::Migrator; |
| 18 | use sqlez::thread_safe_connection::ThreadSafeConnection; | 17 | use sqlez::thread_safe_connection::ThreadSafeConnection; |
| 19 | use sqlez_macros::sql; | 18 | use sqlez_macros::sql; |
| 20 | use std::fs::create_dir_all; | ||
| 21 | use std::future::Future; | 19 | use std::future::Future; |
| 22 | use std::path::{Path, PathBuf}; | 20 | use std::path::{Path, PathBuf}; |
| 23 | use std::sync::atomic::{AtomicBool, Ordering}; | 21 | use std::sync::atomic::{AtomicBool, Ordering}; |
| 24 | use std::time::{SystemTime, UNIX_EPOCH}; | ||
| 25 | use util::channel::ReleaseChannel; | 22 | use util::channel::ReleaseChannel; |
| 26 | use util::{async_iife, ResultExt}; | 23 | use util::{async_iife, ResultExt}; |
| 27 | 24 | ||
| @@ -42,10 +39,8 @@ const DB_FILE_NAME: &'static str = "db.sqlite"; · 14 unmodified lines | |||
| 42 | 39 | ||
| 43 | lazy_static::lazy_static! { | 40 | lazy_static::lazy_static! { |
| 44 | pub static ref ZED_STATELESS: bool = std::env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty()); | 41 | pub static ref ZED_STATELESS: bool = std::env::var("ZED_STATELESS").map_or(false, |v| !v.is_empty()); |
| 45 | pub static ref BACKUP_DB_PATH: RwLock<Option<PathBuf>> = RwLock::new(None); | ||
| 46 | pub static ref ALL_FILE_DB_FAILED: AtomicBool = AtomicBool::new(false); | 42 | pub static ref ALL_FILE_DB_FAILED: AtomicBool = AtomicBool::new(false); |
| 47 | } | 43 | } |
| 48 | static DB_FILE_OPERATIONS: Mutex<()> = Mutex::new(()); | ||
| 49 | 44 | ||
| 50 | /// Open or create a database at the given directory path. | 45 | /// Open or create a database at the given directory path. |
| 51 | /// This will retry a couple times if there are failures. If opening fails once, the db directory | 46 | /// This will retry a couple times if there are failures. If opening fails once, the db directory |
| @@ -63,66 +58,14 @@ pub async fn open_db<M: Migrator + 'static>( · 11 unmodified lines | |||
| 63 | let main_db_dir = db_dir.join(Path::new(&format!("0-{}", release_channel_name))); | 58 | let main_db_dir = db_dir.join(Path::new(&format!("0-{}", release_channel_name))); |
| 64 | 59 | ||
| 65 | let connection = async_iife!({ | 60 | let connection = async_iife!({ |
| 66 | // Note: This still has a race condition where 1 set of migrations succeeds | 61 | smol::fs::create_dir_all(&main_db_dir) |
| 67 | // (e.g. (Workspace, Editor)) and another fails (e.g. (Workspace, Terminal)) | 62 | .await |
| 68 | // This will cause the first connection to have the database taken out | 63 | .context("Could not create db directory") |
| 69 | // from under it. This *should* be fine though. The second dabatase failure will | 64 | .log_err()?; |
| 70 | // cause errors in the log and so should be observed by developers while writing | ||
| 71 | // soon-to-be good migrations. If user databases are corrupted, we toss them out | ||
| 72 | // and try again from a blank. As long as running all migrations from start to end | ||
| 73 | // on a blank database is ok, this race condition will never be triggered. | ||
| 74 | // | ||
| 75 | // Basically: Don't ever push invalid migrations to stable or everyone will have | ||
| 76 | // a bad time. | ||
| 77 | |||
| 78 | // If no db folder, create one at 0-{channel} | ||
| 79 | create_dir_all(&main_db_dir).context("Could not create db directory")?; | ||
| 80 | let db_path = main_db_dir.join(Path::new(DB_FILE_NAME)); | 65 | let db_path = main_db_dir.join(Path::new(DB_FILE_NAME)); |
| 81 | 66 | open_main_db(&db_path).await | |
| 82 | // Optimistically open databases in parallel | 67 | }) |
| 83 | if !DB_FILE_OPERATIONS.is_locked() { | 68 | .await; |
| 84 | // Try building a connection | ||
| 85 | if let Some(connection) = open_main_db(&db_path).await { | ||
| 86 | return Ok(connection) | ||
| 87 | }; | ||
| 88 | } | ||
| 89 | |||
| 90 | // Take a lock in the failure case so that we move the db once per process instead | ||
| 91 | // of potentially multiple times from different threads. This shouldn't happen in the | ||
| 92 | // normal path | ||
| 93 | let _lock = DB_FILE_OPERATIONS.lock(); | ||
| 94 | if let Some(connection) = open_main_db(&db_path).await { | ||
| 95 | return Ok(connection) | ||
| 96 | }; | ||
| 97 | |||
| 98 | let backup_timestamp = SystemTime::now() | ||
| 99 | .duration_since(UNIX_EPOCH) | ||
| 100 | .expect("System clock is set before the unix timestamp, Zed does not support this region of spacetime") | ||
| 101 | .as_millis(); | ||
| 102 | |||
| 103 | // If failed, move 0-{channel} to {current unix timestamp}-{channel} | ||
| 104 | let backup_db_dir = db_dir.join(Path::new(&format!( | ||
| 105 | "{}-{}", | ||
| 106 | backup_timestamp, | ||
| 107 | release_channel_name, | ||
| 108 | ))); | ||
| 109 | |||
| 110 | std::fs::rename(&main_db_dir, &backup_db_dir) | ||
| 111 | .context("Failed clean up corrupted database, panicking.")?; | ||
| 112 | |||
| 113 | // Set a static ref with the failed timestamp and error so we can notify the user | ||
| 114 | { | ||
| 115 | let mut guard = BACKUP_DB_PATH.write(); | ||
| 116 | *guard = Some(backup_db_dir); | ||
| 117 | } | ||
| 118 | |||
| 119 | // Create a new 0-{channel} | ||
| 120 | create_dir_all(&main_db_dir).context("Should be able to create the database directory")?; | ||
| 121 | let db_path = main_db_dir.join(Path::new(DB_FILE_NAME)); | ||
| 122 | |||
| 123 | // Try again | ||
| 124 | open_main_db(&db_path).await.context("Could not newly created db") | ||
| 125 | }).await.log_err(); | ||
| 126 | 69 | ||
| 127 | if let Some(connection) = connection { | 70 | if let Some(connection) = connection { |
| 128 | return connection; | 71 | return connection; |
| @@ -249,13 +192,13 @@ where · 120 unmodified lines | |||
| 249 | 192 | ||
| 250 | #[cfg(test)] | 193 | #[cfg(test)] |
| 251 | mod tests { | 194 | mod tests { |
| 252 | use std::{fs, thread}; | 195 | use std::thread; |
| 253 | 196 | ||
| 254 | use sqlez::{connection::Connection, domain::Domain}; | 197 | use sqlez::domain::Domain; |
| 255 | use sqlez_macros::sql; | 198 | use sqlez_macros::sql; |
| 256 | use tempdir::TempDir; | 199 | use tempdir::TempDir; |
| 257 | 200 | ||
| 258 | use crate::{open_db, DB_FILE_NAME}; | 201 | use crate::open_db; |
| 259 | 202 | ||
| 260 | // Test bad migration panics | 203 | // Test bad migration panics |
| 261 | #[gpui::test] | 204 | #[gpui::test] |
| @@ -321,31 +264,10 @@ mod tests { · 59 unmodified lines | |||
| 321 | .unwrap() | 264 | .unwrap() |
| 322 | .is_none() | 265 | .is_none() |
| 323 | ); | 266 | ); |
| 324 | |||
| 325 | let mut corrupted_backup_dir = fs::read_dir(tempdir.path()) | ||
| 326 | .unwrap() | ||
| 327 | .find(|entry| { | ||
| 328 | !entry | ||
| 329 | .as_ref() | ||
| 330 | .unwrap() | ||
| 331 | .file_name() | ||
| 332 | .to_str() | ||
| 333 | .unwrap() | ||
| 334 | .starts_with("0") | ||
| 335 | }) | ||
| 336 | .unwrap() | ||
| 337 | .unwrap() | ||
| 338 | .path(); | ||
| 339 | corrupted_backup_dir.push(DB_FILE_NAME); | ||
| 340 | |||
| 341 | let backup = Connection::open_file(&corrupted_backup_dir.to_string_lossy()); | ||
| 342 | assert!(backup.select_row::<usize>("SELECT * FROM test").unwrap()() | ||
| 343 | .unwrap() | ||
| 344 | .is_none()); | ||
| 345 | } | 267 | } |
| 346 | 268 | ||
| 347 | /// Test that DB exists but corrupted (causing recreate) | 269 | /// Test that DB exists but corrupted (causing recreate) |
| 348 | #[gpui::test] | 270 | #[gpui::test(iterations = 30)] |
| 349 | async fn test_simultaneous_db_corruption() { | 271 | async fn test_simultaneous_db_corruption() { |
| 350 | enum CorruptedDB {} | 272 | enum CorruptedDB {} |
| 351 | 273 | ||
| @@ -57,16 +57,16 @@ ordered-float.workspace = true · 56 unmodified lines | |||
| 57 | parking_lot.workspace = true | 57 | parking_lot.workspace = true |
| 58 | postage.workspace = true | 58 | postage.workspace = true |
| 59 | pulldown-cmark = { version = "0.9.2", default-features = false } | 59 | pulldown-cmark = { version = "0.9.2", default-features = false } |
| 60 | rand = { workspace = true, optional = true } | ||
| 61 | schemars.workspace = true | 60 | schemars.workspace = true |
| 62 | serde.workspace = true | 61 | serde.workspace = true |
| 63 | serde_derive.workspace = true | 62 | serde_derive.workspace = true |
| 64 | smallvec.workspace = true | 63 | smallvec.workspace = true |
| 65 | smol.workspace = true | 64 | smol.workspace = true |
| 66 | tree-sitter-rust = { version = "*", optional = true } | 65 | |
| 67 | tree-sitter-html = { version = "*", optional = true } | 66 | rand = { workspace = true, optional = true } |
| 68 | tree-sitter-javascript = { version = "*", optional = true } | 67 | tree-sitter-rust = { workspace = true, optional = true } |
| 69 | tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259", optional = true } | 68 | tree-sitter-html = { workspace = true, optional = true } |
| 69 | tree-sitter-typescript = { workspace = true, optional = true } | ||
| 70 | 70 | ||
| 71 | [dev-dependencies] | 71 | [dev-dependencies] |
| 72 | copilot = { path = "../copilot", features = ["test-support"] } | 72 | copilot = { path = "../copilot", features = ["test-support"] } |
| @@ -84,7 +84,6 @@ env_logger.workspace = true · 11 unmodified lines | |||
| 84 | rand.workspace = true | 84 | rand.workspace = true |
| 85 | unindent.workspace = true | 85 | unindent.workspace = true |
| 86 | tree-sitter.workspace = true | 86 | tree-sitter.workspace = true |
| 87 | tree-sitter-rust = "0.20" | 87 | tree-sitter-rust.workspace = true |
| 88 | tree-sitter-html = "0.19" | 88 | tree-sitter-html.workspace = true |
| 89 | tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" } | 89 | tree-sitter-typescript.workspace = true |
| 90 | tree-sitter-javascript = "0.20" | ||
| @@ -271,7 +271,9 @@ actions!( · 270 unmodified lines | |||
| 271 | SelectLargerSyntaxNode, | 271 | SelectLargerSyntaxNode, |
| 272 | SelectSmallerSyntaxNode, | 272 | SelectSmallerSyntaxNode, |
| 273 | GoToDefinition, | 273 | GoToDefinition, |
| 274 | GoToDefinitionSplit, | ||
| 274 | GoToTypeDefinition, | 275 | GoToTypeDefinition, |
| 276 | GoToTypeDefinitionSplit, | ||
| 275 | MoveToEnclosingBracket, | 277 | MoveToEnclosingBracket, |
| 276 | UndoSelection, | 278 | UndoSelection, |
| 277 | RedoSelection, | 279 | RedoSelection, |
| @@ -407,7 +409,9 @@ pub fn init(cx: &mut AppContext) { · 129 unmodified lines | |||
| 407 | cx.add_action(Editor::go_to_hunk); | 409 | cx.add_action(Editor::go_to_hunk); |
| 408 | cx.add_action(Editor::go_to_prev_hunk); | 410 | cx.add_action(Editor::go_to_prev_hunk); |
| 409 | cx.add_action(Editor::go_to_definition); | 411 | cx.add_action(Editor::go_to_definition); |
| 412 | cx.add_action(Editor::go_to_definition_split); | ||
| 410 | cx.add_action(Editor::go_to_type_definition); | 413 | cx.add_action(Editor::go_to_type_definition); |
| 414 | cx.add_action(Editor::go_to_type_definition_split); | ||
| 411 | cx.add_action(Editor::fold); | 415 | cx.add_action(Editor::fold); |
| 412 | cx.add_action(Editor::fold_at); | 416 | cx.add_action(Editor::fold_at); |
| 413 | cx.add_action(Editor::unfold_lines); | 417 | cx.add_action(Editor::unfold_lines); |
| @@ -494,6 +498,7 @@ pub enum SoftWrap { · 80 unmodified lines | |||
| 494 | #[derive(Clone)] | 498 | #[derive(Clone)] |
| 495 | pub struct EditorStyle { | 499 | pub struct EditorStyle { |
| 496 | pub text: TextStyle, | 500 | pub text: TextStyle, |
| 501 | pub line_height_scalar: f32, | ||
| 497 | pub placeholder_text: Option<TextStyle>, | 502 | pub placeholder_text: Option<TextStyle>, |
| 498 | pub theme: theme::Editor, | 503 | pub theme: theme::Editor, |
| 499 | pub theme_id: usize, | 504 | pub theme_id: usize, |
| @@ -6184,14 +6189,31 @@ impl Editor { · 5684 unmodified lines | |||
| 6184 | } | 6189 | } |
| 6185 | 6190 | ||
| 6186 | pub fn go_to_definition(&mut self, _: &GoToDefinition, cx: &mut ViewContext<Self>) { | 6191 | pub fn go_to_definition(&mut self, _: &GoToDefinition, cx: &mut ViewContext<Self>) { |
| 6187 | self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, cx); | 6192 | self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, false, cx); |
| 6188 | } | 6193 | } |
| 6189 | 6194 | ||
| 6190 | pub fn go_to_type_definition(&mut self, _: &GoToTypeDefinition, cx: &mut ViewContext<Self>) { | 6195 | pub fn go_to_type_definition(&mut self, _: &GoToTypeDefinition, cx: &mut ViewContext<Self>) { |
| 6191 | self.go_to_definition_of_kind(GotoDefinitionKind::Type, cx); | 6196 | self.go_to_definition_of_kind(GotoDefinitionKind::Type, false, cx); |
| 6192 | } | 6197 | } |
| 6193 | 6198 | ||
| 6194 | fn go_to_definition_of_kind(&mut self, kind: GotoDefinitionKind, cx: &mut ViewContext<Self>) { | 6199 | pub fn go_to_definition_split(&mut self, _: &GoToDefinitionSplit, cx: &mut ViewContext<Self>) { |
| 6200 | self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, true, cx); | ||
| 6201 | } | ||
| 6202 | |||
| 6203 | pub fn go_to_type_definition_split( | ||
| 6204 | &mut self, | ||
| 6205 | _: &GoToTypeDefinitionSplit, | ||
| 6206 | cx: &mut ViewContext<Self>, | ||
| 6207 | ) { | ||
| 6208 | self.go_to_definition_of_kind(GotoDefinitionKind::Type, true, cx); | ||
| 6209 | } | ||
| 6210 | |||
| 6211 | fn go_to_definition_of_kind( | ||
| 6212 | &mut self, | ||
| 6213 | kind: GotoDefinitionKind, | ||
| 6214 | split: bool, | ||
| 6215 | cx: &mut ViewContext<Self>, | ||
| 6216 | ) { | ||
| 6195 | let Some(workspace) = self.workspace(cx) else { return }; | 6217 | let Some(workspace) = self.workspace(cx) else { return }; |
| 6196 | let buffer = self.buffer.read(cx); | 6218 | let buffer = self.buffer.read(cx); |
| 6197 | let head = self.selections.newest::<usize>(cx).head(); | 6219 | let head = self.selections.newest::<usize>(cx).head(); |
| @@ -6210,7 +6232,7 @@ impl Editor { · 12 unmodified lines | |||
| 6210 | cx.spawn_labeled("Fetching Definition...", |editor, mut cx| async move { | 6232 | cx.spawn_labeled("Fetching Definition...", |editor, mut cx| async move { |
| 6211 | let definitions = definitions.await?; | 6233 | let definitions = definitions.await?; |
| 6212 | editor.update(&mut cx, |editor, cx| { | 6234 | editor.update(&mut cx, |editor, cx| { |
| 6213 | editor.navigate_to_definitions(definitions, cx); | 6235 | editor.navigate_to_definitions(definitions, split, cx); |
| 6214 | })?; | 6236 | })?; |
| 6215 | Ok::<(), anyhow::Error>(()) | 6237 | Ok::<(), anyhow::Error>(()) |
| 6216 | }) | 6238 | }) |
| @@ -6220,6 +6242,7 @@ impl Editor { · 3 unmodified lines | |||
| 6220 | pub fn navigate_to_definitions( | 6242 | pub fn navigate_to_definitions( |
| 6221 | &mut self, | 6243 | &mut self, |
| 6222 | mut definitions: Vec<LocationLink>, | 6244 | mut definitions: Vec<LocationLink>, |
| 6245 | split: bool, | ||
| 6223 | cx: &mut ViewContext<Editor>, | 6246 | cx: &mut ViewContext<Editor>, |
| 6224 | ) { | 6247 | ) { |
| 6225 | let Some(workspace) = self.workspace(cx) else { return }; | 6248 | let Some(workspace) = self.workspace(cx) else { return }; |
| @@ -6239,7 +6262,11 @@ impl Editor { · 13 unmodified lines | |||
| 6239 | } else { | 6262 | } else { |
| 6240 | cx.window_context().defer(move |cx| { | 6263 | cx.window_context().defer(move |cx| { |
| 6241 | let target_editor: ViewHandle<Self> = workspace.update(cx, |workspace, cx| { | 6264 | let target_editor: ViewHandle<Self> = workspace.update(cx, |workspace, cx| { |
| 6242 | workspace.open_project_item(definition.target.buffer.clone(), cx) | 6265 | if split { |
| 6266 | workspace.split_project_item(definition.target.buffer.clone(), cx) | ||
| 6267 | } else { | ||
| 6268 | workspace.open_project_item(definition.target.buffer.clone(), cx) | ||
| 6269 | } | ||
| 6243 | }); | 6270 | }); |
| 6244 | target_editor.update(cx, |target_editor, cx| { | 6271 | target_editor.update(cx, |target_editor, cx| { |
| 6245 | // When selecting a definition in a different buffer, disable the nav history | 6272 | // When selecting a definition in a different buffer, disable the nav history |
| @@ -6275,7 +6302,9 @@ impl Editor { · 29 unmodified lines | |||
| 6275 | .map(|definition| definition.target) | 6302 | .map(|definition| definition.target) |
| 6276 | .collect(); | 6303 | .collect(); |
| 6277 | workspace.update(cx, |workspace, cx| { | 6304 | workspace.update(cx, |workspace, cx| { |
| 6278 | Self::open_locations_in_multibuffer(workspace, locations, replica_id, title, cx) | 6305 | Self::open_locations_in_multibuffer( |
| 6306 | workspace, locations, replica_id, title, split, cx, | ||
| 6307 | ) | ||
| 6279 | }); | 6308 | }); |
| 6280 | }); | 6309 | }); |
| 6281 | } | 6310 | } |
| @@ -6320,7 +6349,7 @@ impl Editor { · 38 unmodified lines | |||
| 6320 | }) | 6349 | }) |
| 6321 | .unwrap(); | 6350 | .unwrap(); |
| 6322 | Self::open_locations_in_multibuffer( | 6351 | Self::open_locations_in_multibuffer( |
| 6323 | workspace, locations, replica_id, title, cx, | 6352 | workspace, locations, replica_id, title, false, cx, |
| 6324 | ); | 6353 | ); |
| 6325 | })?; | 6354 | })?; |
| 6326 | 6355 | ||
| @@ -6335,6 +6364,7 @@ impl Editor { · 8 unmodified lines | |||
| 6335 | mut locations: Vec<Location>, | 6364 | mut locations: Vec<Location>, |
| 6336 | replica_id: ReplicaId, | 6365 | replica_id: ReplicaId, |
| 6337 | title: String, | 6366 | title: String, |
| 6367 | split: bool, | ||
| 6338 | cx: &mut ViewContext<Workspace>, | 6368 | cx: &mut ViewContext<Workspace>, |
| 6339 | ) { | 6369 | ) { |
| 6340 | // If there are multiple definitions, open them in a multibuffer | 6370 | // If there are multiple definitions, open them in a multibuffer |
| @@ -6381,7 +6411,11 @@ impl Editor { · 40 unmodified lines | |||
| 6381 | cx, | 6411 | cx, |
| 6382 | ); | 6412 | ); |
| 6383 | }); | 6413 | }); |
| 6384 | workspace.add_item(Box::new(editor), cx); | 6414 | if split { |
| 6415 | workspace.split_item(Box::new(editor), cx); | ||
| 6416 | } else { | ||
| 6417 | workspace.add_item(Box::new(editor), cx); | ||
| 6418 | } | ||
| 6385 | } | 6419 | } |
| 6386 | 6420 | ||
| 6387 | pub fn rename(&mut self, _: &Rename, cx: &mut ViewContext<Self>) -> Option<Task<Result<()>>> { | 6421 | pub fn rename(&mut self, _: &Rename, cx: &mut ViewContext<Self>) -> Option<Task<Result<()>>> { |
| @@ -8101,7 +8135,7 @@ fn build_style( · 1713 unmodified lines | |||
| 8101 | cx: &AppContext, | 8135 | cx: &AppContext, |
| 8102 | ) -> EditorStyle { | 8136 | ) -> EditorStyle { |
| 8103 | let font_cache = cx.font_cache(); | 8137 | let font_cache = cx.font_cache(); |
| 8104 | 8138 | let line_height_scalar = settings.line_height(); | |
| 8105 | let theme_id = settings.theme.meta.id; | 8139 | let theme_id = settings.theme.meta.id; |
| 8106 | let mut theme = settings.theme.editor.clone(); | 8140 | let mut theme = settings.theme.editor.clone(); |
| 8107 | let mut style = if let Some(get_field_editor_theme) = get_field_editor_theme { | 8141 | let mut style = if let Some(get_field_editor_theme) = get_field_editor_theme { |
| @@ -8115,6 +8149,7 @@ fn build_style( · 7 unmodified lines | |||
| 8115 | EditorStyle { | 8149 | EditorStyle { |
| 8116 | text: field_editor_theme.text, | 8150 | text: field_editor_theme.text, |
| 8117 | placeholder_text: field_editor_theme.placeholder_text, | 8151 | placeholder_text: field_editor_theme.placeholder_text, |
| 8152 | line_height_scalar, | ||
| 8118 | theme, | 8153 | theme, |
| 8119 | theme_id, | 8154 | theme_id, |
| 8120 | } | 8155 | } |
| @@ -8137,6 +8172,7 @@ fn build_style( · 16 unmodified lines | |||
| 8137 | underline: Default::default(), | 8172 | underline: Default::default(), |
| 8138 | }, | 8173 | }, |
| 8139 | placeholder_text: None, | 8174 | placeholder_text: None, |
| 8175 | line_height_scalar, | ||
| 8140 | theme, | 8176 | theme, |
| 8141 | theme_id, | 8177 | theme_id, |
| 8142 | } | 8178 | } |
| @@ -3836,7 +3836,7 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) { · 3835 unmodified lines | |||
| 3836 | autoclose_before: "})]>".into(), | 3836 | autoclose_before: "})]>".into(), |
| 3837 | ..Default::default() | 3837 | ..Default::default() |
| 3838 | }, | 3838 | }, |
| 3839 | Some(tree_sitter_javascript::language()), | 3839 | Some(tree_sitter_typescript::language_tsx()), |
| 3840 | )); | 3840 | )); |
| 3841 | 3841 | ||
| 3842 | let registry = Arc::new(LanguageRegistry::test()); | 3842 | let registry = Arc::new(LanguageRegistry::test()); |
| @@ -5383,7 +5383,7 @@ async fn test_toggle_block_comment(cx: &mut gpui::TestAppContext) { · 1540 unmodified lines | |||
| 5383 | line_comment: Some("// ".into()), | 5383 | line_comment: Some("// ".into()), |
| 5384 | ..Default::default() | 5384 | ..Default::default() |
| 5385 | }, | 5385 | }, |
| 5386 | Some(tree_sitter_javascript::language()), | 5386 | Some(tree_sitter_typescript::language_tsx()), |
| 5387 | )); | 5387 | )); |
| 5388 | 5388 | ||
| 5389 | let registry = Arc::new(LanguageRegistry::test()); | 5389 | let registry = Arc::new(LanguageRegistry::test()); |
| @@ -156,6 +156,7 @@ impl EditorElement { · 155 unmodified lines | |||
| 156 | event.position, | 156 | event.position, |
| 157 | event.cmd, | 157 | event.cmd, |
| 158 | event.shift, | 158 | event.shift, |
| 159 | event.alt, | ||
| 159 | position_map.as_ref(), | 160 | position_map.as_ref(), |
| 160 | text_bounds, | 161 | text_bounds, |
| 161 | cx, | 162 | cx, |
| @@ -308,6 +309,7 @@ impl EditorElement { · 146 unmodified lines | |||
| 308 | position: Vector2F, | 309 | position: Vector2F, |
| 309 | cmd: bool, | 310 | cmd: bool, |
| 310 | shift: bool, | 311 | shift: bool, |
| 312 | alt: bool, | ||
| 311 | position_map: &PositionMap, | 313 | position_map: &PositionMap, |
| 312 | text_bounds: RectF, | 314 | text_bounds: RectF, |
| 313 | cx: &mut EventContext<Editor>, | 315 | cx: &mut EventContext<Editor>, |
| @@ -324,9 +326,9 @@ impl EditorElement { · 10 unmodified lines | |||
| 324 | 326 | ||
| 325 | if point == target_point { | 327 | if point == target_point { |
| 326 | if shift { | 328 | if shift { |
| 327 | go_to_fetched_type_definition(editor, point, cx); | 329 | go_to_fetched_type_definition(editor, point, alt, cx); |
| 328 | } else { | 330 | } else { |
| 329 | go_to_fetched_definition(editor, point, cx); | 331 | go_to_fetched_definition(editor, point, alt, cx); |
| 330 | } | 332 | } |
| 331 | 333 | ||
| 332 | return true; | 334 | return true; |
| @@ -1182,8 +1184,10 @@ impl EditorElement { · 849 unmodified lines | |||
| 1182 | }); | 1184 | }); |
| 1183 | scene.push_mouse_region( | 1185 | scene.push_mouse_region( |
| 1184 | MouseRegion::new::<ScrollbarMouseHandlers>(cx.view_id(), cx.view_id(), track_bounds) | 1186 | MouseRegion::new::<ScrollbarMouseHandlers>(cx.view_id(), cx.view_id(), track_bounds) |
| 1185 | .on_move(move |_, editor: &mut Editor, cx| { | 1187 | .on_move(move |event, editor: &mut Editor, cx| { |
| 1186 | editor.scroll_manager.show_scrollbar(cx); | 1188 | if event.pressed_button.is_none() { |
| 1189 | editor.scroll_manager.show_scrollbar(cx); | ||
| 1190 | } | ||
| 1187 | }) | 1191 | }) |
| 1188 | .on_down(MouseButton::Left, { | 1192 | .on_down(MouseButton::Left, { |
| 1189 | let row_range = row_range.clone(); | 1193 | let row_range = row_range.clone(); |
| @@ -1973,7 +1977,7 @@ impl Element<Editor> for EditorElement { · 783 unmodified lines | |||
| 1973 | 1977 | ||
| 1974 | let snapshot = editor.snapshot(cx); | 1978 | let snapshot = editor.snapshot(cx); |
| 1975 | let style = self.style.clone(); | 1979 | let style = self.style.clone(); |
| 1976 | let line_height = style.text.line_height(cx.font_cache()); | 1980 | let line_height = (style.text.font_size * style.line_height_scalar).round(); |
| 1977 | 1981 | ||
| 1978 | let gutter_padding; | 1982 | let gutter_padding; |
| 1979 | let gutter_width; | 1983 | let gutter_width; |
| @@ -887,10 +887,20 @@ pub(crate) enum BufferSearchHighlights {} · 886 unmodified lines | |||
| 887 | impl SearchableItem for Editor { | 887 | impl SearchableItem for Editor { |
| 888 | type Match = Range<Anchor>; | 888 | type Match = Range<Anchor>; |
| 889 | 889 | ||
| 890 | fn to_search_event(event: &Self::Event) -> Option<SearchEvent> { | 890 | fn to_search_event( |
| 891 | &mut self, | ||
| 892 | event: &Self::Event, | ||
| 893 | _: &mut ViewContext<Self>, | ||
| 894 | ) -> Option<SearchEvent> { | ||
| 891 | match event { | 895 | match event { |
| 892 | Event::BufferEdited => Some(SearchEvent::MatchesInvalidated), | 896 | Event::BufferEdited => Some(SearchEvent::MatchesInvalidated), |
| 893 | Event::SelectionsChanged { .. } => Some(SearchEvent::ActiveMatchChanged), | 897 | Event::SelectionsChanged { .. } => { |
| 898 | if self.selections.disjoint_anchors().len() == 1 { | ||
| 899 | Some(SearchEvent::ActiveMatchChanged) | ||
| 900 | } else { | ||
| 901 | None | ||
| 902 | } | ||
| 903 | } | ||
| 894 | _ => None, | 904 | _ => None, |
| 895 | } | 905 | } |
| 896 | } | 906 | } |
| @@ -941,6 +951,11 @@ impl SearchableItem for Editor { · 44 unmodified lines | |||
| 941 | }); | 951 | }); |
| 942 | } | 952 | } |
| 943 | 953 | ||
| 954 | fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) { | ||
| 955 | self.unfold_ranges(matches.clone(), false, false, cx); | ||
| 956 | self.change_selections(None, cx, |s| s.select_ranges(matches)); | ||
| 957 | } | ||
| 958 | |||
| 944 | fn match_index_for_direction( | 959 | fn match_index_for_direction( |
| 945 | &mut self, | 960 | &mut self, |
| 946 | matches: &Vec<Range<Anchor>>, | 961 | matches: &Vec<Range<Anchor>>, |
| @@ -949,8 +964,16 @@ impl SearchableItem for Editor { · 2 unmodified lines | |||
| 949 | cx: &mut ViewContext<Self>, | 964 | cx: &mut ViewContext<Self>, |
| 950 | ) -> usize { | 965 | ) -> usize { |
| 951 | let buffer = self.buffer().read(cx).snapshot(cx); | 966 | let buffer = self.buffer().read(cx).snapshot(cx); |
| 952 | let cursor = self.selections.newest_anchor().head(); | 967 | let current_index_position = if self.selections.disjoint_anchors().len() == 1 { |
| 953 | if matches[current_index].start.cmp(&cursor, &buffer).is_gt() { | 968 | self.selections.newest_anchor().head() |
| 969 | } else { | ||
| 970 | matches[current_index].start | ||
| 971 | }; | ||
| 972 | if matches[current_index] | ||
| 973 | .start | ||
| 974 | .cmp(¤t_index_position, &buffer) | ||
| 975 | .is_gt() | ||
| 976 | { | ||
| 954 | if direction == Direction::Prev { | 977 | if direction == Direction::Prev { |
| 955 | if current_index == 0 { | 978 | if current_index == 0 { |
| 956 | current_index = matches.len() - 1; | 979 | current_index = matches.len() - 1; |
| @@ -958,7 +981,11 @@ impl SearchableItem for Editor { · 1 unmodified line | |||
| 958 | current_index -= 1; | 981 | current_index -= 1; |
| 959 | } | 982 | } |
| 960 | } | 983 | } |
| 961 | } else if matches[current_index].end.cmp(&cursor, &buffer).is_lt() { | 984 | } else if matches[current_index] |
| 985 | .end | ||
| 986 | .cmp(¤t_index_position, &buffer) | ||
| 987 | .is_lt() | ||
| 988 | { | ||
| 962 | if direction == Direction::Next { | 989 | if direction == Direction::Next { |
| 963 | current_index = 0; | 990 | current_index = 0; |
| 964 | } | 991 | } |
| @@ -246,23 +246,26 @@ pub fn hide_link_definition(editor: &mut Editor, cx: &mut ViewContext<Editor>) { · 245 unmodified lines | |||
| 246 | pub fn go_to_fetched_definition( | 246 | pub fn go_to_fetched_definition( |
| 247 | editor: &mut Editor, | 247 | editor: &mut Editor, |
| 248 | point: DisplayPoint, | 248 | point: DisplayPoint, |
| 249 | split: bool, | ||
| 249 | cx: &mut ViewContext<Editor>, | 250 | cx: &mut ViewContext<Editor>, |
| 250 | ) { | 251 | ) { |
| 251 | go_to_fetched_definition_of_kind(LinkDefinitionKind::Symbol, editor, point, cx); | 252 | go_to_fetched_definition_of_kind(LinkDefinitionKind::Symbol, editor, point, split, cx); |
| 252 | } | 253 | } |
| 253 | 254 | ||
| 254 | pub fn go_to_fetched_type_definition( | 255 | pub fn go_to_fetched_type_definition( |
| 255 | editor: &mut Editor, | 256 | editor: &mut Editor, |
| 256 | point: DisplayPoint, | 257 | point: DisplayPoint, |
| 258 | split: bool, | ||
| 257 | cx: &mut ViewContext<Editor>, | 259 | cx: &mut ViewContext<Editor>, |
| 258 | ) { | 260 | ) { |
| 259 | go_to_fetched_definition_of_kind(LinkDefinitionKind::Type, editor, point, cx); | 261 | go_to_fetched_definition_of_kind(LinkDefinitionKind::Type, editor, point, split, cx); |
| 260 | } | 262 | } |
| 261 | 263 | ||
| 262 | fn go_to_fetched_definition_of_kind( | 264 | fn go_to_fetched_definition_of_kind( |
| 263 | kind: LinkDefinitionKind, | 265 | kind: LinkDefinitionKind, |
| 264 | editor: &mut Editor, | 266 | editor: &mut Editor, |
| 265 | point: DisplayPoint, | 267 | point: DisplayPoint, |
| 268 | split: bool, | ||
| 266 | cx: &mut ViewContext<Editor>, | 269 | cx: &mut ViewContext<Editor>, |
| 267 | ) { | 270 | ) { |
| 268 | let cached_definitions = editor.link_go_to_definition_state.definitions.clone(); | 271 | let cached_definitions = editor.link_go_to_definition_state.definitions.clone(); |
| @@ -275,7 +278,7 @@ fn go_to_fetched_definition_of_kind( · 6 unmodified lines | |||
| 275 | cx.focus_self(); | 278 | cx.focus_self(); |
| 276 | } | 279 | } |
| 277 | 280 | ||
| 278 | editor.navigate_to_definitions(cached_definitions, cx); | 281 | editor.navigate_to_definitions(cached_definitions, split, cx); |
| 279 | } else { | 282 | } else { |
| 280 | editor.select( | 283 | editor.select( |
| 281 | SelectPhase::Begin { | 284 | SelectPhase::Begin { |
| @@ -403,7 +406,7 @@ mod tests { · 121 unmodified lines | |||
| 403 | }); | 406 | }); |
| 404 | 407 | ||
| 405 | cx.update_editor(|editor, cx| { | 408 | cx.update_editor(|editor, cx| { |
| 406 | go_to_fetched_type_definition(editor, hover_point, cx); | 409 | go_to_fetched_type_definition(editor, hover_point, false, cx); |
| 407 | }); | 410 | }); |
| 408 | requests.next().await; | 411 | requests.next().await; |
| 409 | cx.foreground().run_until_parked(); | 412 | cx.foreground().run_until_parked(); |
| @@ -614,7 +617,7 @@ mod tests { · 204 unmodified lines | |||
| 614 | 617 | ||
| 615 | // Cmd click with existing definition doesn't re-request and dismisses highlight | 618 | // Cmd click with existing definition doesn't re-request and dismisses highlight |
| 616 | cx.update_editor(|editor, cx| { | 619 | cx.update_editor(|editor, cx| { |
| 617 | go_to_fetched_definition(editor, hover_point, cx); | 620 | go_to_fetched_definition(editor, hover_point, false, cx); |
| 618 | }); | 621 | }); |
| 619 | // Assert selection moved to to definition | 622 | // Assert selection moved to to definition |
| 620 | cx.lsp | 623 | cx.lsp |
| @@ -655,7 +658,7 @@ mod tests { · 34 unmodified lines | |||
| 655 | ]))) | 658 | ]))) |
| 656 | }); | 659 | }); |
| 657 | cx.update_editor(|editor, cx| { | 660 | cx.update_editor(|editor, cx| { |
| 658 | go_to_fetched_definition(editor, hover_point, cx); | 661 | go_to_fetched_definition(editor, hover_point, false, cx); |
| 659 | }); | 662 | }); |
| 660 | requests.next().await; | 663 | requests.next().await; |
| 661 | cx.foreground().run_until_parked(); | 664 | cx.foreground().run_until_parked(); |
| @@ -16,13 +16,13 @@ use crate::{ · 15 unmodified lines | |||
| 16 | Anchor, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode, ToOffset, | 16 | Anchor, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode, ToOffset, |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | #[derive(Clone)] | 19 | #[derive(Debug, Clone)] |
| 20 | pub struct PendingSelection { | 20 | pub struct PendingSelection { |
| 21 | pub selection: Selection<Anchor>, | 21 | pub selection: Selection<Anchor>, |
| 22 | pub mode: SelectMode, | 22 | pub mode: SelectMode, |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | #[derive(Clone)] | 25 | #[derive(Debug, Clone)] |
| 26 | pub struct SelectionsCollection { | 26 | pub struct SelectionsCollection { |
| 27 | display_map: ModelHandle<DisplayMap>, | 27 | display_map: ModelHandle<DisplayMap>, |
| 28 | buffer: ModelHandle<MultiBuffer>, | 28 | buffer: ModelHandle<MultiBuffer>, |
| @@ -60,6 +60,7 @@ pub(crate) struct FeedbackEditor { · 59 unmodified lines | |||
| 60 | system_specs: SystemSpecs, | 60 | system_specs: SystemSpecs, |
| 61 | editor: ViewHandle<Editor>, | 61 | editor: ViewHandle<Editor>, |
| 62 | project: ModelHandle<Project>, | 62 | project: ModelHandle<Project>, |
| 63 | pub allow_submission: bool, | ||
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | impl FeedbackEditor { | 66 | impl FeedbackEditor { |
| @@ -82,10 +83,15 @@ impl FeedbackEditor { · 16 unmodified lines | |||
| 82 | system_specs: system_specs.clone(), | 83 | system_specs: system_specs.clone(), |
| 83 | editor, | 84 | editor, |
| 84 | project, | 85 | project, |
| 86 | allow_submission: true, | ||
| 85 | } | 87 | } |
| 86 | } | 88 | } |
| 87 | 89 | ||
| 88 | pub fn submit(&mut self, cx: &mut ViewContext<Self>) -> Task<anyhow::Result<()>> { | 90 | pub fn submit(&mut self, cx: &mut ViewContext<Self>) -> Task<anyhow::Result<()>> { |
| 91 | if !self.allow_submission { | ||
| 92 | return Task::ready(Ok(())); | ||
| 93 | } | ||
| 94 | |||
| 89 | let feedback_text = self.editor.read(cx).text(cx); | 95 | let feedback_text = self.editor.read(cx).text(cx); |
| 90 | let feedback_char_count = feedback_text.chars().count(); | 96 | let feedback_char_count = feedback_text.chars().count(); |
| 91 | let feedback_text = feedback_text.trim().to_string(); | 97 | let feedback_text = feedback_text.trim().to_string(); |
| @@ -122,19 +128,26 @@ impl FeedbackEditor { · 30 unmodified lines | |||
| 122 | let answer = answer.recv().await; | 128 | let answer = answer.recv().await; |
| 123 | 129 | ||
| 124 | if answer == Some(0) { | 130 | if answer == Some(0) { |
| 131 | this.update(&mut cx, |feedback_editor, cx| { | ||
| 132 | feedback_editor.set_allow_submission(false, cx); | ||
| 133 | }) | ||
| 134 | .log_err(); | ||
| 135 | |||
| 125 | match FeedbackEditor::submit_feedback(&feedback_text, client, specs).await { | 136 | match FeedbackEditor::submit_feedback(&feedback_text, client, specs).await { |
| 126 | Ok(_) => { | 137 | Ok(_) => { |
| 127 | this.update(&mut cx, |_, cx| cx.emit(editor::Event::Closed)) | 138 | this.update(&mut cx, |_, cx| cx.emit(editor::Event::Closed)) |
| 128 | .log_err(); | 139 | .log_err(); |
| 129 | } | 140 | } |
| 141 | |||
| 130 | Err(error) => { | 142 | Err(error) => { |
| 131 | log::error!("{}", error); | 143 | log::error!("{}", error); |
| 132 | this.update(&mut cx, |_, cx| { | 144 | this.update(&mut cx, |feedback_editor, cx| { |
| 133 | cx.prompt( | 145 | cx.prompt( |
| 134 | PromptLevel::Critical, | 146 | PromptLevel::Critical, |
| 135 | FEEDBACK_SUBMISSION_ERROR_TEXT, | 147 | FEEDBACK_SUBMISSION_ERROR_TEXT, |
| 136 | &["OK"], | 148 | &["OK"], |
| 137 | ); | 149 | ); |
| 150 | feedback_editor.set_allow_submission(true, cx); | ||
| 138 | }) | 151 | }) |
| 139 | .log_err(); | 152 | .log_err(); |
| 140 | } | 153 | } |
| @@ -146,6 +159,11 @@ impl FeedbackEditor { · 5 unmodified lines | |||
| 146 | Task::ready(Ok(())) | 159 | Task::ready(Ok(())) |
| 147 | } | 160 | } |
| 148 | 161 | ||
| 162 | fn set_allow_submission(&mut self, allow_submission: bool, cx: &mut ViewContext<Self>) { | ||
| 163 | self.allow_submission = allow_submission; | ||
| 164 | cx.notify(); | ||
| 165 | } | ||
| 166 | |||
| 149 | async fn submit_feedback( | 167 | async fn submit_feedback( |
| 150 | feedback_text: &str, | 168 | feedback_text: &str, |
| 151 | zed_client: Arc<Client>, | 169 | zed_client: Arc<Client>, |
| @@ -362,8 +380,13 @@ impl Item for FeedbackEditor { · 210 unmodified lines | |||
| 362 | impl SearchableItem for FeedbackEditor { | 380 | impl SearchableItem for FeedbackEditor { |
| 363 | type Match = Range<Anchor>; | 381 | type Match = Range<Anchor>; |
| 364 | 382 | ||
| 365 | fn to_search_event(event: &Self::Event) -> Option<workspace::searchable::SearchEvent> { | 383 | fn to_search_event( |
| 366 | Editor::to_search_event(event) | 384 | &mut self, |
| 385 | event: &Self::Event, | ||
| 386 | cx: &mut ViewContext<Self>, | ||
| 387 | ) -> Option<workspace::searchable::SearchEvent> { | ||
| 388 | self.editor | ||
| 389 | .update(cx, |editor, cx| editor.to_search_event(event, cx)) | ||
| 367 | } | 390 | } |
| 368 | 391 | ||
| 369 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { | 392 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { |
| @@ -391,6 +414,11 @@ impl SearchableItem for FeedbackEditor { · 21 unmodified lines | |||
| 391 | .update(cx, |editor, cx| editor.activate_match(index, matches, cx)) | 414 | .update(cx, |editor, cx| editor.activate_match(index, matches, cx)) |
| 392 | } | 415 | } |
| 393 | 416 | ||
| 417 | fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) { | ||
| 418 | self.editor | ||
| 419 | .update(cx, |e, cx| e.select_matches(matches, cx)) | ||
| 420 | } | ||
| 421 | |||
| 394 | fn find_matches( | 422 | fn find_matches( |
| 395 | &mut self, | 423 | &mut self, |
| 396 | query: project::search::SearchQuery, | 424 | query: project::search::SearchQuery, |
| @@ -46,10 +46,28 @@ impl View for SubmitFeedbackButton { · 45 unmodified lines | |||
| 46 | 46 | ||
| 47 | fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { | 47 | fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { |
| 48 | let theme = theme::current(cx).clone(); | 48 | let theme = theme::current(cx).clone(); |
| 49 | let allow_submission = self | ||
| 50 | .active_item | ||
| 51 | .as_ref() | ||
| 52 | .map_or(true, |i| i.read(cx).allow_submission); | ||
| 53 | |||
| 49 | enum SubmitFeedbackButton {} | 54 | enum SubmitFeedbackButton {} |
| 50 | MouseEventHandler::<SubmitFeedbackButton, Self>::new(0, cx, |state, _| { | 55 | MouseEventHandler::<SubmitFeedbackButton, Self>::new(0, cx, |state, _| { |
| 51 | let style = theme.feedback.submit_button.style_for(state); | 56 | let text; |
| 52 | Label::new("Submit as Markdown", style.text.clone()) | 57 | let style = if allow_submission { |
| 58 | text = "Submit as Markdown"; | ||
| 59 | theme.feedback.submit_button.style_for(state) | ||
| 60 | } else { | ||
| 61 | text = "Submitting..."; | ||
| 62 | theme | ||
| 63 | .feedback | ||
| 64 | .submit_button | ||
| 65 | .disabled | ||
| 66 | .as_ref() | ||
| 67 | .unwrap_or(&theme.feedback.submit_button.default) | ||
| 68 | }; | ||
| 69 | |||
| 70 | Label::new(text, style.text.clone()) | ||
| 53 | .contained() | 71 | .contained() |
| 54 | .with_style(style.container) | 72 | .with_style(style.container) |
| 55 | }) | 73 | }) |
| @@ -442,53 +442,71 @@ impl PickerDelegate for FileFinderDelegate { · 441 unmodified lines | |||
| 442 | } | 442 | } |
| 443 | } | 443 | } |
| 444 | 444 | ||
| 445 | fn confirm(&mut self, cx: &mut ViewContext<FileFinder>) { | 445 | fn confirm(&mut self, secondary: bool, cx: &mut ViewContext<FileFinder>) { |
| 446 | if let Some(m) = self.matches.get(self.selected_index()) { | 446 | if let Some(m) = self.matches.get(self.selected_index()) { |
| 447 | if let Some(workspace) = self.workspace.upgrade(cx) { | 447 | if let Some(workspace) = self.workspace.upgrade(cx) { |
| 448 | let open_task = workspace.update(cx, |workspace, cx| match m { | 448 | let open_task = workspace.update(cx, move |workspace, cx| { |
| 449 | Match::History(history_match) => { | 449 | let split_or_open = |workspace: &mut Workspace, project_path, cx| { |
| 450 | let worktree_id = history_match.project.worktree_id; | 450 | if secondary { |
| 451 | if workspace | 451 | workspace.split_path(project_path, cx) |
| 452 | .project() | ||
| 453 | .read(cx) | ||
| 454 | .worktree_for_id(worktree_id, cx) | ||
| 455 | .is_some() | ||
| 456 | { | ||
| 457 | workspace.open_path( | ||
| 458 | ProjectPath { | ||
| 459 | worktree_id, | ||
| 460 | path: Arc::clone(&history_match.project.path), | ||
| 461 | }, | ||
| 462 | None, | ||
| 463 | true, | ||
| 464 | cx, | ||
| 465 | ) | ||
| 466 | } else { | 452 | } else { |
| 467 | match history_match.absolute.as_ref() { | 453 | workspace.open_path(project_path, None, true, cx) |
| 468 | Some(abs_path) => { | 454 | } |
| 469 | workspace.open_abs_path(abs_path.to_path_buf(), false, cx) | 455 | }; |
| 470 | } | 456 | match m { |
| 471 | None => workspace.open_path( | 457 | Match::History(history_match) => { |
| 458 | let worktree_id = history_match.project.worktree_id; | ||
| 459 | if workspace | ||
| 460 | .project() | ||
| 461 | .read(cx) | ||
| 462 | .worktree_for_id(worktree_id, cx) | ||
| 463 | .is_some() | ||
| 464 | { | ||
| 465 | split_or_open( | ||
| 466 | workspace, | ||
| 472 | ProjectPath { | 467 | ProjectPath { |
| 473 | worktree_id, | 468 | worktree_id, |
| 474 | path: Arc::clone(&history_match.project.path), | 469 | path: Arc::clone(&history_match.project.path), |
| 475 | }, | 470 | }, |
| 476 | None, | ||
| 477 | true, | ||
| 478 | cx, | 471 | cx, |
| 479 | ), | 472 | ) |
| 473 | } else { | ||
| 474 | match history_match.absolute.as_ref() { | ||
| 475 | Some(abs_path) => { | ||
| 476 | if secondary { | ||
| 477 | workspace.split_abs_path( | ||
| 478 | abs_path.to_path_buf(), | ||
| 479 | false, | ||
| 480 | cx, | ||
| 481 | ) | ||
| 482 | } else { | ||
| 483 | workspace.open_abs_path( | ||
| 484 | abs_path.to_path_buf(), | ||
| 485 | false, | ||
| 486 | cx, | ||
| 487 | ) | ||
| 488 | } | ||
| 489 | } | ||
| 490 | None => split_or_open( | ||
| 491 | workspace, | ||
| 492 | ProjectPath { | ||
| 493 | worktree_id, | ||
| 494 | path: Arc::clone(&history_match.project.path), | ||
| 495 | }, | ||
| 496 | cx, | ||
| 497 | ), | ||
| 498 | } | ||
| 480 | } | 499 | } |
| 481 | } | 500 | } |
| 501 | Match::Search(m) => split_or_open( | ||
| 502 | workspace, | ||
| 503 | ProjectPath { | ||
| 504 | worktree_id: WorktreeId::from_usize(m.worktree_id), | ||
| 505 | path: m.path.clone(), | ||
| 506 | }, | ||
| 507 | cx, | ||
| 508 | ), | ||
| 482 | } | 509 | } |
| 483 | Match::Search(m) => workspace.open_path( | ||
| 484 | ProjectPath { | ||
| 485 | worktree_id: WorktreeId::from_usize(m.worktree_id), | ||
| 486 | path: m.path.clone(), | ||
| 487 | }, | ||
| 488 | None, | ||
| 489 | true, | ||
| 490 | cx, | ||
| 491 | ), | ||
| 492 | }); | 510 | }); |
| 493 | 511 | ||
| 494 | let row = self | 512 | let row = self |
| @@ -33,6 +33,7 @@ pub trait GitRepository: Send { · 32 unmodified lines | |||
| 33 | fn statuses(&self) -> Option<TreeMap<RepoPath, GitFileStatus>>; | 33 | fn statuses(&self) -> Option<TreeMap<RepoPath, GitFileStatus>>; |
| 34 | 34 | ||
| 35 | fn status(&self, path: &RepoPath) -> Result<Option<GitFileStatus>>; | 35 | fn status(&self, path: &RepoPath) -> Result<Option<GitFileStatus>>; |
| 36 | |||
| 36 | fn branches(&self) -> Result<Vec<Branch>> { | 37 | fn branches(&self) -> Result<Vec<Branch>> { |
| 37 | Ok(vec![]) | 38 | Ok(vec![]) |
| 38 | } | 39 | } |
| @@ -1073,7 +1073,7 @@ impl AppContext { · 1072 unmodified lines | |||
| 1073 | 1073 | ||
| 1074 | pub fn is_action_available(&self, action: &dyn Action) -> bool { | 1074 | pub fn is_action_available(&self, action: &dyn Action) -> bool { |
| 1075 | let mut available_in_window = false; | 1075 | let mut available_in_window = false; |
| 1076 | let action_type = action.as_any().type_id(); | 1076 | let action_id = action.id(); |
| 1077 | if let Some(window_id) = self.platform.main_window_id() { | 1077 | if let Some(window_id) = self.platform.main_window_id() { |
| 1078 | available_in_window = self | 1078 | available_in_window = self |
| 1079 | .read_window(window_id, |cx| { | 1079 | .read_window(window_id, |cx| { |
| @@ -1083,7 +1083,7 @@ impl AppContext { · 3 unmodified lines | |||
| 1083 | cx.views_metadata.get(&(window_id, view_id)) | 1083 | cx.views_metadata.get(&(window_id, view_id)) |
| 1084 | { | 1084 | { |
| 1085 | if let Some(actions) = cx.actions.get(&view_metadata.type_id) { | 1085 | if let Some(actions) = cx.actions.get(&view_metadata.type_id) { |
| 1086 | if actions.contains_key(&action_type) { | 1086 | if actions.contains_key(&action_id) { |
| 1087 | return true; | 1087 | return true; |
| 1088 | } | 1088 | } |
| 1089 | } | 1089 | } |
| @@ -1094,7 +1094,7 @@ impl AppContext { · 4 unmodified lines | |||
| 1094 | }) | 1094 | }) |
| 1095 | .unwrap_or(false); | 1095 | .unwrap_or(false); |
| 1096 | } | 1096 | } |
| 1097 | available_in_window || self.global_actions.contains_key(&action_type) | 1097 | available_in_window || self.global_actions.contains_key(&action_id) |
| 1098 | } | 1098 | } |
| 1099 | 1099 | ||
| 1100 | fn actions_mut( | 1100 | fn actions_mut( |
| @@ -3399,7 +3399,7 @@ impl<'a, 'b, 'c, V: View> LayoutContext<'a, 'b, 'c, V> { · 2298 unmodified lines | |||
| 3399 | for (i, view_id) in self.ancestors(view_id).enumerate() { | 3399 | for (i, view_id) in self.ancestors(view_id).enumerate() { |
| 3400 | if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) { | 3400 | if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) { |
| 3401 | if let Some(actions) = self.actions.get(&view_metadata.type_id) { | 3401 | if let Some(actions) = self.actions.get(&view_metadata.type_id) { |
| 3402 | if actions.contains_key(&action.as_any().type_id()) { | 3402 | if actions.contains_key(&action.id()) { |
| 3403 | handler_depth = Some(i); | 3403 | handler_depth = Some(i); |
| 3404 | } | 3404 | } |
| 3405 | } | 3405 | } |
| @@ -3407,12 +3407,12 @@ impl<'a, 'b, 'c, V: View> LayoutContext<'a, 'b, 'c, V> { · 1 unmodified line | |||
| 3407 | } | 3407 | } |
| 3408 | } | 3408 | } |
| 3409 | 3409 | ||
| 3410 | if self.global_actions.contains_key(&action.as_any().type_id()) { | 3410 | if self.global_actions.contains_key(&action.id()) { |
| 3411 | handler_depth = Some(contexts.len()) | 3411 | handler_depth = Some(contexts.len()) |
| 3412 | } | 3412 | } |
| 3413 | 3413 | ||
| 3414 | self.keystroke_matcher | 3414 | self.keystroke_matcher |
| 3415 | .bindings_for_action_type(action.as_any().type_id()) | 3415 | .bindings_for_action(action.id()) |
| 3416 | .find_map(|b| { | 3416 | .find_map(|b| { |
| 3417 | let highest_handler = handler_depth?; | 3417 | let highest_handler = handler_depth?; |
| 3418 | if action.eq(b.action()) | 3418 | if action.eq(b.action()) |
| @@ -14,8 +14,8 @@ use crate::{ · 13 unmodified lines | |||
| 14 | text_layout::TextLayoutCache, | 14 | text_layout::TextLayoutCache, |
| 15 | util::post_inc, | 15 | util::post_inc, |
| 16 | Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect, | 16 | Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect, |
| 17 | Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, NoAction, SceneBuilder, | 17 | Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, SceneBuilder, Subscription, |
| 18 | Subscription, View, ViewContext, ViewHandle, WindowInvalidation, | 18 | View, ViewContext, ViewHandle, WindowInvalidation, |
| 19 | }; | 19 | }; |
| 20 | use anyhow::{anyhow, bail, Result}; | 20 | use anyhow::{anyhow, bail, Result}; |
| 21 | use collections::{HashMap, HashSet}; | 21 | use collections::{HashMap, HashSet}; |
| @@ -363,17 +363,13 @@ impl<'a> WindowContext<'a> { · 341 unmodified lines | |||
| 363 | ) -> Vec<(&'static str, Box<dyn Action>, SmallVec<[Binding; 1]>)> { | 363 | ) -> Vec<(&'static str, Box<dyn Action>, SmallVec<[Binding; 1]>)> { |
| 364 | let window_id = self.window_id; | 364 | let window_id = self.window_id; |
| 365 | let mut contexts = Vec::new(); | 365 | let mut contexts = Vec::new(); |
| 366 | let mut handler_depths_by_action_type = HashMap::<TypeId, usize>::default(); | 366 | let mut handler_depths_by_action_id = HashMap::<TypeId, usize>::default(); |
| 367 | for (depth, view_id) in self.ancestors(view_id).enumerate() { | 367 | for (depth, view_id) in self.ancestors(view_id).enumerate() { |
| 368 | if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) { | 368 | if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) { |
| 369 | contexts.push(view_metadata.keymap_context.clone()); | 369 | contexts.push(view_metadata.keymap_context.clone()); |
| 370 | if let Some(actions) = self.actions.get(&view_metadata.type_id) { | 370 | if let Some(actions) = self.actions.get(&view_metadata.type_id) { |
| 371 | handler_depths_by_action_type.extend( | 371 | handler_depths_by_action_id |
| 372 | actions | 372 | .extend(actions.keys().copied().map(|action_id| (action_id, depth))); |
| 373 | .keys() | ||
| 374 | .copied() | ||
| 375 | .map(|action_type| (action_type, depth)), | ||
| 376 | ); | ||
| 377 | } | 373 | } |
| 378 | } else { | 374 | } else { |
| 379 | log::error!( | 375 | log::error!( |
| @@ -383,21 +379,21 @@ impl<'a> WindowContext<'a> { · 3 unmodified lines | |||
| 383 | } | 379 | } |
| 384 | } | 380 | } |
| 385 | 381 | ||
| 386 | handler_depths_by_action_type.extend( | 382 | handler_depths_by_action_id.extend( |
| 387 | self.global_actions | 383 | self.global_actions |
| 388 | .keys() | 384 | .keys() |
| 389 | .copied() | 385 | .copied() |
| 390 | .map(|action_type| (action_type, contexts.len())), | 386 | .map(|action_id| (action_id, contexts.len())), |
| 391 | ); | 387 | ); |
| 392 | 388 | ||
| 393 | self.action_deserializers | 389 | self.action_deserializers |
| 394 | .iter() | 390 | .iter() |
| 395 | .filter_map(move |(name, (type_id, deserialize))| { | 391 | .filter_map(move |(name, (action_id, deserialize))| { |
| 396 | if let Some(action_depth) = handler_depths_by_action_type.get(type_id).copied() { | 392 | if let Some(action_depth) = handler_depths_by_action_id.get(action_id).copied() { |
| 397 | let action = deserialize(serde_json::Value::Object(Default::default())).ok()?; | 393 | let action = deserialize(serde_json::Value::Object(Default::default())).ok()?; |
| 398 | let bindings = self | 394 | let bindings = self |
| 399 | .keystroke_matcher | 395 | .keystroke_matcher |
| 400 | .bindings_for_action_type(*type_id) | 396 | .bindings_for_action(*action_id) |
| 401 | .filter(|b| { | 397 | .filter(|b| { |
| 402 | action.eq(b.action()) | 398 | action.eq(b.action()) |
| 403 | && (0..=action_depth) | 399 | && (0..=action_depth) |
| @@ -434,11 +430,7 @@ impl<'a> WindowContext<'a> { · 30 unmodified lines | |||
| 434 | MatchResult::None => false, | 430 | MatchResult::None => false, |
| 435 | MatchResult::Pending => true, | 431 | MatchResult::Pending => true, |
| 436 | MatchResult::Matches(matches) => { | 432 | MatchResult::Matches(matches) => { |
| 437 | let no_action_id = (NoAction {}).id(); | ||
| 438 | for (view_id, action) in matches { | 433 | for (view_id, action) in matches { |
| 439 | if action.id() == no_action_id { | ||
| 440 | return false; | ||
| 441 | } | ||
| 442 | if self.dispatch_action(Some(*view_id), action.as_ref()) { | 434 | if self.dispatch_action(Some(*view_id), action.as_ref()) { |
| 443 | self.keystroke_matcher.clear_pending(); | 435 | self.keystroke_matcher.clear_pending(); |
| 444 | handled_by = Some(action.boxed_clone()); | 436 | handled_by = Some(action.boxed_clone()); |
| @@ -1268,6 +1260,19 @@ impl Vector2FExt for Vector2F { · 823 unmodified lines | |||
| 1268 | } | 1260 | } |
| 1269 | } | 1261 | } |
| 1270 | 1262 | ||
| 1263 | pub trait RectFExt { | ||
| 1264 | fn length_along(self, axis: Axis) -> f32; | ||
| 1265 | } | ||
| 1266 | |||
| 1267 | impl RectFExt for RectF { | ||
| 1268 | fn length_along(self, axis: Axis) -> f32 { | ||
| 1269 | match axis { | ||
| 1270 | Axis::Horizontal => self.width(), | ||
| 1271 | Axis::Vertical => self.height(), | ||
| 1272 | } | ||
| 1273 | } | ||
| 1274 | } | ||
| 1275 | |||
| 1271 | #[derive(Copy, Clone, Debug)] | 1276 | #[derive(Copy, Clone, Debug)] |
| 1272 | pub struct SizeConstraint { | 1277 | pub struct SizeConstraint { |
| 1273 | pub min: Vector2F, | 1278 | pub min: Vector2F, |
| @@ -27,7 +27,7 @@ pub mod json; · 26 unmodified lines | |||
| 27 | pub mod keymap_matcher; | 27 | pub mod keymap_matcher; |
| 28 | pub mod platform; | 28 | pub mod platform; |
| 29 | pub use gpui_macros::{test, Element}; | 29 | pub use gpui_macros::{test, Element}; |
| 30 | pub use window::{Axis, SizeConstraint, Vector2FExt, WindowContext}; | 30 | pub use window::{Axis, RectFExt, SizeConstraint, Vector2FExt, WindowContext}; |
| 31 | 31 | ||
| 32 | pub use anyhow; | 32 | pub use anyhow; |
| 33 | pub use serde_json; | 33 | pub use serde_json; |
| @@ -8,7 +8,7 @@ use std::{any::TypeId, fmt::Debug}; · 7 unmodified lines | |||
| 8 | use collections::HashMap; | 8 | use collections::HashMap; |
| 9 | use smallvec::SmallVec; | 9 | use smallvec::SmallVec; |
| 10 | 10 | ||
| 11 | use crate::Action; | 11 | use crate::{Action, NoAction}; |
| 12 | 12 | ||
| 13 | pub use binding::{Binding, BindingMatchResult}; | 13 | pub use binding::{Binding, BindingMatchResult}; |
| 14 | pub use keymap::Keymap; | 14 | pub use keymap::Keymap; |
| @@ -47,8 +47,8 @@ impl KeymapMatcher { · 32 unmodified lines | |||
| 47 | self.keymap.clear(); | 47 | self.keymap.clear(); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | pub fn bindings_for_action_type(&self, action_type: TypeId) -> impl Iterator<Item = &Binding> { | 50 | pub fn bindings_for_action(&self, action_id: TypeId) -> impl Iterator<Item = &Binding> { |
| 51 | self.keymap.bindings_for_action_type(action_type) | 51 | self.keymap.bindings_for_action(action_id) |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | pub fn clear_pending(&mut self) { | 54 | pub fn clear_pending(&mut self) { |
| @@ -81,6 +81,7 @@ impl KeymapMatcher { · 26 unmodified lines | |||
| 81 | // The key is the reverse position of the binding in the bindings list so that later bindings | 81 | // The key is the reverse position of the binding in the bindings list so that later bindings |
| 82 | // match before earlier ones in the user's config | 82 | // match before earlier ones in the user's config |
| 83 | let mut matched_bindings: Vec<(usize, Box<dyn Action>)> = Default::default(); | 83 | let mut matched_bindings: Vec<(usize, Box<dyn Action>)> = Default::default(); |
| 84 | let no_action_id = (NoAction {}).id(); | ||
| 84 | 85 | ||
| 85 | let first_keystroke = self.pending_keystrokes.is_empty(); | 86 | let first_keystroke = self.pending_keystrokes.is_empty(); |
| 86 | self.pending_keystrokes.push(keystroke.clone()); | 87 | self.pending_keystrokes.push(keystroke.clone()); |
| @@ -108,7 +109,9 @@ impl KeymapMatcher { · 21 unmodified lines | |||
| 108 | match binding.match_keys_and_context(&self.pending_keystrokes, &self.contexts[i..]) | 109 | match binding.match_keys_and_context(&self.pending_keystrokes, &self.contexts[i..]) |
| 109 | { | 110 | { |
| 110 | BindingMatchResult::Complete(action) => { | 111 | BindingMatchResult::Complete(action) => { |
| 111 | matched_bindings.push((*view_id, action)); | 112 | if action.id() != no_action_id { |
| 113 | matched_bindings.push((*view_id, action)); | ||
| 114 | } | ||
| 112 | } | 115 | } |
| 113 | BindingMatchResult::Partial => { | 116 | BindingMatchResult::Partial => { |
| 114 | self.pending_views | 117 | self.pending_views |
| @@ -7,8 +7,8 @@ use super::{KeymapContext, KeymapContextPredicate, Keystroke}; · 6 unmodified lines | |||
| 7 | 7 | ||
| 8 | pub struct Binding { | 8 | pub struct Binding { |
| 9 | action: Box<dyn Action>, | 9 | action: Box<dyn Action>, |
| 10 | keystrokes: SmallVec<[Keystroke; 2]>, | 10 | pub(super) keystrokes: SmallVec<[Keystroke; 2]>, |
| 11 | context_predicate: Option<KeymapContextPredicate>, | 11 | pub(super) context_predicate: Option<KeymapContextPredicate>, |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | impl std::fmt::Debug for Binding { | 14 | impl std::fmt::Debug for Binding { |
| @@ -1,61 +1,388 @@ | |||
| 1 | use collections::HashSet; | ||
| 1 | use smallvec::SmallVec; | 2 | use smallvec::SmallVec; |
| 2 | use std::{ | 3 | use std::{any::TypeId, collections::HashMap}; |
| 3 | any::{Any, TypeId}, | ||
| 4 | collections::HashMap, | ||
| 5 | }; | ||
| 6 | 4 | ||
| 7 | use super::Binding; | 5 | use crate::{Action, NoAction}; |
| 6 | |||
| 7 | use super::{Binding, KeymapContextPredicate, Keystroke}; | ||
| 8 | 8 | ||
| 9 | #[derive(Default)] | 9 | #[derive(Default)] |
| 10 | pub struct Keymap { | 10 | pub struct Keymap { |
| 11 | bindings: Vec<Binding>, | 11 | bindings: Vec<Binding>, |
| 12 | binding_indices_by_action_type: HashMap<TypeId, SmallVec<[usize; 3]>>, | 12 | binding_indices_by_action_id: HashMap<TypeId, SmallVec<[usize; 3]>>, |
| 13 | disabled_keystrokes: HashMap<SmallVec<[Keystroke; 2]>, HashSet<Option<KeymapContextPredicate>>>, | ||
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | impl Keymap { | 16 | impl Keymap { |
| 16 | pub fn new(bindings: Vec<Binding>) -> Self { | 17 | #[cfg(test)] |
| 17 | let mut binding_indices_by_action_type = HashMap::new(); | 18 | pub(super) fn new(bindings: Vec<Binding>) -> Self { |
| 18 | for (ix, binding) in bindings.iter().enumerate() { | 19 | let mut this = Self::default(); |
| 19 | binding_indices_by_action_type | 20 | this.add_bindings(bindings); |
| 20 | .entry(binding.action().type_id()) | 21 | this |
| 21 | .or_insert_with(SmallVec::new) | ||
| 22 | .push(ix); | ||
| 23 | } | ||
| 24 | |||
| 25 | Self { | ||
| 26 | binding_indices_by_action_type, | ||
| 27 | bindings, | ||
| 28 | } | ||
| 29 | } | 22 | } |
| 30 | 23 | ||
| 31 | pub(crate) fn bindings_for_action_type( | 24 | pub(crate) fn bindings_for_action( |
| 32 | &self, | 25 | &self, |
| 33 | action_type: TypeId, | 26 | action_id: TypeId, |
| 34 | ) -> impl Iterator<Item = &'_ Binding> { | 27 | ) -> impl Iterator<Item = &'_ Binding> { |
| 35 | self.binding_indices_by_action_type | 28 | self.binding_indices_by_action_id |
| 36 | .get(&action_type) | 29 | .get(&action_id) |
| 37 | .map(SmallVec::as_slice) | 30 | .map(SmallVec::as_slice) |
| 38 | .unwrap_or(&[]) | 31 | .unwrap_or(&[]) |
| 39 | .iter() | 32 | .iter() |
| 40 | .map(|ix| &self.bindings[*ix]) | 33 | .map(|ix| &self.bindings[*ix]) |
| 34 | .filter(|binding| !self.binding_disabled(binding)) | ||
| 41 | } | 35 | } |
| 42 | 36 | ||
| 43 | pub(crate) fn add_bindings<T: IntoIterator<Item = Binding>>(&mut self, bindings: T) { | 37 | pub(crate) fn add_bindings<T: IntoIterator<Item = Binding>>(&mut self, bindings: T) { |
| 38 | let no_action_id = (NoAction {}).id(); | ||
| 39 | let mut new_bindings = Vec::new(); | ||
| 40 | let mut has_new_disabled_keystrokes = false; | ||
| 44 | for binding in bindings { | 41 | for binding in bindings { |
| 45 | self.binding_indices_by_action_type | 42 | if binding.action().id() == no_action_id { |
| 46 | .entry(binding.action().as_any().type_id()) | 43 | has_new_disabled_keystrokes |= self |
| 47 | .or_default() | 44 | .disabled_keystrokes |
| 48 | .push(self.bindings.len()); | 45 | .entry(binding.keystrokes) |
| 49 | self.bindings.push(binding); | 46 | .or_default() |
| 47 | .insert(binding.context_predicate); | ||
| 48 | } else { | ||
| 49 | new_bindings.push(binding); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | if has_new_disabled_keystrokes { | ||
| 54 | self.binding_indices_by_action_id.retain(|_, indices| { | ||
| 55 | indices.retain(|ix| { | ||
| 56 | let binding = &self.bindings[*ix]; | ||
| 57 | match self.disabled_keystrokes.get(&binding.keystrokes) { | ||
| 58 | Some(disabled_predicates) => { | ||
| 59 | !disabled_predicates.contains(&binding.context_predicate) | ||
| 60 | } | ||
| 61 | None => true, | ||
| 62 | } | ||
| 63 | }); | ||
| 64 | !indices.is_empty() | ||
| 65 | }); | ||
| 66 | } | ||
| 67 | |||
| 68 | for new_binding in new_bindings { | ||
| 69 | if !self.binding_disabled(&new_binding) { | ||
| 70 | self.binding_indices_by_action_id | ||
| 71 | .entry(new_binding.action().id()) | ||
| 72 | .or_default() | ||
| 73 | .push(self.bindings.len()); | ||
| 74 | self.bindings.push(new_binding); | ||
| 75 | } | ||
| 50 | } | 76 | } |
| 51 | } | 77 | } |
| 52 | 78 | ||
| 53 | pub(crate) fn clear(&mut self) { | 79 | pub(crate) fn clear(&mut self) { |
| 54 | self.bindings.clear(); | 80 | self.bindings.clear(); |
| 55 | self.binding_indices_by_action_type.clear(); | 81 | self.binding_indices_by_action_id.clear(); |
| 82 | self.disabled_keystrokes.clear(); | ||
| 83 | } | ||
| 84 | |||
| 85 | pub fn bindings(&self) -> Vec<&Binding> { | ||
| 86 | self.bindings | ||
| 87 | .iter() | ||
| 88 | .filter(|binding| !self.binding_disabled(binding)) | ||
| 89 | .collect() | ||
| 90 | } | ||
| 91 | |||
| 92 | fn binding_disabled(&self, binding: &Binding) -> bool { | ||
| 93 | match self.disabled_keystrokes.get(&binding.keystrokes) { | ||
| 94 | Some(disabled_predicates) => disabled_predicates.contains(&binding.context_predicate), | ||
| 95 | None => false, | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | #[cfg(test)] | ||
| 101 | mod tests { | ||
| 102 | use crate::actions; | ||
| 103 | |||
| 104 | use super::*; | ||
| 105 | |||
| 106 | actions!( | ||
| 107 | keymap_test, | ||
| 108 | [Present1, Present2, Present3, Duplicate, Missing] | ||
| 109 | ); | ||
| 110 | |||
| 111 | #[test] | ||
| 112 | fn regular_keymap() { | ||
| 113 | let present_1 = Binding::new("ctrl-q", Present1 {}, None); | ||
| 114 | let present_2 = Binding::new("ctrl-w", Present2 {}, Some("pane")); | ||
| 115 | let present_3 = Binding::new("ctrl-e", Present3 {}, Some("editor")); | ||
| 116 | let keystroke_duplicate_to_1 = Binding::new("ctrl-q", Duplicate {}, None); | ||
| 117 | let full_duplicate_to_2 = Binding::new("ctrl-w", Present2 {}, Some("pane")); | ||
| 118 | let missing = Binding::new("ctrl-r", Missing {}, None); | ||
| 119 | let all_bindings = [ | ||
| 120 | &present_1, | ||
| 121 | &present_2, | ||
| 122 | &present_3, | ||
| 123 | &keystroke_duplicate_to_1, | ||
| 124 | &full_duplicate_to_2, | ||
| 125 | &missing, | ||
| 126 | ]; | ||
| 127 | |||
| 128 | let mut keymap = Keymap::default(); | ||
| 129 | assert_absent(&keymap, &all_bindings); | ||
| 130 | assert!(keymap.bindings().is_empty()); | ||
| 131 | |||
| 132 | keymap.add_bindings([present_1.clone(), present_2.clone(), present_3.clone()]); | ||
| 133 | assert_absent(&keymap, &[&keystroke_duplicate_to_1, &missing]); | ||
| 134 | assert_present( | ||
| 135 | &keymap, | ||
| 136 | &[(&present_1, "q"), (&present_2, "w"), (&present_3, "e")], | ||
| 137 | ); | ||
| 138 | |||
| 139 | keymap.add_bindings([ | ||
| 140 | keystroke_duplicate_to_1.clone(), | ||
| 141 | full_duplicate_to_2.clone(), | ||
| 142 | ]); | ||
| 143 | assert_absent(&keymap, &[&missing]); | ||
| 144 | assert!( | ||
| 145 | !keymap.binding_disabled(&keystroke_duplicate_to_1), | ||
| 146 | "Duplicate binding 1 was added and should not be disabled" | ||
| 147 | ); | ||
| 148 | assert!( | ||
| 149 | !keymap.binding_disabled(&full_duplicate_to_2), | ||
| 150 | "Duplicate binding 2 was added and should not be disabled" | ||
| 151 | ); | ||
| 152 | |||
| 153 | assert_eq!( | ||
| 154 | keymap | ||
| 155 | .bindings_for_action(keystroke_duplicate_to_1.action().id()) | ||
| 156 | .map(|binding| &binding.keystrokes) | ||
| 157 | .flatten() | ||
| 158 | .collect::<Vec<_>>(), | ||
| 159 | vec![&Keystroke { | ||
| 160 | ctrl: true, | ||
| 161 | alt: false, | ||
| 162 | shift: false, | ||
| 163 | cmd: false, | ||
| 164 | function: false, | ||
| 165 | key: "q".to_string() | ||
| 166 | }], | ||
| 167 | "{keystroke_duplicate_to_1:?} should have the expected keystroke in the keymap" | ||
| 168 | ); | ||
| 169 | assert_eq!( | ||
| 170 | keymap | ||
| 171 | .bindings_for_action(full_duplicate_to_2.action().id()) | ||
| 172 | .map(|binding| &binding.keystrokes) | ||
| 173 | .flatten() | ||
| 174 | .collect::<Vec<_>>(), | ||
| 175 | vec![ | ||
| 176 | &Keystroke { | ||
| 177 | ctrl: true, | ||
| 178 | alt: false, | ||
| 179 | shift: false, | ||
| 180 | cmd: false, | ||
| 181 | function: false, | ||
| 182 | key: "w".to_string() | ||
| 183 | }, | ||
| 184 | &Keystroke { | ||
| 185 | ctrl: true, | ||
| 186 | alt: false, | ||
| 187 | shift: false, | ||
| 188 | cmd: false, | ||
| 189 | function: false, | ||
| 190 | key: "w".to_string() | ||
| 191 | } | ||
| 192 | ], | ||
| 193 | "{full_duplicate_to_2:?} should have a duplicated keystroke in the keymap" | ||
| 194 | ); | ||
| 195 | |||
| 196 | let updated_bindings = keymap.bindings(); | ||
| 197 | let expected_updated_bindings = vec![ | ||
| 198 | &present_1, | ||
| 199 | &present_2, | ||
| 200 | &present_3, | ||
| 201 | &keystroke_duplicate_to_1, | ||
| 202 | &full_duplicate_to_2, | ||
| 203 | ]; | ||
| 204 | assert_eq!( | ||
| 205 | updated_bindings.len(), | ||
| 206 | expected_updated_bindings.len(), | ||
| 207 | "Unexpected updated keymap bindings {updated_bindings:?}" | ||
| 208 | ); | ||
| 209 | for (i, expected) in expected_updated_bindings.iter().enumerate() { | ||
| 210 | let keymap_binding = &updated_bindings[i]; | ||
| 211 | assert_eq!( | ||
| 212 | keymap_binding.context_predicate, expected.context_predicate, | ||
| 213 | "Unexpected context predicate for keymap {i} element: {keymap_binding:?}" | ||
| 214 | ); | ||
| 215 | assert_eq!( | ||
| 216 | keymap_binding.keystrokes, expected.keystrokes, | ||
| 217 | "Unexpected keystrokes for keymap {i} element: {keymap_binding:?}" | ||
| 218 | ); | ||
| 219 | } | ||
| 220 | |||
| 221 | keymap.clear(); | ||
| 222 | assert_absent(&keymap, &all_bindings); | ||
| 223 | assert!(keymap.bindings().is_empty()); | ||
| 56 | } | 224 | } |
| 57 | 225 | ||
| 58 | pub fn bindings(&self) -> &Vec<Binding> { | 226 | #[test] |
| 59 | &self.bindings | 227 | fn keymap_with_ignored() { |
| 228 | let present_1 = Binding::new("ctrl-q", Present1 {}, None); | ||
| 229 | let present_2 = Binding::new("ctrl-w", Present2 {}, Some("pane")); | ||
| 230 | let present_3 = Binding::new("ctrl-e", Present3 {}, Some("editor")); | ||
| 231 | let keystroke_duplicate_to_1 = Binding::new("ctrl-q", Duplicate {}, None); | ||
| 232 | let full_duplicate_to_2 = Binding::new("ctrl-w", Present2 {}, Some("pane")); | ||
| 233 | let ignored_1 = Binding::new("ctrl-q", NoAction {}, None); | ||
| 234 | let ignored_2 = Binding::new("ctrl-w", NoAction {}, Some("pane")); | ||
| 235 | let ignored_3_with_other_context = | ||
| 236 | Binding::new("ctrl-e", NoAction {}, Some("other_context")); | ||
| 237 | |||
| 238 | let mut keymap = Keymap::default(); | ||
| 239 | |||
| 240 | keymap.add_bindings([ | ||
| 241 | ignored_1.clone(), | ||
| 242 | ignored_2.clone(), | ||
| 243 | ignored_3_with_other_context.clone(), | ||
| 244 | ]); | ||
| 245 | assert_absent(&keymap, &[&present_3]); | ||
| 246 | assert_disabled( | ||
| 247 | &keymap, | ||
| 248 | &[ | ||
| 249 | &present_1, | ||
| 250 | &present_2, | ||
| 251 | &ignored_1, | ||
| 252 | &ignored_2, | ||
| 253 | &ignored_3_with_other_context, | ||
| 254 | ], | ||
| 255 | ); | ||
| 256 | assert!(keymap.bindings().is_empty()); | ||
| 257 | keymap.clear(); | ||
| 258 | |||
| 259 | keymap.add_bindings([ | ||
| 260 | present_1.clone(), | ||
| 261 | present_2.clone(), | ||
| 262 | present_3.clone(), | ||
| 263 | ignored_1.clone(), | ||
| 264 | ignored_2.clone(), | ||
| 265 | ignored_3_with_other_context.clone(), | ||
| 266 | ]); | ||
| 267 | assert_present(&keymap, &[(&present_3, "e")]); | ||
| 268 | assert_disabled( | ||
| 269 | &keymap, | ||
| 270 | &[ | ||
| 271 | &present_1, | ||
| 272 | &present_2, | ||
| 273 | &ignored_1, | ||
| 274 | &ignored_2, | ||
| 275 | &ignored_3_with_other_context, | ||
| 276 | ], | ||
| 277 | ); | ||
| 278 | keymap.clear(); | ||
| 279 | |||
| 280 | keymap.add_bindings([ | ||
| 281 | present_1.clone(), | ||
| 282 | present_2.clone(), | ||
| 283 | present_3.clone(), | ||
| 284 | ignored_1.clone(), | ||
| 285 | ]); | ||
| 286 | assert_present(&keymap, &[(&present_2, "w"), (&present_3, "e")]); | ||
| 287 | assert_disabled(&keymap, &[&present_1, &ignored_1]); | ||
| 288 | assert_absent(&keymap, &[&ignored_2, &ignored_3_with_other_context]); | ||
| 289 | keymap.clear(); | ||
| 290 | |||
| 291 | keymap.add_bindings([ | ||
| 292 | present_1.clone(), | ||
| 293 | present_2.clone(), | ||
| 294 | present_3.clone(), | ||
| 295 | keystroke_duplicate_to_1.clone(), | ||
| 296 | full_duplicate_to_2.clone(), | ||
| 297 | ignored_1.clone(), | ||
| 298 | ignored_2.clone(), | ||
| 299 | ignored_3_with_other_context.clone(), | ||
| 300 | ]); | ||
| 301 | assert_present(&keymap, &[(&present_3, "e")]); | ||
| 302 | assert_disabled( | ||
| 303 | &keymap, | ||
| 304 | &[ | ||
| 305 | &present_1, | ||
| 306 | &present_2, | ||
| 307 | &keystroke_duplicate_to_1, | ||
| 308 | &full_duplicate_to_2, | ||
| 309 | &ignored_1, | ||
| 310 | &ignored_2, | ||
| 311 | &ignored_3_with_other_context, | ||
| 312 | ], | ||
| 313 | ); | ||
| 314 | keymap.clear(); | ||
| 315 | } | ||
| 316 | |||
| 317 | #[track_caller] | ||
| 318 | fn assert_present(keymap: &Keymap, expected_bindings: &[(&Binding, &str)]) { | ||
| 319 | let keymap_bindings = keymap.bindings(); | ||
| 320 | assert_eq!( | ||
| 321 | expected_bindings.len(), | ||
| 322 | keymap_bindings.len(), | ||
| 323 | "Unexpected keymap bindings {keymap_bindings:?}" | ||
| 324 | ); | ||
| 325 | for (i, (expected, expected_key)) in expected_bindings.iter().enumerate() { | ||
| 326 | assert!( | ||
| 327 | !keymap.binding_disabled(expected), | ||
| 328 | "{expected:?} should not be disabled as it was added into keymap for element {i}" | ||
| 329 | ); | ||
| 330 | assert_eq!( | ||
| 331 | keymap | ||
| 332 | .bindings_for_action(expected.action().id()) | ||
| 333 | .map(|binding| &binding.keystrokes) | ||
| 334 | .flatten() | ||
| 335 | .collect::<Vec<_>>(), | ||
| 336 | vec![&Keystroke { | ||
| 337 | ctrl: true, | ||
| 338 | alt: false, | ||
| 339 | shift: false, | ||
| 340 | cmd: false, | ||
| 341 | function: false, | ||
| 342 | key: expected_key.to_string() | ||
| 343 | }], | ||
| 344 | "{expected:?} should have the expected keystroke with key '{expected_key}' in the keymap for element {i}" | ||
| 345 | ); | ||
| 346 | |||
| 347 | let keymap_binding = &keymap_bindings[i]; | ||
| 348 | assert_eq!( | ||
| 349 | keymap_binding.context_predicate, expected.context_predicate, | ||
| 350 | "Unexpected context predicate for keymap {i} element: {keymap_binding:?}" | ||
| 351 | ); | ||
| 352 | assert_eq!( | ||
| 353 | keymap_binding.keystrokes, expected.keystrokes, | ||
| 354 | "Unexpected keystrokes for keymap {i} element: {keymap_binding:?}" | ||
| 355 | ); | ||
| 356 | } | ||
| 357 | } | ||
| 358 | |||
| 359 | #[track_caller] | ||
| 360 | fn assert_absent(keymap: &Keymap, bindings: &[&Binding]) { | ||
| 361 | for binding in bindings.iter() { | ||
| 362 | assert!( | ||
| 363 | !keymap.binding_disabled(binding), | ||
| 364 | "{binding:?} should not be disabled in the keymap where was not added" | ||
| 365 | ); | ||
| 366 | assert_eq!( | ||
| 367 | keymap.bindings_for_action(binding.action().id()).count(), | ||
| 368 | 0, | ||
| 369 | "{binding:?} should have no actions in the keymap where was not added" | ||
| 370 | ); | ||
| 371 | } | ||
| 372 | } | ||
| 373 | |||
| 374 | #[track_caller] | ||
| 375 | fn assert_disabled(keymap: &Keymap, bindings: &[&Binding]) { | ||
| 376 | for binding in bindings.iter() { | ||
| 377 | assert!( | ||
| 378 | keymap.binding_disabled(binding), | ||
| 379 | "{binding:?} should be disabled in the keymap" | ||
| 380 | ); | ||
| 381 | assert_eq!( | ||
| 382 | keymap.bindings_for_action(binding.action().id()).count(), | ||
| 383 | 0, | ||
| 384 | "{binding:?} should have no actions in the keymap where it was disabled" | ||
| 385 | ); | ||
| 386 | } | ||
| 60 | } | 387 | } |
| 61 | } | 388 | } |
| @@ -44,7 +44,7 @@ impl KeymapContext { · 43 unmodified lines | |||
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | #[derive(Clone, Debug, Eq, PartialEq)] | 47 | #[derive(Clone, Debug, Eq, PartialEq, Hash)] |
| 48 | pub enum KeymapContextPredicate { | 48 | pub enum KeymapContextPredicate { |
| 49 | Identifier(String), | 49 | Identifier(String), |
| 50 | Equal(String, String), | 50 | Equal(String, String), |
| @@ -3,7 +3,7 @@ use std::fmt::Write; · 2 unmodified lines | |||
| 3 | use anyhow::anyhow; | 3 | use anyhow::anyhow; |
| 4 | use serde::Deserialize; | 4 | use serde::Deserialize; |
| 5 | 5 | ||
| 6 | #[derive(Clone, Debug, Eq, PartialEq, Default, Deserialize)] | 6 | #[derive(Clone, Debug, Eq, PartialEq, Default, Deserialize, Hash)] |
| 7 | pub struct Keystroke { | 7 | pub struct Keystroke { |
| 8 | pub ctrl: bool, | 8 | pub ctrl: bool, |
| 9 | pub alt: bool, | 9 | pub alt: bool, |
| @@ -231,7 +231,7 @@ impl MacForegroundPlatform { · 230 unmodified lines | |||
| 231 | } => { | 231 | } => { |
| 232 | // TODO | 232 | // TODO |
| 233 | let keystrokes = keystroke_matcher | 233 | let keystrokes = keystroke_matcher |
| 234 | .bindings_for_action_type(action.as_any().type_id()) | 234 | .bindings_for_action(action.id()) |
| 235 | .find(|binding| binding.action().eq(action.as_ref())) | 235 | .find(|binding| binding.action().eq(action.as_ref())) |
| 236 | .map(|binding| binding.keystrokes()); | 236 | .map(|binding| binding.keystrokes()); |
| 237 | let selector = match os_action { | 237 | let selector = match os_action { |
| @@ -46,7 +46,6 @@ lazy_static.workspace = true · 45 unmodified lines | |||
| 46 | log.workspace = true | 46 | log.workspace = true |
| 47 | parking_lot.workspace = true | 47 | parking_lot.workspace = true |
| 48 | postage.workspace = true | 48 | postage.workspace = true |
| 49 | rand = { workspace = true, optional = true } | ||
| 50 | regex.workspace = true | 49 | regex.workspace = true |
| 51 | schemars.workspace = true | 50 | schemars.workspace = true |
| 52 | serde.workspace = true | 51 | serde.workspace = true |
| @@ -56,10 +55,12 @@ similar = "1.3" · 3 unmodified lines | |||
| 56 | smallvec.workspace = true | 55 | smallvec.workspace = true |
| 57 | smol.workspace = true | 56 | smol.workspace = true |
| 58 | tree-sitter.workspace = true | 57 | tree-sitter.workspace = true |
| 59 | tree-sitter-rust = { version = "*", optional = true } | ||
| 60 | tree-sitter-typescript = { version = "*", optional = true } | ||
| 61 | unicase = "2.6" | 58 | unicase = "2.6" |
| 62 | 59 | ||
| 60 | rand = { workspace = true, optional = true } | ||
| 61 | tree-sitter-rust = { workspace = true, optional = true } | ||
| 62 | tree-sitter-typescript = { workspace = true, optional = true } | ||
| 63 | |||
| 63 | [dev-dependencies] | 64 | [dev-dependencies] |
| 64 | client = { path = "../client", features = ["test-support"] } | 65 | client = { path = "../client", features = ["test-support"] } |
| 65 | collections = { path = "../collections", features = ["test-support"] } | 66 | collections = { path = "../collections", features = ["test-support"] } |
| @@ -74,12 +75,13 @@ indoc.workspace = true · 8 unmodified lines | |||
| 74 | rand.workspace = true | 75 | rand.workspace = true |
| 75 | unindent.workspace = true | 76 | unindent.workspace = true |
| 76 | 77 | ||
| 77 | tree-sitter-embedded-template = "*" | 78 | tree-sitter-embedded-template.workspace = true |
| 78 | tree-sitter-html = "*" | 79 | tree-sitter-html.workspace = true |
| 79 | tree-sitter-javascript = "*" | 80 | tree-sitter-json.workspace = true |
| 80 | tree-sitter-json = "*" | 81 | tree-sitter-markdown.workspace = true |
| 81 | tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" } | 82 | tree-sitter-rust.workspace = true |
| 82 | tree-sitter-rust = "*" | 83 | tree-sitter-python.workspace = true |
| 83 | tree-sitter-python = "*" | 84 | tree-sitter-typescript.workspace = true |
| 84 | tree-sitter-typescript = "*" | 85 | tree-sitter-ruby.workspace = true |
| 85 | tree-sitter-ruby = "*" | 86 | tree-sitter-elixir.workspace = true |
| 87 | tree-sitter-heex.workspace = true | ||
| @@ -2145,23 +2145,27 @@ impl BufferSnapshot { · 2144 unmodified lines | |||
| 2145 | 2145 | ||
| 2146 | pub fn language_scope_at<D: ToOffset>(&self, position: D) -> Option<LanguageScope> { | 2146 | pub fn language_scope_at<D: ToOffset>(&self, position: D) -> Option<LanguageScope> { |
| 2147 | let offset = position.to_offset(self); | 2147 | let offset = position.to_offset(self); |
| 2148 | let mut range = 0..self.len(); | ||
| 2149 | let mut scope = self.language.clone().map(|language| LanguageScope { | ||
| 2150 | language, | ||
| 2151 | override_id: None, | ||
| 2152 | }); | ||
| 2148 | 2153 | ||
| 2149 | if let Some(layer_info) = self | 2154 | // Use the layer that has the smallest node intersecting the given point. |
| 2150 | .syntax | 2155 | for layer in self.syntax.layers_for_range(offset..offset, &self.text) { |
| 2151 | .layers_for_range(offset..offset, &self.text) | 2156 | let mut cursor = layer.node().walk(); |
| 2152 | .filter(|l| l.node().end_byte() > offset) | 2157 | while cursor.goto_first_child_for_byte(offset).is_some() {} |
| 2153 | .last() | 2158 | let node_range = cursor.node().byte_range(); |
| 2154 | { | 2159 | if node_range.to_inclusive().contains(&offset) && node_range.len() < range.len() { |
| 2155 | Some(LanguageScope { | 2160 | range = node_range; |
| 2156 | language: layer_info.language.clone(), | 2161 | scope = Some(LanguageScope { |
| 2157 | override_id: layer_info.override_id(offset, &self.text), | 2162 | language: layer.language.clone(), |
| 2158 | }) | 2163 | override_id: layer.override_id(offset, &self.text), |
| 2159 | } else { | 2164 | }); |
| 2160 | self.language.clone().map(|language| LanguageScope { | 2165 | } |
| 2161 | language, | ||
| 2162 | override_id: None, | ||
| 2163 | }) | ||
| 2164 | } | 2166 | } |
| 2167 | |||
| 2168 | scope | ||
| 2165 | } | 2169 | } |
| 2166 | 2170 | ||
| 2167 | pub fn surrounding_word<T: ToOffset>(&self, start: T) -> (Range<usize>, Option<CharKind>) { | 2171 | pub fn surrounding_word<T: ToOffset>(&self, start: T) -> (Range<usize>, Option<CharKind>) { |
| @@ -1533,47 +1533,9 @@ fn test_autoindent_with_injected_languages(cx: &mut AppContext) { · 1532 unmodified lines | |||
| 1533 | ]) | 1533 | ]) |
| 1534 | }); | 1534 | }); |
| 1535 | 1535 | ||
| 1536 | let html_language = Arc::new( | 1536 | let html_language = Arc::new(html_lang()); |
| 1537 | Language::new( | ||
| 1538 | LanguageConfig { | ||
| 1539 | name: "HTML".into(), | ||
| 1540 | ..Default::default() | ||
| 1541 | }, | ||
| 1542 | Some(tree_sitter_html::language()), | ||
| 1543 | ) | ||
| 1544 | .with_indents_query( | ||
| 1545 | " | ||
| 1546 | (element | ||
| 1547 | (start_tag) @start | ||
| 1548 | (end_tag)? @end) @indent | ||
| 1549 | ", | ||
| 1550 | ) | ||
| 1551 | .unwrap() | ||
| 1552 | .with_injection_query( | ||
| 1553 | r#" | ||
| 1554 | (script_element | ||
| 1555 | (raw_text) @content | ||
| 1556 | (#set! "language" "javascript")) | ||
| 1557 | "#, | ||
| 1558 | ) | ||
| 1559 | .unwrap(), | ||
| 1560 | ); | ||
| 1561 | 1537 | ||
| 1562 | let javascript_language = Arc::new( | 1538 | let javascript_language = Arc::new(javascript_lang()); |
| 1563 | Language::new( | ||
| 1564 | LanguageConfig { | ||
| 1565 | name: "JavaScript".into(), | ||
| 1566 | ..Default::default() | ||
| 1567 | }, | ||
| 1568 | Some(tree_sitter_javascript::language()), | ||
| 1569 | ) | ||
| 1570 | .with_indents_query( | ||
| 1571 | r#" | ||
| 1572 | (object "}" @end) @indent | ||
| 1573 | "#, | ||
| 1574 | ) | ||
| 1575 | .unwrap(), | ||
| 1576 | ); | ||
| 1577 | 1539 | ||
| 1578 | let language_registry = Arc::new(LanguageRegistry::test()); | 1540 | let language_registry = Arc::new(LanguageRegistry::test()); |
| 1579 | language_registry.add(html_language.clone()); | 1541 | language_registry.add(html_language.clone()); |
| @@ -1669,7 +1631,7 @@ fn test_autoindent_query_with_outdent_captures(cx: &mut AppContext) { · 89 unmodified lines | |||
| 1669 | } | 1631 | } |
| 1670 | 1632 | ||
| 1671 | #[gpui::test] | 1633 | #[gpui::test] |
| 1672 | fn test_language_config_at(cx: &mut AppContext) { | 1634 | fn test_language_scope_at(cx: &mut AppContext) { |
| 1673 | init_settings(cx, |_| {}); | 1635 | init_settings(cx, |_| {}); |
| 1674 | 1636 | ||
| 1675 | cx.add_model(|cx| { | 1637 | cx.add_model(|cx| { |
| @@ -1709,7 +1671,7 @@ fn test_language_config_at(cx: &mut AppContext) { · 33 unmodified lines | |||
| 1709 | .collect(), | 1671 | .collect(), |
| 1710 | ..Default::default() | 1672 | ..Default::default() |
| 1711 | }, | 1673 | }, |
| 1712 | Some(tree_sitter_javascript::language()), | 1674 | Some(tree_sitter_typescript::language_tsx()), |
| 1713 | ) | 1675 | ) |
| 1714 | .with_override_query( | 1676 | .with_override_query( |
| 1715 | r#" | 1677 | r#" |
| @@ -1756,6 +1718,54 @@ fn test_language_config_at(cx: &mut AppContext) { · 40 unmodified lines | |||
| 1756 | }); | 1718 | }); |
| 1757 | } | 1719 | } |
| 1758 | 1720 | ||
| 1721 | #[gpui::test] | ||
| 1722 | fn test_language_scope_at_with_combined_injections(cx: &mut AppContext) { | ||
| 1723 | init_settings(cx, |_| {}); | ||
| 1724 | |||
| 1725 | cx.add_model(|cx| { | ||
| 1726 | let text = r#" | ||
| 1727 | <ol> | ||
| 1728 | <% people.each do |person| %> | ||
| 1729 | <li> | ||
| 1730 | <%= person.name %> | ||
| 1731 | </li> | ||
| 1732 | <% end %> | ||
| 1733 | </ol> | ||
| 1734 | "# | ||
| 1735 | .unindent(); | ||
| 1736 | |||
| 1737 | let language_registry = Arc::new(LanguageRegistry::test()); | ||
| 1738 | language_registry.add(Arc::new(ruby_lang())); | ||
| 1739 | language_registry.add(Arc::new(html_lang())); | ||
| 1740 | language_registry.add(Arc::new(erb_lang())); | ||
| 1741 | |||
| 1742 | let mut buffer = Buffer::new(0, text, cx); | ||
| 1743 | buffer.set_language_registry(language_registry.clone()); | ||
| 1744 | buffer.set_language( | ||
| 1745 | language_registry | ||
| 1746 | .language_for_name("ERB") | ||
| 1747 | .now_or_never() | ||
| 1748 | .unwrap() | ||
| 1749 | .ok(), | ||
| 1750 | cx, | ||
| 1751 | ); | ||
| 1752 | |||
| 1753 | let snapshot = buffer.snapshot(); | ||
| 1754 | let html_config = snapshot.language_scope_at(Point::new(2, 4)).unwrap(); | ||
| 1755 | assert_eq!(html_config.line_comment_prefix(), None); | ||
| 1756 | assert_eq!( | ||
| 1757 | html_config.block_comment_delimiters(), | ||
| 1758 | Some((&"<!--".into(), &"-->".into())) | ||
| 1759 | ); | ||
| 1760 | |||
| 1761 | let ruby_config = snapshot.language_scope_at(Point::new(3, 12)).unwrap(); | ||
| 1762 | assert_eq!(ruby_config.line_comment_prefix().unwrap().as_ref(), "# "); | ||
| 1763 | assert_eq!(ruby_config.block_comment_delimiters(), None); | ||
| 1764 | |||
| 1765 | buffer | ||
| 1766 | }); | ||
| 1767 | } | ||
| 1768 | |||
| 1759 | #[gpui::test] | 1769 | #[gpui::test] |
| 1760 | fn test_serialization(cx: &mut gpui::AppContext) { | 1770 | fn test_serialization(cx: &mut gpui::AppContext) { |
| 1761 | let mut now = Instant::now(); | 1771 | let mut now = Instant::now(); |
| @@ -2143,6 +2153,7 @@ fn ruby_lang() -> Language { · 381 unmodified lines | |||
| 2143 | LanguageConfig { | 2153 | LanguageConfig { |
| 2144 | name: "Ruby".into(), | 2154 | name: "Ruby".into(), |
| 2145 | path_suffixes: vec!["rb".to_string()], | 2155 | path_suffixes: vec!["rb".to_string()], |
| 2156 | line_comment: Some("# ".into()), | ||
| 2146 | ..Default::default() | 2157 | ..Default::default() |
| 2147 | }, | 2158 | }, |
| 2148 | Some(tree_sitter_ruby::language()), | 2159 | Some(tree_sitter_ruby::language()), |
| @@ -2158,6 +2169,61 @@ fn ruby_lang() -> Language { · 9 unmodified lines | |||
| 2158 | .unwrap() | 2169 | .unwrap() |
| 2159 | } | 2170 | } |
| 2160 | 2171 | ||
| 2172 | fn html_lang() -> Language { | ||
| 2173 | Language::new( | ||
| 2174 | LanguageConfig { | ||
| 2175 | name: "HTML".into(), | ||
| 2176 | block_comment: Some(("<!--".into(), "-->".into())), | ||
| 2177 | ..Default::default() | ||
| 2178 | }, | ||
| 2179 | Some(tree_sitter_html::language()), | ||
| 2180 | ) | ||
| 2181 | .with_indents_query( | ||
| 2182 | " | ||
| 2183 | (element | ||
| 2184 | (start_tag) @start | ||
| 2185 | (end_tag)? @end) @indent | ||
| 2186 | ", | ||
| 2187 | ) | ||
| 2188 | .unwrap() | ||
| 2189 | .with_injection_query( | ||
| 2190 | r#" | ||
| 2191 | (script_element | ||
| 2192 | (raw_text) @content | ||
| 2193 | (#set! "language" "javascript")) | ||
| 2194 | "#, | ||
| 2195 | ) | ||
| 2196 | .unwrap() | ||
| 2197 | } | ||
| 2198 | |||
| 2199 | fn erb_lang() -> Language { | ||
| 2200 | Language::new( | ||
| 2201 | LanguageConfig { | ||
| 2202 | name: "ERB".into(), | ||
| 2203 | path_suffixes: vec!["erb".to_string()], | ||
| 2204 | block_comment: Some(("<%#".into(), "%>".into())), | ||
| 2205 | ..Default::default() | ||
| 2206 | }, | ||
| 2207 | Some(tree_sitter_embedded_template::language()), | ||
| 2208 | ) | ||
| 2209 | .with_injection_query( | ||
| 2210 | r#" | ||
| 2211 | ( | ||
| 2212 | (code) @content | ||
| 2213 | (#set! "language" "ruby") | ||
| 2214 | (#set! "combined") | ||
| 2215 | ) | ||
| 2216 | |||
| 2217 | ( | ||
| 2218 | (content) @content | ||
| 2219 | (#set! "language" "html") | ||
| 2220 | (#set! "combined") | ||
| 2221 | ) | ||
| 2222 | "#, | ||
| 2223 | ) | ||
| 2224 | .unwrap() | ||
| 2225 | } | ||
| 2226 | |||
| 2161 | fn rust_lang() -> Language { | 2227 | fn rust_lang() -> Language { |
| 2162 | Language::new( | 2228 | Language::new( |
| 2163 | LanguageConfig { | 2229 | LanguageConfig { |
| @@ -2227,7 +2293,7 @@ fn javascript_lang() -> Language { · 63 unmodified lines | |||
| 2227 | name: "JavaScript".into(), | 2293 | name: "JavaScript".into(), |
| 2228 | ..Default::default() | 2294 | ..Default::default() |
| 2229 | }, | 2295 | }, |
| 2230 | Some(tree_sitter_javascript::language()), | 2296 | Some(tree_sitter_typescript::language_tsx()), |
| 2231 | ) | 2297 | ) |
| 2232 | .with_brackets_query( | 2298 | .with_brackets_query( |
| 2233 | r#" | 2299 | r#" |
| @@ -2236,6 +2302,12 @@ fn javascript_lang() -> Language { · 2 unmodified lines | |||
| 2236 | "#, | 2302 | "#, |
| 2237 | ) | 2303 | ) |
| 2238 | .unwrap() | 2304 | .unwrap() |
| 2305 | .with_indents_query( | ||
| 2306 | r#" | ||
| 2307 | (object "}" @end) @indent | ||
| 2308 | "#, | ||
| 2309 | ) | ||
| 2310 | .unwrap() | ||
| 2239 | } | 2311 | } |
| 2240 | 2312 | ||
| 2241 | fn get_tree_sexp(buffer: &ModelHandle<Buffer>, cx: &gpui::TestAppContext) -> String { | 2313 | fn get_tree_sexp(buffer: &ModelHandle<Buffer>, cx: &gpui::TestAppContext) -> String { |
| @@ -830,6 +830,7 @@ impl LanguageRegistry { · 829 unmodified lines | |||
| 830 | Ok(language) => { | 830 | Ok(language) => { |
| 831 | let language = Arc::new(language); | 831 | let language = Arc::new(language); |
| 832 | let mut state = this.state.write(); | 832 | let mut state = this.state.write(); |
| 833 | |||
| 833 | state.add(language.clone()); | 834 | state.add(language.clone()); |
| 834 | state.mark_language_loaded(id); | 835 | state.mark_language_loaded(id); |
| 835 | if let Some(mut txs) = state.loading_languages.remove(&id) { | 836 | if let Some(mut txs) = state.loading_languages.remove(&id) { |
| @@ -1787,7 +1788,7 @@ mod tests { · 951 unmodified lines | |||
| 1787 | first_line_pattern: Some(Regex::new(r"\bnode\b").unwrap()), | 1788 | first_line_pattern: Some(Regex::new(r"\bnode\b").unwrap()), |
| 1788 | ..Default::default() | 1789 | ..Default::default() |
| 1789 | }, | 1790 | }, |
| 1790 | tree_sitter_javascript::language(), | 1791 | tree_sitter_typescript::language_tsx(), |
| 1791 | vec![], | 1792 | vec![], |
| 1792 | |_| Default::default(), | 1793 | |_| Default::default(), |
| 1793 | ); | 1794 | ); |
| @@ -569,11 +569,19 @@ impl SyntaxSnapshot { · 568 unmodified lines | |||
| 569 | range.end = range.end.saturating_sub(step_start_byte); | 569 | range.end = range.end.saturating_sub(step_start_byte); |
| 570 | } | 570 | } |
| 571 | 571 | ||
| 572 | included_ranges = splice_included_ranges( | 572 | let changed_indices; |
| 573 | (included_ranges, changed_indices) = splice_included_ranges( | ||
| 573 | old_tree.included_ranges(), | 574 | old_tree.included_ranges(), |
| 574 | &parent_layer_changed_ranges, | 575 | &parent_layer_changed_ranges, |
| 575 | &included_ranges, | 576 | &included_ranges, |
| 576 | ); | 577 | ); |
| 578 | insert_newlines_between_ranges( | ||
| 579 | changed_indices, | ||
| 580 | &mut included_ranges, | ||
| 581 | &text, | ||
| 582 | step_start_byte, | ||
| 583 | step_start_point, | ||
| 584 | ); | ||
| 577 | } | 585 | } |
| 578 | 586 | ||
| 579 | if included_ranges.is_empty() { | 587 | if included_ranges.is_empty() { |
| @@ -586,7 +594,7 @@ impl SyntaxSnapshot { · 6 unmodified lines | |||
| 586 | } | 594 | } |
| 587 | 595 | ||
| 588 | log::trace!( | 596 | log::trace!( |
| 589 | "update layer. language:{}, start:{:?}, ranges:{:?}", | 597 | "update layer. language:{}, start:{:?}, included_ranges:{:?}", |
| 590 | language.name(), | 598 | language.name(), |
| 591 | LogAnchorRange(&step.range, text), | 599 | LogAnchorRange(&step.range, text), |
| 592 | LogIncludedRanges(&included_ranges), | 600 | LogIncludedRanges(&included_ranges), |
| @@ -608,6 +616,16 @@ impl SyntaxSnapshot { · 15 unmodified lines | |||
| 608 | }), | 616 | }), |
| 609 | ); | 617 | ); |
| 610 | } else { | 618 | } else { |
| 619 | if matches!(step.mode, ParseMode::Combined { .. }) { | ||
| 620 | insert_newlines_between_ranges( | ||
| 621 | 0..included_ranges.len(), | ||
| 622 | &mut included_ranges, | ||
| 623 | text, | ||
| 624 | step_start_byte, | ||
| 625 | step_start_point, | ||
| 626 | ); | ||
| 627 | } | ||
| 628 | |||
| 611 | if included_ranges.is_empty() { | 629 | if included_ranges.is_empty() { |
| 612 | included_ranges.push(tree_sitter::Range { | 630 | included_ranges.push(tree_sitter::Range { |
| 613 | start_byte: 0, | 631 | start_byte: 0, |
| @@ -771,8 +789,10 @@ impl SyntaxSnapshot { · 157 unmodified lines | |||
| 771 | range: Range<T>, | 789 | range: Range<T>, |
| 772 | buffer: &'a BufferSnapshot, | 790 | buffer: &'a BufferSnapshot, |
| 773 | ) -> impl 'a + Iterator<Item = SyntaxLayerInfo> { | 791 | ) -> impl 'a + Iterator<Item = SyntaxLayerInfo> { |
| 774 | let start = buffer.anchor_before(range.start.to_offset(buffer)); | 792 | let start_offset = range.start.to_offset(buffer); |
| 775 | let end = buffer.anchor_after(range.end.to_offset(buffer)); | 793 | let end_offset = range.end.to_offset(buffer); |
| 794 | let start = buffer.anchor_before(start_offset); | ||
| 795 | let end = buffer.anchor_after(end_offset); | ||
| 776 | 796 | ||
| 777 | let mut cursor = self.layers.filter::<_, ()>(move |summary| { | 797 | let mut cursor = self.layers.filter::<_, ()>(move |summary| { |
| 778 | if summary.max_depth > summary.min_depth { | 798 | if summary.max_depth > summary.min_depth { |
| @@ -787,20 +807,21 @@ impl SyntaxSnapshot { · 8 unmodified lines | |||
| 787 | cursor.next(buffer); | 807 | cursor.next(buffer); |
| 788 | iter::from_fn(move || { | 808 | iter::from_fn(move || { |
| 789 | while let Some(layer) = cursor.item() { | 809 | while let Some(layer) = cursor.item() { |
| 810 | let mut info = None; | ||
| 790 | if let SyntaxLayerContent::Parsed { tree, language } = &layer.content { | 811 | if let SyntaxLayerContent::Parsed { tree, language } = &layer.content { |
| 791 | let info = SyntaxLayerInfo { | 812 | let layer_start_offset = layer.range.start.to_offset(buffer); |
| 813 | let layer_start_point = layer.range.start.to_point(buffer).to_ts_point(); | ||
| 814 | |||
| 815 | info = Some(SyntaxLayerInfo { | ||
| 792 | tree, | 816 | tree, |
| 793 | language, | 817 | language, |
| 794 | depth: layer.depth, | 818 | depth: layer.depth, |
| 795 | offset: ( | 819 | offset: (layer_start_offset, layer_start_point), |
| 796 | layer.range.start.to_offset(buffer), | 820 | }); |
| 797 | layer.range.start.to_point(buffer).to_ts_point(), | 821 | } |
| 798 | ), | 822 | cursor.next(buffer); |
| 799 | }; | 823 | if info.is_some() { |
| 800 | cursor.next(buffer); | 824 | return info; |
| 801 | return Some(info); | ||
| 802 | } else { | ||
| 803 | cursor.next(buffer); | ||
| 804 | } | 825 | } |
| 805 | } | 826 | } |
| 806 | None | 827 | None |
| @@ -1272,14 +1293,20 @@ fn get_injections( · 465 unmodified lines | |||
| 1272 | } | 1293 | } |
| 1273 | } | 1294 | } |
| 1274 | 1295 | ||
| 1296 | /// Update the given list of included `ranges`, removing any ranges that intersect | ||
| 1297 | /// `removed_ranges`, and inserting the given `new_ranges`. | ||
| 1298 | /// | ||
| 1299 | /// Returns a new vector of ranges, and the range of the vector that was changed, | ||
| 1300 | /// from the previous `ranges` vector. | ||
| 1275 | pub(crate) fn splice_included_ranges( | 1301 | pub(crate) fn splice_included_ranges( |
| 1276 | mut ranges: Vec<tree_sitter::Range>, | 1302 | mut ranges: Vec<tree_sitter::Range>, |
| 1277 | removed_ranges: &[Range<usize>], | 1303 | removed_ranges: &[Range<usize>], |
| 1278 | new_ranges: &[tree_sitter::Range], | 1304 | new_ranges: &[tree_sitter::Range], |
| 1279 | ) -> Vec<tree_sitter::Range> { | 1305 | ) -> (Vec<tree_sitter::Range>, Range<usize>) { |
| 1280 | let mut removed_ranges = removed_ranges.iter().cloned().peekable(); | 1306 | let mut removed_ranges = removed_ranges.iter().cloned().peekable(); |
| 1281 | let mut new_ranges = new_ranges.into_iter().cloned().peekable(); | 1307 | let mut new_ranges = new_ranges.into_iter().cloned().peekable(); |
| 1282 | let mut ranges_ix = 0; | 1308 | let mut ranges_ix = 0; |
| 1309 | let mut changed_portion = usize::MAX..0; | ||
| 1283 | loop { | 1310 | loop { |
| 1284 | let next_new_range = new_ranges.peek(); | 1311 | let next_new_range = new_ranges.peek(); |
| 1285 | let next_removed_range = removed_ranges.peek(); | 1312 | let next_removed_range = removed_ranges.peek(); |
| @@ -1341,11 +1368,69 @@ pub(crate) fn splice_included_ranges( · 55 unmodified lines | |||
| 1341 | } | 1368 | } |
| 1342 | } | 1369 | } |
| 1343 | 1370 | ||
| 1371 | changed_portion.start = changed_portion.start.min(start_ix); | ||
| 1372 | changed_portion.end = changed_portion.end.max(if insert.is_some() { | ||
| 1373 | start_ix + 1 | ||
| 1374 | } else { | ||
| 1375 | start_ix | ||
| 1376 | }); | ||
| 1377 | |||
| 1344 | ranges.splice(start_ix..end_ix, insert); | 1378 | ranges.splice(start_ix..end_ix, insert); |
| 1345 | ranges_ix = start_ix; | 1379 | ranges_ix = start_ix; |
| 1346 | } | 1380 | } |
| 1347 | 1381 | ||
| 1348 | ranges | 1382 | if changed_portion.end < changed_portion.start { |
| 1383 | changed_portion = 0..0; | ||
| 1384 | } | ||
| 1385 | |||
| 1386 | (ranges, changed_portion) | ||
| 1387 | } | ||
| 1388 | |||
| 1389 | /// Ensure there are newline ranges in between content range that appear on | ||
| 1390 | /// different lines. For performance, only iterate through the given range of | ||
| 1391 | /// indices. All of the ranges in the array are relative to a given start byte | ||
| 1392 | /// and point. | ||
| 1393 | fn insert_newlines_between_ranges( | ||
| 1394 | indices: Range<usize>, | ||
| 1395 | ranges: &mut Vec<tree_sitter::Range>, | ||
| 1396 | text: &text::BufferSnapshot, | ||
| 1397 | start_byte: usize, | ||
| 1398 | start_point: Point, | ||
| 1399 | ) { | ||
| 1400 | let mut ix = indices.end + 1; | ||
| 1401 | while ix > indices.start { | ||
| 1402 | ix -= 1; | ||
| 1403 | if 0 == ix || ix == ranges.len() { | ||
| 1404 | continue; | ||
| 1405 | } | ||
| 1406 | |||
| 1407 | let range_b = ranges[ix].clone(); | ||
| 1408 | let range_a = &mut ranges[ix - 1]; | ||
| 1409 | if range_a.end_point.column == 0 { | ||
| 1410 | continue; | ||
| 1411 | } | ||
| 1412 | |||
| 1413 | if range_a.end_point.row < range_b.start_point.row { | ||
| 1414 | let end_point = start_point + Point::from_ts_point(range_a.end_point); | ||
| 1415 | let line_end = Point::new(end_point.row, text.line_len(end_point.row)); | ||
| 1416 | if end_point.column as u32 >= line_end.column { | ||
| 1417 | range_a.end_byte += 1; | ||
| 1418 | range_a.end_point.row += 1; | ||
| 1419 | range_a.end_point.column = 0; | ||
| 1420 | } else { | ||
| 1421 | let newline_offset = text.point_to_offset(line_end); | ||
| 1422 | ranges.insert( | ||
| 1423 | ix, | ||
| 1424 | tree_sitter::Range { | ||
| 1425 | start_byte: newline_offset - start_byte, | ||
| 1426 | end_byte: newline_offset - start_byte + 1, | ||
| 1427 | start_point: (line_end - start_point).to_ts_point(), | ||
| 1428 | end_point: ((line_end - start_point) + Point::new(1, 0)).to_ts_point(), | ||
| 1429 | }, | ||
| 1430 | ) | ||
| 1431 | } | ||
| 1432 | } | ||
| 1433 | } | ||
| 1349 | } | 1434 | } |
| 1350 | 1435 | ||
| 1351 | impl OwnedSyntaxLayerInfo { | 1436 | impl OwnedSyntaxLayerInfo { |
| @@ -11,7 +11,7 @@ use util::test::marked_text_ranges; · 10 unmodified lines | |||
| 11 | fn test_splice_included_ranges() { | 11 | fn test_splice_included_ranges() { |
| 12 | let ranges = vec![ts_range(20..30), ts_range(50..60), ts_range(80..90)]; | 12 | let ranges = vec![ts_range(20..30), ts_range(50..60), ts_range(80..90)]; |
| 13 | 13 | ||
| 14 | let new_ranges = splice_included_ranges( | 14 | let (new_ranges, change) = splice_included_ranges( |
| 15 | ranges.clone(), | 15 | ranges.clone(), |
| 16 | &[54..56, 58..68], | 16 | &[54..56, 58..68], |
| 17 | &[ts_range(50..54), ts_range(59..67)], | 17 | &[ts_range(50..54), ts_range(59..67)], |
| @@ -25,14 +25,16 @@ fn test_splice_included_ranges() { · 7 unmodified lines | |||
| 25 | ts_range(80..90), | 25 | ts_range(80..90), |
| 26 | ] | 26 | ] |
| 27 | ); | 27 | ); |
| 28 | assert_eq!(change, 1..3); | ||
| 28 | 29 | ||
| 29 | let new_ranges = splice_included_ranges(ranges.clone(), &[70..71, 91..100], &[]); | 30 | let (new_ranges, change) = splice_included_ranges(ranges.clone(), &[70..71, 91..100], &[]); |
| 30 | assert_eq!( | 31 | assert_eq!( |
| 31 | new_ranges, | 32 | new_ranges, |
| 32 | &[ts_range(20..30), ts_range(50..60), ts_range(80..90)] | 33 | &[ts_range(20..30), ts_range(50..60), ts_range(80..90)] |
| 33 | ); | 34 | ); |
| 35 | assert_eq!(change, 2..3); | ||
| 34 | 36 | ||
| 35 | let new_ranges = | 37 | let (new_ranges, change) = |
| 36 | splice_included_ranges(ranges.clone(), &[], &[ts_range(0..2), ts_range(70..75)]); | 38 | splice_included_ranges(ranges.clone(), &[], &[ts_range(0..2), ts_range(70..75)]); |
| 37 | assert_eq!( | 39 | assert_eq!( |
| 38 | new_ranges, | 40 | new_ranges, |
| @@ -44,16 +46,21 @@ fn test_splice_included_ranges() { · 5 unmodified lines | |||
| 44 | ts_range(80..90) | 46 | ts_range(80..90) |
| 45 | ] | 47 | ] |
| 46 | ); | 48 | ); |
| 49 | assert_eq!(change, 0..4); | ||
| 47 | 50 | ||
| 48 | let new_ranges = splice_included_ranges(ranges.clone(), &[30..50], &[ts_range(25..55)]); | 51 | let (new_ranges, change) = |
| 52 | splice_included_ranges(ranges.clone(), &[30..50], &[ts_range(25..55)]); | ||
| 49 | assert_eq!(new_ranges, &[ts_range(25..55), ts_range(80..90)]); | 53 | assert_eq!(new_ranges, &[ts_range(25..55), ts_range(80..90)]); |
| 54 | assert_eq!(change, 0..1); | ||
| 50 | 55 | ||
| 51 | // does not create overlapping ranges | 56 | // does not create overlapping ranges |
| 52 | let new_ranges = splice_included_ranges(ranges.clone(), &[0..18], &[ts_range(20..32)]); | 57 | let (new_ranges, change) = |
| 58 | splice_included_ranges(ranges.clone(), &[0..18], &[ts_range(20..32)]); | ||
| 53 | assert_eq!( | 59 | assert_eq!( |
| 54 | new_ranges, | 60 | new_ranges, |
| 55 | &[ts_range(20..32), ts_range(50..60), ts_range(80..90)] | 61 | &[ts_range(20..32), ts_range(50..60), ts_range(80..90)] |
| 56 | ); | 62 | ); |
| 63 | assert_eq!(change, 0..1); | ||
| 57 | 64 | ||
| 58 | fn ts_range(range: Range<usize>) -> tree_sitter::Range { | 65 | fn ts_range(range: Range<usize>) -> tree_sitter::Range { |
| 59 | tree_sitter::Range { | 66 | tree_sitter::Range { |
| @@ -511,7 +518,7 @@ fn test_removing_injection_by_replacing_across_boundary() { · 451 unmodified lines | |||
| 511 | } | 518 | } |
| 512 | 519 | ||
| 513 | #[gpui::test] | 520 | #[gpui::test] |
| 514 | fn test_combined_injections() { | 521 | fn test_combined_injections_simple() { |
| 515 | let (buffer, syntax_map) = test_edit_sequence( | 522 | let (buffer, syntax_map) = test_edit_sequence( |
| 516 | "ERB", | 523 | "ERB", |
| 517 | &[ | 524 | &[ |
| @@ -653,33 +660,78 @@ fn test_combined_injections_editing_after_last_injection() { · 135 unmodified lines | |||
| 653 | 660 | ||
| 654 | #[gpui::test] | 661 | #[gpui::test] |
| 655 | fn test_combined_injections_inside_injections() { | 662 | fn test_combined_injections_inside_injections() { |
| 656 | let (_buffer, _syntax_map) = test_edit_sequence( | 663 | let (buffer, syntax_map) = test_edit_sequence( |
| 657 | "Markdown", | 664 | "Markdown", |
| 658 | &[ | 665 | &[ |
| 659 | r#" | 666 | r#" |
| 660 | here is some ERB code: | 667 | here is |
| 668 | some | ||
| 669 | ERB code: | ||
| 661 | 670 | ||
| 662 | ```erb | 671 | ```erb |
| 663 | <ul> | 672 | <ul> |
| 664 | <% people.each do |person| %> | 673 | <% people.each do |person| %> |
| 665 | <li><%= person.name %></li> | 674 | <li><%= person.name %></li> |
| 675 | <li><%= person.age %></li> | ||
| 666 | <% end %> | 676 | <% end %> |
| 667 | </ul> | 677 | </ul> |
| 668 | ``` | 678 | ``` |
| 669 | "#, | 679 | "#, |
| 670 | r#" | 680 | r#" |
| 671 | here is some ERB code: | 681 | here is |
| 682 | some | ||
| 683 | ERB code: | ||
| 672 | 684 | ||
| 673 | ```erb | 685 | ```erb |
| 674 | <ul> | 686 | <ul> |
| 675 | <% people«2».each do |person| %> | 687 | <% people«2».each do |person| %> |
| 676 | <li><%= person.name %></li> | 688 | <li><%= person.name %></li> |
| 689 | <li><%= person.age %></li> | ||
| 690 | <% end %> | ||
| 691 | </ul> | ||
| 692 | ``` | ||
| 693 | "#, | ||
| 694 | // Inserting a comment character inside one code directive | ||
| 695 | // does not cause the other code directive to become a comment, | ||
| 696 | // because newlines are included in between each injection range. | ||
| 697 | r#" | ||
| 698 | here is | ||
| 699 | some | ||
| 700 | ERB code: | ||
| 701 | |||
| 702 | ```erb | ||
| 703 | <ul> | ||
| 704 | <% people2.each do |person| %> | ||
| 705 | <li><%= «# »person.name %></li> | ||
| 706 | <li><%= person.age %></li> | ||
| 677 | <% end %> | 707 | <% end %> |
| 678 | </ul> | 708 | </ul> |
| 679 | ``` | 709 | ``` |
| 680 | "#, | 710 | "#, |
| 681 | ], | 711 | ], |
| 682 | ); | 712 | ); |
| 713 | |||
| 714 | // Check that the code directive below the ruby comment is | ||
| 715 | // not parsed as a comment. | ||
| 716 | assert_capture_ranges( | ||
| 717 | &syntax_map, | ||
| 718 | &buffer, | ||
| 719 | &["method"], | ||
| 720 | " | ||
| 721 | here is | ||
| 722 | some | ||
| 723 | ERB code: | ||
| 724 | |||
| 725 | ```erb | ||
| 726 | <ul> | ||
| 727 | <% people2.«each» do |person| %> | ||
| 728 | <li><%= # person.name %></li> | ||
| 729 | <li><%= person.«age» %></li> | ||
| 730 | <% end %> | ||
| 731 | </ul> | ||
| 732 | ``` | ||
| 733 | ", | ||
| 734 | ); | ||
| 683 | } | 735 | } |
| 684 | 736 | ||
| 685 | #[gpui::test] | 737 | #[gpui::test] |
| @@ -711,11 +763,7 @@ fn test_empty_combined_injections_inside_injections() { · 25 unmodified lines | |||
| 711 | } | 763 | } |
| 712 | 764 | ||
| 713 | #[gpui::test(iterations = 50)] | 765 | #[gpui::test(iterations = 50)] |
| 714 | fn test_random_syntax_map_edits(mut rng: StdRng) { | 766 | fn test_random_syntax_map_edits_rust_macros(rng: StdRng) { |
| 715 | let operations = env::var("OPERATIONS") | ||
| 716 | .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) | ||
| 717 | .unwrap_or(10); | ||
| 718 | |||
| 719 | let text = r#" | 767 | let text = r#" |
| 720 | fn test_something() { | 768 | fn test_something() { |
| 721 | let vec = vec![5, 1, 3, 8]; | 769 | let vec = vec![5, 1, 3, 8]; |
| @@ -736,68 +784,12 @@ fn test_random_syntax_map_edits(mut rng: StdRng) { · 14 unmodified lines | |||
| 736 | let registry = Arc::new(LanguageRegistry::test()); | 784 | let registry = Arc::new(LanguageRegistry::test()); |
| 737 | let language = Arc::new(rust_lang()); | 785 | let language = Arc::new(rust_lang()); |
| 738 | registry.add(language.clone()); | 786 | registry.add(language.clone()); |
| 739 | let mut buffer = Buffer::new(0, 0, text); | ||
| 740 | |||
| 741 | let mut syntax_map = SyntaxMap::new(); | ||
| 742 | syntax_map.set_language_registry(registry.clone()); | ||
| 743 | syntax_map.reparse(language.clone(), &buffer); | ||
| 744 | |||
| 745 | let mut reference_syntax_map = SyntaxMap::new(); | ||
| 746 | reference_syntax_map.set_language_registry(registry.clone()); | ||
| 747 | |||
| 748 | log::info!("initial text:\n{}", buffer.text()); | ||
| 749 | |||
| 750 | for _ in 0..operations { | ||
| 751 | let prev_buffer = buffer.snapshot(); | ||
| 752 | let prev_syntax_map = syntax_map.snapshot(); | ||
| 753 | |||
| 754 | buffer.randomly_edit(&mut rng, 3); | ||
| 755 | log::info!("text:\n{}", buffer.text()); | ||
| 756 | |||
| 757 | syntax_map.interpolate(&buffer); | ||
| 758 | check_interpolation(&prev_syntax_map, &syntax_map, &prev_buffer, &buffer); | ||
| 759 | |||
| 760 | syntax_map.reparse(language.clone(), &buffer); | ||
| 761 | |||
| 762 | reference_syntax_map.clear(); | ||
| 763 | reference_syntax_map.reparse(language.clone(), &buffer); | ||
| 764 | } | ||
| 765 | |||
| 766 | for i in 0..operations { | ||
| 767 | let i = operations - i - 1; | ||
| 768 | buffer.undo(); | ||
| 769 | log::info!("undoing operation {}", i); | ||
| 770 | log::info!("text:\n{}", buffer.text()); | ||
| 771 | |||
| 772 | syntax_map.interpolate(&buffer); | ||
| 773 | syntax_map.reparse(language.clone(), &buffer); | ||
| 774 | |||
| 775 | reference_syntax_map.clear(); | ||
| 776 | reference_syntax_map.reparse(language.clone(), &buffer); | ||
| 777 | assert_eq!( | ||
| 778 | syntax_map.layers(&buffer).len(), | ||
| 779 | reference_syntax_map.layers(&buffer).len(), | ||
| 780 | "wrong number of layers after undoing edit {i}" | ||
| 781 | ); | ||
| 782 | } | ||
| 783 | 787 | ||
| 784 | let layers = syntax_map.layers(&buffer); | 788 | test_random_edits(text, registry, language, rng); |
| 785 | let reference_layers = reference_syntax_map.layers(&buffer); | ||
| 786 | for (edited_layer, reference_layer) in layers.into_iter().zip(reference_layers.into_iter()) { | ||
| 787 | assert_eq!( | ||
| 788 | edited_layer.node().to_sexp(), | ||
| 789 | reference_layer.node().to_sexp() | ||
| 790 | ); | ||
| 791 | assert_eq!(edited_layer.node().range(), reference_layer.node().range()); | ||
| 792 | } | ||
| 793 | } | 789 | } |
| 794 | 790 | ||
| 795 | #[gpui::test(iterations = 50)] | 791 | #[gpui::test(iterations = 50)] |
| 796 | fn test_random_syntax_map_edits_with_combined_injections(mut rng: StdRng) { | 792 | fn test_random_syntax_map_edits_with_erb(rng: StdRng) { |
| 797 | let operations = env::var("OPERATIONS") | ||
| 798 | .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) | ||
| 799 | .unwrap_or(10); | ||
| 800 | |||
| 801 | let text = r#" | 793 | let text = r#" |
| 802 | <div id="main"> | 794 | <div id="main"> |
| 803 | <% if one?(:two) %> | 795 | <% if one?(:two) %> |
| @@ -814,13 +806,60 @@ fn test_random_syntax_map_edits_with_combined_injections(mut rng: StdRng) { · 10 unmodified lines | |||
| 814 | </div> | 806 | </div> |
| 815 | "# | 807 | "# |
| 816 | .unindent() | 808 | .unindent() |
| 817 | .repeat(8); | 809 | .repeat(5); |
| 818 | 810 | ||
| 819 | let registry = Arc::new(LanguageRegistry::test()); | 811 | let registry = Arc::new(LanguageRegistry::test()); |
| 820 | let language = Arc::new(erb_lang()); | 812 | let language = Arc::new(erb_lang()); |
| 821 | registry.add(language.clone()); | 813 | registry.add(language.clone()); |
| 822 | registry.add(Arc::new(ruby_lang())); | 814 | registry.add(Arc::new(ruby_lang())); |
| 823 | registry.add(Arc::new(html_lang())); | 815 | registry.add(Arc::new(html_lang())); |
| 816 | |||
| 817 | test_random_edits(text, registry, language, rng); | ||
| 818 | } | ||
| 819 | |||
| 820 | #[gpui::test(iterations = 50)] | ||
| 821 | fn test_random_syntax_map_edits_with_heex(rng: StdRng) { | ||
| 822 | let text = r#" | ||
| 823 | defmodule TheModule do | ||
| 824 | def the_method(assigns) do | ||
| 825 | ~H""" | ||
| 826 | <%= if @empty do %> | ||
| 827 | <div class="h-4"></div> | ||
| 828 | <% else %> | ||
| 829 | <div class="max-w-2xl w-full animate-pulse"> | ||
| 830 | <div class="flex-1 space-y-4"> | ||
| 831 | <div class={[@bg_class, "h-4 rounded-lg w-3/4"]}></div> | ||
| 832 | <div class={[@bg_class, "h-4 rounded-lg"]}></div> | ||
| 833 | <div class={[@bg_class, "h-4 rounded-lg w-5/6"]}></div> | ||
| 834 | </div> | ||
| 835 | </div> | ||
| 836 | <% end %> | ||
| 837 | """ | ||
| 838 | end | ||
| 839 | end | ||
| 840 | "# | ||
| 841 | .unindent() | ||
| 842 | .repeat(3); | ||
| 843 | |||
| 844 | let registry = Arc::new(LanguageRegistry::test()); | ||
| 845 | let language = Arc::new(elixir_lang()); | ||
| 846 | registry.add(language.clone()); | ||
| 847 | registry.add(Arc::new(heex_lang())); | ||
| 848 | registry.add(Arc::new(html_lang())); | ||
| 849 | |||
| 850 | test_random_edits(text, registry, language, rng); | ||
| 851 | } | ||
| 852 | |||
| 853 | fn test_random_edits( | ||
| 854 | text: String, | ||
| 855 | registry: Arc<LanguageRegistry>, | ||
| 856 | language: Arc<Language>, | ||
| 857 | mut rng: StdRng, | ||
| 858 | ) { | ||
| 859 | let operations = env::var("OPERATIONS") | ||
| 860 | .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) | ||
| 861 | .unwrap_or(10); | ||
| 862 | |||
| 824 | let mut buffer = Buffer::new(0, 0, text); | 863 | let mut buffer = Buffer::new(0, 0, text); |
| 825 | 864 | ||
| 826 | let mut syntax_map = SyntaxMap::new(); | 865 | let mut syntax_map = SyntaxMap::new(); |
| @@ -984,11 +1023,14 @@ fn check_interpolation( · 157 unmodified lines | |||
| 984 | 1023 | ||
| 985 | fn test_edit_sequence(language_name: &str, steps: &[&str]) -> (Buffer, SyntaxMap) { | 1024 | fn test_edit_sequence(language_name: &str, steps: &[&str]) -> (Buffer, SyntaxMap) { |
| 986 | let registry = Arc::new(LanguageRegistry::test()); | 1025 | let registry = Arc::new(LanguageRegistry::test()); |
| 1026 | registry.add(Arc::new(elixir_lang())); | ||
| 1027 | registry.add(Arc::new(heex_lang())); | ||
| 987 | registry.add(Arc::new(rust_lang())); | 1028 | registry.add(Arc::new(rust_lang())); |
| 988 | registry.add(Arc::new(ruby_lang())); | 1029 | registry.add(Arc::new(ruby_lang())); |
| 989 | registry.add(Arc::new(html_lang())); | 1030 | registry.add(Arc::new(html_lang())); |
| 990 | registry.add(Arc::new(erb_lang())); | 1031 | registry.add(Arc::new(erb_lang())); |
| 991 | registry.add(Arc::new(markdown_lang())); | 1032 | registry.add(Arc::new(markdown_lang())); |
| 1033 | |||
| 992 | let language = registry | 1034 | let language = registry |
| 993 | .language_for_name(language_name) | 1035 | .language_for_name(language_name) |
| 994 | .now_or_never() | 1036 | .now_or_never() |
| @@ -1074,6 +1116,7 @@ fn ruby_lang() -> Language { · 79 unmodified lines | |||
| 1074 | r#" | 1116 | r#" |
| 1075 | ["if" "do" "else" "end"] @keyword | 1117 | ["if" "do" "else" "end"] @keyword |
| 1076 | (instance_variable) @ivar | 1118 | (instance_variable) @ivar |
| 1119 | (call method: (identifier) @method) | ||
| 1077 | "#, | 1120 | "#, |
| 1078 | ) | 1121 | ) |
| 1079 | .unwrap() | 1122 | .unwrap() |
| @@ -1158,6 +1201,52 @@ fn markdown_lang() -> Language { · 78 unmodified lines | |||
| 1158 | .unwrap() | 1201 | .unwrap() |
| 1159 | } | 1202 | } |
| 1160 | 1203 | ||
| 1204 | fn elixir_lang() -> Language { | ||
| 1205 | Language::new( | ||
| 1206 | LanguageConfig { | ||
| 1207 | name: "Elixir".into(), | ||
| 1208 | path_suffixes: vec!["ex".into()], | ||
| 1209 | ..Default::default() | ||
| 1210 | }, | ||
| 1211 | Some(tree_sitter_elixir::language()), | ||
| 1212 | ) | ||
| 1213 | .with_highlights_query( | ||
| 1214 | r#" | ||
| 1215 | |||
| 1216 | "#, | ||
| 1217 | ) | ||
| 1218 | .unwrap() | ||
| 1219 | } | ||
| 1220 | |||
| 1221 | fn heex_lang() -> Language { | ||
| 1222 | Language::new( | ||
| 1223 | LanguageConfig { | ||
| 1224 | name: "HEEx".into(), | ||
| 1225 | path_suffixes: vec!["heex".into()], | ||
| 1226 | ..Default::default() | ||
| 1227 | }, | ||
| 1228 | Some(tree_sitter_heex::language()), | ||
| 1229 | ) | ||
| 1230 | .with_injection_query( | ||
| 1231 | r#" | ||
| 1232 | ( | ||
| 1233 | (directive | ||
| 1234 | [ | ||
| 1235 | (partial_expression_value) | ||
| 1236 | (expression_value) | ||
| 1237 | (ending_expression_value) | ||
| 1238 | ] @content) | ||
| 1239 | (#set! language "elixir") | ||
| 1240 | (#set! combined) | ||
| 1241 | ) | ||
| 1242 | |||
| 1243 | ((expression (expression_value) @content) | ||
| 1244 | (#set! language "elixir")) | ||
| 1245 | "#, | ||
| 1246 | ) | ||
| 1247 | .unwrap() | ||
| 1248 | } | ||
| 1249 | |||
| 1161 | fn range_for_text(buffer: &Buffer, text: &str) -> Range<usize> { | 1250 | fn range_for_text(buffer: &Buffer, text: &str) -> Range<usize> { |
| 1162 | let start = buffer.as_rope().to_string().find(text).unwrap(); | 1251 | let start = buffer.as_rope().to_string().find(text).unwrap(); |
| 1163 | start..start + text.len() | 1252 | start..start + text.len() |
| @@ -93,7 +93,7 @@ impl PickerDelegate for LanguageSelectorDelegate { · 92 unmodified lines | |||
| 93 | self.matches.len() | 93 | self.matches.len() |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | fn confirm(&mut self, cx: &mut ViewContext<Picker<Self>>) { | 96 | fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) { |
| 97 | if let Some(mat) = self.matches.get(self.selected_index) { | 97 | if let Some(mat) = self.matches.get(self.selected_index) { |
| 98 | let language_name = &self.candidates[mat.candidate_id].string; | 98 | let language_name = &self.candidates[mat.candidate_id].string; |
| 99 | let language = self.language_registry.language_for_name(language_name); | 99 | let language = self.language_registry.language_for_name(language_name); |
| @@ -467,8 +467,13 @@ impl Item for LspLogView { · 466 unmodified lines | |||
| 467 | impl SearchableItem for LspLogView { | 467 | impl SearchableItem for LspLogView { |
| 468 | type Match = <Editor as SearchableItem>::Match; | 468 | type Match = <Editor as SearchableItem>::Match; |
| 469 | 469 | ||
| 470 | fn to_search_event(event: &Self::Event) -> Option<workspace::searchable::SearchEvent> { | 470 | fn to_search_event( |
| 471 | Editor::to_search_event(event) | 471 | &mut self, |
| 472 | event: &Self::Event, | ||
| 473 | cx: &mut ViewContext<Self>, | ||
| 474 | ) -> Option<workspace::searchable::SearchEvent> { | ||
| 475 | self.editor | ||
| 476 | .update(cx, |editor, cx| editor.to_search_event(event, cx)) | ||
| 472 | } | 477 | } |
| 473 | 478 | ||
| 474 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { | 479 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { |
| @@ -494,6 +499,11 @@ impl SearchableItem for LspLogView { · 19 unmodified lines | |||
| 494 | .update(cx, |e, cx| e.activate_match(index, matches, cx)) | 499 | .update(cx, |e, cx| e.activate_match(index, matches, cx)) |
| 495 | } | 500 | } |
| 496 | 501 | ||
| 502 | fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) { | ||
| 503 | self.editor | ||
| 504 | .update(cx, |e, cx| e.select_matches(matches, cx)) | ||
| 505 | } | ||
| 506 | |||
| 497 | fn find_matches( | 507 | fn find_matches( |
| 498 | &mut self, | 508 | &mut self, |
| 499 | query: project::search::SearchQuery, | 509 | query: project::search::SearchQuery, |
| @@ -151,16 +151,17 @@ impl LanguageServer { · 150 unmodified lines | |||
| 151 | let stdin = server.stdin.take().unwrap(); | 151 | let stdin = server.stdin.take().unwrap(); |
| 152 | let stout = server.stdout.take().unwrap(); | 152 | let stout = server.stdout.take().unwrap(); |
| 153 | let mut server = Self::new_internal( | 153 | let mut server = Self::new_internal( |
| 154 | server_id, | 154 | server_id.clone(), |
| 155 | stdin, | 155 | stdin, |
| 156 | stout, | 156 | stout, |
| 157 | Some(server), | 157 | Some(server), |
| 158 | root_path, | 158 | root_path, |
| 159 | code_action_kinds, | 159 | code_action_kinds, |
| 160 | cx, | 160 | cx, |
| 161 | |notification| { | 161 | move |notification| { |
| 162 | log::info!( | 162 | log::info!( |
| 163 | "unhandled notification {}:\n{}", | 163 | "{} unhandled notification {}:\n{}", |
| 164 | server_id, | ||
| 164 | notification.method, | 165 | notification.method, |
| 165 | serde_json::to_string_pretty( | 166 | serde_json::to_string_pretty( |
| 166 | ¬ification | 167 | ¬ification |
| @@ -3,6 +3,7 @@ gpui::actions!( · 2 unmodified lines | |||
| 3 | [ | 3 | [ |
| 4 | Cancel, | 4 | Cancel, |
| 5 | Confirm, | 5 | Confirm, |
| 6 | SecondaryConfirm, | ||
| 6 | SelectPrev, | 7 | SelectPrev, |
| 7 | SelectNext, | 8 | SelectNext, |
| 8 | SelectFirst, | 9 | SelectFirst, |
| @@ -6,13 +6,13 @@ use futures::{future::Shared, FutureExt}; · 5 unmodified lines | |||
| 6 | use gpui::{executor::Background, Task}; | 6 | use gpui::{executor::Background, Task}; |
| 7 | use serde::Deserialize; | 7 | use serde::Deserialize; |
| 8 | use smol::{fs, io::BufReader, process::Command}; | 8 | use smol::{fs, io::BufReader, process::Command}; |
| 9 | use std::process::Output; | 9 | use std::process::{Output, Stdio}; |
| 10 | use std::{ | 10 | use std::{ |
| 11 | env::consts, | 11 | env::consts, |
| 12 | path::{Path, PathBuf}, | 12 | path::{Path, PathBuf}, |
| 13 | sync::{Arc, OnceLock}, | 13 | sync::{Arc, OnceLock}, |
| 14 | }; | 14 | }; |
| 15 | use util::{http::HttpClient, ResultExt}; | 15 | use util::http::HttpClient; |
| 16 | 16 | ||
| 17 | const VERSION: &str = "v18.15.0"; | 17 | const VERSION: &str = "v18.15.0"; |
| 18 | 18 | ||
| @@ -84,9 +84,8 @@ impl NodeRuntime { · 65 unmodified lines | |||
| 84 | }; | 84 | }; |
| 85 | 85 | ||
| 86 | let installation_path = self.install_if_needed().await?; | 86 | let installation_path = self.install_if_needed().await?; |
| 87 | let mut output = attempt(installation_path).await; | 87 | let mut output = attempt(installation_path.clone()).await; |
| 88 | if output.is_err() { | 88 | if output.is_err() { |
| 89 | let installation_path = self.reinstall().await?; | ||
| 90 | output = attempt(installation_path).await; | 89 | output = attempt(installation_path).await; |
| 91 | if output.is_err() { | 90 | if output.is_err() { |
| 92 | return Err(anyhow!( | 91 | return Err(anyhow!( |
| @@ -158,29 +157,6 @@ impl NodeRuntime { · 65 unmodified lines | |||
| 158 | Ok(()) | 157 | Ok(()) |
| 159 | } | 158 | } |
| 160 | 159 | ||
| 161 | async fn reinstall(&self) -> Result<PathBuf> { | ||
| 162 | log::info!("beginnning to reinstall Node runtime"); | ||
| 163 | let mut installation_path = self.installation_path.lock().await; | ||
| 164 | |||
| 165 | if let Some(task) = installation_path.as_ref().cloned() { | ||
| 166 | if let Ok(installation_path) = task.await { | ||
| 167 | smol::fs::remove_dir_all(&installation_path) | ||
| 168 | .await | ||
| 169 | .context("node dir removal") | ||
| 170 | .log_err(); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | let http = self.http.clone(); | ||
| 175 | let task = self | ||
| 176 | .background | ||
| 177 | .spawn(async move { Self::install(http).await.map_err(Arc::new) }) | ||
| 178 | .shared(); | ||
| 179 | |||
| 180 | *installation_path = Some(task.clone()); | ||
| 181 | task.await.map_err(|e| anyhow!("{}", e)) | ||
| 182 | } | ||
| 183 | |||
| 184 | async fn install_if_needed(&self) -> Result<PathBuf> { | 160 | async fn install_if_needed(&self) -> Result<PathBuf> { |
| 185 | let task = self | 161 | let task = self |
| 186 | .installation_path | 162 | .installation_path |
| @@ -209,8 +185,19 @@ impl NodeRuntime { · 22 unmodified lines | |||
| 209 | let node_containing_dir = util::paths::SUPPORT_DIR.join("node"); | 185 | let node_containing_dir = util::paths::SUPPORT_DIR.join("node"); |
| 210 | let node_dir = node_containing_dir.join(folder_name); | 186 | let node_dir = node_containing_dir.join(folder_name); |
| 211 | let node_binary = node_dir.join("bin/node"); | 187 | let node_binary = node_dir.join("bin/node"); |
| 212 | 188 | let npm_file = node_dir.join("bin/npm"); | |
| 213 | if fs::metadata(&node_binary).await.is_err() { | 189 | |
| 190 | let result = Command::new(&node_binary) | ||
| 191 | .arg(npm_file) | ||
| 192 | .arg("--version") | ||
| 193 | .stdin(Stdio::null()) | ||
| 194 | .stdout(Stdio::null()) | ||
| 195 | .stderr(Stdio::null()) | ||
| 196 | .status() | ||
| 197 | .await; | ||
| 198 | let valid = matches!(result, Ok(status) if status.success()); | ||
| 199 | |||
| 200 | if !valid { | ||
| 214 | _ = fs::remove_dir_all(&node_containing_dir).await; | 201 | _ = fs::remove_dir_all(&node_containing_dir).await; |
| 215 | fs::create_dir(&node_containing_dir) | 202 | fs::create_dir(&node_containing_dir) |
| 216 | .await | 203 | .await |
| @@ -177,7 +177,7 @@ impl PickerDelegate for OutlineViewDelegate { · 176 unmodified lines | |||
| 177 | Task::ready(()) | 177 | Task::ready(()) |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | fn confirm(&mut self, cx: &mut ViewContext<OutlineView>) { | 180 | fn confirm(&mut self, _: bool, cx: &mut ViewContext<OutlineView>) { |
| 181 | self.prev_scroll_position.take(); | 181 | self.prev_scroll_position.take(); |
| 182 | self.active_editor.update(cx, |active_editor, cx| { | 182 | self.active_editor.update(cx, |active_editor, cx| { |
| 183 | if let Some(rows) = active_editor.highlighted_rows() { | 183 | if let Some(rows) = active_editor.highlighted_rows() { |
| @@ -7,7 +7,7 @@ use gpui::{ · 6 unmodified lines | |||
| 7 | AnyElement, AnyViewHandle, AppContext, Axis, Entity, MouseState, Task, View, ViewContext, | 7 | AnyElement, AnyViewHandle, AppContext, Axis, Entity, MouseState, Task, View, ViewContext, |
| 8 | ViewHandle, | 8 | ViewHandle, |
| 9 | }; | 9 | }; |
| 10 | use menu::{Cancel, Confirm, SelectFirst, SelectLast, SelectNext, SelectPrev}; | 10 | use menu::{Cancel, Confirm, SecondaryConfirm, SelectFirst, SelectLast, SelectNext, SelectPrev}; |
| 11 | use parking_lot::Mutex; | 11 | use parking_lot::Mutex; |
| 12 | use std::{cmp, sync::Arc}; | 12 | use std::{cmp, sync::Arc}; |
| 13 | use util::ResultExt; | 13 | use util::ResultExt; |
| @@ -34,7 +34,7 @@ pub trait PickerDelegate: Sized + 'static { · 20 unmodified lines | |||
| 34 | fn selected_index(&self) -> usize; | 34 | fn selected_index(&self) -> usize; |
| 35 | fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>); | 35 | fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>); |
| 36 | fn update_matches(&mut self, query: String, cx: &mut ViewContext<Picker<Self>>) -> Task<()>; | 36 | fn update_matches(&mut self, query: String, cx: &mut ViewContext<Picker<Self>>) -> Task<()>; |
| 37 | fn confirm(&mut self, cx: &mut ViewContext<Picker<Self>>); | 37 | fn confirm(&mut self, secondary: bool, cx: &mut ViewContext<Picker<Self>>); |
| 38 | fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>); | 38 | fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>); |
| 39 | fn render_match( | 39 | fn render_match( |
| 40 | &self, | 40 | &self, |
| @@ -118,8 +118,8 @@ impl<D: PickerDelegate> View for Picker<D> { · 77 unmodified lines | |||
| 118 | // Capture mouse events | 118 | // Capture mouse events |
| 119 | .on_down(MouseButton::Left, |_, _, _| {}) | 119 | .on_down(MouseButton::Left, |_, _, _| {}) |
| 120 | .on_up(MouseButton::Left, |_, _, _| {}) | 120 | .on_up(MouseButton::Left, |_, _, _| {}) |
| 121 | .on_click(MouseButton::Left, move |_, picker, cx| { | 121 | .on_click(MouseButton::Left, move |click, picker, cx| { |
| 122 | picker.select_index(ix, cx); | 122 | picker.select_index(ix, click.cmd, cx); |
| 123 | }) | 123 | }) |
| 124 | .with_cursor_style(CursorStyle::PointingHand) | 124 | .with_cursor_style(CursorStyle::PointingHand) |
| 125 | .into_any() | 125 | .into_any() |
| @@ -175,6 +175,7 @@ impl<D: PickerDelegate> Picker<D> { · 49 unmodified lines | |||
| 175 | cx.add_action(Self::select_next); | 175 | cx.add_action(Self::select_next); |
| 176 | cx.add_action(Self::select_prev); | 176 | cx.add_action(Self::select_prev); |
| 177 | cx.add_action(Self::confirm); | 177 | cx.add_action(Self::confirm); |
| 178 | cx.add_action(Self::secondary_confirm); | ||
| 178 | cx.add_action(Self::cancel); | 179 | cx.add_action(Self::cancel); |
| 179 | } | 180 | } |
| 180 | 181 | ||
| @@ -288,11 +289,11 @@ impl<D: PickerDelegate> Picker<D> { · 107 unmodified lines | |||
| 288 | cx.notify(); | 289 | cx.notify(); |
| 289 | } | 290 | } |
| 290 | 291 | ||
| 291 | pub fn select_index(&mut self, index: usize, cx: &mut ViewContext<Self>) { | 292 | pub fn select_index(&mut self, index: usize, cmd: bool, cx: &mut ViewContext<Self>) { |
| 292 | if self.delegate.match_count() > 0 { | 293 | if self.delegate.match_count() > 0 { |
| 293 | self.confirmed = true; | 294 | self.confirmed = true; |
| 294 | self.delegate.set_selected_index(index, cx); | 295 | self.delegate.set_selected_index(index, cx); |
| 295 | self.delegate.confirm(cx); | 296 | self.delegate.confirm(cmd, cx); |
| 296 | } | 297 | } |
| 297 | } | 298 | } |
| 298 | 299 | ||
| @@ -330,7 +331,12 @@ impl<D: PickerDelegate> Picker<D> { · 31 unmodified lines | |||
| 330 | 331 | ||
| 331 | pub fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) { | 332 | pub fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) { |
| 332 | self.confirmed = true; | 333 | self.confirmed = true; |
| 333 | self.delegate.confirm(cx); | 334 | self.delegate.confirm(false, cx); |
| 335 | } | ||
| 336 | |||
| 337 | pub fn secondary_confirm(&mut self, _: &SecondaryConfirm, cx: &mut ViewContext<Self>) { | ||
| 338 | self.confirmed = true; | ||
| 339 | self.delegate.confirm(true, cx); | ||
| 334 | } | 340 | } |
| 335 | 341 | ||
| 336 | fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) { | 342 | fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) { |
| @@ -2709,7 +2709,6 @@ impl Project { · 2708 unmodified lines | |||
| 2709 | Some(language_server) => language_server, | 2709 | Some(language_server) => language_server, |
| 2710 | None => return Ok(None), | 2710 | None => return Ok(None), |
| 2711 | }; | 2711 | }; |
| 2712 | |||
| 2713 | let this = match this.upgrade(cx) { | 2712 | let this = match this.upgrade(cx) { |
| 2714 | Some(this) => this, | 2713 | Some(this) => this, |
| 2715 | None => return Err(anyhow!("failed to upgrade project handle")), | 2714 | None => return Err(anyhow!("failed to upgrade project handle")), |
| @@ -3045,6 +3044,8 @@ impl Project { · 329 unmodified lines | |||
| 3045 | ) -> Task<(Option<PathBuf>, Vec<WorktreeId>)> { | 3044 | ) -> Task<(Option<PathBuf>, Vec<WorktreeId>)> { |
| 3046 | let key = (worktree_id, adapter_name); | 3045 | let key = (worktree_id, adapter_name); |
| 3047 | if let Some(server_id) = self.language_server_ids.remove(&key) { | 3046 | if let Some(server_id) = self.language_server_ids.remove(&key) { |
| 3047 | log::info!("stopping language server {}", key.1 .0); | ||
| 3048 | |||
| 3048 | // Remove other entries for this language server as well | 3049 | // Remove other entries for this language server as well |
| 3049 | let mut orphaned_worktrees = vec![worktree_id]; | 3050 | let mut orphaned_worktrees = vec![worktree_id]; |
| 3050 | let other_keys = self.language_server_ids.keys().cloned().collect::<Vec<_>>(); | 3051 | let other_keys = self.language_server_ids.keys().cloned().collect::<Vec<_>>(); |
| @@ -397,6 +397,7 @@ impl Worktree { · 396 unmodified lines | |||
| 397 | })) | 397 | })) |
| 398 | } | 398 | } |
| 399 | 399 | ||
| 400 | // abcdefghi | ||
| 400 | pub fn remote( | 401 | pub fn remote( |
| 401 | project_remote_id: u64, | 402 | project_remote_id: u64, |
| 402 | replica_id: ReplicaId, | 403 | replica_id: ReplicaId, |
| @@ -2022,6 +2023,9 @@ impl LocalSnapshot { · 1619 unmodified lines | |||
| 2022 | ) -> Vec<Arc<Path>> { | 2023 | ) -> Vec<Arc<Path>> { |
| 2023 | let mut changes = vec![]; | 2024 | let mut changes = vec![]; |
| 2024 | let mut edits = vec![]; | 2025 | let mut edits = vec![]; |
| 2026 | |||
| 2027 | let statuses = repo_ptr.statuses(); | ||
| 2028 | |||
| 2025 | for mut entry in self | 2029 | for mut entry in self |
| 2026 | .descendent_entries(false, false, &work_directory.0) | 2030 | .descendent_entries(false, false, &work_directory.0) |
| 2027 | .cloned() | 2031 | .cloned() |
| @@ -2029,10 +2033,8 @@ impl LocalSnapshot { · 1 unmodified line | |||
| 2029 | let Ok(repo_path) = entry.path.strip_prefix(&work_directory.0) else { | 2033 | let Ok(repo_path) = entry.path.strip_prefix(&work_directory.0) else { |
| 2030 | continue; | 2034 | continue; |
| 2031 | }; | 2035 | }; |
| 2032 | let git_file_status = repo_ptr | 2036 | let repo_path = RepoPath(repo_path.to_path_buf()); |
| 2033 | .status(&RepoPath(repo_path.into())) | 2037 | let git_file_status = statuses.as_ref().and_then(|s| s.get(&repo_path).copied()); |
| 2034 | .log_err() | ||
| 2035 | .flatten(); | ||
| 2036 | if entry.git_status != git_file_status { | 2038 | if entry.git_status != git_file_status { |
| 2037 | entry.git_status = git_file_status; | 2039 | entry.git_status = git_file_status; |
| 2038 | changes.push(entry.path.clone()); | 2040 | changes.push(entry.path.clone()); |
| @@ -159,6 +159,9 @@ pub enum Event { · 158 unmodified lines | |||
| 159 | entry_id: ProjectEntryId, | 159 | entry_id: ProjectEntryId, |
| 160 | focus_opened_item: bool, | 160 | focus_opened_item: bool, |
| 161 | }, | 161 | }, |
| 162 | SplitEntry { | ||
| 163 | entry_id: ProjectEntryId, | ||
| 164 | }, | ||
| 162 | DockPositionChanged, | 165 | DockPositionChanged, |
| 163 | Focus, | 166 | Focus, |
| 164 | } | 167 | } |
| @@ -290,6 +293,21 @@ impl ProjectPanel { · 125 unmodified lines | |||
| 290 | } | 293 | } |
| 291 | } | 294 | } |
| 292 | } | 295 | } |
| 296 | &Event::SplitEntry { entry_id } => { | ||
| 297 | if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx) { | ||
| 298 | if let Some(entry) = worktree.read(cx).entry_for_id(entry_id) { | ||
| 299 | workspace | ||
| 300 | .split_path( | ||
| 301 | ProjectPath { | ||
| 302 | worktree_id: worktree.read(cx).id(), | ||
| 303 | path: entry.path.clone(), | ||
| 304 | }, | ||
| 305 | cx, | ||
| 306 | ) | ||
| 307 | .detach_and_log_err(cx); | ||
| 308 | } | ||
| 309 | } | ||
| 310 | } | ||
| 293 | _ => {} | 311 | _ => {} |
| 294 | } | 312 | } |
| 295 | }) | 313 | }) |
| @@ -620,6 +638,10 @@ impl ProjectPanel { · 324 unmodified lines | |||
| 620 | }); | 638 | }); |
| 621 | } | 639 | } |
| 622 | 640 | ||
| 641 | fn split_entry(&mut self, entry_id: ProjectEntryId, cx: &mut ViewContext<Self>) { | ||
| 642 | cx.emit(Event::SplitEntry { entry_id }); | ||
| 643 | } | ||
| 644 | |||
| 623 | fn new_file(&mut self, _: &NewFile, cx: &mut ViewContext<Self>) { | 645 | fn new_file(&mut self, _: &NewFile, cx: &mut ViewContext<Self>) { |
| 624 | self.add_entry(false, cx) | 646 | self.add_entry(false, cx) |
| 625 | } | 647 | } |
| @@ -1333,7 +1355,11 @@ impl ProjectPanel { · 707 unmodified lines | |||
| 1333 | if kind.is_dir() { | 1355 | if kind.is_dir() { |
| 1334 | this.toggle_expanded(entry_id, cx); | 1356 | this.toggle_expanded(entry_id, cx); |
| 1335 | } else { | 1357 | } else { |
| 1336 | this.open_entry(entry_id, event.click_count > 1, cx); | 1358 | if event.cmd { |
| 1359 | this.split_entry(entry_id, cx); | ||
| 1360 | } else if !event.cmd { | ||
| 1361 | this.open_entry(entry_id, event.click_count > 1, cx); | ||
| 1362 | } | ||
| 1337 | } | 1363 | } |
| 1338 | } | 1364 | } |
| 1339 | }) | 1365 | }) |
| @@ -104,7 +104,7 @@ impl PickerDelegate for ProjectSymbolsDelegate { · 103 unmodified lines | |||
| 104 | "Search project symbols...".into() | 104 | "Search project symbols...".into() |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | fn confirm(&mut self, cx: &mut ViewContext<ProjectSymbols>) { | 107 | fn confirm(&mut self, secondary: bool, cx: &mut ViewContext<ProjectSymbols>) { |
| 108 | if let Some(symbol) = self | 108 | if let Some(symbol) = self |
| 109 | .matches | 109 | .matches |
| 110 | .get(self.selected_match_index) | 110 | .get(self.selected_match_index) |
| @@ -122,7 +122,12 @@ impl PickerDelegate for ProjectSymbolsDelegate { · 11 unmodified lines | |||
| 122 | .read(cx) | 122 | .read(cx) |
| 123 | .clip_point_utf16(symbol.range.start, Bias::Left); | 123 | .clip_point_utf16(symbol.range.start, Bias::Left); |
| 124 | 124 | ||
| 125 | let editor = workspace.open_project_item::<Editor>(buffer, cx); | 125 | let editor = if secondary { |
| 126 | workspace.split_project_item::<Editor>(buffer, cx) | ||
| 127 | } else { | ||
| 128 | workspace.open_project_item::<Editor>(buffer, cx) | ||
| 129 | }; | ||
| 130 | |||
| 126 | editor.update(cx, |editor, cx| { | 131 | editor.update(cx, |editor, cx| { |
| 127 | editor.change_selections(Some(Autoscroll::center()), cx, |s| { | 132 | editor.change_selections(Some(Autoscroll::center()), cx, |s| { |
| 128 | s.select_ranges([position..position]) | 133 | s.select_ranges([position..position]) |
| @@ -161,7 +161,7 @@ impl PickerDelegate for RecentProjectsDelegate { · 160 unmodified lines | |||
| 161 | Task::ready(()) | 161 | Task::ready(()) |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | fn confirm(&mut self, cx: &mut ViewContext<RecentProjects>) { | 164 | fn confirm(&mut self, _: bool, cx: &mut ViewContext<RecentProjects>) { |
| 165 | if let Some((selected_match, workspace)) = self | 165 | if let Some((selected_match, workspace)) = self |
| 166 | .matches | 166 | .matches |
| 167 | .get(self.selected_index()) | 167 | .get(self.selected_index()) |
| @@ -1,6 +1,6 @@ | |||
| 1 | use crate::{ | 1 | use crate::{ |
| 2 | SearchOption, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, | 2 | SearchOption, SelectAllMatches, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, |
| 3 | ToggleWholeWord, | 3 | ToggleRegex, ToggleWholeWord, |
| 4 | }; | 4 | }; |
| 5 | use collections::HashMap; | 5 | use collections::HashMap; |
| 6 | use editor::Editor; | 6 | use editor::Editor; |
| @@ -39,8 +39,10 @@ pub fn init(cx: &mut AppContext) { · 32 unmodified lines | |||
| 39 | cx.add_action(BufferSearchBar::focus_editor); | 39 | cx.add_action(BufferSearchBar::focus_editor); |
| 40 | cx.add_action(BufferSearchBar::select_next_match); | 40 | cx.add_action(BufferSearchBar::select_next_match); |
| 41 | cx.add_action(BufferSearchBar::select_prev_match); | 41 | cx.add_action(BufferSearchBar::select_prev_match); |
| 42 | cx.add_action(BufferSearchBar::select_all_matches); | ||
| 42 | cx.add_action(BufferSearchBar::select_next_match_on_pane); | 43 | cx.add_action(BufferSearchBar::select_next_match_on_pane); |
| 43 | cx.add_action(BufferSearchBar::select_prev_match_on_pane); | 44 | cx.add_action(BufferSearchBar::select_prev_match_on_pane); |
| 45 | cx.add_action(BufferSearchBar::select_all_matches_on_pane); | ||
| 44 | cx.add_action(BufferSearchBar::handle_editor_cancel); | 46 | cx.add_action(BufferSearchBar::handle_editor_cancel); |
| 45 | add_toggle_option_action::<ToggleCaseSensitive>(SearchOption::CaseSensitive, cx); | 47 | add_toggle_option_action::<ToggleCaseSensitive>(SearchOption::CaseSensitive, cx); |
| 46 | add_toggle_option_action::<ToggleWholeWord>(SearchOption::WholeWord, cx); | 48 | add_toggle_option_action::<ToggleWholeWord>(SearchOption::WholeWord, cx); |
| @@ -66,7 +68,7 @@ pub struct BufferSearchBar { · 19 unmodified lines | |||
| 66 | active_searchable_item: Option<Box<dyn SearchableItemHandle>>, | 68 | active_searchable_item: Option<Box<dyn SearchableItemHandle>>, |
| 67 | active_match_index: Option<usize>, | 69 | active_match_index: Option<usize>, |
| 68 | active_searchable_item_subscription: Option<Subscription>, | 70 | active_searchable_item_subscription: Option<Subscription>, |
| 69 | seachable_items_with_matches: | 71 | searchable_items_with_matches: |
| 70 | HashMap<Box<dyn WeakSearchableItemHandle>, Vec<Box<dyn Any + Send>>>, | 72 | HashMap<Box<dyn WeakSearchableItemHandle>, Vec<Box<dyn Any + Send>>>, |
| 71 | pending_search: Option<Task<()>>, | 73 | pending_search: Option<Task<()>>, |
| 72 | case_sensitive: bool, | 74 | case_sensitive: bool, |
| @@ -118,7 +120,7 @@ impl View for BufferSearchBar { · 45 unmodified lines | |||
| 118 | .with_children(self.active_searchable_item.as_ref().and_then( | 120 | .with_children(self.active_searchable_item.as_ref().and_then( |
| 119 | |searchable_item| { | 121 | |searchable_item| { |
| 120 | let matches = self | 122 | let matches = self |
| 121 | .seachable_items_with_matches | 123 | .searchable_items_with_matches |
| 122 | .get(&searchable_item.downgrade())?; | 124 | .get(&searchable_item.downgrade())?; |
| 123 | let message = if let Some(match_ix) = self.active_match_index { | 125 | let message = if let Some(match_ix) = self.active_match_index { |
| 124 | format!("{}/{}", match_ix + 1, matches.len()) | 126 | format!("{}/{}", match_ix + 1, matches.len()) |
| @@ -146,6 +148,7 @@ impl View for BufferSearchBar { · 21 unmodified lines | |||
| 146 | Flex::row() | 148 | Flex::row() |
| 147 | .with_child(self.render_nav_button("<", Direction::Prev, cx)) | 149 | .with_child(self.render_nav_button("<", Direction::Prev, cx)) |
| 148 | .with_child(self.render_nav_button(">", Direction::Next, cx)) | 150 | .with_child(self.render_nav_button(">", Direction::Next, cx)) |
| 151 | .with_child(self.render_action_button("Select All", cx)) | ||
| 149 | .aligned(), | 152 | .aligned(), |
| 150 | ) | 153 | ) |
| 151 | .with_child( | 154 | .with_child( |
| @@ -249,7 +252,7 @@ impl BufferSearchBar { · 97 unmodified lines | |||
| 249 | active_searchable_item: None, | 252 | active_searchable_item: None, |
| 250 | active_searchable_item_subscription: None, | 253 | active_searchable_item_subscription: None, |
| 251 | active_match_index: None, | 254 | active_match_index: None, |
| 252 | seachable_items_with_matches: Default::default(), | 255 | searchable_items_with_matches: Default::default(), |
| 253 | case_sensitive: false, | 256 | case_sensitive: false, |
| 254 | whole_word: false, | 257 | whole_word: false, |
| 255 | regex: false, | 258 | regex: false, |
| @@ -265,7 +268,7 @@ impl BufferSearchBar { · 9 unmodified lines | |||
| 265 | 268 | ||
| 266 | pub fn dismiss(&mut self, _: &Dismiss, cx: &mut ViewContext<Self>) { | 269 | pub fn dismiss(&mut self, _: &Dismiss, cx: &mut ViewContext<Self>) { |
| 267 | self.dismissed = true; | 270 | self.dismissed = true; |
| 268 | for searchable_item in self.seachable_items_with_matches.keys() { | 271 | for searchable_item in self.searchable_items_with_matches.keys() { |
| 269 | if let Some(searchable_item) = | 272 | if let Some(searchable_item) = |
| 270 | WeakSearchableItemHandle::upgrade(searchable_item.as_ref(), cx) | 273 | WeakSearchableItemHandle::upgrade(searchable_item.as_ref(), cx) |
| 271 | { | 274 | { |
| @@ -401,6 +404,37 @@ impl BufferSearchBar { · 129 unmodified lines | |||
| 401 | .into_any() | 404 | .into_any() |
| 402 | } | 405 | } |
| 403 | 406 | ||
| 407 | fn render_action_button( | ||
| 408 | &self, | ||
| 409 | icon: &'static str, | ||
| 410 | cx: &mut ViewContext<Self>, | ||
| 411 | ) -> AnyElement<Self> { | ||
| 412 | let tooltip = "Select All Matches"; | ||
| 413 | let tooltip_style = theme::current(cx).tooltip.clone(); | ||
| 414 | let action_type_id = 0_usize; | ||
| 415 | |||
| 416 | enum ActionButton {} | ||
| 417 | MouseEventHandler::<ActionButton, _>::new(action_type_id, cx, |state, cx| { | ||
| 418 | let theme = theme::current(cx); | ||
| 419 | let style = theme.search.action_button.style_for(state); | ||
| 420 | Label::new(icon, style.text.clone()) | ||
| 421 | .contained() | ||
| 422 | .with_style(style.container) | ||
| 423 | }) | ||
| 424 | .on_click(MouseButton::Left, move |_, this, cx| { | ||
| 425 | this.select_all_matches(&SelectAllMatches, cx) | ||
| 426 | }) | ||
| 427 | .with_cursor_style(CursorStyle::PointingHand) | ||
| 428 | .with_tooltip::<ActionButton>( | ||
| 429 | action_type_id, | ||
| 430 | tooltip.to_string(), | ||
| 431 | Some(Box::new(SelectAllMatches)), | ||
| 432 | tooltip_style, | ||
| 433 | cx, | ||
| 434 | ) | ||
| 435 | .into_any() | ||
| 436 | } | ||
| 437 | |||
| 404 | fn render_close_button( | 438 | fn render_close_button( |
| 405 | &self, | 439 | &self, |
| 406 | theme: &theme::Search, | 440 | theme: &theme::Search, |
| @@ -488,11 +522,25 @@ impl BufferSearchBar { · 81 unmodified lines | |||
| 488 | self.select_match(Direction::Prev, cx); | 522 | self.select_match(Direction::Prev, cx); |
| 489 | } | 523 | } |
| 490 | 524 | ||
| 525 | fn select_all_matches(&mut self, _: &SelectAllMatches, cx: &mut ViewContext<Self>) { | ||
| 526 | if !self.dismissed { | ||
| 527 | if let Some(searchable_item) = self.active_searchable_item.as_ref() { | ||
| 528 | if let Some(matches) = self | ||
| 529 | .searchable_items_with_matches | ||
| 530 | .get(&searchable_item.downgrade()) | ||
| 531 | { | ||
| 532 | searchable_item.select_matches(matches, cx); | ||
| 533 | self.focus_editor(&FocusEditor, cx); | ||
| 534 | } | ||
| 535 | } | ||
| 536 | } | ||
| 537 | } | ||
| 538 | |||
| 491 | pub fn select_match(&mut self, direction: Direction, cx: &mut ViewContext<Self>) { | 539 | pub fn select_match(&mut self, direction: Direction, cx: &mut ViewContext<Self>) { |
| 492 | if let Some(index) = self.active_match_index { | 540 | if let Some(index) = self.active_match_index { |
| 493 | if let Some(searchable_item) = self.active_searchable_item.as_ref() { | 541 | if let Some(searchable_item) = self.active_searchable_item.as_ref() { |
| 494 | if let Some(matches) = self | 542 | if let Some(matches) = self |
| 495 | .seachable_items_with_matches | 543 | .searchable_items_with_matches |
| 496 | .get(&searchable_item.downgrade()) | 544 | .get(&searchable_item.downgrade()) |
| 497 | { | 545 | { |
| 498 | let new_match_index = | 546 | let new_match_index = |
| @@ -524,6 +572,16 @@ impl BufferSearchBar { · 25 unmodified lines | |||
| 524 | } | 572 | } |
| 525 | } | 573 | } |
| 526 | 574 | ||
| 575 | fn select_all_matches_on_pane( | ||
| 576 | pane: &mut Pane, | ||
| 577 | action: &SelectAllMatches, | ||
| 578 | cx: &mut ViewContext<Pane>, | ||
| 579 | ) { | ||
| 580 | if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() { | ||
| 581 | search_bar.update(cx, |bar, cx| bar.select_all_matches(action, cx)); | ||
| 582 | } | ||
| 583 | } | ||
| 584 | |||
| 527 | fn on_query_editor_event( | 585 | fn on_query_editor_event( |
| 528 | &mut self, | 586 | &mut self, |
| 529 | _: ViewHandle<Editor>, | 587 | _: ViewHandle<Editor>, |
| @@ -547,7 +605,7 @@ impl BufferSearchBar { · 17 unmodified lines | |||
| 547 | 605 | ||
| 548 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { | 606 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { |
| 549 | let mut active_item_matches = None; | 607 | let mut active_item_matches = None; |
| 550 | for (searchable_item, matches) in self.seachable_items_with_matches.drain() { | 608 | for (searchable_item, matches) in self.searchable_items_with_matches.drain() { |
| 551 | if let Some(searchable_item) = | 609 | if let Some(searchable_item) = |
| 552 | WeakSearchableItemHandle::upgrade(searchable_item.as_ref(), cx) | 610 | WeakSearchableItemHandle::upgrade(searchable_item.as_ref(), cx) |
| 553 | { | 611 | { |
| @@ -559,7 +617,7 @@ impl BufferSearchBar { · 5 unmodified lines | |||
| 559 | } | 617 | } |
| 560 | } | 618 | } |
| 561 | 619 | ||
| 562 | self.seachable_items_with_matches | 620 | self.searchable_items_with_matches |
| 563 | .extend(active_item_matches); | 621 | .extend(active_item_matches); |
| 564 | } | 622 | } |
| 565 | 623 | ||
| @@ -605,13 +663,13 @@ impl BufferSearchBar { · 39 unmodified lines | |||
| 605 | if let Some(active_searchable_item) = | 663 | if let Some(active_searchable_item) = |
| 606 | WeakSearchableItemHandle::upgrade(active_searchable_item.as_ref(), cx) | 664 | WeakSearchableItemHandle::upgrade(active_searchable_item.as_ref(), cx) |
| 607 | { | 665 | { |
| 608 | this.seachable_items_with_matches | 666 | this.searchable_items_with_matches |
| 609 | .insert(active_searchable_item.downgrade(), matches); | 667 | .insert(active_searchable_item.downgrade(), matches); |
| 610 | 668 | ||
| 611 | this.update_match_index(cx); | 669 | this.update_match_index(cx); |
| 612 | if !this.dismissed { | 670 | if !this.dismissed { |
| 613 | let matches = this | 671 | let matches = this |
| 614 | .seachable_items_with_matches | 672 | .searchable_items_with_matches |
| 615 | .get(&active_searchable_item.downgrade()) | 673 | .get(&active_searchable_item.downgrade()) |
| 616 | .unwrap(); | 674 | .unwrap(); |
| 617 | active_searchable_item.update_matches(matches, cx); | 675 | active_searchable_item.update_matches(matches, cx); |
| @@ -637,7 +695,7 @@ impl BufferSearchBar { · 19 unmodified lines | |||
| 637 | .as_ref() | 695 | .as_ref() |
| 638 | .and_then(|searchable_item| { | 696 | .and_then(|searchable_item| { |
| 639 | let matches = self | 697 | let matches = self |
| 640 | .seachable_items_with_matches | 698 | .searchable_items_with_matches |
| 641 | .get(&searchable_item.downgrade())?; | 699 | .get(&searchable_item.downgrade())?; |
| 642 | searchable_item.active_match_index(matches, cx) | 700 | searchable_item.active_match_index(matches, cx) |
| 643 | }); | 701 | }); |
| @@ -966,4 +1024,133 @@ mod tests { · 322 unmodified lines | |||
| 966 | assert_eq!(search_bar.active_match_index, Some(2)); | 1024 | assert_eq!(search_bar.active_match_index, Some(2)); |
| 967 | }); | 1025 | }); |
| 968 | } | 1026 | } |
| 1027 | |||
| 1028 | #[gpui::test] | ||
| 1029 | async fn test_search_select_all_matches(cx: &mut TestAppContext) { | ||
| 1030 | crate::project_search::tests::init_test(cx); | ||
| 1031 | |||
| 1032 | let buffer_text = r#" | ||
| 1033 | A regular expression (shortened as regex or regexp;[1] also referred to as | ||
| 1034 | rational expression[2][3]) is a sequence of characters that specifies a search | ||
| 1035 | pattern in text. Usually such patterns are used by string-searching algorithms | ||
| 1036 | for "find" or "find and replace" operations on strings, or for input validation. | ||
| 1037 | "# | ||
| 1038 | .unindent(); | ||
| 1039 | let expected_query_matches_count = buffer_text | ||
| 1040 | .chars() | ||
| 1041 | .filter(|c| c.to_ascii_lowercase() == 'a') | ||
| 1042 | .count(); | ||
| 1043 | assert!( | ||
| 1044 | expected_query_matches_count > 1, | ||
| 1045 | "Should pick a query with multiple results" | ||
| 1046 | ); | ||
| 1047 | let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx)); | ||
| 1048 | let (window_id, _root_view) = cx.add_window(|_| EmptyView); | ||
| 1049 | |||
| 1050 | let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx)); | ||
| 1051 | |||
| 1052 | let search_bar = cx.add_view(window_id, |cx| { | ||
| 1053 | let mut search_bar = BufferSearchBar::new(cx); | ||
| 1054 | search_bar.set_active_pane_item(Some(&editor), cx); | ||
| 1055 | search_bar.show(false, true, cx); | ||
| 1056 | search_bar | ||
| 1057 | }); | ||
| 1058 | |||
| 1059 | search_bar.update(cx, |search_bar, cx| { | ||
| 1060 | search_bar.set_query("a", cx); | ||
| 1061 | }); | ||
| 1062 | |||
| 1063 | editor.next_notification(cx).await; | ||
| 1064 | let initial_selections = editor.update(cx, |editor, cx| { | ||
| 1065 | let initial_selections = editor.selections.display_ranges(cx); | ||
| 1066 | assert_eq!( | ||
| 1067 | initial_selections.len(), 1, | ||
| 1068 | "Expected to have only one selection before adding carets to all matches, but got: {initial_selections:?}", | ||
| 1069 | ); | ||
| 1070 | initial_selections | ||
| 1071 | }); | ||
| 1072 | search_bar.update(cx, |search_bar, _| { | ||
| 1073 | assert_eq!(search_bar.active_match_index, Some(0)); | ||
| 1074 | }); | ||
| 1075 | |||
| 1076 | search_bar.update(cx, |search_bar, cx| { | ||
| 1077 | search_bar.select_all_matches(&SelectAllMatches, cx); | ||
| 1078 | let all_selections = | ||
| 1079 | editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)); | ||
| 1080 | assert_eq!( | ||
| 1081 | all_selections.len(), | ||
| 1082 | expected_query_matches_count, | ||
| 1083 | "Should select all `a` characters in the buffer, but got: {all_selections:?}" | ||
| 1084 | ); | ||
| 1085 | }); | ||
| 1086 | search_bar.update(cx, |search_bar, _| { | ||
| 1087 | assert_eq!( | ||
| 1088 | search_bar.active_match_index, | ||
| 1089 | Some(0), | ||
| 1090 | "Match index should not change after selecting all matches" | ||
| 1091 | ); | ||
| 1092 | }); | ||
| 1093 | |||
| 1094 | search_bar.update(cx, |search_bar, cx| { | ||
| 1095 | search_bar.select_next_match(&SelectNextMatch, cx); | ||
| 1096 | let all_selections = | ||
| 1097 | editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)); | ||
| 1098 | assert_eq!( | ||
| 1099 | all_selections.len(), | ||
| 1100 | 1, | ||
| 1101 | "On next match, should deselect items and select the next match" | ||
| 1102 | ); | ||
| 1103 | assert_ne!( | ||
| 1104 | all_selections, initial_selections, | ||
| 1105 | "Next match should be different from the first selection" | ||
| 1106 | ); | ||
| 1107 | }); | ||
| 1108 | search_bar.update(cx, |search_bar, _| { | ||
| 1109 | assert_eq!( | ||
| 1110 | search_bar.active_match_index, | ||
| 1111 | Some(1), | ||
| 1112 | "Match index should be updated to the next one" | ||
| 1113 | ); | ||
| 1114 | }); | ||
| 1115 | |||
| 1116 | search_bar.update(cx, |search_bar, cx| { | ||
| 1117 | search_bar.select_all_matches(&SelectAllMatches, cx); | ||
| 1118 | let all_selections = | ||
| 1119 | editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)); | ||
| 1120 | assert_eq!( | ||
| 1121 | all_selections.len(), | ||
| 1122 | expected_query_matches_count, | ||
| 1123 | "Should select all `a` characters in the buffer, but got: {all_selections:?}" | ||
| 1124 | ); | ||
| 1125 | }); | ||
| 1126 | search_bar.update(cx, |search_bar, _| { | ||
| 1127 | assert_eq!( | ||
| 1128 | search_bar.active_match_index, | ||
| 1129 | Some(1), | ||
| 1130 | "Match index should not change after selecting all matches" | ||
| 1131 | ); | ||
| 1132 | }); | ||
| 1133 | |||
| 1134 | search_bar.update(cx, |search_bar, cx| { | ||
| 1135 | search_bar.select_prev_match(&SelectPrevMatch, cx); | ||
| 1136 | let all_selections = | ||
| 1137 | editor.update(cx, |editor, cx| editor.selections.display_ranges(cx)); | ||
| 1138 | assert_eq!( | ||
| 1139 | all_selections.len(), | ||
| 1140 | 1, | ||
| 1141 | "On previous match, should deselect items and select the previous item" | ||
| 1142 | ); | ||
| 1143 | assert_eq!( | ||
| 1144 | all_selections, initial_selections, | ||
| 1145 | "Previous match should be the same as the first selection" | ||
| 1146 | ); | ||
| 1147 | }); | ||
| 1148 | search_bar.update(cx, |search_bar, _| { | ||
| 1149 | assert_eq!( | ||
| 1150 | search_bar.active_match_index, | ||
| 1151 | Some(0), | ||
| 1152 | "Match index should be updated to the previous one" | ||
| 1153 | ); | ||
| 1154 | }); | ||
| 1155 | } | ||
| 969 | } | 1156 | } |
| @@ -17,7 +17,8 @@ actions!( · 16 unmodified lines | |||
| 17 | ToggleCaseSensitive, | 17 | ToggleCaseSensitive, |
| 18 | ToggleRegex, | 18 | ToggleRegex, |
| 19 | SelectNextMatch, | 19 | SelectNextMatch, |
| 20 | SelectPrevMatch | 20 | SelectPrevMatch, |
| 21 | SelectAllMatches, | ||
| 21 | ] | 22 | ] |
| 22 | ); | 23 | ); |
| 23 | 24 | ||
| @@ -67,11 +67,13 @@ impl EmbeddingProvider for DummyEmbeddings { · 66 unmodified lines | |||
| 67 | } | 67 | } |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | const INPUT_LIMIT: usize = 8190; | ||
| 71 | |||
| 70 | impl OpenAIEmbeddings { | 72 | impl OpenAIEmbeddings { |
| 71 | async fn truncate(span: String) -> String { | 73 | fn truncate(span: String) -> String { |
| 72 | let mut tokens = OPENAI_BPE_TOKENIZER.encode_with_special_tokens(span.as_ref()); | 74 | let mut tokens = OPENAI_BPE_TOKENIZER.encode_with_special_tokens(span.as_ref()); |
| 73 | if tokens.len() > 8190 { | 75 | if tokens.len() > INPUT_LIMIT { |
| 74 | tokens.truncate(8190); | 76 | tokens.truncate(INPUT_LIMIT); |
| 75 | let result = OPENAI_BPE_TOKENIZER.decode(tokens.clone()); | 77 | let result = OPENAI_BPE_TOKENIZER.decode(tokens.clone()); |
| 76 | if result.is_ok() { | 78 | if result.is_ok() { |
| 77 | let transformed = result.unwrap(); | 79 | let transformed = result.unwrap(); |
| @@ -80,7 +82,7 @@ impl OpenAIEmbeddings { · 2 unmodified lines | |||
| 80 | } | 82 | } |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | return span.to_string(); | 85 | span |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | async fn send_request(&self, api_key: &str, spans: Vec<&str>) -> Result<Response<AsyncBody>> { | 88 | async fn send_request(&self, api_key: &str, spans: Vec<&str>) -> Result<Response<AsyncBody>> { |
| @@ -142,7 +144,7 @@ impl EmbeddingProvider for OpenAIEmbeddings { · 55 unmodified lines | |||
| 142 | // Don't worry about delaying bad request, as we can assume | 144 | // Don't worry about delaying bad request, as we can assume |
| 143 | // we haven't been rate limited yet. | 145 | // we haven't been rate limited yet. |
| 144 | for span in spans.iter_mut() { | 146 | for span in spans.iter_mut() { |
| 145 | *span = Self::truncate(span.to_string()).await; | 147 | *span = Self::truncate(span.to_string()); |
| 146 | } | 148 | } |
| 147 | } | 149 | } |
| 148 | StatusCode::OK => { | 150 | StatusCode::OK => { |
| @@ -198,7 +198,7 @@ impl TerminalLineHeight { · 197 unmodified lines | |||
| 198 | match self { | 198 | match self { |
| 199 | TerminalLineHeight::Comfortable => 1.618, | 199 | TerminalLineHeight::Comfortable => 1.618, |
| 200 | TerminalLineHeight::Standard => 1.3, | 200 | TerminalLineHeight::Standard => 1.3, |
| 201 | TerminalLineHeight::Custom(line_height) => *line_height, | 201 | TerminalLineHeight::Custom(line_height) => f32::max(*line_height, 1.), |
| 202 | } | 202 | } |
| 203 | } | 203 | } |
| 204 | } | 204 | } |
| @@ -908,6 +908,21 @@ impl Terminal { · 703 unmodified lines | |||
| 908 | } | 908 | } |
| 909 | } | 909 | } |
| 910 | 910 | ||
| 911 | pub fn select_matches(&mut self, matches: Vec<RangeInclusive<Point>>) { | ||
| 912 | let matches_to_select = self | ||
| 913 | .matches | ||
| 914 | .iter() | ||
| 915 | .filter(|self_match| matches.contains(self_match)) | ||
| 916 | .cloned() | ||
| 917 | .collect::<Vec<_>>(); | ||
| 918 | for match_to_select in matches_to_select { | ||
| 919 | self.set_selection(Some(( | ||
| 920 | make_selection(&match_to_select), | ||
| 921 | *match_to_select.end(), | ||
| 922 | ))); | ||
| 923 | } | ||
| 924 | } | ||
| 925 | |||
| 911 | fn set_selection(&mut self, selection: Option<(Selection, Point)>) { | 926 | fn set_selection(&mut self, selection: Option<(Selection, Point)>) { |
| 912 | self.events | 927 | self.events |
| 913 | .push_back(InternalEvent::SetSelection(selection)); | 928 | .push_back(InternalEvent::SetSelection(selection)); |
| @@ -647,7 +647,11 @@ impl SearchableItem for TerminalView { · 646 unmodified lines | |||
| 647 | } | 647 | } |
| 648 | 648 | ||
| 649 | /// Convert events raised by this item into search-relevant events (if applicable) | 649 | /// Convert events raised by this item into search-relevant events (if applicable) |
| 650 | fn to_search_event(event: &Self::Event) -> Option<SearchEvent> { | 650 | fn to_search_event( |
| 651 | &mut self, | ||
| 652 | event: &Self::Event, | ||
| 653 | _: &mut ViewContext<Self>, | ||
| 654 | ) -> Option<SearchEvent> { | ||
| 651 | match event { | 655 | match event { |
| 652 | Event::Wakeup => Some(SearchEvent::MatchesInvalidated), | 656 | Event::Wakeup => Some(SearchEvent::MatchesInvalidated), |
| 653 | Event::SelectionsChanged => Some(SearchEvent::ActiveMatchChanged), | 657 | Event::SelectionsChanged => Some(SearchEvent::ActiveMatchChanged), |
| @@ -682,6 +686,13 @@ impl SearchableItem for TerminalView { · 28 unmodified lines | |||
| 682 | cx.notify(); | 686 | cx.notify(); |
| 683 | } | 687 | } |
| 684 | 688 | ||
| 689 | /// Add selections for all matches given. | ||
| 690 | fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) { | ||
| 691 | self.terminal() | ||
| 692 | .update(cx, |term, _| term.select_matches(matches)); | ||
| 693 | cx.notify(); | ||
| 694 | } | ||
| 695 | |||
| 685 | /// Get all of the matches for this query, should be done on the background | 696 | /// Get all of the matches for this query, should be done on the background |
| 686 | fn find_matches( | 697 | fn find_matches( |
| 687 | &mut self, | 698 | &mut self, |
| @@ -350,6 +350,7 @@ pub struct Tab { · 349 unmodified lines | |||
| 350 | pub icon_close_active: Color, | 350 | pub icon_close_active: Color, |
| 351 | pub icon_dirty: Color, | 351 | pub icon_dirty: Color, |
| 352 | pub icon_conflict: Color, | 352 | pub icon_conflict: Color, |
| 353 | pub git: GitProjectStatus, | ||
| 353 | } | 354 | } |
| 354 | 355 | ||
| 355 | #[derive(Clone, Deserialize, Default, JsonSchema)] | 356 | #[derive(Clone, Deserialize, Default, JsonSchema)] |
| @@ -379,6 +380,7 @@ pub struct Search { · 23 unmodified lines | |||
| 379 | pub invalid_include_exclude_editor: ContainerStyle, | 380 | pub invalid_include_exclude_editor: ContainerStyle, |
| 380 | pub include_exclude_inputs: ContainedText, | 381 | pub include_exclude_inputs: ContainedText, |
| 381 | pub option_button: Toggleable<Interactive<ContainedText>>, | 382 | pub option_button: Toggleable<Interactive<ContainedText>>, |
| 383 | pub action_button: Interactive<ContainedText>, | ||
| 382 | pub match_background: Color, | 384 | pub match_background: Color, |
| 383 | pub match_index: ContainedText, | 385 | pub match_index: ContainedText, |
| 384 | pub results_status: TextStyle, | 386 | pub results_status: TextStyle, |
| @@ -721,12 +723,12 @@ pub struct Scrollbar { · 336 unmodified lines | |||
| 721 | pub thumb: ContainerStyle, | 723 | pub thumb: ContainerStyle, |
| 722 | pub width: f32, | 724 | pub width: f32, |
| 723 | pub min_height_factor: f32, | 725 | pub min_height_factor: f32, |
| 724 | pub git: GitDiffColors, | 726 | pub git: BufferGitDiffColors, |
| 725 | pub selections: Color, | 727 | pub selections: Color, |
| 726 | } | 728 | } |
| 727 | 729 | ||
| 728 | #[derive(Clone, Deserialize, Default, JsonSchema)] | 730 | #[derive(Clone, Deserialize, Default, JsonSchema)] |
| 729 | pub struct GitDiffColors { | 731 | pub struct BufferGitDiffColors { |
| 730 | pub inserted: Color, | 732 | pub inserted: Color, |
| 731 | pub modified: Color, | 733 | pub modified: Color, |
| 732 | pub deleted: Color, | 734 | pub deleted: Color, |
| @@ -5,6 +5,7 @@ use parking_lot::Mutex; · 4 unmodified lines | |||
| 5 | use serde::Deserialize; | 5 | use serde::Deserialize; |
| 6 | use serde_json::Value; | 6 | use serde_json::Value; |
| 7 | use std::{ | 7 | use std::{ |
| 8 | borrow::Cow, | ||
| 8 | collections::HashMap, | 9 | collections::HashMap, |
| 9 | sync::{ | 10 | sync::{ |
| 10 | atomic::{AtomicUsize, Ordering::SeqCst}, | 11 | atomic::{AtomicUsize, Ordering::SeqCst}, |
| @@ -43,7 +44,7 @@ impl ThemeRegistry { · 32 unmodified lines | |||
| 43 | this | 44 | this |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | pub fn list(&self, staff: bool) -> impl Iterator<Item = ThemeMeta> + '_ { | 47 | pub fn list_names(&self, staff: bool) -> impl Iterator<Item = Cow<str>> + '_ { |
| 47 | let mut dirs = self.assets.list("themes/"); | 48 | let mut dirs = self.assets.list("themes/"); |
| 48 | 49 | ||
| 49 | if !staff { | 50 | if !staff { |
| @@ -53,10 +54,21 @@ impl ThemeRegistry { · 3 unmodified lines | |||
| 53 | .collect() | 54 | .collect() |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | dirs.into_iter().filter_map(|path| { | 57 | fn get_name(path: &str) -> Option<&str> { |
| 57 | let filename = path.strip_prefix("themes/")?; | 58 | path.strip_prefix("themes/")?.strip_suffix(".json") |
| 58 | let theme_name = filename.strip_suffix(".json")?; | 59 | } |
| 59 | self.get(theme_name).ok().map(|theme| theme.meta.clone()) | 60 | |
| 61 | dirs.into_iter().filter_map(|path| match path { | ||
| 62 | Cow::Borrowed(path) => Some(Cow::Borrowed(get_name(path)?)), | ||
| 63 | Cow::Owned(path) => Some(Cow::Owned(get_name(&path)?.to_string())), | ||
| 64 | }) | ||
| 65 | } | ||
| 66 | |||
| 67 | pub fn list(&self, staff: bool) -> impl Iterator<Item = ThemeMeta> + '_ { | ||
| 68 | self.list_names(staff).filter_map(|theme_name| { | ||
| 69 | self.get(theme_name.as_ref()) | ||
| 70 | .ok() | ||
| 71 | .map(|theme| theme.meta.clone()) | ||
| 60 | }) | 72 | }) |
| 61 | } | 73 | } |
| 62 | 74 | ||
| @@ -13,6 +13,7 @@ use std::sync::Arc; · 12 unmodified lines | |||
| 13 | use util::ResultExt as _; | 13 | use util::ResultExt as _; |
| 14 | 14 | ||
| 15 | const MIN_FONT_SIZE: f32 = 6.0; | 15 | const MIN_FONT_SIZE: f32 = 6.0; |
| 16 | const MIN_LINE_HEIGHT: f32 = 1.0; | ||
| 16 | 17 | ||
| 17 | #[derive(Clone, JsonSchema)] | 18 | #[derive(Clone, JsonSchema)] |
| 18 | pub struct ThemeSettings { | 19 | pub struct ThemeSettings { |
| @@ -20,6 +21,7 @@ pub struct ThemeSettings { · 1 unmodified line | |||
| 20 | pub buffer_font_features: fonts::Features, | 21 | pub buffer_font_features: fonts::Features, |
| 21 | pub buffer_font_family: FamilyId, | 22 | pub buffer_font_family: FamilyId, |
| 22 | pub(crate) buffer_font_size: f32, | 23 | pub(crate) buffer_font_size: f32, |
| 24 | pub(crate) buffer_line_height: BufferLineHeight, | ||
| 23 | #[serde(skip)] | 25 | #[serde(skip)] |
| 24 | pub theme: Arc<Theme>, | 26 | pub theme: Arc<Theme>, |
| 25 | } | 27 | } |
| @@ -33,11 +35,32 @@ pub struct ThemeSettingsContent { · 7 unmodified lines | |||
| 33 | #[serde(default)] | 35 | #[serde(default)] |
| 34 | pub buffer_font_size: Option<f32>, | 36 | pub buffer_font_size: Option<f32>, |
| 35 | #[serde(default)] | 37 | #[serde(default)] |
| 38 | pub buffer_line_height: Option<BufferLineHeight>, | ||
| 39 | #[serde(default)] | ||
| 36 | pub buffer_font_features: Option<fonts::Features>, | 40 | pub buffer_font_features: Option<fonts::Features>, |
| 37 | #[serde(default)] | 41 | #[serde(default)] |
| 38 | pub theme: Option<String>, | 42 | pub theme: Option<String>, |
| 39 | } | 43 | } |
| 40 | 44 | ||
| 45 | #[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)] | ||
| 46 | #[serde(rename_all = "snake_case")] | ||
| 47 | pub enum BufferLineHeight { | ||
| 48 | #[default] | ||
| 49 | Comfortable, | ||
| 50 | Standard, | ||
| 51 | Custom(f32), | ||
| 52 | } | ||
| 53 | |||
| 54 | impl BufferLineHeight { | ||
| 55 | pub fn value(&self) -> f32 { | ||
| 56 | match self { | ||
| 57 | BufferLineHeight::Comfortable => 1.618, | ||
| 58 | BufferLineHeight::Standard => 1.3, | ||
| 59 | BufferLineHeight::Custom(line_height) => *line_height, | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 41 | impl ThemeSettings { | 64 | impl ThemeSettings { |
| 42 | pub fn buffer_font_size(&self, cx: &AppContext) -> f32 { | 65 | pub fn buffer_font_size(&self, cx: &AppContext) -> f32 { |
| 43 | if cx.has_global::<AdjustedBufferFontSize>() { | 66 | if cx.has_global::<AdjustedBufferFontSize>() { |
| @@ -47,6 +70,10 @@ impl ThemeSettings { · 3 unmodified lines | |||
| 47 | } | 70 | } |
| 48 | .max(MIN_FONT_SIZE) | 71 | .max(MIN_FONT_SIZE) |
| 49 | } | 72 | } |
| 73 | |||
| 74 | pub fn line_height(&self) -> f32 { | ||
| 75 | f32::max(self.buffer_line_height.value(), MIN_LINE_HEIGHT) | ||
| 76 | } | ||
| 50 | } | 77 | } |
| 51 | 78 | ||
| 52 | pub fn adjusted_font_size(size: f32, cx: &AppContext) -> f32 { | 79 | pub fn adjusted_font_size(size: f32, cx: &AppContext) -> f32 { |
| @@ -106,6 +133,7 @@ impl settings::Setting for ThemeSettings { · 53 unmodified lines | |||
| 106 | buffer_font_family_name: defaults.buffer_font_family.clone().unwrap(), | 133 | buffer_font_family_name: defaults.buffer_font_family.clone().unwrap(), |
| 107 | buffer_font_features, | 134 | buffer_font_features, |
| 108 | buffer_font_size: defaults.buffer_font_size.unwrap(), | 135 | buffer_font_size: defaults.buffer_font_size.unwrap(), |
| 136 | buffer_line_height: defaults.buffer_line_height.unwrap(), | ||
| 109 | theme: themes.get(defaults.theme.as_ref().unwrap()).unwrap(), | 137 | theme: themes.get(defaults.theme.as_ref().unwrap()).unwrap(), |
| 110 | }; | 138 | }; |
| 111 | 139 | ||
| @@ -136,6 +164,7 @@ impl settings::Setting for ThemeSettings { · 24 unmodified lines | |||
| 136 | } | 164 | } |
| 137 | 165 | ||
| 138 | merge(&mut this.buffer_font_size, value.buffer_font_size); | 166 | merge(&mut this.buffer_font_size, value.buffer_font_size); |
| 167 | merge(&mut this.buffer_line_height, value.buffer_line_height); | ||
| 139 | } | 168 | } |
| 140 | 169 | ||
| 141 | Ok(this) | 170 | Ok(this) |
| @@ -149,8 +178,8 @@ impl settings::Setting for ThemeSettings { · 7 unmodified lines | |||
| 149 | let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>(); | 178 | let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>(); |
| 150 | let theme_names = cx | 179 | let theme_names = cx |
| 151 | .global::<Arc<ThemeRegistry>>() | 180 | .global::<Arc<ThemeRegistry>>() |
| 152 | .list(params.staff_mode) | 181 | .list_names(params.staff_mode) |
| 153 | .map(|theme| Value::String(theme.name.clone())) | 182 | .map(|theme_name| Value::String(theme_name.to_string())) |
| 154 | .collect(); | 183 | .collect(); |
| 155 | 184 | ||
| 156 | let theme_name_schema = SchemaObject { | 185 | let theme_name_schema = SchemaObject { |
| @@ -120,7 +120,7 @@ impl PickerDelegate for ThemeSelectorDelegate { · 119 unmodified lines | |||
| 120 | self.matches.len() | 120 | self.matches.len() |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | fn confirm(&mut self, cx: &mut ViewContext<ThemeSelector>) { | 123 | fn confirm(&mut self, _: bool, cx: &mut ViewContext<ThemeSelector>) { |
| 124 | self.selection_completed = true; | 124 | self.selection_completed = true; |
| 125 | 125 | ||
| 126 | let theme_name = theme::current(cx).meta.name.clone(); | 126 | let theme_name = theme::current(cx).meta.name.clone(); |
| @@ -106,12 +106,14 @@ impl PickerDelegate for BranchListDelegate { · 105 unmodified lines | |||
| 106 | .read_with(&mut cx, |view, cx| { | 106 | .read_with(&mut cx, |view, cx| { |
| 107 | let delegate = view.delegate(); | 107 | let delegate = view.delegate(); |
| 108 | let project = delegate.workspace.read(cx).project().read(&cx); | 108 | let project = delegate.workspace.read(cx).project().read(&cx); |
| 109 | let mut cwd = | 109 | |
| 110 | project | 110 | let Some(worktree) = project |
| 111 | .visible_worktrees(cx) | 111 | .visible_worktrees(cx) |
| 112 | .next() | 112 | .next() |
| 113 | .unwrap() | 113 | else { |
| 114 | .read(cx) | 114 | bail!("Cannot update branch list as there are no visible worktrees") |
| 115 | }; | ||
| 116 | let mut cwd = worktree .read(cx) | ||
| 115 | .abs_path() | 117 | .abs_path() |
| 116 | .to_path_buf(); | 118 | .to_path_buf(); |
| 117 | cwd.push(".git"); | 119 | cwd.push(".git"); |
| @@ -180,9 +182,11 @@ impl PickerDelegate for BranchListDelegate { · 62 unmodified lines | |||
| 180 | }) | 182 | }) |
| 181 | } | 183 | } |
| 182 | 184 | ||
| 183 | fn confirm(&mut self, cx: &mut ViewContext<Picker<Self>>) { | 185 | fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<Self>>) { |
| 184 | let current_pick = self.selected_index(); | 186 | let current_pick = self.selected_index(); |
| 185 | let current_pick = self.matches[current_pick].string.clone(); | 187 | let Some(current_pick) = self.matches.get(current_pick).map(|pick| pick.string.clone()) else { |
| 188 | return; | ||
| 189 | }; | ||
| 186 | cx.spawn(|picker, mut cx| async move { | 190 | cx.spawn(|picker, mut cx| async move { |
| 187 | picker | 191 | picker |
| 188 | .update(&mut cx, |this, cx| { | 192 | .update(&mut cx, |this, cx| { |
| @@ -120,7 +120,7 @@ impl PickerDelegate for BaseKeymapSelectorDelegate { · 119 unmodified lines | |||
| 120 | }) | 120 | }) |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | fn confirm(&mut self, cx: &mut ViewContext<BaseKeymapSelector>) { | 123 | fn confirm(&mut self, _: bool, cx: &mut ViewContext<BaseKeymapSelector>) { |
| 124 | if let Some(selection) = self.matches.get(self.selected_index) { | 124 | if let Some(selection) = self.matches.get(self.selected_index) { |
| 125 | let base_keymap = BaseKeymap::from_names(&selection.string); | 125 | let base_keymap = BaseKeymap::from_names(&selection.string); |
| 126 | update_settings_file::<BaseKeymap>(self.fs.clone(), cx, move |setting| { | 126 | update_settings_file::<BaseKeymap>(self.fs.clone(), cx, move |setting| { |
| @@ -10,6 +10,9 @@ use gpui::{ · 9 unmodified lines | |||
| 10 | ViewContext, ViewHandle, WeakViewHandle, WindowContext, | 10 | ViewContext, ViewHandle, WeakViewHandle, WindowContext, |
| 11 | }; | 11 | }; |
| 12 | use project::{Project, ProjectEntryId, ProjectPath}; | 12 | use project::{Project, ProjectEntryId, ProjectPath}; |
| 13 | use schemars::JsonSchema; | ||
| 14 | use serde_derive::{Deserialize, Serialize}; | ||
| 15 | use settings::Setting; | ||
| 13 | use smallvec::SmallVec; | 16 | use smallvec::SmallVec; |
| 14 | use std::{ | 17 | use std::{ |
| 15 | any::{Any, TypeId}, | 18 | any::{Any, TypeId}, |
| @@ -27,6 +30,49 @@ use std::{ · 11 unmodified lines | |||
| 27 | }; | 30 | }; |
| 28 | use theme::Theme; | 31 | use theme::Theme; |
| 29 | 32 | ||
| 33 | #[derive(Deserialize)] | ||
| 34 | pub struct ItemSettings { | ||
| 35 | pub git_status: bool, | ||
| 36 | pub close_position: ClosePosition, | ||
| 37 | } | ||
| 38 | |||
| 39 | #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] | ||
| 40 | #[serde(rename_all = "lowercase")] | ||
| 41 | pub enum ClosePosition { | ||
| 42 | Left, | ||
| 43 | #[default] | ||
| 44 | Right, | ||
| 45 | } | ||
| 46 | |||
| 47 | impl ClosePosition { | ||
| 48 | pub fn right(&self) -> bool { | ||
| 49 | match self { | ||
| 50 | ClosePosition::Left => false, | ||
| 51 | ClosePosition::Right => true, | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] | ||
| 57 | pub struct ItemSettingsContent { | ||
| 58 | git_status: Option<bool>, | ||
| 59 | close_position: Option<ClosePosition>, | ||
| 60 | } | ||
| 61 | |||
| 62 | impl Setting for ItemSettings { | ||
| 63 | const KEY: Option<&'static str> = Some("tabs"); | ||
| 64 | |||
| 65 | type FileContent = ItemSettingsContent; | ||
| 66 | |||
| 67 | fn load( | ||
| 68 | default_value: &Self::FileContent, | ||
| 69 | user_values: &[&Self::FileContent], | ||
| 70 | _: &gpui::AppContext, | ||
| 71 | ) -> anyhow::Result<Self> { | ||
| 72 | Self::load_via_json_merge(default_value, user_values) | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 30 | #[derive(Eq, PartialEq, Hash, Debug)] | 76 | #[derive(Eq, PartialEq, Hash, Debug)] |
| 31 | pub enum ItemEvent { | 77 | pub enum ItemEvent { |
| 32 | CloseItem, | 78 | CloseItem, |
| @@ -3,14 +3,16 @@ mod dragged_item_receiver; · 2 unmodified lines | |||
| 3 | use super::{ItemHandle, SplitDirection}; | 3 | use super::{ItemHandle, SplitDirection}; |
| 4 | pub use crate::toolbar::Toolbar; | 4 | pub use crate::toolbar::Toolbar; |
| 5 | use crate::{ | 5 | use crate::{ |
| 6 | item::WeakItemHandle, notify_of_new_dock, AutosaveSetting, Item, NewCenterTerminal, NewFile, | 6 | item::{ItemSettings, WeakItemHandle}, |
| 7 | NewSearch, ToggleZoom, Workspace, WorkspaceSettings, | 7 | notify_of_new_dock, AutosaveSetting, Item, NewCenterTerminal, NewFile, NewSearch, ToggleZoom, |
| 8 | Workspace, WorkspaceSettings, | ||
| 8 | }; | 9 | }; |
| 9 | use anyhow::Result; | 10 | use anyhow::Result; |
| 10 | use collections::{HashMap, HashSet, VecDeque}; | 11 | use collections::{HashMap, HashSet, VecDeque}; |
| 11 | use context_menu::{ContextMenu, ContextMenuItem}; | 12 | use context_menu::{ContextMenu, ContextMenuItem}; |
| 12 | use drag_and_drop::{DragAndDrop, Draggable}; | 13 | use drag_and_drop::{DragAndDrop, Draggable}; |
| 13 | use dragged_item_receiver::dragged_item_receiver; | 14 | use dragged_item_receiver::dragged_item_receiver; |
| 15 | use fs::repository::GitFileStatus; | ||
| 14 | use futures::StreamExt; | 16 | use futures::StreamExt; |
| 15 | use gpui::{ | 17 | use gpui::{ |
| 16 | actions, | 18 | actions, |
| @@ -866,6 +868,7 @@ impl Pane { · 849 unmodified lines | |||
| 866 | .paths_by_item | 868 | .paths_by_item |
| 867 | .get(&item.id()) | 869 | .get(&item.id()) |
| 868 | .and_then(|(_, abs_path)| abs_path.clone()); | 870 | .and_then(|(_, abs_path)| abs_path.clone()); |
| 871 | |||
| 869 | self.nav_history | 872 | self.nav_history |
| 870 | .0 | 873 | .0 |
| 871 | .borrow_mut() | 874 | .borrow_mut() |
| @@ -1157,6 +1160,11 @@ impl Pane { · 285 unmodified lines | |||
| 1157 | .zip(self.tab_details(cx)) | 1160 | .zip(self.tab_details(cx)) |
| 1158 | .enumerate() | 1161 | .enumerate() |
| 1159 | { | 1162 | { |
| 1163 | let git_status = item | ||
| 1164 | .project_path(cx) | ||
| 1165 | .and_then(|path| self.project.read(cx).entry_for_path(&path, cx)) | ||
| 1166 | .and_then(|entry| entry.git_status()); | ||
| 1167 | |||
| 1160 | let detail = if detail == 0 { None } else { Some(detail) }; | 1168 | let detail = if detail == 0 { None } else { Some(detail) }; |
| 1161 | let tab_active = ix == self.active_item_index; | 1169 | let tab_active = ix == self.active_item_index; |
| 1162 | 1170 | ||
| @@ -1174,9 +1182,21 @@ impl Pane { · 11 unmodified lines | |||
| 1174 | let tab_tooltip_text = | 1182 | let tab_tooltip_text = |
| 1175 | item.tab_tooltip_text(cx).map(|text| text.into_owned()); | 1183 | item.tab_tooltip_text(cx).map(|text| text.into_owned()); |
| 1176 | 1184 | ||
| 1185 | let mut tab_style = theme | ||
| 1186 | .workspace | ||
| 1187 | .tab_bar | ||
| 1188 | .tab_style(pane_active, tab_active) | ||
| 1189 | .clone(); | ||
| 1190 | let should_show_status = settings::get::<ItemSettings>(cx).git_status; | ||
| 1191 | if should_show_status && git_status != None { | ||
| 1192 | tab_style.label.text.color = match git_status.unwrap() { | ||
| 1193 | GitFileStatus::Added => tab_style.git.inserted, | ||
| 1194 | GitFileStatus::Modified => tab_style.git.modified, | ||
| 1195 | GitFileStatus::Conflict => tab_style.git.conflict, | ||
| 1196 | }; | ||
| 1197 | } | ||
| 1198 | |||
| 1177 | move |mouse_state, cx| { | 1199 | move |mouse_state, cx| { |
| 1178 | let tab_style = | ||
| 1179 | theme.workspace.tab_bar.tab_style(pane_active, tab_active); | ||
| 1180 | let hovered = mouse_state.hovered(); | 1200 | let hovered = mouse_state.hovered(); |
| 1181 | 1201 | ||
| 1182 | enum Tab {} | 1202 | enum Tab {} |
| @@ -1188,7 +1208,7 @@ impl Pane { · 5 unmodified lines | |||
| 1188 | ix == 0, | 1208 | ix == 0, |
| 1189 | detail, | 1209 | detail, |
| 1190 | hovered, | 1210 | hovered, |
| 1191 | tab_style, | 1211 | &tab_style, |
| 1192 | cx, | 1212 | cx, |
| 1193 | ) | 1213 | ) |
| 1194 | }) | 1214 | }) |
| @@ -1350,81 +1370,94 @@ impl Pane { · 155 unmodified lines | |||
| 1350 | container.border.left = false; | 1370 | container.border.left = false; |
| 1351 | } | 1371 | } |
| 1352 | 1372 | ||
| 1353 | Flex::row() | 1373 | let buffer_jewel_element = { |
| 1354 | .with_child({ | 1374 | let diameter = 7.0; |
| 1355 | let diameter = 7.0; | 1375 | let icon_color = if item.has_conflict(cx) { |
| 1356 | let icon_color = if item.has_conflict(cx) { | 1376 | Some(tab_style.icon_conflict) |
| 1357 | Some(tab_style.icon_conflict) | 1377 | } else if item.is_dirty(cx) { |
| 1358 | } else if item.is_dirty(cx) { | 1378 | Some(tab_style.icon_dirty) |
| 1359 | Some(tab_style.icon_dirty) | 1379 | } else { |
| 1360 | } else { | 1380 | None |
| 1361 | None | 1381 | }; |
| 1362 | }; | ||
| 1363 | 1382 | ||
| 1364 | Canvas::new(move |scene, bounds, _, _, _| { | 1383 | Canvas::new(move |scene, bounds, _, _, _| { |
| 1365 | if let Some(color) = icon_color { | 1384 | if let Some(color) = icon_color { |
| 1366 | let square = RectF::new(bounds.origin(), vec2f(diameter, diameter)); | 1385 | let square = RectF::new(bounds.origin(), vec2f(diameter, diameter)); |
| 1367 | scene.push_quad(Quad { | 1386 | scene.push_quad(Quad { |
| 1368 | bounds: square, | 1387 | bounds: square, |
| 1369 | background: Some(color), | 1388 | background: Some(color), |
| 1370 | border: Default::default(), | 1389 | border: Default::default(), |
| 1371 | corner_radius: diameter / 2., | 1390 | corner_radius: diameter / 2., |
| 1372 | }); | 1391 | }); |
| 1373 | } | 1392 | } |
| 1374 | }) | ||
| 1375 | .constrained() | ||
| 1376 | .with_width(diameter) | ||
| 1377 | .with_height(diameter) | ||
| 1378 | .aligned() | ||
| 1379 | }) | 1393 | }) |
| 1380 | .with_child(title.aligned().contained().with_style(ContainerStyle { | 1394 | .constrained() |
| 1381 | margin: Margin { | 1395 | .with_width(diameter) |
| 1382 | left: tab_style.spacing, | 1396 | .with_height(diameter) |
| 1383 | right: tab_style.spacing, | 1397 | .aligned() |
| 1384 | ..Default::default() | 1398 | }; |
| 1385 | }, | 1399 | |
| 1400 | let title_element = title.aligned().contained().with_style(ContainerStyle { | ||
| 1401 | margin: Margin { | ||
| 1402 | left: tab_style.spacing, | ||
| 1403 | right: tab_style.spacing, | ||
| 1386 | ..Default::default() | 1404 | ..Default::default() |
| 1387 | })) | 1405 | }, |
| 1388 | .with_child( | 1406 | ..Default::default() |
| 1389 | if hovered { | 1407 | }); |
| 1390 | let item_id = item.id(); | 1408 | |
| 1391 | enum TabCloseButton {} | 1409 | let close_element = if hovered { |
| 1392 | let icon = Svg::new("icons/x_mark_8.svg"); | 1410 | let item_id = item.id(); |
| 1393 | MouseEventHandler::<TabCloseButton, _>::new(item_id, cx, |mouse_state, _| { | 1411 | enum TabCloseButton {} |
| 1394 | if mouse_state.hovered() { | 1412 | let icon = Svg::new("icons/x_mark_8.svg"); |
| 1395 | icon.with_color(tab_style.icon_close_active) | 1413 | MouseEventHandler::<TabCloseButton, _>::new(item_id, cx, |mouse_state, _| { |
| 1396 | } else { | 1414 | if mouse_state.hovered() { |
| 1397 | icon.with_color(tab_style.icon_close) | 1415 | icon.with_color(tab_style.icon_close_active) |
| 1398 | } | 1416 | } else { |
| 1399 | }) | 1417 | icon.with_color(tab_style.icon_close) |
| 1400 | .with_padding(Padding::uniform(4.)) | 1418 | } |
| 1401 | .with_cursor_style(CursorStyle::PointingHand) | 1419 | }) |
| 1402 | .on_click(MouseButton::Left, { | 1420 | .with_padding(Padding::uniform(4.)) |
| 1403 | let pane = pane.clone(); | 1421 | .with_cursor_style(CursorStyle::PointingHand) |
| 1404 | move |_, _, cx| { | 1422 | .on_click(MouseButton::Left, { |
| 1405 | let pane = pane.clone(); | 1423 | let pane = pane.clone(); |
| 1406 | cx.window_context().defer(move |cx| { | 1424 | move |_, _, cx| { |
| 1407 | if let Some(pane) = pane.upgrade(cx) { | 1425 | let pane = pane.clone(); |
| 1408 | pane.update(cx, |pane, cx| { | 1426 | cx.window_context().defer(move |cx| { |
| 1409 | pane.close_item_by_id(item_id, cx).detach_and_log_err(cx); | 1427 | if let Some(pane) = pane.upgrade(cx) { |
| 1410 | }); | 1428 | pane.update(cx, |pane, cx| { |
| 1411 | } | 1429 | pane.close_item_by_id(item_id, cx).detach_and_log_err(cx); |
| 1412 | }); | 1430 | }); |
| 1413 | } | 1431 | } |
| 1414 | }) | 1432 | }); |
| 1415 | .into_any_named("close-tab-icon") | ||
| 1416 | .constrained() | ||
| 1417 | } else { | ||
| 1418 | Empty::new().constrained() | ||
| 1419 | } | 1433 | } |
| 1420 | .with_width(tab_style.close_icon_width) | 1434 | }) |
| 1421 | .aligned(), | 1435 | .into_any_named("close-tab-icon") |
| 1422 | ) | ||
| 1423 | .contained() | ||
| 1424 | .with_style(container) | ||
| 1425 | .constrained() | 1436 | .constrained() |
| 1426 | .with_height(tab_style.height) | 1437 | } else { |
| 1427 | .into_any() | 1438 | Empty::new().constrained() |
| 1439 | } | ||
| 1440 | .with_width(tab_style.close_icon_width) | ||
| 1441 | .aligned(); | ||
| 1442 | |||
| 1443 | let close_right = settings::get::<ItemSettings>(cx).close_position.right(); | ||
| 1444 | |||
| 1445 | if close_right { | ||
| 1446 | Flex::row() | ||
| 1447 | .with_child(buffer_jewel_element) | ||
| 1448 | .with_child(title_element) | ||
| 1449 | .with_child(close_element) | ||
| 1450 | } else { | ||
| 1451 | Flex::row() | ||
| 1452 | .with_child(close_element) | ||
| 1453 | .with_child(title_element) | ||
| 1454 | .with_child(buffer_jewel_element) | ||
| 1455 | } | ||
| 1456 | .contained() | ||
| 1457 | .with_style(container) | ||
| 1458 | .constrained() | ||
| 1459 | .with_height(tab_style.height) | ||
| 1460 | .into_any() | ||
| 1428 | } | 1461 | } |
| 1429 | 1462 | ||
| 1430 | pub fn render_tab_bar_button< | 1463 | pub fn render_tab_bar_button< |
| @@ -1,6 +1,8 @@ | |||
| 1 | use std::sync::Arc; | 1 | use std::{cell::RefCell, rc::Rc, sync::Arc}; |
| 2 | 2 | ||
| 3 | use crate::{AppState, FollowerStatesByLeader, Pane, Workspace, WorkspaceSettings}; | 3 | use crate::{ |
| 4 | pane_group::element::PaneAxisElement, AppState, FollowerStatesByLeader, Pane, Workspace, | ||
| 5 | }; | ||
| 4 | use anyhow::{anyhow, Result}; | 6 | use anyhow::{anyhow, Result}; |
| 5 | use call::{ActiveCall, ParticipantLocation}; | 7 | use call::{ActiveCall, ParticipantLocation}; |
| 6 | use gpui::{ | 8 | use gpui::{ |
| @@ -13,7 +15,11 @@ use project::Project; · 6 unmodified lines | |||
| 13 | use serde::Deserialize; | 15 | use serde::Deserialize; |
| 14 | use theme::Theme; | 16 | use theme::Theme; |
| 15 | 17 | ||
| 16 | #[derive(Clone, Debug, Eq, PartialEq)] | 18 | const HANDLE_HITBOX_SIZE: f32 = 4.0; |
| 19 | const HORIZONTAL_MIN_SIZE: f32 = 80.; | ||
| 20 | const VERTICAL_MIN_SIZE: f32 = 100.; | ||
| 21 | |||
| 22 | #[derive(Clone, Debug, PartialEq)] | ||
| 17 | pub struct PaneGroup { | 23 | pub struct PaneGroup { |
| 18 | pub(crate) root: Member, | 24 | pub(crate) root: Member, |
| 19 | } | 25 | } |
| @@ -77,6 +83,7 @@ impl PaneGroup { · 57 unmodified lines | |||
| 77 | ) -> AnyElement<Workspace> { | 83 | ) -> AnyElement<Workspace> { |
| 78 | self.root.render( | 84 | self.root.render( |
| 79 | project, | 85 | project, |
| 86 | 0, | ||
| 80 | theme, | 87 | theme, |
| 81 | follower_states, | 88 | follower_states, |
| 82 | active_call, | 89 | active_call, |
| @@ -94,7 +101,7 @@ impl PaneGroup { · 11 unmodified lines | |||
| 94 | } | 101 | } |
| 95 | } | 102 | } |
| 96 | 103 | ||
| 97 | #[derive(Clone, Debug, Eq, PartialEq)] | 104 | #[derive(Clone, Debug, PartialEq)] |
| 98 | pub(crate) enum Member { | 105 | pub(crate) enum Member { |
| 99 | Axis(PaneAxis), | 106 | Axis(PaneAxis), |
| 100 | Pane(ViewHandle<Pane>), | 107 | Pane(ViewHandle<Pane>), |
| @@ -119,7 +126,7 @@ impl Member { · 18 unmodified lines | |||
| 119 | Down | Right => vec![Member::Pane(old_pane), Member::Pane(new_pane)], | 126 | Down | Right => vec![Member::Pane(old_pane), Member::Pane(new_pane)], |
| 120 | }; | 127 | }; |
| 121 | 128 | ||
| 122 | Member::Axis(PaneAxis { axis, members }) | 129 | Member::Axis(PaneAxis::new(axis, members)) |
| 123 | } | 130 | } |
| 124 | 131 | ||
| 125 | fn contains(&self, needle: &ViewHandle<Pane>) -> bool { | 132 | fn contains(&self, needle: &ViewHandle<Pane>) -> bool { |
| @@ -132,6 +139,7 @@ impl Member { · 6 unmodified lines | |||
| 132 | pub fn render( | 139 | pub fn render( |
| 133 | &self, | 140 | &self, |
| 134 | project: &ModelHandle<Project>, | 141 | project: &ModelHandle<Project>, |
| 142 | basis: usize, | ||
| 135 | theme: &Theme, | 143 | theme: &Theme, |
| 136 | follower_states: &FollowerStatesByLeader, | 144 | follower_states: &FollowerStatesByLeader, |
| 137 | active_call: Option<&ModelHandle<ActiveCall>>, | 145 | active_call: Option<&ModelHandle<ActiveCall>>, |
| @@ -272,6 +280,7 @@ impl Member { · 134 unmodified lines | |||
| 272 | } | 280 | } |
| 273 | Member::Axis(axis) => axis.render( | 281 | Member::Axis(axis) => axis.render( |
| 274 | project, | 282 | project, |
| 283 | basis + 1, | ||
| 275 | theme, | 284 | theme, |
| 276 | follower_states, | 285 | follower_states, |
| 277 | active_call, | 286 | active_call, |
| @@ -295,13 +304,35 @@ impl Member { · 17 unmodified lines | |||
| 295 | } | 304 | } |
| 296 | } | 305 | } |
| 297 | 306 | ||
| 298 | #[derive(Clone, Debug, Eq, PartialEq)] | 307 | #[derive(Clone, Debug, PartialEq)] |
| 299 | pub(crate) struct PaneAxis { | 308 | pub(crate) struct PaneAxis { |
| 300 | pub axis: Axis, | 309 | pub axis: Axis, |
| 301 | pub members: Vec<Member>, | 310 | pub members: Vec<Member>, |
| 311 | pub flexes: Rc<RefCell<Vec<f32>>>, | ||
| 302 | } | 312 | } |
| 303 | 313 | ||
| 304 | impl PaneAxis { | 314 | impl PaneAxis { |
| 315 | pub fn new(axis: Axis, members: Vec<Member>) -> Self { | ||
| 316 | let flexes = Rc::new(RefCell::new(vec![1.; members.len()])); | ||
| 317 | Self { | ||
| 318 | axis, | ||
| 319 | members, | ||
| 320 | flexes, | ||
| 321 | } | ||
| 322 | } | ||
| 323 | |||
| 324 | pub fn load(axis: Axis, members: Vec<Member>, flexes: Option<Vec<f32>>) -> Self { | ||
| 325 | let flexes = flexes.unwrap_or_else(|| vec![1.; members.len()]); | ||
| 326 | debug_assert!(members.len() == flexes.len()); | ||
| 327 | |||
| 328 | let flexes = Rc::new(RefCell::new(flexes)); | ||
| 329 | Self { | ||
| 330 | axis, | ||
| 331 | members, | ||
| 332 | flexes, | ||
| 333 | } | ||
| 334 | } | ||
| 335 | |||
| 305 | fn split( | 336 | fn split( |
| 306 | &mut self, | 337 | &mut self, |
| 307 | old_pane: &ViewHandle<Pane>, | 338 | old_pane: &ViewHandle<Pane>, |
| @@ -323,6 +354,7 @@ impl PaneAxis { · 15 unmodified lines | |||
| 323 | } | 354 | } |
| 324 | 355 | ||
| 325 | self.members.insert(idx, Member::Pane(new_pane.clone())); | 356 | self.members.insert(idx, Member::Pane(new_pane.clone())); |
| 357 | *self.flexes.borrow_mut() = vec![1.; self.members.len()]; | ||
| 326 | } else { | 358 | } else { |
| 327 | *member = | 359 | *member = |
| 328 | Member::new_axis(old_pane.clone(), new_pane.clone(), direction); | 360 | Member::new_axis(old_pane.clone(), new_pane.clone(), direction); |
| @@ -362,10 +394,13 @@ impl PaneAxis { · 33 unmodified lines | |||
| 362 | if found_pane { | 394 | if found_pane { |
| 363 | if let Some(idx) = remove_member { | 395 | if let Some(idx) = remove_member { |
| 364 | self.members.remove(idx); | 396 | self.members.remove(idx); |
| 397 | *self.flexes.borrow_mut() = vec![1.; self.members.len()]; | ||
| 365 | } | 398 | } |
| 366 | 399 | ||
| 367 | if self.members.len() == 1 { | 400 | if self.members.len() == 1 { |
| 368 | Ok(self.members.pop()) | 401 | let result = self.members.pop(); |
| 402 | *self.flexes.borrow_mut() = vec![1.; self.members.len()]; | ||
| 403 | Ok(result) | ||
| 369 | } else { | 404 | } else { |
| 370 | Ok(None) | 405 | Ok(None) |
| 371 | } | 406 | } |
| @@ -377,6 +412,7 @@ impl PaneAxis { · 5 unmodified lines | |||
| 377 | fn render( | 412 | fn render( |
| 378 | &self, | 413 | &self, |
| 379 | project: &ModelHandle<Project>, | 414 | project: &ModelHandle<Project>, |
| 415 | basis: usize, | ||
| 380 | theme: &Theme, | 416 | theme: &Theme, |
| 381 | follower_state: &FollowerStatesByLeader, | 417 | follower_state: &FollowerStatesByLeader, |
| 382 | active_call: Option<&ModelHandle<ActiveCall>>, | 418 | active_call: Option<&ModelHandle<ActiveCall>>, |
| @@ -385,40 +421,50 @@ impl PaneAxis { · 2 unmodified lines | |||
| 385 | app_state: &Arc<AppState>, | 421 | app_state: &Arc<AppState>, |
| 386 | cx: &mut ViewContext<Workspace>, | 422 | cx: &mut ViewContext<Workspace>, |
| 387 | ) -> AnyElement<Workspace> { | 423 | ) -> AnyElement<Workspace> { |
| 388 | let last_member_ix = self.members.len() - 1; | 424 | debug_assert!(self.members.len() == self.flexes.borrow().len()); |
| 389 | Flex::new(self.axis) | ||
| 390 | .with_children(self.members.iter().enumerate().map(|(ix, member)| { | ||
| 391 | let mut flex = 1.0; | ||
| 392 | if member.contains(active_pane) { | ||
| 393 | flex = settings::get::<WorkspaceSettings>(cx).active_pane_magnification; | ||
| 394 | } | ||
| 395 | 425 | ||
| 396 | let mut member = member.render( | 426 | let mut pane_axis = PaneAxisElement::new(self.axis, basis, self.flexes.clone()); |
| 397 | project, | 427 | let mut active_pane_ix = None; |
| 398 | theme, | 428 | |
| 399 | follower_state, | 429 | let mut members = self.members.iter().enumerate().peekable(); |
| 400 | active_call, | 430 | while let Some((ix, member)) = members.next() { |
| 401 | active_pane, | 431 | let last = members.peek().is_none(); |
| 402 | zoomed, | 432 | |
| 403 | app_state, | 433 | if member.contains(active_pane) { |
| 404 | cx, | 434 | active_pane_ix = Some(ix); |
| 405 | ); | 435 | } |
| 406 | if ix < last_member_ix { | 436 | |
| 407 | let mut border = theme.workspace.pane_divider; | 437 | let mut member = member.render( |
| 408 | border.left = false; | 438 | project, |
| 409 | border.right = false; | 439 | (basis + ix) * 10, |
| 410 | border.top = false; | 440 | theme, |
| 411 | border.bottom = false; | 441 | follower_state, |
| 412 | match self.axis { | 442 | active_call, |
| 413 | Axis::Vertical => border.bottom = true, | 443 | active_pane, |
| 414 | Axis::Horizontal => border.right = true, | 444 | zoomed, |
| 415 | } | 445 | app_state, |
| 416 | member = member.contained().with_border(border).into_any(); | 446 | cx, |
| 447 | ); | ||
| 448 | |||
| 449 | if !last { | ||
| 450 | let mut border = theme.workspace.pane_divider; | ||
| 451 | border.left = false; | ||
| 452 | border.right = false; | ||
| 453 | border.top = false; | ||
| 454 | border.bottom = false; | ||
| 455 | |||
| 456 | match self.axis { | ||
| 457 | Axis::Vertical => border.bottom = true, | ||
| 458 | Axis::Horizontal => border.right = true, | ||
| 417 | } | 459 | } |
| 418 | 460 | ||
| 419 | FlexItem::new(member).flex(flex, true) | 461 | member = member.contained().with_border(border).into_any(); |
| 420 | })) | 462 | } |
| 421 | .into_any() | 463 | |
| 464 | pane_axis = pane_axis.with_child(member.into_any()); | ||
| 465 | } | ||
| 466 | pane_axis.set_active_pane(active_pane_ix); | ||
| 467 | pane_axis.into_any() | ||
| 422 | } | 468 | } |
| 423 | } | 469 | } |
| 424 | 470 | ||
| @@ -474,3 +520,336 @@ impl SplitDirection { · 49 unmodified lines | |||
| 474 | } | 520 | } |
| 475 | } | 521 | } |
| 476 | } | 522 | } |
| 523 | |||
| 524 | mod element { | ||
| 525 | use std::{cell::RefCell, ops::Range, rc::Rc}; | ||
| 526 | |||
| 527 | use gpui::{ | ||
| 528 | geometry::{ | ||
| 529 | rect::RectF, | ||
| 530 | vector::{vec2f, Vector2F}, | ||
| 531 | }, | ||
| 532 | json::{self, ToJson}, | ||
| 533 | platform::{CursorStyle, MouseButton}, | ||
| 534 | AnyElement, Axis, CursorRegion, Element, LayoutContext, MouseRegion, RectFExt, | ||
| 535 | SceneBuilder, SizeConstraint, Vector2FExt, ViewContext, | ||
| 536 | }; | ||
| 537 | |||
| 538 | use crate::{ | ||
| 539 | pane_group::{HANDLE_HITBOX_SIZE, HORIZONTAL_MIN_SIZE, VERTICAL_MIN_SIZE}, | ||
| 540 | Workspace, WorkspaceSettings, | ||
| 541 | }; | ||
| 542 | |||
| 543 | pub struct PaneAxisElement { | ||
| 544 | axis: Axis, | ||
| 545 | basis: usize, | ||
| 546 | active_pane_ix: Option<usize>, | ||
| 547 | flexes: Rc<RefCell<Vec<f32>>>, | ||
| 548 | children: Vec<AnyElement<Workspace>>, | ||
| 549 | } | ||
| 550 | |||
| 551 | impl PaneAxisElement { | ||
| 552 | pub fn new(axis: Axis, basis: usize, flexes: Rc<RefCell<Vec<f32>>>) -> Self { | ||
| 553 | Self { | ||
| 554 | axis, | ||
| 555 | basis, | ||
| 556 | flexes, | ||
| 557 | active_pane_ix: None, | ||
| 558 | children: Default::default(), | ||
| 559 | } | ||
| 560 | } | ||
| 561 | |||
| 562 | pub fn set_active_pane(&mut self, active_pane_ix: Option<usize>) { | ||
| 563 | self.active_pane_ix = active_pane_ix; | ||
| 564 | } | ||
| 565 | |||
| 566 | fn layout_children( | ||
| 567 | &mut self, | ||
| 568 | active_pane_magnification: f32, | ||
| 569 | constraint: SizeConstraint, | ||
| 570 | remaining_space: &mut f32, | ||
| 571 | remaining_flex: &mut f32, | ||
| 572 | cross_axis_max: &mut f32, | ||
| 573 | view: &mut Workspace, | ||
| 574 | cx: &mut LayoutContext<Workspace>, | ||
| 575 | ) { | ||
| 576 | let flexes = self.flexes.borrow(); | ||
| 577 | let cross_axis = self.axis.invert(); | ||
| 578 | for (ix, child) in self.children.iter_mut().enumerate() { | ||
| 579 | let flex = if active_pane_magnification != 1. { | ||
| 580 | if let Some(active_pane_ix) = self.active_pane_ix { | ||
| 581 | if ix == active_pane_ix { | ||
| 582 | active_pane_magnification | ||
| 583 | } else { | ||
| 584 | 1. | ||
| 585 | } | ||
| 586 | } else { | ||
| 587 | 1. | ||
| 588 | } | ||
| 589 | } else { | ||
| 590 | flexes[ix] | ||
| 591 | }; | ||
| 592 | |||
| 593 | let child_size = if *remaining_flex == 0.0 { | ||
| 594 | *remaining_space | ||
| 595 | } else { | ||
| 596 | let space_per_flex = *remaining_space / *remaining_flex; | ||
| 597 | space_per_flex * flex | ||
| 598 | }; | ||
| 599 | |||
| 600 | let child_constraint = match self.axis { | ||
| 601 | Axis::Horizontal => SizeConstraint::new( | ||
| 602 | vec2f(child_size, constraint.min.y()), | ||
| 603 | vec2f(child_size, constraint.max.y()), | ||
| 604 | ), | ||
| 605 | Axis::Vertical => SizeConstraint::new( | ||
| 606 | vec2f(constraint.min.x(), child_size), | ||
| 607 | vec2f(constraint.max.x(), child_size), | ||
| 608 | ), | ||
| 609 | }; | ||
| 610 | let child_size = child.layout(child_constraint, view, cx); | ||
| 611 | *remaining_space -= child_size.along(self.axis); | ||
| 612 | *remaining_flex -= flex; | ||
| 613 | *cross_axis_max = cross_axis_max.max(child_size.along(cross_axis)); | ||
| 614 | } | ||
| 615 | } | ||
| 616 | } | ||
| 617 | |||
| 618 | impl Extend<AnyElement<Workspace>> for PaneAxisElement { | ||
| 619 | fn extend<T: IntoIterator<Item = AnyElement<Workspace>>>(&mut self, children: T) { | ||
| 620 | self.children.extend(children); | ||
| 621 | } | ||
| 622 | } | ||
| 623 | |||
| 624 | impl Element<Workspace> for PaneAxisElement { | ||
| 625 | type LayoutState = f32; | ||
| 626 | type PaintState = (); | ||
| 627 | |||
| 628 | fn layout( | ||
| 629 | &mut self, | ||
| 630 | constraint: SizeConstraint, | ||
| 631 | view: &mut Workspace, | ||
| 632 | cx: &mut LayoutContext<Workspace>, | ||
| 633 | ) -> (Vector2F, Self::LayoutState) { | ||
| 634 | debug_assert!(self.children.len() == self.flexes.borrow().len()); | ||
| 635 | |||
| 636 | let active_pane_magnification = | ||
| 637 | settings::get::<WorkspaceSettings>(cx).active_pane_magnification; | ||
| 638 | |||
| 639 | let mut remaining_flex = 0.; | ||
| 640 | |||
| 641 | if active_pane_magnification != 1. { | ||
| 642 | let active_pane_flex = self | ||
| 643 | .active_pane_ix | ||
| 644 | .map(|_| active_pane_magnification) | ||
| 645 | .unwrap_or(1.); | ||
| 646 | remaining_flex += self.children.len() as f32 - 1. + active_pane_flex; | ||
| 647 | } else { | ||
| 648 | for flex in self.flexes.borrow().iter() { | ||
| 649 | remaining_flex += flex; | ||
| 650 | } | ||
| 651 | } | ||
| 652 | |||
| 653 | let mut cross_axis_max: f32 = 0.0; | ||
| 654 | let mut remaining_space = constraint.max_along(self.axis); | ||
| 655 | |||
| 656 | if remaining_space.is_infinite() { | ||
| 657 | panic!("flex contains flexible children but has an infinite constraint along the flex axis"); | ||
| 658 | } | ||
| 659 | |||
| 660 | self.layout_children( | ||
| 661 | active_pane_magnification, | ||
| 662 | constraint, | ||
| 663 | &mut remaining_space, | ||
| 664 | &mut remaining_flex, | ||
| 665 | &mut cross_axis_max, | ||
| 666 | view, | ||
| 667 | cx, | ||
| 668 | ); | ||
| 669 | |||
| 670 | let mut size = match self.axis { | ||
| 671 | Axis::Horizontal => vec2f(constraint.max.x() - remaining_space, cross_axis_max), | ||
| 672 | Axis::Vertical => vec2f(cross_axis_max, constraint.max.y() - remaining_space), | ||
| 673 | }; | ||
| 674 | |||
| 675 | if constraint.min.x().is_finite() { | ||
| 676 | size.set_x(size.x().max(constraint.min.x())); | ||
| 677 | } | ||
| 678 | if constraint.min.y().is_finite() { | ||
| 679 | size.set_y(size.y().max(constraint.min.y())); | ||
| 680 | } | ||
| 681 | |||
| 682 | if size.x() > constraint.max.x() { | ||
| 683 | size.set_x(constraint.max.x()); | ||
| 684 | } | ||
| 685 | if size.y() > constraint.max.y() { | ||
| 686 | size.set_y(constraint.max.y()); | ||
| 687 | } | ||
| 688 | |||
| 689 | (size, remaining_space) | ||
| 690 | } | ||
| 691 | |||
| 692 | fn paint( | ||
| 693 | &mut self, | ||
| 694 | scene: &mut SceneBuilder, | ||
| 695 | bounds: RectF, | ||
| 696 | visible_bounds: RectF, | ||
| 697 | remaining_space: &mut Self::LayoutState, | ||
| 698 | view: &mut Workspace, | ||
| 699 | cx: &mut ViewContext<Workspace>, | ||
| 700 | ) -> Self::PaintState { | ||
| 701 | let can_resize = settings::get::<WorkspaceSettings>(cx).active_pane_magnification == 1.; | ||
| 702 | let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default(); | ||
| 703 | |||
| 704 | let overflowing = *remaining_space < 0.; | ||
| 705 | if overflowing { | ||
| 706 | scene.push_layer(Some(visible_bounds)); | ||
| 707 | } | ||
| 708 | |||
| 709 | let mut child_origin = bounds.origin(); | ||
| 710 | |||
| 711 | let mut children_iter = self.children.iter_mut().enumerate().peekable(); | ||
| 712 | while let Some((ix, child)) = children_iter.next() { | ||
| 713 | let child_start = child_origin.clone(); | ||
| 714 | child.paint(scene, child_origin, visible_bounds, view, cx); | ||
| 715 | |||
| 716 | match self.axis { | ||
| 717 | Axis::Horizontal => child_origin += vec2f(child.size().x(), 0.0), | ||
| 718 | Axis::Vertical => child_origin += vec2f(0.0, child.size().y()), | ||
| 719 | } | ||
| 720 | |||
| 721 | if let Some(Some((next_ix, next_child))) = can_resize.then(|| children_iter.peek()) | ||
| 722 | { | ||
| 723 | scene.push_stacking_context(None, None); | ||
| 724 | |||
| 725 | let handle_origin = match self.axis { | ||
| 726 | Axis::Horizontal => child_origin - vec2f(HANDLE_HITBOX_SIZE / 2., 0.0), | ||
| 727 | Axis::Vertical => child_origin - vec2f(0.0, HANDLE_HITBOX_SIZE / 2.), | ||
| 728 | }; | ||
| 729 | |||
| 730 | let handle_bounds = match self.axis { | ||
| 731 | Axis::Horizontal => RectF::new( | ||
| 732 | handle_origin, | ||
| 733 | vec2f(HANDLE_HITBOX_SIZE, visible_bounds.height()), | ||
| 734 | ), | ||
| 735 | Axis::Vertical => RectF::new( | ||
| 736 | handle_origin, | ||
| 737 | vec2f(visible_bounds.width(), HANDLE_HITBOX_SIZE), | ||
| 738 | ), | ||
| 739 | }; | ||
| 740 | |||
| 741 | let style = match self.axis { | ||
| 742 | Axis::Horizontal => CursorStyle::ResizeLeftRight, | ||
| 743 | Axis::Vertical => CursorStyle::ResizeUpDown, | ||
| 744 | }; | ||
| 745 | |||
| 746 | scene.push_cursor_region(CursorRegion { | ||
| 747 | bounds: handle_bounds, | ||
| 748 | style, | ||
| 749 | }); | ||
| 750 | |||
| 751 | let axis = self.axis; | ||
| 752 | let child_size = child.size(); | ||
| 753 | let next_child_size = next_child.size(); | ||
| 754 | let drag_bounds = visible_bounds.clone(); | ||
| 755 | let flexes = self.flexes.clone(); | ||
| 756 | let current_flex = flexes.borrow()[ix]; | ||
| 757 | let next_ix = *next_ix; | ||
| 758 | let next_flex = flexes.borrow()[next_ix]; | ||
| 759 | enum ResizeHandle {} | ||
| 760 | let mut mouse_region = MouseRegion::new::<ResizeHandle>( | ||
| 761 | cx.view_id(), | ||
| 762 | self.basis + ix, | ||
| 763 | handle_bounds, | ||
| 764 | ); | ||
| 765 | mouse_region = mouse_region.on_drag( | ||
| 766 | MouseButton::Left, | ||
| 767 | move |drag, workspace: &mut Workspace, cx| { | ||
| 768 | let min_size = match axis { | ||
| 769 | Axis::Horizontal => HORIZONTAL_MIN_SIZE, | ||
| 770 | Axis::Vertical => VERTICAL_MIN_SIZE, | ||
| 771 | }; | ||
| 772 | // Don't allow resizing to less than the minimum size, if elements are already too small | ||
| 773 | if min_size - 1. > child_size.along(axis) | ||
| 774 | || min_size - 1. > next_child_size.along(axis) | ||
| 775 | { | ||
| 776 | return; | ||
| 777 | } | ||
| 778 | |||
| 779 | let mut current_target_size = (drag.position - child_start).along(axis); | ||
| 780 | |||
| 781 | let proposed_current_pixel_change = | ||
| 782 | current_target_size - child_size.along(axis); | ||
| 783 | |||
| 784 | if proposed_current_pixel_change < 0. { | ||
| 785 | current_target_size = f32::max(current_target_size, min_size); | ||
| 786 | } else if proposed_current_pixel_change > 0. { | ||
| 787 | // TODO: cascade this change to other children if current item is at min size | ||
| 788 | let next_target_size = f32::max( | ||
| 789 | next_child_size.along(axis) - proposed_current_pixel_change, | ||
| 790 | min_size, | ||
| 791 | ); | ||
| 792 | current_target_size = f32::min( | ||
| 793 | current_target_size, | ||
| 794 | child_size.along(axis) + next_child_size.along(axis) | ||
| 795 | - next_target_size, | ||
| 796 | ); | ||
| 797 | } | ||
| 798 | |||
| 799 | let current_pixel_change = current_target_size - child_size.along(axis); | ||
| 800 | let flex_change = current_pixel_change / drag_bounds.length_along(axis); | ||
| 801 | let current_target_flex = current_flex + flex_change; | ||
| 802 | let next_target_flex = next_flex - flex_change; | ||
| 803 | |||
| 804 | let mut borrow = flexes.borrow_mut(); | ||
| 805 | *borrow.get_mut(ix).unwrap() = current_target_flex; | ||
| 806 | *borrow.get_mut(next_ix).unwrap() = next_target_flex; | ||
| 807 | |||
| 808 | workspace.schedule_serialize(cx); | ||
| 809 | cx.notify(); | ||
| 810 | }, | ||
| 811 | ); | ||
| 812 | scene.push_mouse_region(mouse_region); | ||
| 813 | |||
| 814 | scene.pop_stacking_context(); | ||
| 815 | } | ||
| 816 | } | ||
| 817 | |||
| 818 | if overflowing { | ||
| 819 | scene.pop_layer(); | ||
| 820 | } | ||
| 821 | } | ||
| 822 | |||
| 823 | fn rect_for_text_range( | ||
| 824 | &self, | ||
| 825 | range_utf16: Range<usize>, | ||
| 826 | _: RectF, | ||
| 827 | _: RectF, | ||
| 828 | _: &Self::LayoutState, | ||
| 829 | _: &Self::PaintState, | ||
| 830 | view: &Workspace, | ||
| 831 | cx: &ViewContext<Workspace>, | ||
| 832 | ) -> Option<RectF> { | ||
| 833 | self.children | ||
| 834 | .iter() | ||
| 835 | .find_map(|child| child.rect_for_text_range(range_utf16.clone(), view, cx)) | ||
| 836 | } | ||
| 837 | |||
| 838 | fn debug( | ||
| 839 | &self, | ||
| 840 | bounds: RectF, | ||
| 841 | _: &Self::LayoutState, | ||
| 842 | _: &Self::PaintState, | ||
| 843 | view: &Workspace, | ||
| 844 | cx: &ViewContext<Workspace>, | ||
| 845 | ) -> json::Value { | ||
| 846 | serde_json::json!({ | ||
| 847 | "type": "PaneAxis", | ||
| 848 | "bounds": bounds.to_json(), | ||
| 849 | "axis": self.axis.to_json(), | ||
| 850 | "flexes": *self.flexes.borrow(), | ||
| 851 | "children": self.children.iter().map(|child| child.debug(view, cx)).collect::<Vec<json::Value>>() | ||
| 852 | }) | ||
| 853 | } | ||
| 854 | } | ||
| 855 | } | ||
| @@ -45,6 +45,7 @@ define_connection! { · 44 unmodified lines | |||
| 45 | // parent_group_id: Option<usize>, // None indicates that this is the root node | 45 | // parent_group_id: Option<usize>, // None indicates that this is the root node |
| 46 | // position: Optiopn<usize>, // None indicates that this is the root node | 46 | // position: Optiopn<usize>, // None indicates that this is the root node |
| 47 | // axis: Option<Axis>, // 'Vertical', 'Horizontal' | 47 | // axis: Option<Axis>, // 'Vertical', 'Horizontal' |
| 48 | // flexes: Option<Vec<f32>>, // A JSON array of floats | ||
| 48 | // ) | 49 | // ) |
| 49 | // | 50 | // |
| 50 | // panes( | 51 | // panes( |
| @@ -168,7 +169,12 @@ define_connection! { · 117 unmodified lines | |||
| 168 | ALTER TABLE workspaces ADD COLUMN left_dock_zoom INTEGER; //bool | 169 | ALTER TABLE workspaces ADD COLUMN left_dock_zoom INTEGER; //bool |
| 169 | ALTER TABLE workspaces ADD COLUMN right_dock_zoom INTEGER; //bool | 170 | ALTER TABLE workspaces ADD COLUMN right_dock_zoom INTEGER; //bool |
| 170 | ALTER TABLE workspaces ADD COLUMN bottom_dock_zoom INTEGER; //bool | 171 | ALTER TABLE workspaces ADD COLUMN bottom_dock_zoom INTEGER; //bool |
| 171 | )]; | 172 | ), |
| 173 | // Add pane group flex data | ||
| 174 | sql!( | ||
| 175 | ALTER TABLE pane_groups ADD COLUMN flexes TEXT; | ||
| 176 | ) | ||
| 177 | ]; | ||
| 172 | } | 178 | } |
| 173 | 179 | ||
| 174 | impl WorkspaceDb { | 180 | impl WorkspaceDb { |
| @@ -359,38 +365,51 @@ impl WorkspaceDb { · 184 unmodified lines | |||
| 359 | group_id: Option<GroupId>, | 365 | group_id: Option<GroupId>, |
| 360 | ) -> Result<Vec<SerializedPaneGroup>> { | 366 | ) -> Result<Vec<SerializedPaneGroup>> { |
| 361 | type GroupKey = (Option<GroupId>, WorkspaceId); | 367 | type GroupKey = (Option<GroupId>, WorkspaceId); |
| 362 | type GroupOrPane = (Option<GroupId>, Option<Axis>, Option<PaneId>, Option<bool>); | 368 | type GroupOrPane = ( |
| 369 | Option<GroupId>, | ||
| 370 | Option<Axis>, | ||
| 371 | Option<PaneId>, | ||
| 372 | Option<bool>, | ||
| 373 | Option<String>, | ||
| 374 | ); | ||
| 363 | self.select_bound::<GroupKey, GroupOrPane>(sql!( | 375 | self.select_bound::<GroupKey, GroupOrPane>(sql!( |
| 364 | SELECT group_id, axis, pane_id, active | 376 | SELECT group_id, axis, pane_id, active, flexes |
| 365 | FROM (SELECT | 377 | FROM (SELECT |
| 366 | group_id, | 378 | group_id, |
| 367 | axis, | 379 | axis, |
| 368 | NULL as pane_id, | 380 | NULL as pane_id, |
| 369 | NULL as active, | 381 | NULL as active, |
| 370 | position, | 382 | position, |
| 371 | parent_group_id, | 383 | parent_group_id, |
| 372 | workspace_id | 384 | workspace_id, |
| 373 | FROM pane_groups | 385 | flexes |
| 386 | FROM pane_groups | ||
| 374 | UNION | 387 | UNION |
| 375 | SELECT | 388 | SELECT |
| 376 | NULL, | 389 | NULL, |
| 377 | NULL, | 390 | NULL, |
| 378 | center_panes.pane_id, | 391 | center_panes.pane_id, |
| 379 | panes.active as active, | 392 | panes.active as active, |
| 380 | position, | 393 | position, |
| 381 | parent_group_id, | 394 | parent_group_id, |
| 382 | panes.workspace_id as workspace_id | 395 | panes.workspace_id as workspace_id, |
| 383 | FROM center_panes | 396 | NULL |
| 384 | JOIN panes ON center_panes.pane_id = panes.pane_id) | 397 | FROM center_panes |
| 398 | JOIN panes ON center_panes.pane_id = panes.pane_id) | ||
| 385 | WHERE parent_group_id IS ? AND workspace_id = ? | 399 | WHERE parent_group_id IS ? AND workspace_id = ? |
| 386 | ORDER BY position | 400 | ORDER BY position |
| 387 | ))?((group_id, workspace_id))? | 401 | ))?((group_id, workspace_id))? |
| 388 | .into_iter() | 402 | .into_iter() |
| 389 | .map(|(group_id, axis, pane_id, active)| { | 403 | .map(|(group_id, axis, pane_id, active, flexes)| { |
| 390 | if let Some((group_id, axis)) = group_id.zip(axis) { | 404 | if let Some((group_id, axis)) = group_id.zip(axis) { |
| 405 | let flexes = flexes | ||
| 406 | .map(|flexes| serde_json::from_str::<Vec<f32>>(&flexes)) | ||
| 407 | .transpose()?; | ||
| 408 | |||
| 391 | Ok(SerializedPaneGroup::Group { | 409 | Ok(SerializedPaneGroup::Group { |
| 392 | axis, | 410 | axis, |
| 393 | children: self.get_pane_group(workspace_id, Some(group_id))?, | 411 | children: self.get_pane_group(workspace_id, Some(group_id))?, |
| 412 | flexes, | ||
| 394 | }) | 413 | }) |
| 395 | } else if let Some((pane_id, active)) = pane_id.zip(active) { | 414 | } else if let Some((pane_id, active)) = pane_id.zip(active) { |
| 396 | Ok(SerializedPaneGroup::Pane(SerializedPane::new( | 415 | Ok(SerializedPaneGroup::Pane(SerializedPane::new( |
| @@ -417,14 +436,34 @@ impl WorkspaceDb { · 20 unmodified lines | |||
| 417 | parent: Option<(GroupId, usize)>, | 436 | parent: Option<(GroupId, usize)>, |
| 418 | ) -> Result<()> { | 437 | ) -> Result<()> { |
| 419 | match pane_group { | 438 | match pane_group { |
| 420 | SerializedPaneGroup::Group { axis, children } => { | 439 | SerializedPaneGroup::Group { |
| 440 | axis, | ||
| 441 | children, | ||
| 442 | flexes, | ||
| 443 | } => { | ||
| 421 | let (parent_id, position) = unzip_option(parent); | 444 | let (parent_id, position) = unzip_option(parent); |
| 422 | 445 | ||
| 446 | let flex_string = flexes | ||
| 447 | .as_ref() | ||
| 448 | .map(|flexes| serde_json::json!(flexes).to_string()); | ||
| 449 | |||
| 423 | let group_id = conn.select_row_bound::<_, i64>(sql!( | 450 | let group_id = conn.select_row_bound::<_, i64>(sql!( |
| 424 | INSERT INTO pane_groups(workspace_id, parent_group_id, position, axis) | 451 | INSERT INTO pane_groups( |
| 425 | VALUES (?, ?, ?, ?) | 452 | workspace_id, |
| 453 | parent_group_id, | ||
| 454 | position, | ||
| 455 | axis, | ||
| 456 | flexes | ||
| 457 | ) | ||
| 458 | VALUES (?, ?, ?, ?, ?) | ||
| 426 | RETURNING group_id | 459 | RETURNING group_id |
| 427 | ))?((workspace_id, parent_id, position, *axis))? | 460 | ))?(( |
| 461 | workspace_id, | ||
| 462 | parent_id, | ||
| 463 | position, | ||
| 464 | *axis, | ||
| 465 | flex_string, | ||
| 466 | ))? | ||
| 428 | .ok_or_else(|| anyhow!("Couldn't retrieve group_id from inserted pane_group"))?; | 467 | .ok_or_else(|| anyhow!("Couldn't retrieve group_id from inserted pane_group"))?; |
| 429 | 468 | ||
| 430 | for (position, group) in children.iter().enumerate() { | 469 | for (position, group) in children.iter().enumerate() { |
| @@ -641,6 +680,14 @@ mod tests { · 210 unmodified lines | |||
| 641 | assert_eq!(test_text_1, "test-text-1"); | 680 | assert_eq!(test_text_1, "test-text-1"); |
| 642 | } | 681 | } |
| 643 | 682 | ||
| 683 | fn group(axis: gpui::Axis, children: Vec<SerializedPaneGroup>) -> SerializedPaneGroup { | ||
| 684 | SerializedPaneGroup::Group { | ||
| 685 | axis, | ||
| 686 | flexes: None, | ||
| 687 | children, | ||
| 688 | } | ||
| 689 | } | ||
| 690 | |||
| 644 | #[gpui::test] | 691 | #[gpui::test] |
| 645 | async fn test_full_workspace_serialization() { | 692 | async fn test_full_workspace_serialization() { |
| 646 | env_logger::try_init().ok(); | 693 | env_logger::try_init().ok(); |
| @@ -652,12 +699,12 @@ mod tests { · 5 unmodified lines | |||
| 652 | // | - - - | | | 699 | // | - - - | | |
| 653 | // | 3,4 | | | 700 | // | 3,4 | | |
| 654 | // ----------------- | 701 | // ----------------- |
| 655 | let center_group = SerializedPaneGroup::Group { | 702 | let center_group = group( |
| 656 | axis: gpui::Axis::Horizontal, | 703 | gpui::Axis::Horizontal, |
| 657 | children: vec![ | 704 | vec![ |
| 658 | SerializedPaneGroup::Group { | 705 | group( |
| 659 | axis: gpui::Axis::Vertical, | 706 | gpui::Axis::Vertical, |
| 660 | children: vec![ | 707 | vec![ |
| 661 | SerializedPaneGroup::Pane(SerializedPane::new( | 708 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 662 | vec![ | 709 | vec![ |
| 663 | SerializedItem::new("Terminal", 5, false), | 710 | SerializedItem::new("Terminal", 5, false), |
| @@ -673,7 +720,7 @@ mod tests { · 9 unmodified lines | |||
| 673 | false, | 720 | false, |
| 674 | )), | 721 | )), |
| 675 | ], | 722 | ], |
| 676 | }, | 723 | ), |
| 677 | SerializedPaneGroup::Pane(SerializedPane::new( | 724 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 678 | vec![ | 725 | vec![ |
| 679 | SerializedItem::new("Terminal", 9, false), | 726 | SerializedItem::new("Terminal", 9, false), |
| @@ -682,7 +729,7 @@ mod tests { · 2 unmodified lines | |||
| 682 | false, | 729 | false, |
| 683 | )), | 730 | )), |
| 684 | ], | 731 | ], |
| 685 | }; | 732 | ); |
| 686 | 733 | ||
| 687 | let workspace = SerializedWorkspace { | 734 | let workspace = SerializedWorkspace { |
| 688 | id: 5, | 735 | id: 5, |
| @@ -811,12 +858,12 @@ mod tests { · 122 unmodified lines | |||
| 811 | // | - - - | | | 858 | // | - - - | | |
| 812 | // | 3,4 | | | 859 | // | 3,4 | | |
| 813 | // ----------------- | 860 | // ----------------- |
| 814 | let center_pane = SerializedPaneGroup::Group { | 861 | let center_pane = group( |
| 815 | axis: gpui::Axis::Horizontal, | 862 | gpui::Axis::Horizontal, |
| 816 | children: vec![ | 863 | vec![ |
| 817 | SerializedPaneGroup::Group { | 864 | group( |
| 818 | axis: gpui::Axis::Vertical, | 865 | gpui::Axis::Vertical, |
| 819 | children: vec![ | 866 | vec![ |
| 820 | SerializedPaneGroup::Pane(SerializedPane::new( | 867 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 821 | vec![ | 868 | vec![ |
| 822 | SerializedItem::new("Terminal", 1, false), | 869 | SerializedItem::new("Terminal", 1, false), |
| @@ -832,7 +879,7 @@ mod tests { · 9 unmodified lines | |||
| 832 | true, | 879 | true, |
| 833 | )), | 880 | )), |
| 834 | ], | 881 | ], |
| 835 | }, | 882 | ), |
| 836 | SerializedPaneGroup::Pane(SerializedPane::new( | 883 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 837 | vec![ | 884 | vec![ |
| 838 | SerializedItem::new("Terminal", 5, true), | 885 | SerializedItem::new("Terminal", 5, true), |
| @@ -841,7 +888,7 @@ mod tests { · 2 unmodified lines | |||
| 841 | false, | 888 | false, |
| 842 | )), | 889 | )), |
| 843 | ], | 890 | ], |
| 844 | }; | 891 | ); |
| 845 | 892 | ||
| 846 | let workspace = default_workspace(&["/tmp"], ¢er_pane); | 893 | let workspace = default_workspace(&["/tmp"], ¢er_pane); |
| 847 | 894 | ||
| @@ -858,12 +905,12 @@ mod tests { · 10 unmodified lines | |||
| 858 | 905 | ||
| 859 | let db = WorkspaceDb(open_test_db("test_cleanup_panes").await); | 906 | let db = WorkspaceDb(open_test_db("test_cleanup_panes").await); |
| 860 | 907 | ||
| 861 | let center_pane = SerializedPaneGroup::Group { | 908 | let center_pane = group( |
| 862 | axis: gpui::Axis::Horizontal, | 909 | gpui::Axis::Horizontal, |
| 863 | children: vec![ | 910 | vec![ |
| 864 | SerializedPaneGroup::Group { | 911 | group( |
| 865 | axis: gpui::Axis::Vertical, | 912 | gpui::Axis::Vertical, |
| 866 | children: vec![ | 913 | vec![ |
| 867 | SerializedPaneGroup::Pane(SerializedPane::new( | 914 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 868 | vec![ | 915 | vec![ |
| 869 | SerializedItem::new("Terminal", 1, false), | 916 | SerializedItem::new("Terminal", 1, false), |
| @@ -879,7 +926,7 @@ mod tests { · 9 unmodified lines | |||
| 879 | true, | 926 | true, |
| 880 | )), | 927 | )), |
| 881 | ], | 928 | ], |
| 882 | }, | 929 | ), |
| 883 | SerializedPaneGroup::Pane(SerializedPane::new( | 930 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 884 | vec![ | 931 | vec![ |
| 885 | SerializedItem::new("Terminal", 5, false), | 932 | SerializedItem::new("Terminal", 5, false), |
| @@ -888,7 +935,7 @@ mod tests { · 2 unmodified lines | |||
| 888 | false, | 935 | false, |
| 889 | )), | 936 | )), |
| 890 | ], | 937 | ], |
| 891 | }; | 938 | ); |
| 892 | 939 | ||
| 893 | let id = &["/tmp"]; | 940 | let id = &["/tmp"]; |
| 894 | 941 | ||
| @@ -896,9 +943,9 @@ mod tests { · 1 unmodified line | |||
| 896 | 943 | ||
| 897 | db.save_workspace(workspace.clone()).await; | 944 | db.save_workspace(workspace.clone()).await; |
| 898 | 945 | ||
| 899 | workspace.center_group = SerializedPaneGroup::Group { | 946 | workspace.center_group = group( |
| 900 | axis: gpui::Axis::Vertical, | 947 | gpui::Axis::Vertical, |
| 901 | children: vec![ | 948 | vec![ |
| 902 | SerializedPaneGroup::Pane(SerializedPane::new( | 949 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 903 | vec![ | 950 | vec![ |
| 904 | SerializedItem::new("Terminal", 1, false), | 951 | SerializedItem::new("Terminal", 1, false), |
| @@ -914,7 +961,7 @@ mod tests { · 9 unmodified lines | |||
| 914 | true, | 961 | true, |
| 915 | )), | 962 | )), |
| 916 | ], | 963 | ], |
| 917 | }; | 964 | ); |
| 918 | 965 | ||
| 919 | db.save_workspace(workspace.clone()).await; | 966 | db.save_workspace(workspace.clone()).await; |
| 920 | 967 | ||
| @@ -127,10 +127,11 @@ impl Bind for DockData { · 126 unmodified lines | |||
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | #[derive(Debug, PartialEq, Eq, Clone)] | 130 | #[derive(Debug, PartialEq, Clone)] |
| 131 | pub enum SerializedPaneGroup { | 131 | pub enum SerializedPaneGroup { |
| 132 | Group { | 132 | Group { |
| 133 | axis: Axis, | 133 | axis: Axis, |
| 134 | flexes: Option<Vec<f32>>, | ||
| 134 | children: Vec<SerializedPaneGroup>, | 135 | children: Vec<SerializedPaneGroup>, |
| 135 | }, | 136 | }, |
| 136 | Pane(SerializedPane), | 137 | Pane(SerializedPane), |
| @@ -149,7 +150,7 @@ impl Default for SerializedPaneGroup { · 12 unmodified lines | |||
| 149 | impl SerializedPaneGroup { | 150 | impl SerializedPaneGroup { |
| 150 | #[async_recursion(?Send)] | 151 | #[async_recursion(?Send)] |
| 151 | pub(crate) async fn deserialize( | 152 | pub(crate) async fn deserialize( |
| 152 | &self, | 153 | self, |
| 153 | project: &ModelHandle<Project>, | 154 | project: &ModelHandle<Project>, |
| 154 | workspace_id: WorkspaceId, | 155 | workspace_id: WorkspaceId, |
| 155 | workspace: &WeakViewHandle<Workspace>, | 156 | workspace: &WeakViewHandle<Workspace>, |
| @@ -160,7 +161,11 @@ impl SerializedPaneGroup { · 4 unmodified lines | |||
| 160 | Vec<Option<Box<dyn ItemHandle>>>, | 161 | Vec<Option<Box<dyn ItemHandle>>>, |
| 161 | )> { | 162 | )> { |
| 162 | match self { | 163 | match self { |
| 163 | SerializedPaneGroup::Group { axis, children } => { | 164 | SerializedPaneGroup::Group { |
| 165 | axis, | ||
| 166 | children, | ||
| 167 | flexes, | ||
| 168 | } => { | ||
| 164 | let mut current_active_pane = None; | 169 | let mut current_active_pane = None; |
| 165 | let mut members = Vec::new(); | 170 | let mut members = Vec::new(); |
| 166 | let mut items = Vec::new(); | 171 | let mut items = Vec::new(); |
| @@ -184,10 +189,7 @@ impl SerializedPaneGroup { · 17 unmodified lines | |||
| 184 | } | 189 | } |
| 185 | 190 | ||
| 186 | Some(( | 191 | Some(( |
| 187 | Member::Axis(PaneAxis { | 192 | Member::Axis(PaneAxis::load(axis, members, flexes)), |
| 188 | axis: *axis, | ||
| 189 | members, | ||
| 190 | }), | ||
| 191 | current_active_pane, | 193 | current_active_pane, |
| 192 | items, | 194 | items, |
| 193 | )) | 195 | )) |
| @@ -37,7 +37,11 @@ pub trait SearchableItem: Item { · 36 unmodified lines | |||
| 37 | regex: true, | 37 | regex: true, |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | fn to_search_event(event: &Self::Event) -> Option<SearchEvent>; | 40 | fn to_search_event( |
| 41 | &mut self, | ||
| 42 | event: &Self::Event, | ||
| 43 | cx: &mut ViewContext<Self>, | ||
| 44 | ) -> Option<SearchEvent>; | ||
| 41 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>); | 45 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>); |
| 42 | fn update_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>); | 46 | fn update_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>); |
| 43 | fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String; | 47 | fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String; |
| @@ -47,6 +51,7 @@ pub trait SearchableItem: Item { · 3 unmodified lines | |||
| 47 | matches: Vec<Self::Match>, | 51 | matches: Vec<Self::Match>, |
| 48 | cx: &mut ViewContext<Self>, | 52 | cx: &mut ViewContext<Self>, |
| 49 | ); | 53 | ); |
| 54 | fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>); | ||
| 50 | fn match_index_for_direction( | 55 | fn match_index_for_direction( |
| 51 | &mut self, | 56 | &mut self, |
| 52 | matches: &Vec<Self::Match>, | 57 | matches: &Vec<Self::Match>, |
| @@ -102,6 +107,7 @@ pub trait SearchableItemHandle: ItemHandle { · 49 unmodified lines | |||
| 102 | matches: &Vec<Box<dyn Any + Send>>, | 107 | matches: &Vec<Box<dyn Any + Send>>, |
| 103 | cx: &mut WindowContext, | 108 | cx: &mut WindowContext, |
| 104 | ); | 109 | ); |
| 110 | fn select_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut WindowContext); | ||
| 105 | fn match_index_for_direction( | 111 | fn match_index_for_direction( |
| 106 | &self, | 112 | &self, |
| 107 | matches: &Vec<Box<dyn Any + Send>>, | 113 | matches: &Vec<Box<dyn Any + Send>>, |
| @@ -139,8 +145,9 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> { · 31 unmodified lines | |||
| 139 | cx: &mut WindowContext, | 145 | cx: &mut WindowContext, |
| 140 | handler: Box<dyn Fn(SearchEvent, &mut WindowContext)>, | 146 | handler: Box<dyn Fn(SearchEvent, &mut WindowContext)>, |
| 141 | ) -> Subscription { | 147 | ) -> Subscription { |
| 142 | cx.subscribe(self, move |_, event, cx| { | 148 | cx.subscribe(self, move |handle, event, cx| { |
| 143 | if let Some(search_event) = T::to_search_event(event) { | 149 | let search_event = handle.update(cx, |handle, cx| handle.to_search_event(event, cx)); |
| 150 | if let Some(search_event) = search_event { | ||
| 144 | handler(search_event, cx) | 151 | handler(search_event, cx) |
| 145 | } | 152 | } |
| 146 | }) | 153 | }) |
| @@ -165,6 +172,12 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> { · 18 unmodified lines | |||
| 165 | let matches = downcast_matches(matches); | 172 | let matches = downcast_matches(matches); |
| 166 | self.update(cx, |this, cx| this.activate_match(index, matches, cx)); | 173 | self.update(cx, |this, cx| this.activate_match(index, matches, cx)); |
| 167 | } | 174 | } |
| 175 | |||
| 176 | fn select_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut WindowContext) { | ||
| 177 | let matches = downcast_matches(matches); | ||
| 178 | self.update(cx, |this, cx| this.select_matches(matches, cx)); | ||
| 179 | } | ||
| 180 | |||
| 168 | fn match_index_for_direction( | 181 | fn match_index_for_direction( |
| 169 | &self, | 182 | &self, |
| 170 | matches: &Vec<Box<dyn Any + Send>>, | 183 | matches: &Vec<Box<dyn Any + Send>>, |
| @@ -1,8 +1,4 @@ | |||
| 1 | pub mod dock; | 1 | pub mod dock; |
| 2 | /// NOTE: Focus only 'takes' after an update has flushed_effects. | ||
| 3 | /// | ||
| 4 | /// This may cause issues when you're trying to write tests that use workspace focus to add items at | ||
| 5 | /// specific locations. | ||
| 6 | pub mod item; | 2 | pub mod item; |
| 7 | pub mod notifications; | 3 | pub mod notifications; |
| 8 | pub mod pane; | 4 | pub mod pane; |
| @@ -207,6 +203,7 @@ pub type WorkspaceId = i64; · 198 unmodified lines | |||
| 207 | 203 | ||
| 208 | pub fn init_settings(cx: &mut AppContext) { | 204 | pub fn init_settings(cx: &mut AppContext) { |
| 209 | settings::register::<WorkspaceSettings>(cx); | 205 | settings::register::<WorkspaceSettings>(cx); |
| 206 | settings::register::<item::ItemSettings>(cx); | ||
| 210 | } | 207 | } |
| 211 | 208 | ||
| 212 | pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) { | 209 | pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) { |
| @@ -508,6 +505,7 @@ pub struct Workspace { · 295 unmodified lines | |||
| 508 | subscriptions: Vec<Subscription>, | 505 | subscriptions: Vec<Subscription>, |
| 509 | _apply_leader_updates: Task<Result<()>>, | 506 | _apply_leader_updates: Task<Result<()>>, |
| 510 | _observe_current_user: Task<Result<()>>, | 507 | _observe_current_user: Task<Result<()>>, |
| 508 | _schedule_serialize: Option<Task<()>>, | ||
| 511 | pane_history_timestamp: Arc<AtomicUsize>, | 509 | pane_history_timestamp: Arc<AtomicUsize>, |
| 512 | } | 510 | } |
| 513 | 511 | ||
| @@ -722,6 +720,7 @@ impl Workspace { · 208 unmodified lines | |||
| 722 | app_state, | 720 | app_state, |
| 723 | _observe_current_user, | 721 | _observe_current_user, |
| 724 | _apply_leader_updates, | 722 | _apply_leader_updates, |
| 723 | _schedule_serialize: None, | ||
| 725 | leader_updates_tx, | 724 | leader_updates_tx, |
| 726 | subscriptions, | 725 | subscriptions, |
| 727 | pane_history_timestamp, | 726 | pane_history_timestamp, |
| @@ -1823,6 +1822,13 @@ impl Workspace { · 1095 unmodified lines | |||
| 1823 | .update(cx, |pane, cx| pane.add_item(item, true, true, None, cx)); | 1822 | .update(cx, |pane, cx| pane.add_item(item, true, true, None, cx)); |
| 1824 | } | 1823 | } |
| 1825 | 1824 | ||
| 1825 | pub fn split_item(&mut self, item: Box<dyn ItemHandle>, cx: &mut ViewContext<Self>) { | ||
| 1826 | let new_pane = self.split_pane(self.active_pane.clone(), SplitDirection::Right, cx); | ||
| 1827 | new_pane.update(cx, move |new_pane, cx| { | ||
| 1828 | new_pane.add_item(item, true, true, None, cx) | ||
| 1829 | }) | ||
| 1830 | } | ||
| 1831 | |||
| 1826 | pub fn open_abs_path( | 1832 | pub fn open_abs_path( |
| 1827 | &mut self, | 1833 | &mut self, |
| 1828 | abs_path: PathBuf, | 1834 | abs_path: PathBuf, |
| @@ -1853,6 +1859,21 @@ impl Workspace { · 24 unmodified lines | |||
| 1853 | }) | 1859 | }) |
| 1854 | } | 1860 | } |
| 1855 | 1861 | ||
| 1862 | pub fn split_abs_path( | ||
| 1863 | &mut self, | ||
| 1864 | abs_path: PathBuf, | ||
| 1865 | visible: bool, | ||
| 1866 | cx: &mut ViewContext<Self>, | ||
| 1867 | ) -> Task<anyhow::Result<Box<dyn ItemHandle>>> { | ||
| 1868 | let project_path_task = | ||
| 1869 | Workspace::project_path_for_path(self.project.clone(), &abs_path, visible, cx); | ||
| 1870 | cx.spawn(|this, mut cx| async move { | ||
| 1871 | let (_, path) = project_path_task.await?; | ||
| 1872 | this.update(&mut cx, |this, cx| this.split_path(path, cx))? | ||
| 1873 | .await | ||
| 1874 | }) | ||
| 1875 | } | ||
| 1876 | |||
| 1856 | pub fn open_path( | 1877 | pub fn open_path( |
| 1857 | &mut self, | 1878 | &mut self, |
| 1858 | path: impl Into<ProjectPath>, | 1879 | path: impl Into<ProjectPath>, |
| @@ -1878,6 +1899,38 @@ impl Workspace { · 19 unmodified lines | |||
| 1878 | }) | 1899 | }) |
| 1879 | } | 1900 | } |
| 1880 | 1901 | ||
| 1902 | pub fn split_path( | ||
| 1903 | &mut self, | ||
| 1904 | path: impl Into<ProjectPath>, | ||
| 1905 | cx: &mut ViewContext<Self>, | ||
| 1906 | ) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> { | ||
| 1907 | let pane = self.last_active_center_pane.clone().unwrap_or_else(|| { | ||
| 1908 | self.panes | ||
| 1909 | .first() | ||
| 1910 | .expect("There must be an active pane") | ||
| 1911 | .downgrade() | ||
| 1912 | }); | ||
| 1913 | |||
| 1914 | if let Member::Pane(center_pane) = &self.center.root { | ||
| 1915 | if center_pane.read(cx).items_len() == 0 { | ||
| 1916 | return self.open_path(path, Some(pane), true, cx); | ||
| 1917 | } | ||
| 1918 | } | ||
| 1919 | |||
| 1920 | let task = self.load_path(path.into(), cx); | ||
| 1921 | cx.spawn(|this, mut cx| async move { | ||
| 1922 | let (project_entry_id, build_item) = task.await?; | ||
| 1923 | this.update(&mut cx, move |this, cx| -> Option<_> { | ||
| 1924 | let pane = pane.upgrade(cx)?; | ||
| 1925 | let new_pane = this.split_pane(pane, SplitDirection::Right, cx); | ||
| 1926 | new_pane.update(cx, |new_pane, cx| { | ||
| 1927 | Some(new_pane.open_item(project_entry_id, true, cx, build_item)) | ||
| 1928 | }) | ||
| 1929 | }) | ||
| 1930 | .map(|option| option.ok_or_else(|| anyhow!("pane was dropped")))? | ||
| 1931 | }) | ||
| 1932 | } | ||
| 1933 | |||
| 1881 | pub(crate) fn load_path( | 1934 | pub(crate) fn load_path( |
| 1882 | &mut self, | 1935 | &mut self, |
| 1883 | path: ProjectPath, | 1936 | path: ProjectPath, |
| @@ -1928,6 +1981,30 @@ impl Workspace { · 44 unmodified lines | |||
| 1928 | item | 1981 | item |
| 1929 | } | 1982 | } |
| 1930 | 1983 | ||
| 1984 | pub fn split_project_item<T>( | ||
| 1985 | &mut self, | ||
| 1986 | project_item: ModelHandle<T::Item>, | ||
| 1987 | cx: &mut ViewContext<Self>, | ||
| 1988 | ) -> ViewHandle<T> | ||
| 1989 | where | ||
| 1990 | T: ProjectItem, | ||
| 1991 | { | ||
| 1992 | use project::Item as _; | ||
| 1993 | |||
| 1994 | let entry_id = project_item.read(cx).entry_id(cx); | ||
| 1995 | if let Some(item) = entry_id | ||
| 1996 | .and_then(|entry_id| self.active_pane().read(cx).item_for_entry(entry_id, cx)) | ||
| 1997 | .and_then(|item| item.downcast()) | ||
| 1998 | { | ||
| 1999 | self.activate_item(&item, cx); | ||
| 2000 | return item; | ||
| 2001 | } | ||
| 2002 | |||
| 2003 | let item = cx.add_view(|cx| T::for_project_item(self.project().clone(), project_item, cx)); | ||
| 2004 | self.split_item(Box::new(item.clone()), cx); | ||
| 2005 | item | ||
| 2006 | } | ||
| 2007 | |||
| 1931 | pub fn open_shared_screen(&mut self, peer_id: PeerId, cx: &mut ViewContext<Self>) { | 2008 | pub fn open_shared_screen(&mut self, peer_id: PeerId, cx: &mut ViewContext<Self>) { |
| 1932 | if let Some(shared_screen) = self.shared_screen_for_peer(peer_id, &self.active_pane, cx) { | 2009 | if let Some(shared_screen) = self.shared_screen_for_peer(peer_id, &self.active_pane, cx) { |
| 1933 | self.active_pane.update(cx, |pane, cx| { | 2010 | self.active_pane.update(cx, |pane, cx| { |
| @@ -1955,7 +2032,7 @@ impl Workspace { · 21 unmodified lines | |||
| 1955 | if let Some(pane) = panes.get(action.0).map(|p| (*p).clone()) { | 2032 | if let Some(pane) = panes.get(action.0).map(|p| (*p).clone()) { |
| 1956 | cx.focus(&pane); | 2033 | cx.focus(&pane); |
| 1957 | } else { | 2034 | } else { |
| 1958 | self.split_pane(self.active_pane.clone(), SplitDirection::Right, cx); | 2035 | self.split_and_clone(self.active_pane.clone(), SplitDirection::Right, cx); |
| 1959 | } | 2036 | } |
| 1960 | } | 2037 | } |
| 1961 | 2038 | ||
| @@ -2008,7 +2085,7 @@ impl Workspace { · 46 unmodified lines | |||
| 2008 | match event { | 2085 | match event { |
| 2009 | pane::Event::AddItem { item } => item.added_to_pane(self, pane, cx), | 2086 | pane::Event::AddItem { item } => item.added_to_pane(self, pane, cx), |
| 2010 | pane::Event::Split(direction) => { | 2087 | pane::Event::Split(direction) => { |
| 2011 | self.split_pane(pane, *direction, cx); | 2088 | self.split_and_clone(pane, *direction, cx); |
| 2012 | } | 2089 | } |
| 2013 | pane::Event::Remove => self.remove_pane(pane, cx), | 2090 | pane::Event::Remove => self.remove_pane(pane, cx), |
| 2014 | pane::Event::ActivateItem { local } => { | 2091 | pane::Event::ActivateItem { local } => { |
| @@ -2059,6 +2136,20 @@ impl Workspace { · 44 unmodified lines | |||
| 2059 | } | 2136 | } |
| 2060 | 2137 | ||
| 2061 | pub fn split_pane( | 2138 | pub fn split_pane( |
| 2139 | &mut self, | ||
| 2140 | pane_to_split: ViewHandle<Pane>, | ||
| 2141 | split_direction: SplitDirection, | ||
| 2142 | cx: &mut ViewContext<Self>, | ||
| 2143 | ) -> ViewHandle<Pane> { | ||
| 2144 | let new_pane = self.add_pane(cx); | ||
| 2145 | self.center | ||
| 2146 | .split(&pane_to_split, &new_pane, split_direction) | ||
| 2147 | .unwrap(); | ||
| 2148 | cx.notify(); | ||
| 2149 | new_pane | ||
| 2150 | } | ||
| 2151 | |||
| 2152 | pub fn split_and_clone( | ||
| 2062 | &mut self, | 2153 | &mut self, |
| 2063 | pane: ViewHandle<Pane>, | 2154 | pane: ViewHandle<Pane>, |
| 2064 | direction: SplitDirection, | 2155 | direction: SplitDirection, |
| @@ -2897,6 +2988,14 @@ impl Workspace { · 832 unmodified lines | |||
| 2897 | cx.notify(); | 2988 | cx.notify(); |
| 2898 | } | 2989 | } |
| 2899 | 2990 | ||
| 2991 | fn schedule_serialize(&mut self, cx: &mut ViewContext<Self>) { | ||
| 2992 | self._schedule_serialize = Some(cx.spawn(|this, cx| async move { | ||
| 2993 | cx.background().timer(Duration::from_millis(100)).await; | ||
| 2994 | this.read_with(&cx, |this, cx| this.serialize_workspace(cx)) | ||
| 2995 | .ok(); | ||
| 2996 | })); | ||
| 2997 | } | ||
| 2998 | |||
| 2900 | fn serialize_workspace(&self, cx: &ViewContext<Self>) { | 2999 | fn serialize_workspace(&self, cx: &ViewContext<Self>) { |
| 2901 | fn serialize_pane_handle( | 3000 | fn serialize_pane_handle( |
| 2902 | pane_handle: &ViewHandle<Pane>, | 3001 | pane_handle: &ViewHandle<Pane>, |
| @@ -2927,12 +3026,17 @@ impl Workspace { · 24 unmodified lines | |||
| 2927 | cx: &AppContext, | 3026 | cx: &AppContext, |
| 2928 | ) -> SerializedPaneGroup { | 3027 | ) -> SerializedPaneGroup { |
| 2929 | match pane_group { | 3028 | match pane_group { |
| 2930 | Member::Axis(PaneAxis { axis, members }) => SerializedPaneGroup::Group { | 3029 | Member::Axis(PaneAxis { |
| 3030 | axis, | ||
| 3031 | members, | ||
| 3032 | flexes, | ||
| 3033 | }) => SerializedPaneGroup::Group { | ||
| 2931 | axis: *axis, | 3034 | axis: *axis, |
| 2932 | children: members | 3035 | children: members |
| 2933 | .iter() | 3036 | .iter() |
| 2934 | .map(|member| build_serialized_pane_group(member, cx)) | 3037 | .map(|member| build_serialized_pane_group(member, cx)) |
| 2935 | .collect::<Vec<_>>(), | 3038 | .collect::<Vec<_>>(), |
| 3039 | flexes: Some(flexes.borrow().clone()), | ||
| 2936 | }, | 3040 | }, |
| 2937 | Member::Pane(pane_handle) => { | 3041 | Member::Pane(pane_handle) => { |
| 2938 | SerializedPaneGroup::Pane(serialize_pane_handle(&pane_handle, cx)) | 3042 | SerializedPaneGroup::Pane(serialize_pane_handle(&pane_handle, cx)) |
| @@ -3399,27 +3503,11 @@ fn notify_if_database_failed(workspace: &WeakViewHandle<Workspace>, cx: &mut Asy · 460 unmodified lines | |||
| 3399 | if (*db::ALL_FILE_DB_FAILED).load(std::sync::atomic::Ordering::Acquire) { | 3503 | if (*db::ALL_FILE_DB_FAILED).load(std::sync::atomic::Ordering::Acquire) { |
| 3400 | workspace.show_notification_once(0, cx, |cx| { | 3504 | workspace.show_notification_once(0, cx, |cx| { |
| 3401 | cx.add_view(|_| { | 3505 | cx.add_view(|_| { |
| 3402 | MessageNotification::new("Failed to load any database file.") | 3506 | MessageNotification::new("Failed to load the database file.") |
| 3403 | .with_click_message("Click to let us know about this error") | 3507 | .with_click_message("Click to let us know about this error") |
| 3404 | .on_click(|cx| cx.platform().open_url(REPORT_ISSUE_URL)) | 3508 | .on_click(|cx| cx.platform().open_url(REPORT_ISSUE_URL)) |
| 3405 | }) | 3509 | }) |
| 3406 | }); | 3510 | }); |
| 3407 | } else { | ||
| 3408 | let backup_path = (*db::BACKUP_DB_PATH).read(); | ||
| 3409 | if let Some(backup_path) = backup_path.clone() { | ||
| 3410 | workspace.show_notification_once(1, cx, move |cx| { | ||
| 3411 | cx.add_view(move |_| { | ||
| 3412 | MessageNotification::new(format!( | ||
| 3413 | "Database file was corrupted. Old database backed up to {}", | ||
| 3414 | backup_path.display() | ||
| 3415 | )) | ||
| 3416 | .with_click_message("Click to show old database in finder") | ||
| 3417 | .on_click(move |cx| { | ||
| 3418 | cx.platform().open_url(&backup_path.to_string_lossy()) | ||
| 3419 | }) | ||
| 3420 | }) | ||
| 3421 | }); | ||
| 3422 | } | ||
| 3423 | } | 3511 | } |
| 3424 | }) | 3512 | }) |
| 3425 | .log_err(); | 3513 | .log_err(); |
| @@ -4235,7 +4323,7 @@ mod tests { · 809 unmodified lines | |||
| 4235 | }); | 4323 | }); |
| 4236 | 4324 | ||
| 4237 | workspace | 4325 | workspace |
| 4238 | .split_pane(left_pane.clone(), SplitDirection::Right, cx) | 4326 | .split_and_clone(left_pane.clone(), SplitDirection::Right, cx) |
| 4239 | .unwrap(); | 4327 | .unwrap(); |
| 4240 | 4328 | ||
| 4241 | left_pane | 4329 | left_pane |
| @@ -104,25 +104,28 @@ thiserror.workspace = true · 103 unmodified lines | |||
| 104 | tiny_http = "0.8" | 104 | tiny_http = "0.8" |
| 105 | toml.workspace = true | 105 | toml.workspace = true |
| 106 | tree-sitter.workspace = true | 106 | tree-sitter.workspace = true |
| 107 | tree-sitter-c = "0.20.1" | 107 | tree-sitter-c.workspace = true |
| 108 | tree-sitter-cpp = "0.20.0" | 108 | tree-sitter-cpp.workspace = true |
| 109 | tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } | 109 | tree-sitter-css.workspace = true |
| 110 | tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" } | 110 | tree-sitter-elixir.workspace = true |
| 111 | tree-sitter-embedded-template = "0.20.0" | 111 | tree-sitter-embedded-template.workspace = true |
| 112 | tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "aeb2f33b366fd78d5789ff104956ce23508b85db" } | 112 | tree-sitter-go.workspace = true |
| 113 | tree-sitter-heex = { git = "https://github.com/phoenixframework/tree-sitter-heex", rev = "2e1348c3cf2c9323e87c2744796cf3f3868aa82a" } | 113 | tree-sitter-heex.workspace = true |
| 114 | tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "40a81c01a40ac48744e0c8ccabbaba1920441199" } | 114 | tree-sitter-json.workspace = true |
| 115 | tree-sitter-rust = "0.20.3" | 115 | tree-sitter-rust.workspace = true |
| 116 | tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" } | 116 | tree-sitter-markdown.workspace = true |
| 117 | tree-sitter-python = "0.20.2" | 117 | tree-sitter-python.workspace = true |
| 118 | tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" } | 118 | tree-sitter-toml.workspace = true |
| 119 | tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" } | 119 | tree-sitter-typescript.workspace = true |
| 120 | tree-sitter-ruby = "0.20.0" | 120 | tree-sitter-ruby.workspace = true |
| 121 | tree-sitter-html = "0.19.0" | 121 | tree-sitter-html.workspace = true |
| 122 | tree-sitter-scheme = { git = "https://github.com/6cdh/tree-sitter-scheme", rev = "af0fd1fa452cb2562dc7b5c8a8c55551c39273b9"} | 122 | tree-sitter-php.workspace = true |
| 123 | tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a"} | 123 | tree-sitter-scheme.workspace = true |
| 124 | tree-sitter-yaml = { git = "https://github.com/zed-industries/tree-sitter-yaml", rev = "f545a41f57502e1b5ddf2a6668896c1b0620f930"} | 124 | tree-sitter-svelte.workspace = true |
| 125 | tree-sitter-lua = "0.0.14" | 125 | tree-sitter-racket.workspace = true |
| 126 | tree-sitter-yaml.workspace = true | ||
| 127 | tree-sitter-lua.workspace = true | ||
| 128 | |||
| 126 | url = "2.2" | 129 | url = "2.2" |
| 127 | urlencoding = "2.1.2" | 130 | urlencoding = "2.1.2" |
| 128 | uuid = { version = "1.1.2", features = ["v4"] } | 131 | uuid = { version = "1.1.2", features = ["v4"] } |
| @@ -13,9 +13,11 @@ mod json; · 12 unmodified lines | |||
| 13 | #[cfg(feature = "plugin_runtime")] | 13 | #[cfg(feature = "plugin_runtime")] |
| 14 | mod language_plugin; | 14 | mod language_plugin; |
| 15 | mod lua; | 15 | mod lua; |
| 16 | mod php; | ||
| 16 | mod python; | 17 | mod python; |
| 17 | mod ruby; | 18 | mod ruby; |
| 18 | mod rust; | 19 | mod rust; |
| 20 | mod svelte; | ||
| 19 | mod typescript; | 21 | mod typescript; |
| 20 | mod yaml; | 22 | mod yaml; |
| 21 | 23 | ||
| @@ -135,7 +137,19 @@ pub fn init(languages: Arc<LanguageRegistry>, node_runtime: Arc<NodeRuntime>) { · 113 unmodified lines | |||
| 135 | language( | 137 | language( |
| 136 | "yaml", | 138 | "yaml", |
| 137 | tree_sitter_yaml::language(), | 139 | tree_sitter_yaml::language(), |
| 138 | vec![Arc::new(yaml::YamlLspAdapter::new(node_runtime))], | 140 | vec![Arc::new(yaml::YamlLspAdapter::new(node_runtime.clone()))], |
| 141 | ); | ||
| 142 | language( | ||
| 143 | "svelte", | ||
| 144 | tree_sitter_svelte::language(), | ||
| 145 | vec![Arc::new(svelte::SvelteLspAdapter::new( | ||
| 146 | node_runtime.clone(), | ||
| 147 | ))], | ||
| 148 | ); | ||
| 149 | language( | ||
| 150 | "php", | ||
| 151 | tree_sitter_php::language(), | ||
| 152 | vec![Arc::new(php::IntelephenseLspAdapter::new(node_runtime))], | ||
| 139 | ); | 153 | ); |
| 140 | } | 154 | } |
| 141 | 155 | ||
| @@ -4,4 +4,4 @@ autoclose_before = ">})" · 3 unmodified lines | |||
| 4 | brackets = [ | 4 | brackets = [ |
| 5 | { start = "<", end = ">", close = true, newline = true }, | 5 | { start = "<", end = ">", close = true, newline = true }, |
| 6 | ] | 6 | ] |
| 7 | block_comment = ["<%#", "%>"] | 7 | block_comment = ["<%!-- ", " --%>"] |
| @@ -1,10 +1,7 @@ | |||
| 1 | ; HEEx delimiters | 1 | ; HEEx delimiters |
| 2 | [ | 2 | [ |
| 3 | "--%>" | ||
| 4 | "-->" | ||
| 5 | "/>" | 3 | "/>" |
| 6 | "<!" | 4 | "<!" |
| 7 | "<!--" | ||
| 8 | "<" | 5 | "<" |
| 9 | "</" | 6 | "</" |
| 10 | "</:" | 7 | "</:" |
| @@ -21,6 +18,9 @@ · 10 unmodified lines | |||
| 21 | "<%%=" | 18 | "<%%=" |
| 22 | "<%=" | 19 | "<%=" |
| 23 | "%>" | 20 | "%>" |
| 21 | "--%>" | ||
| 22 | "-->" | ||
| 23 | "<!--" | ||
| 24 | ] @keyword | 24 | ] @keyword |
| 25 | 25 | ||
| 26 | ; HEEx operators are highlighted as such | 26 | ; HEEx operators are highlighted as such |
| @@ -0,0 +1,133 @@ | |||
| 1 | use anyhow::{anyhow, Result}; | ||
| 2 | |||
| 3 | use async_trait::async_trait; | ||
| 4 | use collections::HashMap; | ||
| 5 | |||
| 6 | use language::{LanguageServerName, LspAdapter, LspAdapterDelegate}; | ||
| 7 | use lsp::LanguageServerBinary; | ||
| 8 | use node_runtime::NodeRuntime; | ||
| 9 | |||
| 10 | use smol::{fs, stream::StreamExt}; | ||
| 11 | use std::{ | ||
| 12 | any::Any, | ||
| 13 | ffi::OsString, | ||
| 14 | path::{Path, PathBuf}, | ||
| 15 | sync::Arc, | ||
| 16 | }; | ||
| 17 | use util::ResultExt; | ||
| 18 | |||
| 19 | fn intelephense_server_binary_arguments(server_path: &Path) -> Vec<OsString> { | ||
| 20 | vec![server_path.into(), "--stdio".into()] | ||
| 21 | } | ||
| 22 | |||
| 23 | pub struct IntelephenseVersion(String); | ||
| 24 | |||
| 25 | pub struct IntelephenseLspAdapter { | ||
| 26 | node: Arc<NodeRuntime>, | ||
| 27 | } | ||
| 28 | |||
| 29 | impl IntelephenseLspAdapter { | ||
| 30 | const SERVER_PATH: &'static str = "node_modules/intelephense/lib/intelephense.js"; | ||
| 31 | |||
| 32 | #[allow(unused)] | ||
| 33 | pub fn new(node: Arc<NodeRuntime>) -> Self { | ||
| 34 | Self { node } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | #[async_trait] | ||
| 39 | impl LspAdapter for IntelephenseLspAdapter { | ||
| 40 | async fn name(&self) -> LanguageServerName { | ||
| 41 | LanguageServerName("intelephense".into()) | ||
| 42 | } | ||
| 43 | |||
| 44 | async fn fetch_latest_server_version( | ||
| 45 | &self, | ||
| 46 | _delegate: &dyn LspAdapterDelegate, | ||
| 47 | ) -> Result<Box<dyn 'static + Send + Any>> { | ||
| 48 | Ok(Box::new(IntelephenseVersion( | ||
| 49 | self.node.npm_package_latest_version("intelephense").await?, | ||
| 50 | )) as Box<_>) | ||
| 51 | } | ||
| 52 | |||
| 53 | async fn fetch_server_binary( | ||
| 54 | &self, | ||
| 55 | version: Box<dyn 'static + Send + Any>, | ||
| 56 | container_dir: PathBuf, | ||
| 57 | _delegate: &dyn LspAdapterDelegate, | ||
| 58 | ) -> Result<LanguageServerBinary> { | ||
| 59 | let version = version.downcast::<IntelephenseVersion>().unwrap(); | ||
| 60 | let server_path = container_dir.join(Self::SERVER_PATH); | ||
| 61 | |||
| 62 | if fs::metadata(&server_path).await.is_err() { | ||
| 63 | self.node | ||
| 64 | .npm_install_packages(&container_dir, [("intelephense", version.0.as_str())]) | ||
| 65 | .await?; | ||
| 66 | } | ||
| 67 | Ok(LanguageServerBinary { | ||
| 68 | path: self.node.binary_path().await?, | ||
| 69 | arguments: intelephense_server_binary_arguments(&server_path), | ||
| 70 | }) | ||
| 71 | } | ||
| 72 | |||
| 73 | async fn cached_server_binary( | ||
| 74 | &self, | ||
| 75 | container_dir: PathBuf, | ||
| 76 | _: &dyn LspAdapterDelegate, | ||
| 77 | ) -> Option<LanguageServerBinary> { | ||
| 78 | get_cached_server_binary(container_dir, &self.node).await | ||
| 79 | } | ||
| 80 | |||
| 81 | async fn installation_test_binary( | ||
| 82 | &self, | ||
| 83 | container_dir: PathBuf, | ||
| 84 | ) -> Option<LanguageServerBinary> { | ||
| 85 | get_cached_server_binary(container_dir, &self.node).await | ||
| 86 | } | ||
| 87 | |||
| 88 | async fn label_for_completion( | ||
| 89 | &self, | ||
| 90 | _item: &lsp::CompletionItem, | ||
| 91 | _language: &Arc<language::Language>, | ||
| 92 | ) -> Option<language::CodeLabel> { | ||
| 93 | None | ||
| 94 | } | ||
| 95 | |||
| 96 | async fn initialization_options(&self) -> Option<serde_json::Value> { | ||
| 97 | None | ||
| 98 | } | ||
| 99 | async fn language_ids(&self) -> HashMap<String, String> { | ||
| 100 | HashMap::from_iter([("PHP".into(), "php".into())]) | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | async fn get_cached_server_binary( | ||
| 105 | container_dir: PathBuf, | ||
| 106 | node: &NodeRuntime, | ||
| 107 | ) -> Option<LanguageServerBinary> { | ||
| 108 | (|| async move { | ||
| 109 | let mut last_version_dir = None; | ||
| 110 | let mut entries = fs::read_dir(&container_dir).await?; | ||
| 111 | while let Some(entry) = entries.next().await { | ||
| 112 | let entry = entry?; | ||
| 113 | if entry.file_type().await?.is_dir() { | ||
| 114 | last_version_dir = Some(entry.path()); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | let last_version_dir = last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?; | ||
| 118 | let server_path = last_version_dir.join(IntelephenseLspAdapter::SERVER_PATH); | ||
| 119 | if server_path.exists() { | ||
| 120 | Ok(LanguageServerBinary { | ||
| 121 | path: node.binary_path().await?, | ||
| 122 | arguments: intelephense_server_binary_arguments(&server_path), | ||
| 123 | }) | ||
| 124 | } else { | ||
| 125 | Err(anyhow!( | ||
| 126 | "missing executable in directory {:?}", | ||
| 127 | last_version_dir | ||
| 128 | )) | ||
| 129 | } | ||
| 130 | })() | ||
| 131 | .await | ||
| 132 | .log_err() | ||
| 133 | } | ||
| @@ -0,0 +1,11 @@ | |||
| 1 | name = "PHP" | ||
| 2 | path_suffixes = ["php"] | ||
| 3 | first_line_pattern = '^#!.*php' | ||
| 4 | line_comment = "// " | ||
| 5 | autoclose_before = ";:.,=}])>" | ||
| 6 | brackets = [ | ||
| 7 | { start = "{", end = "}", close = true, newline = true }, | ||
| 8 | { start = "[", end = "]", close = true, newline = true }, | ||
| 9 | { start = "(", end = ")", close = true, newline = true }, | ||
| 10 | { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, | ||
| 11 | ] | ||
| @@ -0,0 +1,123 @@ | |||
| 1 | (php_tag) @tag | ||
| 2 | "?>" @tag | ||
| 3 | |||
| 4 | ; Types | ||
| 5 | |||
| 6 | (primitive_type) @type.builtin | ||
| 7 | (cast_type) @type.builtin | ||
| 8 | (named_type (name) @type) @type | ||
| 9 | (named_type (qualified_name) @type) @type | ||
| 10 | |||
| 11 | ; Functions | ||
| 12 | |||
| 13 | (array_creation_expression "array" @function.builtin) | ||
| 14 | (list_literal "list" @function.builtin) | ||
| 15 | |||
| 16 | (method_declaration | ||
| 17 | name: (name) @function.method) | ||
| 18 | |||
| 19 | (function_call_expression | ||
| 20 | function: [(qualified_name (name)) (name)] @function) | ||
| 21 | |||
| 22 | (scoped_call_expression | ||
| 23 | name: (name) @function) | ||
| 24 | |||
| 25 | (member_call_expression | ||
| 26 | name: (name) @function.method) | ||
| 27 | |||
| 28 | (function_definition | ||
| 29 | name: (name) @function) | ||
| 30 | |||
| 31 | ; Member | ||
| 32 | |||
| 33 | (property_element | ||
| 34 | (variable_name) @property) | ||
| 35 | |||
| 36 | (member_access_expression | ||
| 37 | name: (variable_name (name)) @property) | ||
| 38 | (member_access_expression | ||
| 39 | name: (name) @property) | ||
| 40 | |||
| 41 | ; Variables | ||
| 42 | |||
| 43 | (relative_scope) @variable.builtin | ||
| 44 | |||
| 45 | ((name) @constant | ||
| 46 | (#match? @constant "^_?[A-Z][A-Z\\d_]+$")) | ||
| 47 | ((name) @constant.builtin | ||
| 48 | (#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) | ||
| 49 | |||
| 50 | ((name) @constructor | ||
| 51 | (#match? @constructor "^[A-Z]")) | ||
| 52 | |||
| 53 | ((name) @variable.builtin | ||
| 54 | (#eq? @variable.builtin "this")) | ||
| 55 | |||
| 56 | (variable_name) @variable | ||
| 57 | |||
| 58 | ; Basic tokens | ||
| 59 | [ | ||
| 60 | (string) | ||
| 61 | (string_value) | ||
| 62 | (encapsed_string) | ||
| 63 | (heredoc) | ||
| 64 | (heredoc_body) | ||
| 65 | (nowdoc_body) | ||
| 66 | ] @string | ||
| 67 | (boolean) @constant.builtin | ||
| 68 | (null) @constant.builtin | ||
| 69 | (integer) @number | ||
| 70 | (float) @number | ||
| 71 | (comment) @comment | ||
| 72 | |||
| 73 | "$" @operator | ||
| 74 | |||
| 75 | ; Keywords | ||
| 76 | |||
| 77 | "abstract" @keyword | ||
| 78 | "as" @keyword | ||
| 79 | "break" @keyword | ||
| 80 | "case" @keyword | ||
| 81 | "catch" @keyword | ||
| 82 | "class" @keyword | ||
| 83 | "const" @keyword | ||
| 84 | "continue" @keyword | ||
| 85 | "declare" @keyword | ||
| 86 | "default" @keyword | ||
| 87 | "do" @keyword | ||
| 88 | "echo" @keyword | ||
| 89 | "else" @keyword | ||
| 90 | "elseif" @keyword | ||
| 91 | "enum" @keyword | ||
| 92 | "enddeclare" @keyword | ||
| 93 | "endforeach" @keyword | ||
| 94 | "endif" @keyword | ||
| 95 | "endswitch" @keyword | ||
| 96 | "endwhile" @keyword | ||
| 97 | "extends" @keyword | ||
| 98 | "final" @keyword | ||
| 99 | "finally" @keyword | ||
| 100 | "foreach" @keyword | ||
| 101 | "function" @keyword | ||
| 102 | "global" @keyword | ||
| 103 | "if" @keyword | ||
| 104 | "implements" @keyword | ||
| 105 | "include_once" @keyword | ||
| 106 | "include" @keyword | ||
| 107 | "insteadof" @keyword | ||
| 108 | "interface" @keyword | ||
| 109 | "namespace" @keyword | ||
| 110 | "new" @keyword | ||
| 111 | "private" @keyword | ||
| 112 | "protected" @keyword | ||
| 113 | "public" @keyword | ||
| 114 | "require_once" @keyword | ||
| 115 | "require" @keyword | ||
| 116 | "return" @keyword | ||
| 117 | "static" @keyword | ||
| 118 | "switch" @keyword | ||
| 119 | "throw" @keyword | ||
| 120 | "trait" @keyword | ||
| 121 | "try" @keyword | ||
| 122 | "use" @keyword | ||
| 123 | "while" @keyword | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | ((text) @content | ||
| 2 | (#set! "language" "html") | ||
| 3 | (#set! "combined")) | ||
| @@ -0,0 +1,26 @@ | |||
| 1 | (class_declaration | ||
| 2 | "class" @context | ||
| 3 | name: (name) @name | ||
| 4 | ) @item | ||
| 5 | |||
| 6 | (function_definition | ||
| 7 | "function" @context | ||
| 8 | name: (_) @name | ||
| 9 | ) @item | ||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | (method_declaration | ||
| 14 | "function" @context | ||
| 15 | name: (_) @name | ||
| 16 | ) @item | ||
| 17 | |||
| 18 | (interface_declaration | ||
| 19 | "interface" @context | ||
| 20 | name: (_) @name | ||
| 21 | ) @item | ||
| 22 | |||
| 23 | (enum_declaration | ||
| 24 | "enum" @context | ||
| 25 | name: (_) @name | ||
| 26 | ) @item | ||
| @@ -0,0 +1,40 @@ | |||
| 1 | (namespace_definition | ||
| 2 | name: (namespace_name) @name) @module | ||
| 3 | |||
| 4 | (interface_declaration | ||
| 5 | name: (name) @name) @definition.interface | ||
| 6 | |||
| 7 | (trait_declaration | ||
| 8 | name: (name) @name) @definition.interface | ||
| 9 | |||
| 10 | (class_declaration | ||
| 11 | name: (name) @name) @definition.class | ||
| 12 | |||
| 13 | (class_interface_clause [(name) (qualified_name)] @name) @impl | ||
| 14 | |||
| 15 | (property_declaration | ||
| 16 | (property_element (variable_name (name) @name))) @definition.field | ||
| 17 | |||
| 18 | (function_definition | ||
| 19 | name: (name) @name) @definition.function | ||
| 20 | |||
| 21 | (method_declaration | ||
| 22 | name: (name) @name) @definition.function | ||
| 23 | |||
| 24 | (object_creation_expression | ||
| 25 | [ | ||
| 26 | (qualified_name (name) @name) | ||
| 27 | (variable_name (name) @name) | ||
| 28 | ]) @reference.class | ||
| 29 | |||
| 30 | (function_call_expression | ||
| 31 | function: [ | ||
| 32 | (qualified_name (name) @name) | ||
| 33 | (variable_name (name)) @name | ||
| 34 | ]) @reference.call | ||
| 35 | |||
| 36 | (scoped_call_expression | ||
| 37 | name: (name) @name) @reference.call | ||
| 38 | |||
| 39 | (member_call_expression | ||
| 40 | name: (name) @name) @reference.call | ||
| @@ -6,4 +6,4 @@ · 5 unmodified lines | |||
| 6 | (function_definition | 6 | (function_definition |
| 7 | "async"? @context | 7 | "async"? @context |
| 8 | "def" @context | 8 | "def" @context |
| 9 | name: (_) @name) @item | 9 | name: (_) @name) @item |
| @@ -0,0 +1,125 @@ | |||
| 1 | use anyhow::{anyhow, Result}; | ||
| 2 | use async_trait::async_trait; | ||
| 3 | use futures::StreamExt; | ||
| 4 | use language::{LanguageServerName, LspAdapter, LspAdapterDelegate}; | ||
| 5 | use lsp::LanguageServerBinary; | ||
| 6 | use node_runtime::NodeRuntime; | ||
| 7 | use serde_json::json; | ||
| 8 | use smol::fs; | ||
| 9 | use std::{ | ||
| 10 | any::Any, | ||
| 11 | ffi::OsString, | ||
| 12 | path::{Path, PathBuf}, | ||
| 13 | sync::Arc, | ||
| 14 | }; | ||
| 15 | use util::ResultExt; | ||
| 16 | |||
| 17 | const SERVER_PATH: &'static str = "node_modules/svelte-language-server/bin/server.js"; | ||
| 18 | |||
| 19 | fn server_binary_arguments(server_path: &Path) -> Vec<OsString> { | ||
| 20 | vec![server_path.into(), "--stdio".into()] | ||
| 21 | } | ||
| 22 | |||
| 23 | pub struct SvelteLspAdapter { | ||
| 24 | node: Arc<NodeRuntime>, | ||
| 25 | } | ||
| 26 | |||
| 27 | impl SvelteLspAdapter { | ||
| 28 | pub fn new(node: Arc<NodeRuntime>) -> Self { | ||
| 29 | SvelteLspAdapter { node } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | #[async_trait] | ||
| 34 | impl LspAdapter for SvelteLspAdapter { | ||
| 35 | async fn name(&self) -> LanguageServerName { | ||
| 36 | LanguageServerName("svelte-language-server".into()) | ||
| 37 | } | ||
| 38 | |||
| 39 | async fn fetch_latest_server_version( | ||
| 40 | &self, | ||
| 41 | _: &dyn LspAdapterDelegate, | ||
| 42 | ) -> Result<Box<dyn 'static + Any + Send>> { | ||
| 43 | Ok(Box::new( | ||
| 44 | self.node | ||
| 45 | .npm_package_latest_version("svelte-language-server") | ||
| 46 | .await?, | ||
| 47 | ) as Box<_>) | ||
| 48 | } | ||
| 49 | |||
| 50 | async fn fetch_server_binary( | ||
| 51 | &self, | ||
| 52 | version: Box<dyn 'static + Send + Any>, | ||
| 53 | container_dir: PathBuf, | ||
| 54 | _: &dyn LspAdapterDelegate, | ||
| 55 | ) -> Result<LanguageServerBinary> { | ||
| 56 | let version = version.downcast::<String>().unwrap(); | ||
| 57 | let server_path = container_dir.join(SERVER_PATH); | ||
| 58 | |||
| 59 | if fs::metadata(&server_path).await.is_err() { | ||
| 60 | self.node | ||
| 61 | .npm_install_packages( | ||
| 62 | &container_dir, | ||
| 63 | [("svelte-language-server", version.as_str())], | ||
| 64 | ) | ||
| 65 | .await?; | ||
| 66 | } | ||
| 67 | |||
| 68 | Ok(LanguageServerBinary { | ||
| 69 | path: self.node.binary_path().await?, | ||
| 70 | arguments: server_binary_arguments(&server_path), | ||
| 71 | }) | ||
| 72 | } | ||
| 73 | |||
| 74 | async fn cached_server_binary( | ||
| 75 | &self, | ||
| 76 | container_dir: PathBuf, | ||
| 77 | _: &dyn LspAdapterDelegate, | ||
| 78 | ) -> Option<LanguageServerBinary> { | ||
| 79 | get_cached_server_binary(container_dir, &self.node).await | ||
| 80 | } | ||
| 81 | |||
| 82 | async fn installation_test_binary( | ||
| 83 | &self, | ||
| 84 | container_dir: PathBuf, | ||
| 85 | ) -> Option<LanguageServerBinary> { | ||
| 86 | get_cached_server_binary(container_dir, &self.node).await | ||
| 87 | } | ||
| 88 | |||
| 89 | async fn initialization_options(&self) -> Option<serde_json::Value> { | ||
| 90 | Some(json!({ | ||
| 91 | "provideFormatter": true | ||
| 92 | })) | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | async fn get_cached_server_binary( | ||
| 97 | container_dir: PathBuf, | ||
| 98 | node: &NodeRuntime, | ||
| 99 | ) -> Option<LanguageServerBinary> { | ||
| 100 | (|| async move { | ||
| 101 | let mut last_version_dir = None; | ||
| 102 | let mut entries = fs::read_dir(&container_dir).await?; | ||
| 103 | while let Some(entry) = entries.next().await { | ||
| 104 | let entry = entry?; | ||
| 105 | if entry.file_type().await?.is_dir() { | ||
| 106 | last_version_dir = Some(entry.path()); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | let last_version_dir = last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?; | ||
| 110 | let server_path = last_version_dir.join(SERVER_PATH); | ||
| 111 | if server_path.exists() { | ||
| 112 | Ok(LanguageServerBinary { | ||
| 113 | path: node.binary_path().await?, | ||
| 114 | arguments: server_binary_arguments(&server_path), | ||
| 115 | }) | ||
| 116 | } else { | ||
| 117 | Err(anyhow!( | ||
| 118 | "missing executable in directory {:?}", | ||
| 119 | last_version_dir | ||
| 120 | )) | ||
| 121 | } | ||
| 122 | })() | ||
| 123 | .await | ||
| 124 | .log_err() | ||
| 125 | } | ||
| @@ -0,0 +1,18 @@ | |||
| 1 | name = "Svelte" | ||
| 2 | path_suffixes = ["svelte"] | ||
| 3 | line_comment = "// " | ||
| 4 | autoclose_before = ";:.,=}])>" | ||
| 5 | brackets = [ | ||
| 6 | { start = "{", end = "}", close = true, newline = true }, | ||
| 7 | { start = "[", end = "]", close = true, newline = true }, | ||
| 8 | { start = "(", end = ")", close = true, newline = true }, | ||
| 9 | { start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] }, | ||
| 10 | { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, | ||
| 11 | { start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] }, | ||
| 12 | { start = "`", end = "`", close = true, newline = false, not_in = ["string"] }, | ||
| 13 | { start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] }, | ||
| 14 | ] | ||
| 15 | |||
| 16 | [overrides.element] | ||
| 17 | line_comment = { remove = true } | ||
| 18 | block_comment = ["{/* ", " */}"] | ||
| @@ -0,0 +1,9 @@ | |||
| 1 | [ | ||
| 2 | (style_element) | ||
| 3 | (script_element) | ||
| 4 | (element) | ||
| 5 | (if_statement) | ||
| 6 | (else_statement) | ||
| 7 | (each_statement) | ||
| 8 | (await_statement) | ||
| 9 | ] @fold | ||
| @@ -0,0 +1,42 @@ | |||
| 1 | ; Special identifiers | ||
| 2 | ;-------------------- | ||
| 3 | |||
| 4 | ; TODO: | ||
| 5 | (tag_name) @tag | ||
| 6 | (attribute_name) @property | ||
| 7 | (erroneous_end_tag_name) @keyword | ||
| 8 | (comment) @comment | ||
| 9 | |||
| 10 | [ | ||
| 11 | (attribute_value) | ||
| 12 | (quoted_attribute_value) | ||
| 13 | ] @string | ||
| 14 | |||
| 15 | [ | ||
| 16 | (text) | ||
| 17 | (raw_text_expr) | ||
| 18 | ] @none | ||
| 19 | |||
| 20 | [ | ||
| 21 | (special_block_keyword) | ||
| 22 | (then) | ||
| 23 | (as) | ||
| 24 | ] @keyword | ||
| 25 | |||
| 26 | [ | ||
| 27 | "{" | ||
| 28 | "}" | ||
| 29 | ] @punctuation.bracket | ||
| 30 | |||
| 31 | "=" @operator | ||
| 32 | |||
| 33 | [ | ||
| 34 | "<" | ||
| 35 | ">" | ||
| 36 | "</" | ||
| 37 | "/>" | ||
| 38 | "#" | ||
| 39 | ":" | ||
| 40 | "/" | ||
| 41 | "@" | ||
| 42 | ] @tag.delimiter | ||
| @@ -0,0 +1,8 @@ | |||
| 1 | [ | ||
| 2 | (element) | ||
| 3 | (if_statement) | ||
| 4 | (each_statement) | ||
| 5 | (await_statement) | ||
| 6 | (script_element) | ||
| 7 | (style_element) | ||
| 8 | ] @indent | ||
| @@ -0,0 +1,28 @@ | |||
| 1 | ; injections.scm | ||
| 2 | ; -------------- | ||
| 3 | (script_element | ||
| 4 | (raw_text) @content | ||
| 5 | (#set! "language" "javascript")) | ||
| 6 | |||
| 7 | ((script_element | ||
| 8 | (start_tag | ||
| 9 | (attribute | ||
| 10 | (quoted_attribute_value (attribute_value) @_language))) | ||
| 11 | (raw_text) @content) | ||
| 12 | (#eq? @_language "ts") | ||
| 13 | (#set! "language" "typescript")) | ||
| 14 | |||
| 15 | ((script_element | ||
| 16 | (start_tag | ||
| 17 | (attribute | ||
| 18 | (quoted_attribute_value (attribute_value) @_language))) | ||
| 19 | (raw_text) @content) | ||
| 20 | (#eq? @_language "typescript") | ||
| 21 | (#set! "language" "typescript")) | ||
| 22 | |||
| 23 | (style_element | ||
| 24 | (raw_text) @content | ||
| 25 | (#set! "language" "css")) | ||
| 26 | |||
| 27 | ((raw_text_expr) @content | ||
| 28 | (#set! "language" "javascript")) | ||
| @@ -36,7 +36,7 @@ use std::{ · 35 unmodified lines | |||
| 36 | path::{Path, PathBuf}, | 36 | path::{Path, PathBuf}, |
| 37 | str, | 37 | str, |
| 38 | sync::{ | 38 | sync::{ |
| 39 | atomic::{AtomicBool, Ordering}, | 39 | atomic::{AtomicBool, AtomicU32, Ordering}, |
| 40 | Arc, Weak, | 40 | Arc, Weak, |
| 41 | }, | 41 | }, |
| 42 | thread, | 42 | thread, |
| @@ -405,11 +405,18 @@ struct PanicRequest { · 362 unmodified lines | |||
| 405 | token: String, | 405 | token: String, |
| 406 | } | 406 | } |
| 407 | 407 | ||
| 408 | static PANIC_COUNT: AtomicU32 = AtomicU32::new(0); | ||
| 409 | |||
| 408 | fn init_panic_hook(app: &App, installation_id: Option<String>) { | 410 | fn init_panic_hook(app: &App, installation_id: Option<String>) { |
| 409 | let is_pty = stdout_is_a_pty(); | 411 | let is_pty = stdout_is_a_pty(); |
| 410 | let platform = app.platform(); | 412 | let platform = app.platform(); |
| 411 | 413 | ||
| 412 | panic::set_hook(Box::new(move |info| { | 414 | panic::set_hook(Box::new(move |info| { |
| 415 | let prior_panic_count = PANIC_COUNT.fetch_add(1, Ordering::SeqCst); | ||
| 416 | if prior_panic_count > 0 { | ||
| 417 | std::panic::resume_unwind(Box::new(())); | ||
| 418 | } | ||
| 419 | |||
| 413 | let app_version = ZED_APP_VERSION | 420 | let app_version = ZED_APP_VERSION |
| 414 | .or_else(|| platform.app_version().ok()) | 421 | .or_else(|| platform.app_version().ok()) |
| 415 | .map_or("dev".to_string(), |v| v.to_string()); | 422 | .map_or("dev".to_string(), |v| v.to_string()); |
| @@ -464,7 +471,6 @@ fn init_panic_hook(app: &App, installation_id: Option<String>) { · 48 unmodified lines | |||
| 464 | if is_pty { | 471 | if is_pty { |
| 465 | if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() { | 472 | if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() { |
| 466 | eprintln!("{}", panic_data_json); | 473 | eprintln!("{}", panic_data_json); |
| 467 | return; | ||
| 468 | } | 474 | } |
| 469 | } else { | 475 | } else { |
| 470 | if let Some(panic_data_json) = serde_json::to_string(&panic_data).log_err() { | 476 | if let Some(panic_data_json) = serde_json::to_string(&panic_data).log_err() { |
| @@ -481,6 +487,8 @@ fn init_panic_hook(app: &App, installation_id: Option<String>) { · 10 unmodified lines | |||
| 481 | } | 487 | } |
| 482 | } | 488 | } |
| 483 | } | 489 | } |
| 490 | |||
| 491 | std::process::abort(); | ||
| 484 | })); | 492 | })); |
| 485 | } | 493 | } |
| 486 | 494 | ||
| @@ -517,11 +517,7 @@ pub fn handle_keymap_file_changes( · 516 unmodified lines | |||
| 517 | let mut settings_subscription = None; | 517 | let mut settings_subscription = None; |
| 518 | while let Some(user_keymap_content) = user_keymap_file_rx.next().await { | 518 | while let Some(user_keymap_content) = user_keymap_file_rx.next().await { |
| 519 | if let Ok(keymap_content) = KeymapFile::parse(&user_keymap_content) { | 519 | if let Ok(keymap_content) = KeymapFile::parse(&user_keymap_content) { |
| 520 | cx.update(|cx| { | 520 | cx.update(|cx| reload_keymaps(cx, &keymap_content)); |
| 521 | cx.clear_bindings(); | ||
| 522 | load_default_keymap(cx); | ||
| 523 | keymap_content.clone().add_to_cx(cx).log_err(); | ||
| 524 | }); | ||
| 525 | 521 | ||
| 526 | let mut old_base_keymap = cx.read(|cx| *settings::get::<BaseKeymap>(cx)); | 522 | let mut old_base_keymap = cx.read(|cx| *settings::get::<BaseKeymap>(cx)); |
| 527 | drop(settings_subscription); | 523 | drop(settings_subscription); |
| @@ -530,10 +526,7 @@ pub fn handle_keymap_file_changes( · 2 unmodified lines | |||
| 530 | let new_base_keymap = *settings::get::<BaseKeymap>(cx); | 526 | let new_base_keymap = *settings::get::<BaseKeymap>(cx); |
| 531 | if new_base_keymap != old_base_keymap { | 527 | if new_base_keymap != old_base_keymap { |
| 532 | old_base_keymap = new_base_keymap.clone(); | 528 | old_base_keymap = new_base_keymap.clone(); |
| 533 | 529 | reload_keymaps(cx, &keymap_content); | |
| 534 | cx.clear_bindings(); | ||
| 535 | load_default_keymap(cx); | ||
| 536 | keymap_content.clone().add_to_cx(cx).log_err(); | ||
| 537 | } | 530 | } |
| 538 | }) | 531 | }) |
| 539 | .detach(); | 532 | .detach(); |
| @@ -544,6 +537,13 @@ pub fn handle_keymap_file_changes( · 4 unmodified lines | |||
| 544 | .detach(); | 537 | .detach(); |
| 545 | } | 538 | } |
| 546 | 539 | ||
| 540 | fn reload_keymaps(cx: &mut AppContext, keymap_content: &KeymapFile) { | ||
| 541 | cx.clear_bindings(); | ||
| 542 | load_default_keymap(cx); | ||
| 543 | keymap_content.clone().add_to_cx(cx).log_err(); | ||
| 544 | cx.set_menus(menus::menus()); | ||
| 545 | } | ||
| 546 | |||
| 547 | fn open_local_settings_file( | 547 | fn open_local_settings_file( |
| 548 | workspace: &mut Workspace, | 548 | workspace: &mut Workspace, |
| 549 | _: &OpenLocalSettings, | 549 | _: &OpenLocalSettings, |
| @@ -1021,7 +1021,7 @@ mod tests { · 471 unmodified lines | |||
| 1021 | // Split the pane with the first entry, then open the second entry again. | 1021 | // Split the pane with the first entry, then open the second entry again. |
| 1022 | workspace | 1022 | workspace |
| 1023 | .update(cx, |w, cx| { | 1023 | .update(cx, |w, cx| { |
| 1024 | w.split_pane(w.active_pane().clone(), SplitDirection::Right, cx); | 1024 | w.split_and_clone(w.active_pane().clone(), SplitDirection::Right, cx); |
| 1025 | w.open_path(file2.clone(), None, true, cx) | 1025 | w.open_path(file2.clone(), None, true, cx) |
| 1026 | }) | 1026 | }) |
| 1027 | .await | 1027 | .await |
| @@ -1344,7 +1344,11 @@ mod tests { · 316 unmodified lines | |||
| 1344 | cx.dispatch_action(window_id, NewFile); | 1344 | cx.dispatch_action(window_id, NewFile); |
| 1345 | workspace | 1345 | workspace |
| 1346 | .update(cx, |workspace, cx| { | 1346 | .update(cx, |workspace, cx| { |
| 1347 | workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); | 1347 | workspace.split_and_clone( |
| 1348 | workspace.active_pane().clone(), | ||
| 1349 | SplitDirection::Right, | ||
| 1350 | cx, | ||
| 1351 | ); | ||
| 1348 | workspace.open_path((worktree.read(cx).id(), "the-new-name.rs"), None, true, cx) | 1352 | workspace.open_path((worktree.read(cx).id(), "the-new-name.rs"), None, true, cx) |
| 1349 | }) | 1353 | }) |
| 1350 | .await | 1354 | .await |
| @@ -114,7 +114,7 @@ export default function editor(): any { · 113 unmodified lines | |||
| 114 | color: foreground(layer, "default"), | 114 | color: foreground(layer, "default"), |
| 115 | }, | 115 | }, |
| 116 | hovered: { | 116 | hovered: { |
| 117 | color: foreground(layer, "variant"), | 117 | color: foreground(layer, "on"), |
| 118 | }, | 118 | }, |
| 119 | }, | 119 | }, |
| 120 | }, | 120 | }, |
| @@ -33,6 +33,11 @@ export default function feedback(): any { · 32 unmodified lines | |||
| 33 | background: background(theme.highest, "on", "hovered"), | 33 | background: background(theme.highest, "on", "hovered"), |
| 34 | border: border(theme.highest, "on", "hovered"), | 34 | border: border(theme.highest, "on", "hovered"), |
| 35 | }, | 35 | }, |
| 36 | disabled: { | ||
| 37 | ...text(theme.highest, "mono", "on", "disabled"), | ||
| 38 | background: background(theme.highest, "on", "disabled"), | ||
| 39 | border: border(theme.highest, "on", "disabled"), | ||
| 40 | } | ||
| 36 | }, | 41 | }, |
| 37 | }), | 42 | }), |
| 38 | button_margin: 8, | 43 | button_margin: 8, |
| @@ -83,6 +83,35 @@ export default function search(): any { · 82 unmodified lines | |||
| 83 | }, | 83 | }, |
| 84 | }, | 84 | }, |
| 85 | }), | 85 | }), |
| 86 | action_button: interactive({ | ||
| 87 | base: { | ||
| 88 | ...text(theme.highest, "mono", "on"), | ||
| 89 | background: background(theme.highest, "on"), | ||
| 90 | corner_radius: 6, | ||
| 91 | border: border(theme.highest, "on"), | ||
| 92 | margin: { | ||
| 93 | right: 4, | ||
| 94 | }, | ||
| 95 | padding: { | ||
| 96 | bottom: 2, | ||
| 97 | left: 10, | ||
| 98 | right: 10, | ||
| 99 | top: 2, | ||
| 100 | }, | ||
| 101 | }, | ||
| 102 | state: { | ||
| 103 | hovered: { | ||
| 104 | ...text(theme.highest, "mono", "on", "hovered"), | ||
| 105 | background: background(theme.highest, "on", "hovered"), | ||
| 106 | border: border(theme.highest, "on", "hovered"), | ||
| 107 | }, | ||
| 108 | clicked: { | ||
| 109 | ...text(theme.highest, "mono", "on", "pressed"), | ||
| 110 | background: background(theme.highest, "on", "pressed"), | ||
| 111 | border: border(theme.highest, "on", "pressed"), | ||
| 112 | }, | ||
| 113 | }, | ||
| 114 | }), | ||
| 86 | editor, | 115 | editor, |
| 87 | invalid_editor: { | 116 | invalid_editor: { |
| 88 | ...editor, | 117 | ...editor, |
| @@ -6,6 +6,8 @@ import { useTheme } from "../common" · 5 unmodified lines | |||
| 6 | export default function tab_bar(): any { | 6 | export default function tab_bar(): any { |
| 7 | const theme = useTheme() | 7 | const theme = useTheme() |
| 8 | 8 | ||
| 9 | const { is_light } = theme | ||
| 10 | |||
| 9 | const height = 32 | 11 | const height = 32 |
| 10 | 12 | ||
| 11 | const active_layer = theme.highest | 13 | const active_layer = theme.highest |
| @@ -38,6 +40,18 @@ export default function tab_bar(): any { · 26 unmodified lines | |||
| 38 | icon_conflict: foreground(layer, "warning"), | 40 | icon_conflict: foreground(layer, "warning"), |
| 39 | icon_dirty: foreground(layer, "accent"), | 41 | icon_dirty: foreground(layer, "accent"), |
| 40 | 42 | ||
| 43 | git: { | ||
| 44 | modified: is_light | ||
| 45 | ? theme.ramps.yellow(0.6).hex() | ||
| 46 | : theme.ramps.yellow(0.5).hex(), | ||
| 47 | inserted: is_light | ||
| 48 | ? theme.ramps.green(0.45).hex() | ||
| 49 | : theme.ramps.green(0.5).hex(), | ||
| 50 | conflict: is_light | ||
| 51 | ? theme.ramps.red(0.6).hex() | ||
| 52 | : theme.ramps.red(0.5).hex(), | ||
| 53 | }, | ||
| 54 | |||
| 41 | // When two tabs of the same name are open, a label appears next to them | 55 | // When two tabs of the same name are open, a label appears next to them |
| 42 | description: { | 56 | description: { |
| 43 | margin: { left: 8 }, | 57 | margin: { left: 8 }, |