Unified · Split
| @@ -148,8 +148,8 @@ jobs: · 147 unmodified lines | ||
| 148 | 148 | - name: Create app bundle |
| 149 | 149 | run: script/bundle |
| 150 | 150 | |
| 151 | − - name: Upload app bundle to workflow run if main branch or specifi label | |
| 152 | − uses: actions/upload-artifact@v2 | |
| 151 | + - name: Upload app bundle to workflow run if main branch or specific label | |
| 152 | + uses: actions/upload-artifact@v3 | |
| 153 | 153 | if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-build-dmg') }} |
| 154 | 154 | with: |
| 155 | 155 | name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.dmg |
| @@ -1243,9 +1243,9 @@ dependencies = [ · 1242 unmodified lines | ||
| 1243 | 1243 | |
| 1244 | 1244 | [[package]] |
| 1245 | 1245 | name = "clap" |
| 1246 | −version = "4.3.14" | |
| 1246 | +version = "4.3.15" | |
| 1247 | 1247 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1248 | −checksum = "98330784c494e49850cb23b8e2afcca13587d2500b2e3f1f78ae20248059c9be" | |
| 1248 | +checksum = "8f644d0dac522c8b05ddc39aaaccc5b136d5dc4ff216610c5641e3be5becf56c" | |
| 1249 | 1249 | dependencies = [ |
| 1250 | 1250 | "clap_builder", |
| 1251 | 1251 | "clap_derive 4.3.12", |
| @@ -1254,9 +1254,9 @@ dependencies = [ · 2 unmodified lines | ||
| 1254 | 1254 | |
| 1255 | 1255 | [[package]] |
| 1256 | 1256 | name = "clap_builder" |
| 1257 | −version = "4.3.14" | |
| 1257 | +version = "4.3.15" | |
| 1258 | 1258 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1259 | −checksum = "e182eb5f2562a67dda37e2c57af64d720a9e010c5e860ed87c056586aeafa52e" | |
| 1259 | +checksum = "af410122b9778e024f9e0fb35682cc09cc3f85cad5e8d3ba8f47a9702df6e73d" | |
| 1260 | 1260 | dependencies = [ |
| 1261 | 1261 | "anstream", |
| 1262 | 1262 | "anstyle", |
| @@ -2253,7 +2253,6 @@ dependencies = [ · 990 unmodified lines | ||
| 2253 | 2253 | "theme", |
| 2254 | 2254 | "tree-sitter", |
| 2255 | 2255 | "tree-sitter-html", |
| 2256 | − "tree-sitter-javascript", | |
| 2257 | 2256 | "tree-sitter-rust", |
| 2258 | 2257 | "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", |
| 2259 | 2258 | "unindent", |
| @@ -3750,15 +3749,16 @@ dependencies = [ · 1490 unmodified lines | ||
| 3750 | 3749 | "text", |
| 3751 | 3750 | "theme", |
| 3752 | 3751 | "tree-sitter", |
| 3752 | + "tree-sitter-elixir 0.1.0 (git+https://github.com/elixir-lang/tree-sitter-elixir?rev=4ba9dab6e2602960d95b2b625f3386c27e08084e)", | |
| 3753 | 3753 | "tree-sitter-embedded-template", |
| 3754 | + "tree-sitter-heex", | |
| 3754 | 3755 | "tree-sitter-html", |
| 3755 | − "tree-sitter-javascript", | |
| 3756 | − "tree-sitter-json 0.19.0", | |
| 3756 | + "tree-sitter-json 0.20.0", | |
| 3757 | 3757 | "tree-sitter-markdown", |
| 3758 | 3758 | "tree-sitter-python", |
| 3759 | 3759 | "tree-sitter-ruby", |
| 3760 | 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 | 3762 | "unicase", |
| 3763 | 3763 | "unindent", |
| 3764 | 3764 | "util", |
| @@ -8083,16 +8083,6 @@ dependencies = [ · 4318 unmodified lines | ||
| 8083 | 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 | 8086 | [[package]] |
| 8097 | 8087 | name = "tree-sitter-json" |
| 8098 | 8088 | version = "0.19.0" |
| @@ -8131,6 +8121,15 @@ dependencies = [ · 32 unmodified lines | ||
| 8131 | 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 | 8133 | [[package]] |
| 8135 | 8134 | name = "tree-sitter-python" |
| 8136 | 8135 | version = "0.20.2" |
| @@ -8179,6 +8178,15 @@ dependencies = [ · 42 unmodified lines | ||
| 8179 | 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 | 8190 | [[package]] |
| 8183 | 8191 | name = "tree-sitter-toml" |
| 8184 | 8192 | version = "0.5.1" |
| @@ -9449,7 +9457,7 @@ name = "xtask" · 1264 unmodified lines | ||
| 9449 | 9457 | version = "0.1.0" |
| 9450 | 9458 | dependencies = [ |
| 9451 | 9459 | "anyhow", |
| 9452 | − "clap 4.3.14", | |
| 9460 | + "clap 4.3.15", | |
| 9453 | 9461 | "schemars", |
| 9454 | 9462 | "serde_json", |
| 9455 | 9463 | "theme", |
| @@ -9580,11 +9588,13 @@ dependencies = [ · 124 unmodified lines | ||
| 9580 | 9588 | "tree-sitter-json 0.20.0", |
| 9581 | 9589 | "tree-sitter-lua", |
| 9582 | 9590 | "tree-sitter-markdown", |
| 9591 | + "tree-sitter-php", | |
| 9583 | 9592 | "tree-sitter-python", |
| 9584 | 9593 | "tree-sitter-racket", |
| 9585 | 9594 | "tree-sitter-ruby", |
| 9586 | 9595 | "tree-sitter-rust", |
| 9587 | 9596 | "tree-sitter-scheme", |
| 9597 | + "tree-sitter-svelte", | |
| 9588 | 9598 | "tree-sitter-toml 0.5.1", |
| 9589 | 9599 | "tree-sitter-typescript 0.20.2 (git+https://github.com/tree-sitter/tree-sitter-typescript?rev=5d20856f34315b068c41edaee2ac8a100081d259)", |
| 9590 | 9600 | "tree-sitter-yaml", |
| @@ -107,6 +107,28 @@ tree-sitter = "0.20" · 106 unmodified lines | ||
| 107 | 107 | unindent = { version = "0.1.7" } |
| 108 | 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 | 132 | [patch.crates-io] |
| 111 | 133 | tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "49226023693107fba9a1191136a4f47f38cdca73" } |
| 112 | 134 | async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" } |
| @@ -9,6 +9,7 @@ · 8 unmodified lines | ||
| 9 | 9 | "context": "Editor", |
| 10 | 10 | "bindings": { |
| 11 | 11 | "cmd-b": "editor::GoToDefinition", |
| 12 | + "alt-cmd-b": "editor::GoToDefinitionSplit", | |
| 12 | 13 | "cmd-<": "editor::ScrollCursorCenter", |
| 13 | 14 | "cmd-g": [ |
| 14 | 15 | "editor::SelectNext", |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | "cmd-up": "menu::SelectFirst", |
| 14 | 14 | "cmd-down": "menu::SelectLast", |
| 15 | 15 | "enter": "menu::Confirm", |
| 16 | + "cmd-enter": "menu::SecondaryConfirm", | |
| 16 | 17 | "escape": "menu::Cancel", |
| 17 | 18 | "ctrl-c": "menu::Cancel", |
| 18 | 19 | "cmd-{": "pane::ActivatePrevItem", |
| @@ -194,8 +195,8 @@ · 175 unmodified lines | ||
| 194 | 195 | { |
| 195 | 196 | "context": "Editor && mode == auto_height", |
| 196 | 197 | "bindings": { |
| 197 | − "alt-enter": "editor::Newline", | |
| 198 | − "cmd-alt-enter": "editor::NewlineBelow" | |
| 198 | + "shift-enter": "editor::Newline", | |
| 199 | + "cmd-shift-enter": "editor::NewlineBelow" | |
| 199 | 200 | } |
| 200 | 201 | }, |
| 201 | 202 | { |
| @@ -221,7 +222,8 @@ · 19 unmodified lines | ||
| 221 | 222 | "escape": "buffer_search::Dismiss", |
| 222 | 223 | "tab": "buffer_search::FocusEditor", |
| 223 | 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 | 244 | "cmd-f": "project_search::ToggleFocus", |
| 243 | 245 | "cmd-g": "search::SelectNextMatch", |
| 244 | 246 | "cmd-shift-g": "search::SelectPrevMatch", |
| 247 | + "alt-enter": "search::SelectAllMatches", | |
| 245 | 248 | "alt-cmd-c": "search::ToggleCaseSensitive", |
| 246 | 249 | "alt-cmd-w": "search::ToggleWholeWord", |
| 247 | 250 | "alt-cmd-r": "search::ToggleRegex" |
| @@ -296,7 +299,9 @@ · 48 unmodified lines | ||
| 296 | 299 | "shift-f8": "editor::GoToPrevDiagnostic", |
| 297 | 300 | "f2": "editor::Rename", |
| 298 | 301 | "f12": "editor::GoToDefinition", |
| 302 | + "alt-f12": "editor::GoToDefinitionSplit", | |
| 299 | 303 | "cmd-f12": "editor::GoToTypeDefinition", |
| 304 | + "alt-cmd-f12": "editor::GoToTypeDefinitionSplit", | |
| 300 | 305 | "alt-shift-f12": "editor::FindAllReferences", |
| 301 | 306 | "ctrl-m": "editor::MoveToEnclosingBracket", |
| 302 | 307 | "alt-cmd-[": "editor::Fold", |
| @@ -46,8 +46,9 @@ · 45 unmodified lines | ||
| 46 | 46 | "alt-f7": "editor::FindAllReferences", |
| 47 | 47 | "cmd-alt-f7": "editor::FindAllReferences", |
| 48 | 48 | "cmd-b": "editor::GoToDefinition", |
| 49 | − "cmd-alt-b": "editor::GoToDefinition", | |
| 49 | + "cmd-alt-b": "editor::GoToDefinitionSplit", | |
| 50 | 50 | "cmd-shift-b": "editor::GoToTypeDefinition", |
| 51 | + "cmd-alt-shift-b": "editor::GoToTypeDefinitionSplit", | |
| 51 | 52 | "alt-enter": "editor::ToggleCodeActions", |
| 52 | 53 | "f2": "editor::GoToDiagnostic", |
| 53 | 54 | "cmd-f2": "editor::GoToPrevDiagnostic", |
| @@ -20,6 +20,7 @@ · 19 unmodified lines | ||
| 20 | 20 | "cmd-shift-a": "editor::SelectLargerSyntaxNode", |
| 21 | 21 | "shift-f12": "editor::FindAllReferences", |
| 22 | 22 | "alt-cmd-down": "editor::GoToDefinition", |
| 23 | + "ctrl-alt-cmd-down": "editor::GoToDefinitionSplit", | |
| 23 | 24 | "alt-shift-cmd-down": "editor::FindAllReferences", |
| 24 | 25 | "ctrl-.": "editor::GoToHunk", |
| 25 | 26 | "ctrl-,": "editor::GoToPrevHunk", |
| @@ -12,6 +12,7 @@ · 11 unmodified lines | ||
| 12 | 12 | "cmd-l": "go_to_line::Toggle", |
| 13 | 13 | "ctrl-shift-d": "editor::DuplicateLine", |
| 14 | 14 | "cmd-b": "editor::GoToDefinition", |
| 15 | + "alt-cmd-b": "editor::GoToDefinition", | |
| 15 | 16 | "cmd-j": "editor::ScrollCursorCenter", |
| 16 | 17 | "cmd-shift-l": "editor::SelectLine", |
| 17 | 18 | "cmd-shift-t": "outline::Toggle", |
| @@ -99,6 +99,10 @@ · 98 unmodified lines | ||
| 99 | 99 | "vim::SwitchMode", |
| 100 | 100 | "Normal" |
| 101 | 101 | ], |
| 102 | + "ctrl+[": [ | |
| 103 | + "vim::SwitchMode", | |
| 104 | + "Normal" | |
| 105 | + ], | |
| 102 | 106 | "0": "vim::StartOfLine", // When no number operator present, use start of line motion |
| 103 | 107 | "1": [ |
| 104 | 108 | "vim::Number", |
| @@ -234,10 +238,6 @@ · 129 unmodified lines | ||
| 234 | 238 | "h": "editor::Hover", |
| 235 | 239 | "t": "pane::ActivateNextItem", |
| 236 | 240 | "shift-t": "pane::ActivatePrevItem", |
| 237 | − "escape": [ | |
| 238 | − "vim::SwitchMode", | |
| 239 | − "Normal" | |
| 240 | − ], | |
| 241 | 241 | "d": "editor::GoToDefinition" |
| 242 | 242 | } |
| 243 | 243 | }, |
| @@ -265,10 +265,6 @@ · 21 unmodified lines | ||
| 265 | 265 | "t": "editor::ScrollCursorTop", |
| 266 | 266 | "z": "editor::ScrollCursorCenter", |
| 267 | 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 | 318 | "context": "Editor && vim_mode == insert", |
| 323 | 319 | "bindings": { |
| 324 | 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 | 330 | "escape": [ |
| 334 | 331 | "vim::SwitchMode", |
| 335 | 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 | 25 | // The default font size for text in the editor |
| 26 | 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 | 38 | // The factor to grow the active pane by. Defaults to 1.0 |
| 28 | 39 | // which gives the same size as all other panes. |
| 29 | 40 | "active_pane_magnification": 1.0, |
| @@ -117,6 +128,13 @@ · 87 unmodified lines | ||
| 117 | 128 | // 4. Save when idle for a certain amount of time: |
| 118 | 129 | // "autosave": { "after_delay": {"milliseconds": 500} }, |
| 119 | 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 | 138 | // Whether or not to remove any trailing whitespace from lines of a buffer |
| 121 | 139 | // before saving it. |
| 122 | 140 | "remove_trailing_whitespace_on_save": true, |
| @@ -282,7 +300,6 @@ · 159 unmodified lines | ||
| 282 | 300 | // "line_height": { |
| 283 | 301 | // "custom": 2 |
| 284 | 302 | // }, |
| 285 | − // | |
| 286 | 303 | "line_height": "comfortable" |
| 287 | 304 | // Set the terminal's font size. If this option is not included, |
| 288 | 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 | 7218 | // Clients A and B follow each other in split panes |
| 7219 | 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 | 7222 | workspace_a |
| 7223 | 7223 | .update(cx_a, |workspace, cx| { |
| @@ -7228,7 +7228,7 @@ async fn test_peers_following_each_other( · 4 unmodified lines | ||
| 7228 | 7228 | .await |
| 7229 | 7229 | .unwrap(); |
| 7230 | 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 | 7233 | workspace_b |
| 7234 | 7234 | .update(cx_b, |workspace, cx| { |
| @@ -7455,7 +7455,7 @@ async fn test_auto_unfollowing( · 220 unmodified lines | ||
| 7455 | 7455 | |
| 7456 | 7456 | // When client B activates a different pane, it continues following client A in the original pane. |
| 7457 | 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 | 7460 | assert_eq!( |
| 7461 | 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 | 71 | if let Some(user) = self.potential_contacts.get(self.selected_index) { |
| 72 | 72 | let user_store = self.user_store.read(cx); |
| 73 | 73 | match user_store.contact_request_status(user) { |
| @@ -160,7 +160,7 @@ impl PickerDelegate for CommandPaletteDelegate { · 159 unmodified lines | ||
| 160 | 160 | |
| 161 | 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 | 164 | if !self.matches.is_empty() { |
| 165 | 165 | let window_id = cx.window_id(); |
| 166 | 166 | let focused_view_id = self.focused_view_id; |
| @@ -7,7 +7,6 @@ use anyhow::Context; · 6 unmodified lines | ||
| 7 | 7 | use gpui::AppContext; |
| 8 | 8 | pub use indoc::indoc; |
| 9 | 9 | pub use lazy_static; |
| 10 | −use parking_lot::{Mutex, RwLock}; | |
| 11 | 10 | pub use smol; |
| 12 | 11 | pub use sqlez; |
| 13 | 12 | pub use sqlez_macros; |
| @@ -17,11 +16,9 @@ pub use util::paths::DB_DIR; · 3 unmodified lines | ||
| 17 | 16 | use sqlez::domain::Migrator; |
| 18 | 17 | use sqlez::thread_safe_connection::ThreadSafeConnection; |
| 19 | 18 | use sqlez_macros::sql; |
| 20 | −use std::fs::create_dir_all; | |
| 21 | 19 | use std::future::Future; |
| 22 | 20 | use std::path::{Path, PathBuf}; |
| 23 | 21 | use std::sync::atomic::{AtomicBool, Ordering}; |
| 24 | −use std::time::{SystemTime, UNIX_EPOCH}; | |
| 25 | 22 | use util::channel::ReleaseChannel; |
| 26 | 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 | 40 | lazy_static::lazy_static! { |
| 44 | 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 | 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 | 45 | /// Open or create a database at the given directory path. |
| 51 | 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 | 58 | let main_db_dir = db_dir.join(Path::new(&format!("0-{}", release_channel_name))); |
| 64 | 59 | |
| 65 | 60 | let connection = async_iife!({ |
| 66 | − // Note: This still has a race condition where 1 set of migrations succeeds | |
| 67 | − // (e.g. (Workspace, Editor)) and another fails (e.g. (Workspace, Terminal)) | |
| 68 | − // This will cause the first connection to have the database taken out | |
| 69 | − // from under it. This *should* be fine though. The second dabatase failure will | |
| 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")?; | |
| 61 | + smol::fs::create_dir_all(&main_db_dir) | |
| 62 | + .await | |
| 63 | + .context("Could not create db directory") | |
| 64 | + .log_err()?; | |
| 80 | 65 | let db_path = main_db_dir.join(Path::new(DB_FILE_NAME)); |
| 81 | − | |
| 82 | − // Optimistically open databases in parallel | |
| 83 | − if !DB_FILE_OPERATIONS.is_locked() { | |
| 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(); | |
| 66 | + open_main_db(&db_path).await | |
| 67 | + }) | |
| 68 | + .await; | |
| 126 | 69 | |
| 127 | 70 | if let Some(connection) = connection { |
| 128 | 71 | return connection; |
| @@ -249,13 +192,13 @@ where · 120 unmodified lines | ||
| 249 | 192 | |
| 250 | 193 | #[cfg(test)] |
| 251 | 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 | 198 | use sqlez_macros::sql; |
| 256 | 199 | use tempdir::TempDir; |
| 257 | 200 | |
| 258 | − use crate::{open_db, DB_FILE_NAME}; | |
| 201 | + use crate::open_db; | |
| 259 | 202 | |
| 260 | 203 | // Test bad migration panics |
| 261 | 204 | #[gpui::test] |
| @@ -321,31 +264,10 @@ mod tests { · 59 unmodified lines | ||
| 321 | 264 | .unwrap() |
| 322 | 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 | 269 | /// Test that DB exists but corrupted (causing recreate) |
| 348 | − #[gpui::test] | |
| 270 | + #[gpui::test(iterations = 30)] | |
| 349 | 271 | async fn test_simultaneous_db_corruption() { |
| 350 | 272 | enum CorruptedDB {} |
| 351 | 273 | |
| @@ -57,16 +57,16 @@ ordered-float.workspace = true · 56 unmodified lines | ||
| 57 | 57 | parking_lot.workspace = true |
| 58 | 58 | postage.workspace = true |
| 59 | 59 | pulldown-cmark = { version = "0.9.2", default-features = false } |
| 60 | −rand = { workspace = true, optional = true } | |
| 61 | 60 | schemars.workspace = true |
| 62 | 61 | serde.workspace = true |
| 63 | 62 | serde_derive.workspace = true |
| 64 | 63 | smallvec.workspace = true |
| 65 | 64 | smol.workspace = true |
| 66 | −tree-sitter-rust = { version = "*", optional = true } | |
| 67 | −tree-sitter-html = { version = "*", optional = true } | |
| 68 | −tree-sitter-javascript = { version = "*", optional = true } | |
| 69 | −tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259", optional = true } | |
| 65 | + | |
| 66 | +rand = { workspace = true, optional = true } | |
| 67 | +tree-sitter-rust = { workspace = true, optional = true } | |
| 68 | +tree-sitter-html = { workspace = true, optional = true } | |
| 69 | +tree-sitter-typescript = { workspace = true, optional = true } | |
| 70 | 70 | |
| 71 | 71 | [dev-dependencies] |
| 72 | 72 | copilot = { path = "../copilot", features = ["test-support"] } |
| @@ -84,7 +84,6 @@ env_logger.workspace = true · 11 unmodified lines | ||
| 84 | 84 | rand.workspace = true |
| 85 | 85 | unindent.workspace = true |
| 86 | 86 | tree-sitter.workspace = true |
| 87 | −tree-sitter-rust = "0.20" | |
| 88 | −tree-sitter-html = "0.19" | |
| 89 | −tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" } | |
| 90 | −tree-sitter-javascript = "0.20" | |
| 87 | +tree-sitter-rust.workspace = true | |
| 88 | +tree-sitter-html.workspace = true | |
| 89 | +tree-sitter-typescript.workspace = true | |
| @@ -271,7 +271,9 @@ actions!( · 270 unmodified lines | ||
| 271 | 271 | SelectLargerSyntaxNode, |
| 272 | 272 | SelectSmallerSyntaxNode, |
| 273 | 273 | GoToDefinition, |
| 274 | + GoToDefinitionSplit, | |
| 274 | 275 | GoToTypeDefinition, |
| 276 | + GoToTypeDefinitionSplit, | |
| 275 | 277 | MoveToEnclosingBracket, |
| 276 | 278 | UndoSelection, |
| 277 | 279 | RedoSelection, |
| @@ -407,7 +409,9 @@ pub fn init(cx: &mut AppContext) { · 129 unmodified lines | ||
| 407 | 409 | cx.add_action(Editor::go_to_hunk); |
| 408 | 410 | cx.add_action(Editor::go_to_prev_hunk); |
| 409 | 411 | cx.add_action(Editor::go_to_definition); |
| 412 | + cx.add_action(Editor::go_to_definition_split); | |
| 410 | 413 | cx.add_action(Editor::go_to_type_definition); |
| 414 | + cx.add_action(Editor::go_to_type_definition_split); | |
| 411 | 415 | cx.add_action(Editor::fold); |
| 412 | 416 | cx.add_action(Editor::fold_at); |
| 413 | 417 | cx.add_action(Editor::unfold_lines); |
| @@ -494,6 +498,7 @@ pub enum SoftWrap { · 80 unmodified lines | ||
| 494 | 498 | #[derive(Clone)] |
| 495 | 499 | pub struct EditorStyle { |
| 496 | 500 | pub text: TextStyle, |
| 501 | + pub line_height_scalar: f32, | |
| 497 | 502 | pub placeholder_text: Option<TextStyle>, |
| 498 | 503 | pub theme: theme::Editor, |
| 499 | 504 | pub theme_id: usize, |
| @@ -6184,14 +6189,31 @@ impl Editor { · 5684 unmodified lines | ||
| 6184 | 6189 | } |
| 6185 | 6190 | |
| 6186 | 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 | 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 | 6217 | let Some(workspace) = self.workspace(cx) else { return }; |
| 6196 | 6218 | let buffer = self.buffer.read(cx); |
| 6197 | 6219 | let head = self.selections.newest::<usize>(cx).head(); |
| @@ -6210,7 +6232,7 @@ impl Editor { · 12 unmodified lines | ||
| 6210 | 6232 | cx.spawn_labeled("Fetching Definition...", |editor, mut cx| async move { |
| 6211 | 6233 | let definitions = definitions.await?; |
| 6212 | 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 | 6237 | Ok::<(), anyhow::Error>(()) |
| 6216 | 6238 | }) |
| @@ -6220,6 +6242,7 @@ impl Editor { · 3 unmodified lines | ||
| 6220 | 6242 | pub fn navigate_to_definitions( |
| 6221 | 6243 | &mut self, |
| 6222 | 6244 | mut definitions: Vec<LocationLink>, |
| 6245 | + split: bool, | |
| 6223 | 6246 | cx: &mut ViewContext<Editor>, |
| 6224 | 6247 | ) { |
| 6225 | 6248 | let Some(workspace) = self.workspace(cx) else { return }; |
| @@ -6239,7 +6262,11 @@ impl Editor { · 13 unmodified lines | ||
| 6239 | 6262 | } else { |
| 6240 | 6263 | cx.window_context().defer(move |cx| { |
| 6241 | 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 | 6271 | target_editor.update(cx, |target_editor, cx| { |
| 6245 | 6272 | // When selecting a definition in a different buffer, disable the nav history |
| @@ -6275,7 +6302,9 @@ impl Editor { · 29 unmodified lines | ||
| 6275 | 6302 | .map(|definition| definition.target) |
| 6276 | 6303 | .collect(); |
| 6277 | 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 | 6350 | .unwrap(); |
| 6322 | 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 | 6364 | mut locations: Vec<Location>, |
| 6336 | 6365 | replica_id: ReplicaId, |
| 6337 | 6366 | title: String, |
| 6367 | + split: bool, | |
| 6338 | 6368 | cx: &mut ViewContext<Workspace>, |
| 6339 | 6369 | ) { |
| 6340 | 6370 | // If there are multiple definitions, open them in a multibuffer |
| @@ -6381,7 +6411,11 @@ impl Editor { · 40 unmodified lines | ||
| 6381 | 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 | 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 | 8135 | cx: &AppContext, |
| 8102 | 8136 | ) -> EditorStyle { |
| 8103 | 8137 | let font_cache = cx.font_cache(); |
| 8104 | − | |
| 8138 | + let line_height_scalar = settings.line_height(); | |
| 8105 | 8139 | let theme_id = settings.theme.meta.id; |
| 8106 | 8140 | let mut theme = settings.theme.editor.clone(); |
| 8107 | 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 | 8149 | EditorStyle { |
| 8116 | 8150 | text: field_editor_theme.text, |
| 8117 | 8151 | placeholder_text: field_editor_theme.placeholder_text, |
| 8152 | + line_height_scalar, | |
| 8118 | 8153 | theme, |
| 8119 | 8154 | theme_id, |
| 8120 | 8155 | } |
| @@ -8137,6 +8172,7 @@ fn build_style( · 16 unmodified lines | ||
| 8137 | 8172 | underline: Default::default(), |
| 8138 | 8173 | }, |
| 8139 | 8174 | placeholder_text: None, |
| 8175 | + line_height_scalar, | |
| 8140 | 8176 | theme, |
| 8141 | 8177 | theme_id, |
| 8142 | 8178 | } |
| @@ -3836,7 +3836,7 @@ async fn test_autoclose_with_embedded_language(cx: &mut gpui::TestAppContext) { · 3835 unmodified lines | ||
| 3836 | 3836 | autoclose_before: "})]>".into(), |
| 3837 | 3837 | ..Default::default() |
| 3838 | 3838 | }, |
| 3839 | − Some(tree_sitter_javascript::language()), | |
| 3839 | + Some(tree_sitter_typescript::language_tsx()), | |
| 3840 | 3840 | )); |
| 3841 | 3841 | |
| 3842 | 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 | 5383 | line_comment: Some("// ".into()), |
| 5384 | 5384 | ..Default::default() |
| 5385 | 5385 | }, |
| 5386 | − Some(tree_sitter_javascript::language()), | |
| 5386 | + Some(tree_sitter_typescript::language_tsx()), | |
| 5387 | 5387 | )); |
| 5388 | 5388 | |
| 5389 | 5389 | let registry = Arc::new(LanguageRegistry::test()); |
| @@ -156,6 +156,7 @@ impl EditorElement { · 155 unmodified lines | ||
| 156 | 156 | event.position, |
| 157 | 157 | event.cmd, |
| 158 | 158 | event.shift, |
| 159 | + event.alt, | |
| 159 | 160 | position_map.as_ref(), |
| 160 | 161 | text_bounds, |
| 161 | 162 | cx, |
| @@ -308,6 +309,7 @@ impl EditorElement { · 146 unmodified lines | ||
| 308 | 309 | position: Vector2F, |
| 309 | 310 | cmd: bool, |
| 310 | 311 | shift: bool, |
| 312 | + alt: bool, | |
| 311 | 313 | position_map: &PositionMap, |
| 312 | 314 | text_bounds: RectF, |
| 313 | 315 | cx: &mut EventContext<Editor>, |
| @@ -324,9 +326,9 @@ impl EditorElement { · 10 unmodified lines | ||
| 324 | 326 | |
| 325 | 327 | if point == target_point { |
| 326 | 328 | if shift { |
| 327 | − go_to_fetched_type_definition(editor, point, cx); | |
| 329 | + go_to_fetched_type_definition(editor, point, alt, cx); | |
| 328 | 330 | } else { |
| 329 | − go_to_fetched_definition(editor, point, cx); | |
| 331 | + go_to_fetched_definition(editor, point, alt, cx); | |
| 330 | 332 | } |
| 331 | 333 | |
| 332 | 334 | return true; |
| @@ -1182,8 +1184,10 @@ impl EditorElement { · 849 unmodified lines | ||
| 1182 | 1184 | }); |
| 1183 | 1185 | scene.push_mouse_region( |
| 1184 | 1186 | MouseRegion::new::<ScrollbarMouseHandlers>(cx.view_id(), cx.view_id(), track_bounds) |
| 1185 | − .on_move(move |_, editor: &mut Editor, cx| { | |
| 1186 | − editor.scroll_manager.show_scrollbar(cx); | |
| 1187 | + .on_move(move |event, editor: &mut Editor, cx| { | |
| 1188 | + if event.pressed_button.is_none() { | |
| 1189 | + editor.scroll_manager.show_scrollbar(cx); | |
| 1190 | + } | |
| 1187 | 1191 | }) |
| 1188 | 1192 | .on_down(MouseButton::Left, { |
| 1189 | 1193 | let row_range = row_range.clone(); |
| @@ -1973,7 +1977,7 @@ impl Element<Editor> for EditorElement { · 783 unmodified lines | ||
| 1973 | 1977 | |
| 1974 | 1978 | let snapshot = editor.snapshot(cx); |
| 1975 | 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 | 1982 | let gutter_padding; |
| 1979 | 1983 | let gutter_width; |
| @@ -887,10 +887,20 @@ pub(crate) enum BufferSearchHighlights {} · 886 unmodified lines | ||
| 887 | 887 | impl SearchableItem for Editor { |
| 888 | 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 | 895 | match event { |
| 892 | 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 | 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 | 959 | fn match_index_for_direction( |
| 945 | 960 | &mut self, |
| 946 | 961 | matches: &Vec<Range<Anchor>>, |
| @@ -949,8 +964,16 @@ impl SearchableItem for Editor { · 2 unmodified lines | ||
| 949 | 964 | cx: &mut ViewContext<Self>, |
| 950 | 965 | ) -> usize { |
| 951 | 966 | let buffer = self.buffer().read(cx).snapshot(cx); |
| 952 | − let cursor = self.selections.newest_anchor().head(); | |
| 953 | − if matches[current_index].start.cmp(&cursor, &buffer).is_gt() { | |
| 967 | + let current_index_position = if self.selections.disjoint_anchors().len() == 1 { | |
| 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 | 977 | if direction == Direction::Prev { |
| 955 | 978 | if current_index == 0 { |
| 956 | 979 | current_index = matches.len() - 1; |
| @@ -958,7 +981,11 @@ impl SearchableItem for Editor { · 1 unmodified line | ||
| 958 | 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 | 989 | if direction == Direction::Next { |
| 963 | 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 | 246 | pub fn go_to_fetched_definition( |
| 247 | 247 | editor: &mut Editor, |
| 248 | 248 | point: DisplayPoint, |
| 249 | + split: bool, | |
| 249 | 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 | 255 | pub fn go_to_fetched_type_definition( |
| 255 | 256 | editor: &mut Editor, |
| 256 | 257 | point: DisplayPoint, |
| 258 | + split: bool, | |
| 257 | 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 | 264 | fn go_to_fetched_definition_of_kind( |
| 263 | 265 | kind: LinkDefinitionKind, |
| 264 | 266 | editor: &mut Editor, |
| 265 | 267 | point: DisplayPoint, |
| 268 | + split: bool, | |
| 266 | 269 | cx: &mut ViewContext<Editor>, |
| 267 | 270 | ) { |
| 268 | 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 | 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 | 282 | } else { |
| 280 | 283 | editor.select( |
| 281 | 284 | SelectPhase::Begin { |
| @@ -403,7 +406,7 @@ mod tests { · 121 unmodified lines | ||
| 403 | 406 | }); |
| 404 | 407 | |
| 405 | 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 | 411 | requests.next().await; |
| 409 | 412 | cx.foreground().run_until_parked(); |
| @@ -614,7 +617,7 @@ mod tests { · 204 unmodified lines | ||
| 614 | 617 | |
| 615 | 618 | // Cmd click with existing definition doesn't re-request and dismisses highlight |
| 616 | 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 | 622 | // Assert selection moved to to definition |
| 620 | 623 | cx.lsp |
| @@ -655,7 +658,7 @@ mod tests { · 34 unmodified lines | ||
| 655 | 658 | ]))) |
| 656 | 659 | }); |
| 657 | 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 | 663 | requests.next().await; |
| 661 | 664 | cx.foreground().run_until_parked(); |
| @@ -16,13 +16,13 @@ use crate::{ · 15 unmodified lines | ||
| 16 | 16 | Anchor, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode, ToOffset, |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | −#[derive(Clone)] | |
| 19 | +#[derive(Debug, Clone)] | |
| 20 | 20 | pub struct PendingSelection { |
| 21 | 21 | pub selection: Selection<Anchor>, |
| 22 | 22 | pub mode: SelectMode, |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | −#[derive(Clone)] | |
| 25 | +#[derive(Debug, Clone)] | |
| 26 | 26 | pub struct SelectionsCollection { |
| 27 | 27 | display_map: ModelHandle<DisplayMap>, |
| 28 | 28 | buffer: ModelHandle<MultiBuffer>, |
| @@ -60,6 +60,7 @@ pub(crate) struct FeedbackEditor { · 59 unmodified lines | ||
| 60 | 60 | system_specs: SystemSpecs, |
| 61 | 61 | editor: ViewHandle<Editor>, |
| 62 | 62 | project: ModelHandle<Project>, |
| 63 | + pub allow_submission: bool, | |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | 66 | impl FeedbackEditor { |
| @@ -82,10 +83,15 @@ impl FeedbackEditor { · 16 unmodified lines | ||
| 82 | 83 | system_specs: system_specs.clone(), |
| 83 | 84 | editor, |
| 84 | 85 | project, |
| 86 | + allow_submission: true, | |
| 85 | 87 | } |
| 86 | 88 | } |
| 87 | 89 | |
| 88 | 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 | 95 | let feedback_text = self.editor.read(cx).text(cx); |
| 90 | 96 | let feedback_char_count = feedback_text.chars().count(); |
| 91 | 97 | let feedback_text = feedback_text.trim().to_string(); |
| @@ -122,19 +128,26 @@ impl FeedbackEditor { · 30 unmodified lines | ||
| 122 | 128 | let answer = answer.recv().await; |
| 123 | 129 | |
| 124 | 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 | 136 | match FeedbackEditor::submit_feedback(&feedback_text, client, specs).await { |
| 126 | 137 | Ok(_) => { |
| 127 | 138 | this.update(&mut cx, |_, cx| cx.emit(editor::Event::Closed)) |
| 128 | 139 | .log_err(); |
| 129 | 140 | } |
| 141 | + | |
| 130 | 142 | Err(error) => { |
| 131 | 143 | log::error!("{}", error); |
| 132 | − this.update(&mut cx, |_, cx| { | |
| 144 | + this.update(&mut cx, |feedback_editor, cx| { | |
| 133 | 145 | cx.prompt( |
| 134 | 146 | PromptLevel::Critical, |
| 135 | 147 | FEEDBACK_SUBMISSION_ERROR_TEXT, |
| 136 | 148 | &["OK"], |
| 137 | 149 | ); |
| 150 | + feedback_editor.set_allow_submission(true, cx); | |
| 138 | 151 | }) |
| 139 | 152 | .log_err(); |
| 140 | 153 | } |
| @@ -146,6 +159,11 @@ impl FeedbackEditor { · 5 unmodified lines | ||
| 146 | 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 | 167 | async fn submit_feedback( |
| 150 | 168 | feedback_text: &str, |
| 151 | 169 | zed_client: Arc<Client>, |
| @@ -362,8 +380,13 @@ impl Item for FeedbackEditor { · 210 unmodified lines | ||
| 362 | 380 | impl SearchableItem for FeedbackEditor { |
| 363 | 381 | type Match = Range<Anchor>; |
| 364 | 382 | |
| 365 | − fn to_search_event(event: &Self::Event) -> Option<workspace::searchable::SearchEvent> { | |
| 366 | − Editor::to_search_event(event) | |
| 383 | + fn to_search_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 | 392 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { |
| @@ -391,6 +414,11 @@ impl SearchableItem for FeedbackEditor { · 21 unmodified lines | ||
| 391 | 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 | 422 | fn find_matches( |
| 395 | 423 | &mut self, |
| 396 | 424 | query: project::search::SearchQuery, |
| @@ -46,10 +46,28 @@ impl View for SubmitFeedbackButton { · 45 unmodified lines | ||
| 46 | 46 | |
| 47 | 47 | fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { |
| 48 | 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 | 54 | enum SubmitFeedbackButton {} |
| 50 | 55 | MouseEventHandler::<SubmitFeedbackButton, Self>::new(0, cx, |state, _| { |
| 51 | − let style = theme.feedback.submit_button.style_for(state); | |
| 52 | − Label::new("Submit as Markdown", style.text.clone()) | |
| 56 | + let text; | |
| 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 | 71 | .contained() |
| 54 | 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 | 446 | if let Some(m) = self.matches.get(self.selected_index()) { |
| 447 | 447 | if let Some(workspace) = self.workspace.upgrade(cx) { |
| 448 | − let open_task = workspace.update(cx, |workspace, cx| match m { | |
| 449 | − Match::History(history_match) => { | |
| 450 | − let worktree_id = history_match.project.worktree_id; | |
| 451 | − if workspace | |
| 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 | − ) | |
| 448 | + let open_task = workspace.update(cx, move |workspace, cx| { | |
| 449 | + let split_or_open = |workspace: &mut Workspace, project_path, cx| { | |
| 450 | + if secondary { | |
| 451 | + workspace.split_path(project_path, cx) | |
| 466 | 452 | } else { |
| 467 | − match history_match.absolute.as_ref() { | |
| 468 | − Some(abs_path) => { | |
| 469 | − workspace.open_abs_path(abs_path.to_path_buf(), false, cx) | |
| 470 | − } | |
| 471 | − None => workspace.open_path( | |
| 453 | + workspace.open_path(project_path, None, true, cx) | |
| 454 | + } | |
| 455 | + }; | |
| 456 | + match m { | |
| 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 | 467 | ProjectPath { |
| 473 | 468 | worktree_id, |
| 474 | 469 | path: Arc::clone(&history_match.project.path), |
| 475 | 470 | }, |
| 476 | − None, | |
| 477 | − true, | |
| 478 | 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 | 512 | let row = self |
| @@ -33,6 +33,7 @@ pub trait GitRepository: Send { · 32 unmodified lines | ||
| 33 | 33 | fn statuses(&self) -> Option<TreeMap<RepoPath, GitFileStatus>>; |
| 34 | 34 | |
| 35 | 35 | fn status(&self, path: &RepoPath) -> Result<Option<GitFileStatus>>; |
| 36 | + | |
| 36 | 37 | fn branches(&self) -> Result<Vec<Branch>> { |
| 37 | 38 | Ok(vec![]) |
| 38 | 39 | } |
| @@ -1073,7 +1073,7 @@ impl AppContext { · 1072 unmodified lines | ||
| 1073 | 1073 | |
| 1074 | 1074 | pub fn is_action_available(&self, action: &dyn Action) -> bool { |
| 1075 | 1075 | let mut available_in_window = false; |
| 1076 | − let action_type = action.as_any().type_id(); | |
| 1076 | + let action_id = action.id(); | |
| 1077 | 1077 | if let Some(window_id) = self.platform.main_window_id() { |
| 1078 | 1078 | available_in_window = self |
| 1079 | 1079 | .read_window(window_id, |cx| { |
| @@ -1083,7 +1083,7 @@ impl AppContext { · 3 unmodified lines | ||
| 1083 | 1083 | cx.views_metadata.get(&(window_id, view_id)) |
| 1084 | 1084 | { |
| 1085 | 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 | 1087 | return true; |
| 1088 | 1088 | } |
| 1089 | 1089 | } |
| @@ -1094,7 +1094,7 @@ impl AppContext { · 4 unmodified lines | ||
| 1094 | 1094 | }) |
| 1095 | 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 | 1100 | fn actions_mut( |
| @@ -3399,7 +3399,7 @@ impl<'a, 'b, 'c, V: View> LayoutContext<'a, 'b, 'c, V> { · 2298 unmodified lines | ||
| 3399 | 3399 | for (i, view_id) in self.ancestors(view_id).enumerate() { |
| 3400 | 3400 | if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) { |
| 3401 | 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 | 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 | 3411 | handler_depth = Some(contexts.len()) |
| 3412 | 3412 | } |
| 3413 | 3413 | |
| 3414 | 3414 | self.keystroke_matcher |
| 3415 | − .bindings_for_action_type(action.as_any().type_id()) | |
| 3415 | + .bindings_for_action(action.id()) | |
| 3416 | 3416 | .find_map(|b| { |
| 3417 | 3417 | let highest_handler = handler_depth?; |
| 3418 | 3418 | if action.eq(b.action()) |
| @@ -14,8 +14,8 @@ use crate::{ · 13 unmodified lines | ||
| 14 | 14 | text_layout::TextLayoutCache, |
| 15 | 15 | util::post_inc, |
| 16 | 16 | Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect, |
| 17 | − Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, NoAction, SceneBuilder, | |
| 18 | − Subscription, View, ViewContext, ViewHandle, WindowInvalidation, | |
| 17 | + Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, SceneBuilder, Subscription, | |
| 18 | + View, ViewContext, ViewHandle, WindowInvalidation, | |
| 19 | 19 | }; |
| 20 | 20 | use anyhow::{anyhow, bail, Result}; |
| 21 | 21 | use collections::{HashMap, HashSet}; |
| @@ -363,17 +363,13 @@ impl<'a> WindowContext<'a> { · 341 unmodified lines | ||
| 363 | 363 | ) -> Vec<(&'static str, Box<dyn Action>, SmallVec<[Binding; 1]>)> { |
| 364 | 364 | let window_id = self.window_id; |
| 365 | 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 | 367 | for (depth, view_id) in self.ancestors(view_id).enumerate() { |
| 368 | 368 | if let Some(view_metadata) = self.views_metadata.get(&(window_id, view_id)) { |
| 369 | 369 | contexts.push(view_metadata.keymap_context.clone()); |
| 370 | 370 | if let Some(actions) = self.actions.get(&view_metadata.type_id) { |
| 371 | − handler_depths_by_action_type.extend( | |
| 372 | − actions | |
| 373 | − .keys() | |
| 374 | − .copied() | |
| 375 | − .map(|action_type| (action_type, depth)), | |
| 376 | − ); | |
| 371 | + handler_depths_by_action_id | |
| 372 | + .extend(actions.keys().copied().map(|action_id| (action_id, depth))); | |
| 377 | 373 | } |
| 378 | 374 | } else { |
| 379 | 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 | 383 | self.global_actions |
| 388 | 384 | .keys() |
| 389 | 385 | .copied() |
| 390 | − .map(|action_type| (action_type, contexts.len())), | |
| 386 | + .map(|action_id| (action_id, contexts.len())), | |
| 391 | 387 | ); |
| 392 | 388 | |
| 393 | 389 | self.action_deserializers |
| 394 | 390 | .iter() |
| 395 | − .filter_map(move |(name, (type_id, deserialize))| { | |
| 396 | − if let Some(action_depth) = handler_depths_by_action_type.get(type_id).copied() { | |
| 391 | + .filter_map(move |(name, (action_id, deserialize))| { | |
| 392 | + if let Some(action_depth) = handler_depths_by_action_id.get(action_id).copied() { | |
| 397 | 393 | let action = deserialize(serde_json::Value::Object(Default::default())).ok()?; |
| 398 | 394 | let bindings = self |
| 399 | 395 | .keystroke_matcher |
| 400 | − .bindings_for_action_type(*type_id) | |
| 396 | + .bindings_for_action(*action_id) | |
| 401 | 397 | .filter(|b| { |
| 402 | 398 | action.eq(b.action()) |
| 403 | 399 | && (0..=action_depth) |
| @@ -434,11 +430,7 @@ impl<'a> WindowContext<'a> { · 30 unmodified lines | ||
| 434 | 430 | MatchResult::None => false, |
| 435 | 431 | MatchResult::Pending => true, |
| 436 | 432 | MatchResult::Matches(matches) => { |
| 437 | − let no_action_id = (NoAction {}).id(); | |
| 438 | 433 | for (view_id, action) in matches { |
| 439 | − if action.id() == no_action_id { | |
| 440 | − return false; | |
| 441 | − } | |
| 442 | 434 | if self.dispatch_action(Some(*view_id), action.as_ref()) { |
| 443 | 435 | self.keystroke_matcher.clear_pending(); |
| 444 | 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 | 1276 | #[derive(Copy, Clone, Debug)] |
| 1272 | 1277 | pub struct SizeConstraint { |
| 1273 | 1278 | pub min: Vector2F, |
| @@ -27,7 +27,7 @@ pub mod json; · 26 unmodified lines | ||
| 27 | 27 | pub mod keymap_matcher; |
| 28 | 28 | pub mod platform; |
| 29 | 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 | 32 | pub use anyhow; |
| 33 | 33 | pub use serde_json; |
| @@ -8,7 +8,7 @@ use std::{any::TypeId, fmt::Debug}; · 7 unmodified lines | ||
| 8 | 8 | use collections::HashMap; |
| 9 | 9 | use smallvec::SmallVec; |
| 10 | 10 | |
| 11 | −use crate::Action; | |
| 11 | +use crate::{Action, NoAction}; | |
| 12 | 12 | |
| 13 | 13 | pub use binding::{Binding, BindingMatchResult}; |
| 14 | 14 | pub use keymap::Keymap; |
| @@ -47,8 +47,8 @@ impl KeymapMatcher { · 32 unmodified lines | ||
| 47 | 47 | self.keymap.clear(); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | − pub fn bindings_for_action_type(&self, action_type: TypeId) -> impl Iterator<Item = &Binding> { | |
| 51 | − self.keymap.bindings_for_action_type(action_type) | |
| 50 | + pub fn bindings_for_action(&self, action_id: TypeId) -> impl Iterator<Item = &Binding> { | |
| 51 | + self.keymap.bindings_for_action(action_id) | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | pub fn clear_pending(&mut self) { |
| @@ -81,6 +81,7 @@ impl KeymapMatcher { · 26 unmodified lines | ||
| 81 | 81 | // The key is the reverse position of the binding in the bindings list so that later bindings |
| 82 | 82 | // match before earlier ones in the user's config |
| 83 | 83 | let mut matched_bindings: Vec<(usize, Box<dyn Action>)> = Default::default(); |
| 84 | + let no_action_id = (NoAction {}).id(); | |
| 84 | 85 | |
| 85 | 86 | let first_keystroke = self.pending_keystrokes.is_empty(); |
| 86 | 87 | self.pending_keystrokes.push(keystroke.clone()); |
| @@ -108,7 +109,9 @@ impl KeymapMatcher { · 21 unmodified lines | ||
| 108 | 109 | match binding.match_keys_and_context(&self.pending_keystrokes, &self.contexts[i..]) |
| 109 | 110 | { |
| 110 | 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 | 116 | BindingMatchResult::Partial => { |
| 114 | 117 | self.pending_views |
| @@ -7,8 +7,8 @@ use super::{KeymapContext, KeymapContextPredicate, Keystroke}; · 6 unmodified lines | ||
| 7 | 7 | |
| 8 | 8 | pub struct Binding { |
| 9 | 9 | action: Box<dyn Action>, |
| 10 | − keystrokes: SmallVec<[Keystroke; 2]>, | |
| 11 | − context_predicate: Option<KeymapContextPredicate>, | |
| 10 | + pub(super) keystrokes: SmallVec<[Keystroke; 2]>, | |
| 11 | + pub(super) context_predicate: Option<KeymapContextPredicate>, | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | impl std::fmt::Debug for Binding { |
| @@ -1,61 +1,388 @@ | ||
| 1 | +use collections::HashSet; | |
| 1 | 2 | use smallvec::SmallVec; |
| 2 | −use std::{ | |
| 3 | − any::{Any, TypeId}, | |
| 4 | − collections::HashMap, | |
| 5 | −}; | |
| 3 | +use std::{any::TypeId, collections::HashMap}; | |
| 6 | 4 | |
| 7 | −use super::Binding; | |
| 5 | +use crate::{Action, NoAction}; | |
| 6 | + | |
| 7 | +use super::{Binding, KeymapContextPredicate, Keystroke}; | |
| 8 | 8 | |
| 9 | 9 | #[derive(Default)] |
| 10 | 10 | pub struct Keymap { |
| 11 | 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 | 16 | impl Keymap { |
| 16 | − pub fn new(bindings: Vec<Binding>) -> Self { | |
| 17 | − let mut binding_indices_by_action_type = HashMap::new(); | |
| 18 | − for (ix, binding) in bindings.iter().enumerate() { | |
| 19 | − binding_indices_by_action_type | |
| 20 | − .entry(binding.action().type_id()) | |
| 21 | − .or_insert_with(SmallVec::new) | |
| 22 | − .push(ix); | |
| 23 | − } | |
| 24 | − | |
| 25 | − Self { | |
| 26 | − binding_indices_by_action_type, | |
| 27 | − bindings, | |
| 28 | − } | |
| 17 | + #[cfg(test)] | |
| 18 | + pub(super) fn new(bindings: Vec<Binding>) -> Self { | |
| 19 | + let mut this = Self::default(); | |
| 20 | + this.add_bindings(bindings); | |
| 21 | + this | |
| 29 | 22 | } |
| 30 | 23 | |
| 31 | − pub(crate) fn bindings_for_action_type( | |
| 24 | + pub(crate) fn bindings_for_action( | |
| 32 | 25 | &self, |
| 33 | − action_type: TypeId, | |
| 26 | + action_id: TypeId, | |
| 34 | 27 | ) -> impl Iterator<Item = &'_ Binding> { |
| 35 | − self.binding_indices_by_action_type | |
| 36 | − .get(&action_type) | |
| 28 | + self.binding_indices_by_action_id | |
| 29 | + .get(&action_id) | |
| 37 | 30 | .map(SmallVec::as_slice) |
| 38 | 31 | .unwrap_or(&[]) |
| 39 | 32 | .iter() |
| 40 | 33 | .map(|ix| &self.bindings[*ix]) |
| 34 | + .filter(|binding| !self.binding_disabled(binding)) | |
| 41 | 35 | } |
| 42 | 36 | |
| 43 | 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 | 41 | for binding in bindings { |
| 45 | − self.binding_indices_by_action_type | |
| 46 | − .entry(binding.action().as_any().type_id()) | |
| 47 | − .or_default() | |
| 48 | − .push(self.bindings.len()); | |
| 49 | − self.bindings.push(binding); | |
| 42 | + if binding.action().id() == no_action_id { | |
| 43 | + has_new_disabled_keystrokes |= self | |
| 44 | + .disabled_keystrokes | |
| 45 | + .entry(binding.keystrokes) | |
| 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 | 79 | pub(crate) fn clear(&mut self) { |
| 54 | 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> { | |
| 59 | − &self.bindings | |
| 226 | + #[test] | |
| 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 | 48 | pub enum KeymapContextPredicate { |
| 49 | 49 | Identifier(String), |
| 50 | 50 | Equal(String, String), |
| @@ -3,7 +3,7 @@ use std::fmt::Write; · 2 unmodified lines | ||
| 3 | 3 | use anyhow::anyhow; |
| 4 | 4 | use serde::Deserialize; |
| 5 | 5 | |
| 6 | −#[derive(Clone, Debug, Eq, PartialEq, Default, Deserialize)] | |
| 6 | +#[derive(Clone, Debug, Eq, PartialEq, Default, Deserialize, Hash)] | |
| 7 | 7 | pub struct Keystroke { |
| 8 | 8 | pub ctrl: bool, |
| 9 | 9 | pub alt: bool, |
| @@ -231,7 +231,7 @@ impl MacForegroundPlatform { · 230 unmodified lines | ||
| 231 | 231 | } => { |
| 232 | 232 | // TODO |
| 233 | 233 | let keystrokes = keystroke_matcher |
| 234 | − .bindings_for_action_type(action.as_any().type_id()) | |
| 234 | + .bindings_for_action(action.id()) | |
| 235 | 235 | .find(|binding| binding.action().eq(action.as_ref())) |
| 236 | 236 | .map(|binding| binding.keystrokes()); |
| 237 | 237 | let selector = match os_action { |
| @@ -46,7 +46,6 @@ lazy_static.workspace = true · 45 unmodified lines | ||
| 46 | 46 | log.workspace = true |
| 47 | 47 | parking_lot.workspace = true |
| 48 | 48 | postage.workspace = true |
| 49 | −rand = { workspace = true, optional = true } | |
| 50 | 49 | regex.workspace = true |
| 51 | 50 | schemars.workspace = true |
| 52 | 51 | serde.workspace = true |
| @@ -56,10 +55,12 @@ similar = "1.3" · 3 unmodified lines | ||
| 56 | 55 | smallvec.workspace = true |
| 57 | 56 | smol.workspace = true |
| 58 | 57 | tree-sitter.workspace = true |
| 59 | −tree-sitter-rust = { version = "*", optional = true } | |
| 60 | −tree-sitter-typescript = { version = "*", optional = true } | |
| 61 | 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 | 64 | [dev-dependencies] |
| 64 | 65 | client = { path = "../client", features = ["test-support"] } |
| 65 | 66 | collections = { path = "../collections", features = ["test-support"] } |
| @@ -74,12 +75,13 @@ indoc.workspace = true · 8 unmodified lines | ||
| 74 | 75 | rand.workspace = true |
| 75 | 76 | unindent.workspace = true |
| 76 | 77 | |
| 77 | −tree-sitter-embedded-template = "*" | |
| 78 | −tree-sitter-html = "*" | |
| 79 | −tree-sitter-javascript = "*" | |
| 80 | −tree-sitter-json = "*" | |
| 81 | −tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" } | |
| 82 | −tree-sitter-rust = "*" | |
| 83 | −tree-sitter-python = "*" | |
| 84 | −tree-sitter-typescript = "*" | |
| 85 | −tree-sitter-ruby = "*" | |
| 78 | +tree-sitter-embedded-template.workspace = true | |
| 79 | +tree-sitter-html.workspace = true | |
| 80 | +tree-sitter-json.workspace = true | |
| 81 | +tree-sitter-markdown.workspace = true | |
| 82 | +tree-sitter-rust.workspace = true | |
| 83 | +tree-sitter-python.workspace = true | |
| 84 | +tree-sitter-typescript.workspace = true | |
| 85 | +tree-sitter-ruby.workspace = true | |
| 86 | +tree-sitter-elixir.workspace = true | |
| 87 | +tree-sitter-heex.workspace = true | |
| @@ -2145,23 +2145,27 @@ impl BufferSnapshot { · 2144 unmodified lines | ||
| 2145 | 2145 | |
| 2146 | 2146 | pub fn language_scope_at<D: ToOffset>(&self, position: D) -> Option<LanguageScope> { |
| 2147 | 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 | |
| 2150 | − .syntax | |
| 2151 | − .layers_for_range(offset..offset, &self.text) | |
| 2152 | − .filter(|l| l.node().end_byte() > offset) | |
| 2153 | − .last() | |
| 2154 | − { | |
| 2155 | − Some(LanguageScope { | |
| 2156 | − language: layer_info.language.clone(), | |
| 2157 | − override_id: layer_info.override_id(offset, &self.text), | |
| 2158 | − }) | |
| 2159 | − } else { | |
| 2160 | − self.language.clone().map(|language| LanguageScope { | |
| 2161 | − language, | |
| 2162 | − override_id: None, | |
| 2163 | − }) | |
| 2154 | + // Use the layer that has the smallest node intersecting the given point. | |
| 2155 | + for layer in self.syntax.layers_for_range(offset..offset, &self.text) { | |
| 2156 | + let mut cursor = layer.node().walk(); | |
| 2157 | + while cursor.goto_first_child_for_byte(offset).is_some() {} | |
| 2158 | + let node_range = cursor.node().byte_range(); | |
| 2159 | + if node_range.to_inclusive().contains(&offset) && node_range.len() < range.len() { | |
| 2160 | + range = node_range; | |
| 2161 | + scope = Some(LanguageScope { | |
| 2162 | + language: layer.language.clone(), | |
| 2163 | + override_id: layer.override_id(offset, &self.text), | |
| 2164 | + }); | |
| 2165 | + } | |
| 2164 | 2166 | } |
| 2167 | + | |
| 2168 | + scope | |
| 2165 | 2169 | } |
| 2166 | 2170 | |
| 2167 | 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( | |
| 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 | − ); | |
| 1536 | + let html_language = Arc::new(html_lang()); | |
| 1561 | 1537 | |
| 1562 | − let javascript_language = Arc::new( | |
| 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 | − ); | |
| 1538 | + let javascript_language = Arc::new(javascript_lang()); | |
| 1577 | 1539 | |
| 1578 | 1540 | let language_registry = Arc::new(LanguageRegistry::test()); |
| 1579 | 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 | 1633 | #[gpui::test] |
| 1672 | −fn test_language_config_at(cx: &mut AppContext) { | |
| 1634 | +fn test_language_scope_at(cx: &mut AppContext) { | |
| 1673 | 1635 | init_settings(cx, |_| {}); |
| 1674 | 1636 | |
| 1675 | 1637 | cx.add_model(|cx| { |
| @@ -1709,7 +1671,7 @@ fn test_language_config_at(cx: &mut AppContext) { · 33 unmodified lines | ||
| 1709 | 1671 | .collect(), |
| 1710 | 1672 | ..Default::default() |
| 1711 | 1673 | }, |
| 1712 | − Some(tree_sitter_javascript::language()), | |
| 1674 | + Some(tree_sitter_typescript::language_tsx()), | |
| 1713 | 1675 | ) |
| 1714 | 1676 | .with_override_query( |
| 1715 | 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 | 1769 | #[gpui::test] |
| 1760 | 1770 | fn test_serialization(cx: &mut gpui::AppContext) { |
| 1761 | 1771 | let mut now = Instant::now(); |
| @@ -2143,6 +2153,7 @@ fn ruby_lang() -> Language { · 381 unmodified lines | ||
| 2143 | 2153 | LanguageConfig { |
| 2144 | 2154 | name: "Ruby".into(), |
| 2145 | 2155 | path_suffixes: vec!["rb".to_string()], |
| 2156 | + line_comment: Some("# ".into()), | |
| 2146 | 2157 | ..Default::default() |
| 2147 | 2158 | }, |
| 2148 | 2159 | Some(tree_sitter_ruby::language()), |
| @@ -2158,6 +2169,61 @@ fn ruby_lang() -> Language { · 9 unmodified lines | ||
| 2158 | 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 | 2227 | fn rust_lang() -> Language { |
| 2162 | 2228 | Language::new( |
| 2163 | 2229 | LanguageConfig { |
| @@ -2227,7 +2293,7 @@ fn javascript_lang() -> Language { · 63 unmodified lines | ||
| 2227 | 2293 | name: "JavaScript".into(), |
| 2228 | 2294 | ..Default::default() |
| 2229 | 2295 | }, |
| 2230 | − Some(tree_sitter_javascript::language()), | |
| 2296 | + Some(tree_sitter_typescript::language_tsx()), | |
| 2231 | 2297 | ) |
| 2232 | 2298 | .with_brackets_query( |
| 2233 | 2299 | r#" |
| @@ -2236,6 +2302,12 @@ fn javascript_lang() -> Language { · 2 unmodified lines | ||
| 2236 | 2302 | "#, |
| 2237 | 2303 | ) |
| 2238 | 2304 | .unwrap() |
| 2305 | + .with_indents_query( | |
| 2306 | + r#" | |
| 2307 | + (object "}" @end) @indent | |
| 2308 | + "#, | |
| 2309 | + ) | |
| 2310 | + .unwrap() | |
| 2239 | 2311 | } |
| 2240 | 2312 | |
| 2241 | 2313 | fn get_tree_sexp(buffer: &ModelHandle<Buffer>, cx: &gpui::TestAppContext) -> String { |
| @@ -830,6 +830,7 @@ impl LanguageRegistry { · 829 unmodified lines | ||
| 830 | 830 | Ok(language) => { |
| 831 | 831 | let language = Arc::new(language); |
| 832 | 832 | let mut state = this.state.write(); |
| 833 | + | |
| 833 | 834 | state.add(language.clone()); |
| 834 | 835 | state.mark_language_loaded(id); |
| 835 | 836 | if let Some(mut txs) = state.loading_languages.remove(&id) { |
| @@ -1787,7 +1788,7 @@ mod tests { · 951 unmodified lines | ||
| 1787 | 1788 | first_line_pattern: Some(Regex::new(r"\bnode\b").unwrap()), |
| 1788 | 1789 | ..Default::default() |
| 1789 | 1790 | }, |
| 1790 | − tree_sitter_javascript::language(), | |
| 1791 | + tree_sitter_typescript::language_tsx(), | |
| 1791 | 1792 | vec![], |
| 1792 | 1793 | |_| Default::default(), |
| 1793 | 1794 | ); |
| @@ -569,11 +569,19 @@ impl SyntaxSnapshot { · 568 unmodified lines | ||
| 569 | 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 | 574 | old_tree.included_ranges(), |
| 574 | 575 | &parent_layer_changed_ranges, |
| 575 | 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 | 587 | if included_ranges.is_empty() { |
| @@ -586,7 +594,7 @@ impl SyntaxSnapshot { · 6 unmodified lines | ||
| 586 | 594 | } |
| 587 | 595 | |
| 588 | 596 | log::trace!( |
| 589 | − "update layer. language:{}, start:{:?}, ranges:{:?}", | |
| 597 | + "update layer. language:{}, start:{:?}, included_ranges:{:?}", | |
| 590 | 598 | language.name(), |
| 591 | 599 | LogAnchorRange(&step.range, text), |
| 592 | 600 | LogIncludedRanges(&included_ranges), |
| @@ -608,6 +616,16 @@ impl SyntaxSnapshot { · 15 unmodified lines | ||
| 608 | 616 | }), |
| 609 | 617 | ); |
| 610 | 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 | 629 | if included_ranges.is_empty() { |
| 612 | 630 | included_ranges.push(tree_sitter::Range { |
| 613 | 631 | start_byte: 0, |
| @@ -771,8 +789,10 @@ impl SyntaxSnapshot { · 157 unmodified lines | ||
| 771 | 789 | range: Range<T>, |
| 772 | 790 | buffer: &'a BufferSnapshot, |
| 773 | 791 | ) -> impl 'a + Iterator<Item = SyntaxLayerInfo> { |
| 774 | − let start = buffer.anchor_before(range.start.to_offset(buffer)); | |
| 775 | − let end = buffer.anchor_after(range.end.to_offset(buffer)); | |
| 792 | + let start_offset = range.start.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 | 797 | let mut cursor = self.layers.filter::<_, ()>(move |summary| { |
| 778 | 798 | if summary.max_depth > summary.min_depth { |
| @@ -787,20 +807,21 @@ impl SyntaxSnapshot { · 8 unmodified lines | ||
| 787 | 807 | cursor.next(buffer); |
| 788 | 808 | iter::from_fn(move || { |
| 789 | 809 | while let Some(layer) = cursor.item() { |
| 810 | + let mut info = None; | |
| 790 | 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 | 816 | tree, |
| 793 | 817 | language, |
| 794 | 818 | depth: layer.depth, |
| 795 | − offset: ( | |
| 796 | − layer.range.start.to_offset(buffer), | |
| 797 | − layer.range.start.to_point(buffer).to_ts_point(), | |
| 798 | − ), | |
| 799 | − }; | |
| 800 | − cursor.next(buffer); | |
| 801 | − return Some(info); | |
| 802 | − } else { | |
| 803 | − cursor.next(buffer); | |
| 819 | + offset: (layer_start_offset, layer_start_point), | |
| 820 | + }); | |
| 821 | + } | |
| 822 | + cursor.next(buffer); | |
| 823 | + if info.is_some() { | |
| 824 | + return info; | |
| 804 | 825 | } |
| 805 | 826 | } |
| 806 | 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 | 1301 | pub(crate) fn splice_included_ranges( |
| 1276 | 1302 | mut ranges: Vec<tree_sitter::Range>, |
| 1277 | 1303 | removed_ranges: &[Range<usize>], |
| 1278 | 1304 | new_ranges: &[tree_sitter::Range], |
| 1279 | −) -> Vec<tree_sitter::Range> { | |
| 1305 | +) -> (Vec<tree_sitter::Range>, Range<usize>) { | |
| 1280 | 1306 | let mut removed_ranges = removed_ranges.iter().cloned().peekable(); |
| 1281 | 1307 | let mut new_ranges = new_ranges.into_iter().cloned().peekable(); |
| 1282 | 1308 | let mut ranges_ix = 0; |
| 1309 | + let mut changed_portion = usize::MAX..0; | |
| 1283 | 1310 | loop { |
| 1284 | 1311 | let next_new_range = new_ranges.peek(); |
| 1285 | 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 | 1378 | ranges.splice(start_ix..end_ix, insert); |
| 1345 | 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 | 1436 | impl OwnedSyntaxLayerInfo { |
| @@ -11,7 +11,7 @@ use util::test::marked_text_ranges; · 10 unmodified lines | ||
| 11 | 11 | fn test_splice_included_ranges() { |
| 12 | 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 | 15 | ranges.clone(), |
| 16 | 16 | &[54..56, 58..68], |
| 17 | 17 | &[ts_range(50..54), ts_range(59..67)], |
| @@ -25,14 +25,16 @@ fn test_splice_included_ranges() { · 7 unmodified lines | ||
| 25 | 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 | 31 | assert_eq!( |
| 31 | 32 | new_ranges, |
| 32 | 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 | 38 | splice_included_ranges(ranges.clone(), &[], &[ts_range(0..2), ts_range(70..75)]); |
| 37 | 39 | assert_eq!( |
| 38 | 40 | new_ranges, |
| @@ -44,16 +46,21 @@ fn test_splice_included_ranges() { · 5 unmodified lines | ||
| 44 | 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 | 53 | assert_eq!(new_ranges, &[ts_range(25..55), ts_range(80..90)]); |
| 54 | + assert_eq!(change, 0..1); | |
| 50 | 55 | |
| 51 | 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 | 59 | assert_eq!( |
| 54 | 60 | new_ranges, |
| 55 | 61 | &[ts_range(20..32), ts_range(50..60), ts_range(80..90)] |
| 56 | 62 | ); |
| 63 | + assert_eq!(change, 0..1); | |
| 57 | 64 | |
| 58 | 65 | fn ts_range(range: Range<usize>) -> tree_sitter::Range { |
| 59 | 66 | tree_sitter::Range { |
| @@ -511,7 +518,7 @@ fn test_removing_injection_by_replacing_across_boundary() { · 451 unmodified lines | ||
| 511 | 518 | } |
| 512 | 519 | |
| 513 | 520 | #[gpui::test] |
| 514 | −fn test_combined_injections() { | |
| 521 | +fn test_combined_injections_simple() { | |
| 515 | 522 | let (buffer, syntax_map) = test_edit_sequence( |
| 516 | 523 | "ERB", |
| 517 | 524 | &[ |
| @@ -653,33 +660,78 @@ fn test_combined_injections_editing_after_last_injection() { · 135 unmodified lines | ||
| 653 | 660 | |
| 654 | 661 | #[gpui::test] |
| 655 | 662 | fn test_combined_injections_inside_injections() { |
| 656 | − let (_buffer, _syntax_map) = test_edit_sequence( | |
| 663 | + let (buffer, syntax_map) = test_edit_sequence( | |
| 657 | 664 | "Markdown", |
| 658 | 665 | &[ |
| 659 | 666 | r#" |
| 660 | − here is some ERB code: | |
| 667 | + here is | |
| 668 | + some | |
| 669 | + ERB code: | |
| 661 | 670 | |
| 662 | 671 | ```erb |
| 663 | 672 | <ul> |
| 664 | 673 | <% people.each do |person| %> |
| 665 | 674 | <li><%= person.name %></li> |
| 675 | + <li><%= person.age %></li> | |
| 666 | 676 | <% end %> |
| 667 | 677 | </ul> |
| 668 | 678 | ``` |
| 669 | 679 | "#, |
| 670 | 680 | r#" |
| 671 | − here is some ERB code: | |
| 681 | + here is | |
| 682 | + some | |
| 683 | + ERB code: | |
| 672 | 684 | |
| 673 | 685 | ```erb |
| 674 | 686 | <ul> |
| 675 | 687 | <% people«2».each do |person| %> |
| 676 | 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 | 707 | <% end %> |
| 678 | 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 | 737 | #[gpui::test] |
| @@ -711,11 +763,7 @@ fn test_empty_combined_injections_inside_injections() { · 25 unmodified lines | ||
| 711 | 763 | } |
| 712 | 764 | |
| 713 | 765 | #[gpui::test(iterations = 50)] |
| 714 | −fn test_random_syntax_map_edits(mut rng: StdRng) { | |
| 715 | − let operations = env::var("OPERATIONS") | |
| 716 | − .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) | |
| 717 | − .unwrap_or(10); | |
| 718 | − | |
| 766 | +fn test_random_syntax_map_edits_rust_macros(rng: StdRng) { | |
| 719 | 767 | let text = r#" |
| 720 | 768 | fn test_something() { |
| 721 | 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 | 784 | let registry = Arc::new(LanguageRegistry::test()); |
| 737 | 785 | let language = Arc::new(rust_lang()); |
| 738 | 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); | |
| 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 | − } | |
| 788 | + test_random_edits(text, registry, language, rng); | |
| 793 | 789 | } |
| 794 | 790 | |
| 795 | 791 | #[gpui::test(iterations = 50)] |
| 796 | −fn test_random_syntax_map_edits_with_combined_injections(mut rng: StdRng) { | |
| 797 | − let operations = env::var("OPERATIONS") | |
| 798 | − .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) | |
| 799 | − .unwrap_or(10); | |
| 800 | − | |
| 792 | +fn test_random_syntax_map_edits_with_erb(rng: StdRng) { | |
| 801 | 793 | let text = r#" |
| 802 | 794 | <div id="main"> |
| 803 | 795 | <% if one?(:two) %> |
| @@ -814,13 +806,60 @@ fn test_random_syntax_map_edits_with_combined_injections(mut rng: StdRng) { · 10 unmodified lines | ||
| 814 | 806 | </div> |
| 815 | 807 | "# |
| 816 | 808 | .unindent() |
| 817 | − .repeat(8); | |
| 809 | + .repeat(5); | |
| 818 | 810 | |
| 819 | 811 | let registry = Arc::new(LanguageRegistry::test()); |
| 820 | 812 | let language = Arc::new(erb_lang()); |
| 821 | 813 | registry.add(language.clone()); |
| 822 | 814 | registry.add(Arc::new(ruby_lang())); |
| 823 | 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 | 863 | let mut buffer = Buffer::new(0, 0, text); |
| 825 | 864 | |
| 826 | 865 | let mut syntax_map = SyntaxMap::new(); |
| @@ -984,11 +1023,14 @@ fn check_interpolation( · 157 unmodified lines | ||
| 984 | 1023 | |
| 985 | 1024 | fn test_edit_sequence(language_name: &str, steps: &[&str]) -> (Buffer, SyntaxMap) { |
| 986 | 1025 | let registry = Arc::new(LanguageRegistry::test()); |
| 1026 | + registry.add(Arc::new(elixir_lang())); | |
| 1027 | + registry.add(Arc::new(heex_lang())); | |
| 987 | 1028 | registry.add(Arc::new(rust_lang())); |
| 988 | 1029 | registry.add(Arc::new(ruby_lang())); |
| 989 | 1030 | registry.add(Arc::new(html_lang())); |
| 990 | 1031 | registry.add(Arc::new(erb_lang())); |
| 991 | 1032 | registry.add(Arc::new(markdown_lang())); |
| 1033 | + | |
| 992 | 1034 | let language = registry |
| 993 | 1035 | .language_for_name(language_name) |
| 994 | 1036 | .now_or_never() |
| @@ -1074,6 +1116,7 @@ fn ruby_lang() -> Language { · 79 unmodified lines | ||
| 1074 | 1116 | r#" |
| 1075 | 1117 | ["if" "do" "else" "end"] @keyword |
| 1076 | 1118 | (instance_variable) @ivar |
| 1119 | + (call method: (identifier) @method) | |
| 1077 | 1120 | "#, |
| 1078 | 1121 | ) |
| 1079 | 1122 | .unwrap() |
| @@ -1158,6 +1201,52 @@ fn markdown_lang() -> Language { · 78 unmodified lines | ||
| 1158 | 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 | 1250 | fn range_for_text(buffer: &Buffer, text: &str) -> Range<usize> { |
| 1162 | 1251 | let start = buffer.as_rope().to_string().find(text).unwrap(); |
| 1163 | 1252 | start..start + text.len() |
| @@ -93,7 +93,7 @@ impl PickerDelegate for LanguageSelectorDelegate { · 92 unmodified lines | ||
| 93 | 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 | 97 | if let Some(mat) = self.matches.get(self.selected_index) { |
| 98 | 98 | let language_name = &self.candidates[mat.candidate_id].string; |
| 99 | 99 | let language = self.language_registry.language_for_name(language_name); |
| @@ -467,8 +467,13 @@ impl Item for LspLogView { · 466 unmodified lines | ||
| 467 | 467 | impl SearchableItem for LspLogView { |
| 468 | 468 | type Match = <Editor as SearchableItem>::Match; |
| 469 | 469 | |
| 470 | − fn to_search_event(event: &Self::Event) -> Option<workspace::searchable::SearchEvent> { | |
| 471 | − Editor::to_search_event(event) | |
| 470 | + fn to_search_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 | 479 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { |
| @@ -494,6 +499,11 @@ impl SearchableItem for LspLogView { · 19 unmodified lines | ||
| 494 | 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 | 507 | fn find_matches( |
| 498 | 508 | &mut self, |
| 499 | 509 | query: project::search::SearchQuery, |
| @@ -151,16 +151,17 @@ impl LanguageServer { · 150 unmodified lines | ||
| 151 | 151 | let stdin = server.stdin.take().unwrap(); |
| 152 | 152 | let stout = server.stdout.take().unwrap(); |
| 153 | 153 | let mut server = Self::new_internal( |
| 154 | − server_id, | |
| 154 | + server_id.clone(), | |
| 155 | 155 | stdin, |
| 156 | 156 | stout, |
| 157 | 157 | Some(server), |
| 158 | 158 | root_path, |
| 159 | 159 | code_action_kinds, |
| 160 | 160 | cx, |
| 161 | − |notification| { | |
| 161 | + move |notification| { | |
| 162 | 162 | log::info!( |
| 163 | − "unhandled notification {}:\n{}", | |
| 163 | + "{} unhandled notification {}:\n{}", | |
| 164 | + server_id, | |
| 164 | 165 | notification.method, |
| 165 | 166 | serde_json::to_string_pretty( |
| 166 | 167 | ¬ification |
| @@ -3,6 +3,7 @@ gpui::actions!( · 2 unmodified lines | ||
| 3 | 3 | [ |
| 4 | 4 | Cancel, |
| 5 | 5 | Confirm, |
| 6 | + SecondaryConfirm, | |
| 6 | 7 | SelectPrev, |
| 7 | 8 | SelectNext, |
| 8 | 9 | SelectFirst, |
| @@ -6,13 +6,13 @@ use futures::{future::Shared, FutureExt}; · 5 unmodified lines | ||
| 6 | 6 | use gpui::{executor::Background, Task}; |
| 7 | 7 | use serde::Deserialize; |
| 8 | 8 | use smol::{fs, io::BufReader, process::Command}; |
| 9 | −use std::process::Output; | |
| 9 | +use std::process::{Output, Stdio}; | |
| 10 | 10 | use std::{ |
| 11 | 11 | env::consts, |
| 12 | 12 | path::{Path, PathBuf}, |
| 13 | 13 | sync::{Arc, OnceLock}, |
| 14 | 14 | }; |
| 15 | −use util::{http::HttpClient, ResultExt}; | |
| 15 | +use util::http::HttpClient; | |
| 16 | 16 | |
| 17 | 17 | const VERSION: &str = "v18.15.0"; |
| 18 | 18 | |
| @@ -84,9 +84,8 @@ impl NodeRuntime { · 65 unmodified lines | ||
| 84 | 84 | }; |
| 85 | 85 | |
| 86 | 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 | 88 | if output.is_err() { |
| 89 | − let installation_path = self.reinstall().await?; | |
| 90 | 89 | output = attempt(installation_path).await; |
| 91 | 90 | if output.is_err() { |
| 92 | 91 | return Err(anyhow!( |
| @@ -158,29 +157,6 @@ impl NodeRuntime { · 65 unmodified lines | ||
| 158 | 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 | 160 | async fn install_if_needed(&self) -> Result<PathBuf> { |
| 185 | 161 | let task = self |
| 186 | 162 | .installation_path |
| @@ -209,8 +185,19 @@ impl NodeRuntime { · 22 unmodified lines | ||
| 209 | 185 | let node_containing_dir = util::paths::SUPPORT_DIR.join("node"); |
| 210 | 186 | let node_dir = node_containing_dir.join(folder_name); |
| 211 | 187 | let node_binary = node_dir.join("bin/node"); |
| 212 | − | |
| 213 | − if fs::metadata(&node_binary).await.is_err() { | |
| 188 | + let npm_file = node_dir.join("bin/npm"); | |
| 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 | 201 | _ = fs::remove_dir_all(&node_containing_dir).await; |
| 215 | 202 | fs::create_dir(&node_containing_dir) |
| 216 | 203 | .await |
| @@ -177,7 +177,7 @@ impl PickerDelegate for OutlineViewDelegate { · 176 unmodified lines | ||
| 177 | 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 | 181 | self.prev_scroll_position.take(); |
| 182 | 182 | self.active_editor.update(cx, |active_editor, cx| { |
| 183 | 183 | if let Some(rows) = active_editor.highlighted_rows() { |
| @@ -7,7 +7,7 @@ use gpui::{ · 6 unmodified lines | ||
| 7 | 7 | AnyElement, AnyViewHandle, AppContext, Axis, Entity, MouseState, Task, View, ViewContext, |
| 8 | 8 | ViewHandle, |
| 9 | 9 | }; |
| 10 | −use menu::{Cancel, Confirm, SelectFirst, SelectLast, SelectNext, SelectPrev}; | |
| 10 | +use menu::{Cancel, Confirm, SecondaryConfirm, SelectFirst, SelectLast, SelectNext, SelectPrev}; | |
| 11 | 11 | use parking_lot::Mutex; |
| 12 | 12 | use std::{cmp, sync::Arc}; |
| 13 | 13 | use util::ResultExt; |
| @@ -34,7 +34,7 @@ pub trait PickerDelegate: Sized + 'static { · 20 unmodified lines | ||
| 34 | 34 | fn selected_index(&self) -> usize; |
| 35 | 35 | fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>); |
| 36 | 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 | 38 | fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>); |
| 39 | 39 | fn render_match( |
| 40 | 40 | &self, |
| @@ -118,8 +118,8 @@ impl<D: PickerDelegate> View for Picker<D> { · 77 unmodified lines | ||
| 118 | 118 | // Capture mouse events |
| 119 | 119 | .on_down(MouseButton::Left, |_, _, _| {}) |
| 120 | 120 | .on_up(MouseButton::Left, |_, _, _| {}) |
| 121 | − .on_click(MouseButton::Left, move |_, picker, cx| { | |
| 122 | − picker.select_index(ix, cx); | |
| 121 | + .on_click(MouseButton::Left, move |click, picker, cx| { | |
| 122 | + picker.select_index(ix, click.cmd, cx); | |
| 123 | 123 | }) |
| 124 | 124 | .with_cursor_style(CursorStyle::PointingHand) |
| 125 | 125 | .into_any() |
| @@ -175,6 +175,7 @@ impl<D: PickerDelegate> Picker<D> { · 49 unmodified lines | ||
| 175 | 175 | cx.add_action(Self::select_next); |
| 176 | 176 | cx.add_action(Self::select_prev); |
| 177 | 177 | cx.add_action(Self::confirm); |
| 178 | + cx.add_action(Self::secondary_confirm); | |
| 178 | 179 | cx.add_action(Self::cancel); |
| 179 | 180 | } |
| 180 | 181 | |
| @@ -288,11 +289,11 @@ impl<D: PickerDelegate> Picker<D> { · 107 unmodified lines | ||
| 288 | 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 | 293 | if self.delegate.match_count() > 0 { |
| 293 | 294 | self.confirmed = true; |
| 294 | 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 | 332 | pub fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) { |
| 332 | 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 | 342 | fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) { |
| @@ -2709,7 +2709,6 @@ impl Project { · 2708 unmodified lines | ||
| 2709 | 2709 | Some(language_server) => language_server, |
| 2710 | 2710 | None => return Ok(None), |
| 2711 | 2711 | }; |
| 2712 | − | |
| 2713 | 2712 | let this = match this.upgrade(cx) { |
| 2714 | 2713 | Some(this) => this, |
| 2715 | 2714 | None => return Err(anyhow!("failed to upgrade project handle")), |
| @@ -3045,6 +3044,8 @@ impl Project { · 329 unmodified lines | ||
| 3045 | 3044 | ) -> Task<(Option<PathBuf>, Vec<WorktreeId>)> { |
| 3046 | 3045 | let key = (worktree_id, adapter_name); |
| 3047 | 3046 | if let Some(server_id) = self.language_server_ids.remove(&key) { |
| 3047 | + log::info!("stopping language server {}", key.1 .0); | |
| 3048 | + | |
| 3048 | 3049 | // Remove other entries for this language server as well |
| 3049 | 3050 | let mut orphaned_worktrees = vec![worktree_id]; |
| 3050 | 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 | 401 | pub fn remote( |
| 401 | 402 | project_remote_id: u64, |
| 402 | 403 | replica_id: ReplicaId, |
| @@ -2022,6 +2023,9 @@ impl LocalSnapshot { · 1619 unmodified lines | ||
| 2022 | 2023 | ) -> Vec<Arc<Path>> { |
| 2023 | 2024 | let mut changes = vec![]; |
| 2024 | 2025 | let mut edits = vec![]; |
| 2026 | + | |
| 2027 | + let statuses = repo_ptr.statuses(); | |
| 2028 | + | |
| 2025 | 2029 | for mut entry in self |
| 2026 | 2030 | .descendent_entries(false, false, &work_directory.0) |
| 2027 | 2031 | .cloned() |
| @@ -2029,10 +2033,8 @@ impl LocalSnapshot { · 1 unmodified line | ||
| 2029 | 2033 | let Ok(repo_path) = entry.path.strip_prefix(&work_directory.0) else { |
| 2030 | 2034 | continue; |
| 2031 | 2035 | }; |
| 2032 | − let git_file_status = repo_ptr | |
| 2033 | − .status(&RepoPath(repo_path.into())) | |
| 2034 | − .log_err() | |
| 2035 | − .flatten(); | |
| 2036 | + let repo_path = RepoPath(repo_path.to_path_buf()); | |
| 2037 | + let git_file_status = statuses.as_ref().and_then(|s| s.get(&repo_path).copied()); | |
| 2036 | 2038 | if entry.git_status != git_file_status { |
| 2037 | 2039 | entry.git_status = git_file_status; |
| 2038 | 2040 | changes.push(entry.path.clone()); |
| @@ -159,6 +159,9 @@ pub enum Event { · 158 unmodified lines | ||
| 159 | 159 | entry_id: ProjectEntryId, |
| 160 | 160 | focus_opened_item: bool, |
| 161 | 161 | }, |
| 162 | + SplitEntry { | |
| 163 | + entry_id: ProjectEntryId, | |
| 164 | + }, | |
| 162 | 165 | DockPositionChanged, |
| 163 | 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 | 645 | fn new_file(&mut self, _: &NewFile, cx: &mut ViewContext<Self>) { |
| 624 | 646 | self.add_entry(false, cx) |
| 625 | 647 | } |
| @@ -1333,7 +1355,11 @@ impl ProjectPanel { · 707 unmodified lines | ||
| 1333 | 1355 | if kind.is_dir() { |
| 1334 | 1356 | this.toggle_expanded(entry_id, cx); |
| 1335 | 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 | 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 | 108 | if let Some(symbol) = self |
| 109 | 109 | .matches |
| 110 | 110 | .get(self.selected_match_index) |
| @@ -122,7 +122,12 @@ impl PickerDelegate for ProjectSymbolsDelegate { · 11 unmodified lines | ||
| 122 | 122 | .read(cx) |
| 123 | 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 | 131 | editor.update(cx, |editor, cx| { |
| 127 | 132 | editor.change_selections(Some(Autoscroll::center()), cx, |s| { |
| 128 | 133 | s.select_ranges([position..position]) |
| @@ -161,7 +161,7 @@ impl PickerDelegate for RecentProjectsDelegate { · 160 unmodified lines | ||
| 161 | 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 | 165 | if let Some((selected_match, workspace)) = self |
| 166 | 166 | .matches |
| 167 | 167 | .get(self.selected_index()) |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | − SearchOption, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleRegex, | |
| 3 | − ToggleWholeWord, | |
| 2 | + SearchOption, SelectAllMatches, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, | |
| 3 | + ToggleRegex, ToggleWholeWord, | |
| 4 | 4 | }; |
| 5 | 5 | use collections::HashMap; |
| 6 | 6 | use editor::Editor; |
| @@ -39,8 +39,10 @@ pub fn init(cx: &mut AppContext) { · 32 unmodified lines | ||
| 39 | 39 | cx.add_action(BufferSearchBar::focus_editor); |
| 40 | 40 | cx.add_action(BufferSearchBar::select_next_match); |
| 41 | 41 | cx.add_action(BufferSearchBar::select_prev_match); |
| 42 | + cx.add_action(BufferSearchBar::select_all_matches); | |
| 42 | 43 | cx.add_action(BufferSearchBar::select_next_match_on_pane); |
| 43 | 44 | cx.add_action(BufferSearchBar::select_prev_match_on_pane); |
| 45 | + cx.add_action(BufferSearchBar::select_all_matches_on_pane); | |
| 44 | 46 | cx.add_action(BufferSearchBar::handle_editor_cancel); |
| 45 | 47 | add_toggle_option_action::<ToggleCaseSensitive>(SearchOption::CaseSensitive, cx); |
| 46 | 48 | add_toggle_option_action::<ToggleWholeWord>(SearchOption::WholeWord, cx); |
| @@ -66,7 +68,7 @@ pub struct BufferSearchBar { · 19 unmodified lines | ||
| 66 | 68 | active_searchable_item: Option<Box<dyn SearchableItemHandle>>, |
| 67 | 69 | active_match_index: Option<usize>, |
| 68 | 70 | active_searchable_item_subscription: Option<Subscription>, |
| 69 | − seachable_items_with_matches: | |
| 71 | + searchable_items_with_matches: | |
| 70 | 72 | HashMap<Box<dyn WeakSearchableItemHandle>, Vec<Box<dyn Any + Send>>>, |
| 71 | 73 | pending_search: Option<Task<()>>, |
| 72 | 74 | case_sensitive: bool, |
| @@ -118,7 +120,7 @@ impl View for BufferSearchBar { · 45 unmodified lines | ||
| 118 | 120 | .with_children(self.active_searchable_item.as_ref().and_then( |
| 119 | 121 | |searchable_item| { |
| 120 | 122 | let matches = self |
| 121 | − .seachable_items_with_matches | |
| 123 | + .searchable_items_with_matches | |
| 122 | 124 | .get(&searchable_item.downgrade())?; |
| 123 | 125 | let message = if let Some(match_ix) = self.active_match_index { |
| 124 | 126 | format!("{}/{}", match_ix + 1, matches.len()) |
| @@ -146,6 +148,7 @@ impl View for BufferSearchBar { · 21 unmodified lines | ||
| 146 | 148 | Flex::row() |
| 147 | 149 | .with_child(self.render_nav_button("<", Direction::Prev, cx)) |
| 148 | 150 | .with_child(self.render_nav_button(">", Direction::Next, cx)) |
| 151 | + .with_child(self.render_action_button("Select All", cx)) | |
| 149 | 152 | .aligned(), |
| 150 | 153 | ) |
| 151 | 154 | .with_child( |
| @@ -249,7 +252,7 @@ impl BufferSearchBar { · 97 unmodified lines | ||
| 249 | 252 | active_searchable_item: None, |
| 250 | 253 | active_searchable_item_subscription: None, |
| 251 | 254 | active_match_index: None, |
| 252 | − seachable_items_with_matches: Default::default(), | |
| 255 | + searchable_items_with_matches: Default::default(), | |
| 253 | 256 | case_sensitive: false, |
| 254 | 257 | whole_word: false, |
| 255 | 258 | regex: false, |
| @@ -265,7 +268,7 @@ impl BufferSearchBar { · 9 unmodified lines | ||
| 265 | 268 | |
| 266 | 269 | pub fn dismiss(&mut self, _: &Dismiss, cx: &mut ViewContext<Self>) { |
| 267 | 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 | 272 | if let Some(searchable_item) = |
| 270 | 273 | WeakSearchableItemHandle::upgrade(searchable_item.as_ref(), cx) |
| 271 | 274 | { |
| @@ -401,6 +404,37 @@ impl BufferSearchBar { · 129 unmodified lines | ||
| 401 | 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 | 438 | fn render_close_button( |
| 405 | 439 | &self, |
| 406 | 440 | theme: &theme::Search, |
| @@ -488,11 +522,25 @@ impl BufferSearchBar { · 81 unmodified lines | ||
| 488 | 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 | 539 | pub fn select_match(&mut self, direction: Direction, cx: &mut ViewContext<Self>) { |
| 492 | 540 | if let Some(index) = self.active_match_index { |
| 493 | 541 | if let Some(searchable_item) = self.active_searchable_item.as_ref() { |
| 494 | 542 | if let Some(matches) = self |
| 495 | − .seachable_items_with_matches | |
| 543 | + .searchable_items_with_matches | |
| 496 | 544 | .get(&searchable_item.downgrade()) |
| 497 | 545 | { |
| 498 | 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 | 585 | fn on_query_editor_event( |
| 528 | 586 | &mut self, |
| 529 | 587 | _: ViewHandle<Editor>, |
| @@ -547,7 +605,7 @@ impl BufferSearchBar { · 17 unmodified lines | ||
| 547 | 605 | |
| 548 | 606 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>) { |
| 549 | 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 | 609 | if let Some(searchable_item) = |
| 552 | 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 | 621 | .extend(active_item_matches); |
| 564 | 622 | } |
| 565 | 623 | |
| @@ -605,13 +663,13 @@ impl BufferSearchBar { · 39 unmodified lines | ||
| 605 | 663 | if let Some(active_searchable_item) = |
| 606 | 664 | WeakSearchableItemHandle::upgrade(active_searchable_item.as_ref(), cx) |
| 607 | 665 | { |
| 608 | − this.seachable_items_with_matches | |
| 666 | + this.searchable_items_with_matches | |
| 609 | 667 | .insert(active_searchable_item.downgrade(), matches); |
| 610 | 668 | |
| 611 | 669 | this.update_match_index(cx); |
| 612 | 670 | if !this.dismissed { |
| 613 | 671 | let matches = this |
| 614 | − .seachable_items_with_matches | |
| 672 | + .searchable_items_with_matches | |
| 615 | 673 | .get(&active_searchable_item.downgrade()) |
| 616 | 674 | .unwrap(); |
| 617 | 675 | active_searchable_item.update_matches(matches, cx); |
| @@ -637,7 +695,7 @@ impl BufferSearchBar { · 19 unmodified lines | ||
| 637 | 695 | .as_ref() |
| 638 | 696 | .and_then(|searchable_item| { |
| 639 | 697 | let matches = self |
| 640 | − .seachable_items_with_matches | |
| 698 | + .searchable_items_with_matches | |
| 641 | 699 | .get(&searchable_item.downgrade())?; |
| 642 | 700 | searchable_item.active_match_index(matches, cx) |
| 643 | 701 | }); |
| @@ -966,4 +1024,133 @@ mod tests { · 322 unmodified lines | ||
| 966 | 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 | 17 | ToggleCaseSensitive, |
| 18 | 18 | ToggleRegex, |
| 19 | 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 | 72 | impl OpenAIEmbeddings { |
| 71 | − async fn truncate(span: String) -> String { | |
| 73 | + fn truncate(span: String) -> String { | |
| 72 | 74 | let mut tokens = OPENAI_BPE_TOKENIZER.encode_with_special_tokens(span.as_ref()); |
| 73 | − if tokens.len() > 8190 { | |
| 74 | − tokens.truncate(8190); | |
| 75 | + if tokens.len() > INPUT_LIMIT { | |
| 76 | + tokens.truncate(INPUT_LIMIT); | |
| 75 | 77 | let result = OPENAI_BPE_TOKENIZER.decode(tokens.clone()); |
| 76 | 78 | if result.is_ok() { |
| 77 | 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 | 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 | 144 | // Don't worry about delaying bad request, as we can assume |
| 143 | 145 | // we haven't been rate limited yet. |
| 144 | 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 | 150 | StatusCode::OK => { |
| @@ -198,7 +198,7 @@ impl TerminalLineHeight { · 197 unmodified lines | ||
| 198 | 198 | match self { |
| 199 | 199 | TerminalLineHeight::Comfortable => 1.618, |
| 200 | 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 | 926 | fn set_selection(&mut self, selection: Option<(Selection, Point)>) { |
| 912 | 927 | self.events |
| 913 | 928 | .push_back(InternalEvent::SetSelection(selection)); |
| @@ -647,7 +647,11 @@ impl SearchableItem for TerminalView { · 646 unmodified lines | ||
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 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 | 655 | match event { |
| 652 | 656 | Event::Wakeup => Some(SearchEvent::MatchesInvalidated), |
| 653 | 657 | Event::SelectionsChanged => Some(SearchEvent::ActiveMatchChanged), |
| @@ -682,6 +686,13 @@ impl SearchableItem for TerminalView { · 28 unmodified lines | ||
| 682 | 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 | 696 | /// Get all of the matches for this query, should be done on the background |
| 686 | 697 | fn find_matches( |
| 687 | 698 | &mut self, |
| @@ -350,6 +350,7 @@ pub struct Tab { · 349 unmodified lines | ||
| 350 | 350 | pub icon_close_active: Color, |
| 351 | 351 | pub icon_dirty: Color, |
| 352 | 352 | pub icon_conflict: Color, |
| 353 | + pub git: GitProjectStatus, | |
| 353 | 354 | } |
| 354 | 355 | |
| 355 | 356 | #[derive(Clone, Deserialize, Default, JsonSchema)] |
| @@ -379,6 +380,7 @@ pub struct Search { · 23 unmodified lines | ||
| 379 | 380 | pub invalid_include_exclude_editor: ContainerStyle, |
| 380 | 381 | pub include_exclude_inputs: ContainedText, |
| 381 | 382 | pub option_button: Toggleable<Interactive<ContainedText>>, |
| 383 | + pub action_button: Interactive<ContainedText>, | |
| 382 | 384 | pub match_background: Color, |
| 383 | 385 | pub match_index: ContainedText, |
| 384 | 386 | pub results_status: TextStyle, |
| @@ -721,12 +723,12 @@ pub struct Scrollbar { · 336 unmodified lines | ||
| 721 | 723 | pub thumb: ContainerStyle, |
| 722 | 724 | pub width: f32, |
| 723 | 725 | pub min_height_factor: f32, |
| 724 | − pub git: GitDiffColors, | |
| 726 | + pub git: BufferGitDiffColors, | |
| 725 | 727 | pub selections: Color, |
| 726 | 728 | } |
| 727 | 729 | |
| 728 | 730 | #[derive(Clone, Deserialize, Default, JsonSchema)] |
| 729 | −pub struct GitDiffColors { | |
| 731 | +pub struct BufferGitDiffColors { | |
| 730 | 732 | pub inserted: Color, |
| 731 | 733 | pub modified: Color, |
| 732 | 734 | pub deleted: Color, |
| @@ -5,6 +5,7 @@ use parking_lot::Mutex; · 4 unmodified lines | ||
| 5 | 5 | use serde::Deserialize; |
| 6 | 6 | use serde_json::Value; |
| 7 | 7 | use std::{ |
| 8 | + borrow::Cow, | |
| 8 | 9 | collections::HashMap, |
| 9 | 10 | sync::{ |
| 10 | 11 | atomic::{AtomicUsize, Ordering::SeqCst}, |
| @@ -43,7 +44,7 @@ impl ThemeRegistry { · 32 unmodified lines | ||
| 43 | 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 | 48 | let mut dirs = self.assets.list("themes/"); |
| 48 | 49 | |
| 49 | 50 | if !staff { |
| @@ -53,10 +54,21 @@ impl ThemeRegistry { · 3 unmodified lines | ||
| 53 | 54 | .collect() |
| 54 | 55 | } |
| 55 | 56 | |
| 56 | − dirs.into_iter().filter_map(|path| { | |
| 57 | − let filename = path.strip_prefix("themes/")?; | |
| 58 | − let theme_name = filename.strip_suffix(".json")?; | |
| 59 | − self.get(theme_name).ok().map(|theme| theme.meta.clone()) | |
| 57 | + fn get_name(path: &str) -> Option<&str> { | |
| 58 | + path.strip_prefix("themes/")?.strip_suffix(".json") | |
| 59 | + } | |
| 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 | 13 | use util::ResultExt as _; |
| 14 | 14 | |
| 15 | 15 | const MIN_FONT_SIZE: f32 = 6.0; |
| 16 | +const MIN_LINE_HEIGHT: f32 = 1.0; | |
| 16 | 17 | |
| 17 | 18 | #[derive(Clone, JsonSchema)] |
| 18 | 19 | pub struct ThemeSettings { |
| @@ -20,6 +21,7 @@ pub struct ThemeSettings { · 1 unmodified line | ||
| 20 | 21 | pub buffer_font_features: fonts::Features, |
| 21 | 22 | pub buffer_font_family: FamilyId, |
| 22 | 23 | pub(crate) buffer_font_size: f32, |
| 24 | + pub(crate) buffer_line_height: BufferLineHeight, | |
| 23 | 25 | #[serde(skip)] |
| 24 | 26 | pub theme: Arc<Theme>, |
| 25 | 27 | } |
| @@ -33,11 +35,32 @@ pub struct ThemeSettingsContent { · 7 unmodified lines | ||
| 33 | 35 | #[serde(default)] |
| 34 | 36 | pub buffer_font_size: Option<f32>, |
| 35 | 37 | #[serde(default)] |
| 38 | + pub buffer_line_height: Option<BufferLineHeight>, | |
| 39 | + #[serde(default)] | |
| 36 | 40 | pub buffer_font_features: Option<fonts::Features>, |
| 37 | 41 | #[serde(default)] |
| 38 | 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 | 64 | impl ThemeSettings { |
| 42 | 65 | pub fn buffer_font_size(&self, cx: &AppContext) -> f32 { |
| 43 | 66 | if cx.has_global::<AdjustedBufferFontSize>() { |
| @@ -47,6 +70,10 @@ impl ThemeSettings { · 3 unmodified lines | ||
| 47 | 70 | } |
| 48 | 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 | 79 | pub fn adjusted_font_size(size: f32, cx: &AppContext) -> f32 { |
| @@ -106,6 +133,7 @@ impl settings::Setting for ThemeSettings { · 53 unmodified lines | ||
| 106 | 133 | buffer_font_family_name: defaults.buffer_font_family.clone().unwrap(), |
| 107 | 134 | buffer_font_features, |
| 108 | 135 | buffer_font_size: defaults.buffer_font_size.unwrap(), |
| 136 | + buffer_line_height: defaults.buffer_line_height.unwrap(), | |
| 109 | 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 | 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 | 170 | Ok(this) |
| @@ -149,8 +178,8 @@ impl settings::Setting for ThemeSettings { · 7 unmodified lines | ||
| 149 | 178 | let mut root_schema = generator.root_schema_for::<ThemeSettingsContent>(); |
| 150 | 179 | let theme_names = cx |
| 151 | 180 | .global::<Arc<ThemeRegistry>>() |
| 152 | − .list(params.staff_mode) | |
| 153 | − .map(|theme| Value::String(theme.name.clone())) | |
| 181 | + .list_names(params.staff_mode) | |
| 182 | + .map(|theme_name| Value::String(theme_name.to_string())) | |
| 154 | 183 | .collect(); |
| 155 | 184 | |
| 156 | 185 | let theme_name_schema = SchemaObject { |
| @@ -120,7 +120,7 @@ impl PickerDelegate for ThemeSelectorDelegate { · 119 unmodified lines | ||
| 120 | 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 | 124 | self.selection_completed = true; |
| 125 | 125 | |
| 126 | 126 | let theme_name = theme::current(cx).meta.name.clone(); |
| @@ -106,12 +106,14 @@ impl PickerDelegate for BranchListDelegate { · 105 unmodified lines | ||
| 106 | 106 | .read_with(&mut cx, |view, cx| { |
| 107 | 107 | let delegate = view.delegate(); |
| 108 | 108 | let project = delegate.workspace.read(cx).project().read(&cx); |
| 109 | − let mut cwd = | |
| 110 | − project | |
| 109 | + | |
| 110 | + let Some(worktree) = project | |
| 111 | 111 | .visible_worktrees(cx) |
| 112 | 112 | .next() |
| 113 | − .unwrap() | |
| 114 | − .read(cx) | |
| 113 | + else { | |
| 114 | + bail!("Cannot update branch list as there are no visible worktrees") | |
| 115 | + }; | |
| 116 | + let mut cwd = worktree .read(cx) | |
| 115 | 117 | .abs_path() |
| 116 | 118 | .to_path_buf(); |
| 117 | 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 | 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 | 190 | cx.spawn(|picker, mut cx| async move { |
| 187 | 191 | picker |
| 188 | 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 | 124 | if let Some(selection) = self.matches.get(self.selected_index) { |
| 125 | 125 | let base_keymap = BaseKeymap::from_names(&selection.string); |
| 126 | 126 | update_settings_file::<BaseKeymap>(self.fs.clone(), cx, move |setting| { |
| @@ -10,6 +10,9 @@ use gpui::{ · 9 unmodified lines | ||
| 10 | 10 | ViewContext, ViewHandle, WeakViewHandle, WindowContext, |
| 11 | 11 | }; |
| 12 | 12 | use project::{Project, ProjectEntryId, ProjectPath}; |
| 13 | +use schemars::JsonSchema; | |
| 14 | +use serde_derive::{Deserialize, Serialize}; | |
| 15 | +use settings::Setting; | |
| 13 | 16 | use smallvec::SmallVec; |
| 14 | 17 | use std::{ |
| 15 | 18 | any::{Any, TypeId}, |
| @@ -27,6 +30,49 @@ use std::{ · 11 unmodified lines | ||
| 27 | 30 | }; |
| 28 | 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 | 76 | #[derive(Eq, PartialEq, Hash, Debug)] |
| 31 | 77 | pub enum ItemEvent { |
| 32 | 78 | CloseItem, |
| @@ -3,14 +3,16 @@ mod dragged_item_receiver; · 2 unmodified lines | ||
| 3 | 3 | use super::{ItemHandle, SplitDirection}; |
| 4 | 4 | pub use crate::toolbar::Toolbar; |
| 5 | 5 | use crate::{ |
| 6 | − item::WeakItemHandle, notify_of_new_dock, AutosaveSetting, Item, NewCenterTerminal, NewFile, | |
| 7 | − NewSearch, ToggleZoom, Workspace, WorkspaceSettings, | |
| 6 | + item::{ItemSettings, WeakItemHandle}, | |
| 7 | + notify_of_new_dock, AutosaveSetting, Item, NewCenterTerminal, NewFile, NewSearch, ToggleZoom, | |
| 8 | + Workspace, WorkspaceSettings, | |
| 8 | 9 | }; |
| 9 | 10 | use anyhow::Result; |
| 10 | 11 | use collections::{HashMap, HashSet, VecDeque}; |
| 11 | 12 | use context_menu::{ContextMenu, ContextMenuItem}; |
| 12 | 13 | use drag_and_drop::{DragAndDrop, Draggable}; |
| 13 | 14 | use dragged_item_receiver::dragged_item_receiver; |
| 15 | +use fs::repository::GitFileStatus; | |
| 14 | 16 | use futures::StreamExt; |
| 15 | 17 | use gpui::{ |
| 16 | 18 | actions, |
| @@ -866,6 +868,7 @@ impl Pane { · 849 unmodified lines | ||
| 866 | 868 | .paths_by_item |
| 867 | 869 | .get(&item.id()) |
| 868 | 870 | .and_then(|(_, abs_path)| abs_path.clone()); |
| 871 | + | |
| 869 | 872 | self.nav_history |
| 870 | 873 | .0 |
| 871 | 874 | .borrow_mut() |
| @@ -1157,6 +1160,11 @@ impl Pane { · 285 unmodified lines | ||
| 1157 | 1160 | .zip(self.tab_details(cx)) |
| 1158 | 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 | 1168 | let detail = if detail == 0 { None } else { Some(detail) }; |
| 1161 | 1169 | let tab_active = ix == self.active_item_index; |
| 1162 | 1170 | |
| @@ -1174,9 +1182,21 @@ impl Pane { · 11 unmodified lines | ||
| 1174 | 1182 | let tab_tooltip_text = |
| 1175 | 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 | 1199 | move |mouse_state, cx| { |
| 1178 | − let tab_style = | |
| 1179 | − theme.workspace.tab_bar.tab_style(pane_active, tab_active); | |
| 1180 | 1200 | let hovered = mouse_state.hovered(); |
| 1181 | 1201 | |
| 1182 | 1202 | enum Tab {} |
| @@ -1188,7 +1208,7 @@ impl Pane { · 5 unmodified lines | ||
| 1188 | 1208 | ix == 0, |
| 1189 | 1209 | detail, |
| 1190 | 1210 | hovered, |
| 1191 | − tab_style, | |
| 1211 | + &tab_style, | |
| 1192 | 1212 | cx, |
| 1193 | 1213 | ) |
| 1194 | 1214 | }) |
| @@ -1350,81 +1370,94 @@ impl Pane { · 155 unmodified lines | ||
| 1350 | 1370 | container.border.left = false; |
| 1351 | 1371 | } |
| 1352 | 1372 | |
| 1353 | − Flex::row() | |
| 1354 | − .with_child({ | |
| 1355 | − let diameter = 7.0; | |
| 1356 | − let icon_color = if item.has_conflict(cx) { | |
| 1357 | − Some(tab_style.icon_conflict) | |
| 1358 | − } else if item.is_dirty(cx) { | |
| 1359 | − Some(tab_style.icon_dirty) | |
| 1360 | − } else { | |
| 1361 | − None | |
| 1362 | − }; | |
| 1373 | + let buffer_jewel_element = { | |
| 1374 | + let diameter = 7.0; | |
| 1375 | + let icon_color = if item.has_conflict(cx) { | |
| 1376 | + Some(tab_style.icon_conflict) | |
| 1377 | + } else if item.is_dirty(cx) { | |
| 1378 | + Some(tab_style.icon_dirty) | |
| 1379 | + } else { | |
| 1380 | + None | |
| 1381 | + }; | |
| 1363 | 1382 | |
| 1364 | − Canvas::new(move |scene, bounds, _, _, _| { | |
| 1365 | − if let Some(color) = icon_color { | |
| 1366 | − let square = RectF::new(bounds.origin(), vec2f(diameter, diameter)); | |
| 1367 | − scene.push_quad(Quad { | |
| 1368 | − bounds: square, | |
| 1369 | − background: Some(color), | |
| 1370 | − border: Default::default(), | |
| 1371 | − corner_radius: diameter / 2., | |
| 1372 | − }); | |
| 1373 | − } | |
| 1374 | − }) | |
| 1375 | − .constrained() | |
| 1376 | − .with_width(diameter) | |
| 1377 | − .with_height(diameter) | |
| 1378 | − .aligned() | |
| 1383 | + Canvas::new(move |scene, bounds, _, _, _| { | |
| 1384 | + if let Some(color) = icon_color { | |
| 1385 | + let square = RectF::new(bounds.origin(), vec2f(diameter, diameter)); | |
| 1386 | + scene.push_quad(Quad { | |
| 1387 | + bounds: square, | |
| 1388 | + background: Some(color), | |
| 1389 | + border: Default::default(), | |
| 1390 | + corner_radius: diameter / 2., | |
| 1391 | + }); | |
| 1392 | + } | |
| 1379 | 1393 | }) |
| 1380 | − .with_child(title.aligned().contained().with_style(ContainerStyle { | |
| 1381 | − margin: Margin { | |
| 1382 | − left: tab_style.spacing, | |
| 1383 | − right: tab_style.spacing, | |
| 1384 | − ..Default::default() | |
| 1385 | − }, | |
| 1394 | + .constrained() | |
| 1395 | + .with_width(diameter) | |
| 1396 | + .with_height(diameter) | |
| 1397 | + .aligned() | |
| 1398 | + }; | |
| 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 | 1404 | ..Default::default() |
| 1387 | − })) | |
| 1388 | − .with_child( | |
| 1389 | − if hovered { | |
| 1390 | − let item_id = item.id(); | |
| 1391 | − enum TabCloseButton {} | |
| 1392 | − let icon = Svg::new("icons/x_mark_8.svg"); | |
| 1393 | − MouseEventHandler::<TabCloseButton, _>::new(item_id, cx, |mouse_state, _| { | |
| 1394 | − if mouse_state.hovered() { | |
| 1395 | − icon.with_color(tab_style.icon_close_active) | |
| 1396 | − } else { | |
| 1397 | − icon.with_color(tab_style.icon_close) | |
| 1398 | − } | |
| 1399 | − }) | |
| 1400 | − .with_padding(Padding::uniform(4.)) | |
| 1401 | − .with_cursor_style(CursorStyle::PointingHand) | |
| 1402 | − .on_click(MouseButton::Left, { | |
| 1403 | − let pane = pane.clone(); | |
| 1404 | − move |_, _, cx| { | |
| 1405 | − let pane = pane.clone(); | |
| 1406 | − cx.window_context().defer(move |cx| { | |
| 1407 | − if let Some(pane) = pane.upgrade(cx) { | |
| 1408 | − pane.update(cx, |pane, cx| { | |
| 1409 | − pane.close_item_by_id(item_id, cx).detach_and_log_err(cx); | |
| 1410 | − }); | |
| 1411 | − } | |
| 1405 | + }, | |
| 1406 | + ..Default::default() | |
| 1407 | + }); | |
| 1408 | + | |
| 1409 | + let close_element = if hovered { | |
| 1410 | + let item_id = item.id(); | |
| 1411 | + enum TabCloseButton {} | |
| 1412 | + let icon = Svg::new("icons/x_mark_8.svg"); | |
| 1413 | + MouseEventHandler::<TabCloseButton, _>::new(item_id, cx, |mouse_state, _| { | |
| 1414 | + if mouse_state.hovered() { | |
| 1415 | + icon.with_color(tab_style.icon_close_active) | |
| 1416 | + } else { | |
| 1417 | + icon.with_color(tab_style.icon_close) | |
| 1418 | + } | |
| 1419 | + }) | |
| 1420 | + .with_padding(Padding::uniform(4.)) | |
| 1421 | + .with_cursor_style(CursorStyle::PointingHand) | |
| 1422 | + .on_click(MouseButton::Left, { | |
| 1423 | + let pane = pane.clone(); | |
| 1424 | + move |_, _, cx| { | |
| 1425 | + let pane = pane.clone(); | |
| 1426 | + cx.window_context().defer(move |cx| { | |
| 1427 | + if let Some(pane) = pane.upgrade(cx) { | |
| 1428 | + pane.update(cx, |pane, cx| { | |
| 1429 | + pane.close_item_by_id(item_id, cx).detach_and_log_err(cx); | |
| 1412 | 1430 | }); |
| 1413 | 1431 | } |
| 1414 | − }) | |
| 1415 | − .into_any_named("close-tab-icon") | |
| 1416 | − .constrained() | |
| 1417 | − } else { | |
| 1418 | − Empty::new().constrained() | |
| 1432 | + }); | |
| 1419 | 1433 | } |
| 1420 | − .with_width(tab_style.close_icon_width) | |
| 1421 | − .aligned(), | |
| 1422 | − ) | |
| 1423 | − .contained() | |
| 1424 | − .with_style(container) | |
| 1434 | + }) | |
| 1435 | + .into_any_named("close-tab-icon") | |
| 1425 | 1436 | .constrained() |
| 1426 | − .with_height(tab_style.height) | |
| 1427 | − .into_any() | |
| 1437 | + } else { | |
| 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 | 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 | 6 | use anyhow::{anyhow, Result}; |
| 5 | 7 | use call::{ActiveCall, ParticipantLocation}; |
| 6 | 8 | use gpui::{ |
| @@ -13,7 +15,11 @@ use project::Project; · 6 unmodified lines | ||
| 13 | 15 | use serde::Deserialize; |
| 14 | 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 | 23 | pub struct PaneGroup { |
| 18 | 24 | pub(crate) root: Member, |
| 19 | 25 | } |
| @@ -77,6 +83,7 @@ impl PaneGroup { · 57 unmodified lines | ||
| 77 | 83 | ) -> AnyElement<Workspace> { |
| 78 | 84 | self.root.render( |
| 79 | 85 | project, |
| 86 | + 0, | |
| 80 | 87 | theme, |
| 81 | 88 | follower_states, |
| 82 | 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 | 105 | pub(crate) enum Member { |
| 99 | 106 | Axis(PaneAxis), |
| 100 | 107 | Pane(ViewHandle<Pane>), |
| @@ -119,7 +126,7 @@ impl Member { · 18 unmodified lines | ||
| 119 | 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 | 132 | fn contains(&self, needle: &ViewHandle<Pane>) -> bool { |
| @@ -132,6 +139,7 @@ impl Member { · 6 unmodified lines | ||
| 132 | 139 | pub fn render( |
| 133 | 140 | &self, |
| 134 | 141 | project: &ModelHandle<Project>, |
| 142 | + basis: usize, | |
| 135 | 143 | theme: &Theme, |
| 136 | 144 | follower_states: &FollowerStatesByLeader, |
| 137 | 145 | active_call: Option<&ModelHandle<ActiveCall>>, |
| @@ -272,6 +280,7 @@ impl Member { · 134 unmodified lines | ||
| 272 | 280 | } |
| 273 | 281 | Member::Axis(axis) => axis.render( |
| 274 | 282 | project, |
| 283 | + basis + 1, | |
| 275 | 284 | theme, |
| 276 | 285 | follower_states, |
| 277 | 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 | 308 | pub(crate) struct PaneAxis { |
| 300 | 309 | pub axis: Axis, |
| 301 | 310 | pub members: Vec<Member>, |
| 311 | + pub flexes: Rc<RefCell<Vec<f32>>>, | |
| 302 | 312 | } |
| 303 | 313 | |
| 304 | 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 | 336 | fn split( |
| 306 | 337 | &mut self, |
| 307 | 338 | old_pane: &ViewHandle<Pane>, |
| @@ -323,6 +354,7 @@ impl PaneAxis { · 15 unmodified lines | ||
| 323 | 354 | } |
| 324 | 355 | |
| 325 | 356 | self.members.insert(idx, Member::Pane(new_pane.clone())); |
| 357 | + *self.flexes.borrow_mut() = vec![1.; self.members.len()]; | |
| 326 | 358 | } else { |
| 327 | 359 | *member = |
| 328 | 360 | Member::new_axis(old_pane.clone(), new_pane.clone(), direction); |
| @@ -362,10 +394,13 @@ impl PaneAxis { · 33 unmodified lines | ||
| 362 | 394 | if found_pane { |
| 363 | 395 | if let Some(idx) = remove_member { |
| 364 | 396 | self.members.remove(idx); |
| 397 | + *self.flexes.borrow_mut() = vec![1.; self.members.len()]; | |
| 365 | 398 | } |
| 366 | 399 | |
| 367 | 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 | 404 | } else { |
| 370 | 405 | Ok(None) |
| 371 | 406 | } |
| @@ -377,6 +412,7 @@ impl PaneAxis { · 5 unmodified lines | ||
| 377 | 412 | fn render( |
| 378 | 413 | &self, |
| 379 | 414 | project: &ModelHandle<Project>, |
| 415 | + basis: usize, | |
| 380 | 416 | theme: &Theme, |
| 381 | 417 | follower_state: &FollowerStatesByLeader, |
| 382 | 418 | active_call: Option<&ModelHandle<ActiveCall>>, |
| @@ -385,40 +421,50 @@ impl PaneAxis { · 2 unmodified lines | ||
| 385 | 421 | app_state: &Arc<AppState>, |
| 386 | 422 | cx: &mut ViewContext<Workspace>, |
| 387 | 423 | ) -> AnyElement<Workspace> { |
| 388 | − let last_member_ix = self.members.len() - 1; | |
| 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 | − } | |
| 424 | + debug_assert!(self.members.len() == self.flexes.borrow().len()); | |
| 395 | 425 | |
| 396 | − let mut member = member.render( | |
| 397 | − project, | |
| 398 | − theme, | |
| 399 | − follower_state, | |
| 400 | − active_call, | |
| 401 | − active_pane, | |
| 402 | − zoomed, | |
| 403 | − app_state, | |
| 404 | − cx, | |
| 405 | − ); | |
| 406 | − if ix < last_member_ix { | |
| 407 | − let mut border = theme.workspace.pane_divider; | |
| 408 | − border.left = false; | |
| 409 | − border.right = false; | |
| 410 | − border.top = false; | |
| 411 | − border.bottom = false; | |
| 412 | − match self.axis { | |
| 413 | − Axis::Vertical => border.bottom = true, | |
| 414 | − Axis::Horizontal => border.right = true, | |
| 415 | − } | |
| 416 | − member = member.contained().with_border(border).into_any(); | |
| 426 | + let mut pane_axis = PaneAxisElement::new(self.axis, basis, self.flexes.clone()); | |
| 427 | + let mut active_pane_ix = None; | |
| 428 | + | |
| 429 | + let mut members = self.members.iter().enumerate().peekable(); | |
| 430 | + while let Some((ix, member)) = members.next() { | |
| 431 | + let last = members.peek().is_none(); | |
| 432 | + | |
| 433 | + if member.contains(active_pane) { | |
| 434 | + active_pane_ix = Some(ix); | |
| 435 | + } | |
| 436 | + | |
| 437 | + let mut member = member.render( | |
| 438 | + project, | |
| 439 | + (basis + ix) * 10, | |
| 440 | + theme, | |
| 441 | + follower_state, | |
| 442 | + active_call, | |
| 443 | + active_pane, | |
| 444 | + zoomed, | |
| 445 | + app_state, | |
| 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) | |
| 420 | − })) | |
| 421 | − .into_any() | |
| 461 | + member = member.contained().with_border(border).into_any(); | |
| 462 | + } | |
| 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 | 45 | // parent_group_id: Option<usize>, // None indicates that this is the root node |
| 46 | 46 | // position: Optiopn<usize>, // None indicates that this is the root node |
| 47 | 47 | // axis: Option<Axis>, // 'Vertical', 'Horizontal' |
| 48 | + // flexes: Option<Vec<f32>>, // A JSON array of floats | |
| 48 | 49 | // ) |
| 49 | 50 | // |
| 50 | 51 | // panes( |
| @@ -168,7 +169,12 @@ define_connection! { · 117 unmodified lines | ||
| 168 | 169 | ALTER TABLE workspaces ADD COLUMN left_dock_zoom INTEGER; //bool |
| 169 | 170 | ALTER TABLE workspaces ADD COLUMN right_dock_zoom INTEGER; //bool |
| 170 | 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 | 180 | impl WorkspaceDb { |
| @@ -359,38 +365,51 @@ impl WorkspaceDb { · 184 unmodified lines | ||
| 359 | 365 | group_id: Option<GroupId>, |
| 360 | 366 | ) -> Result<Vec<SerializedPaneGroup>> { |
| 361 | 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 | 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 | 377 | FROM (SELECT |
| 366 | − group_id, | |
| 367 | − axis, | |
| 368 | − NULL as pane_id, | |
| 369 | − NULL as active, | |
| 370 | − position, | |
| 371 | − parent_group_id, | |
| 372 | − workspace_id | |
| 373 | − FROM pane_groups | |
| 378 | + group_id, | |
| 379 | + axis, | |
| 380 | + NULL as pane_id, | |
| 381 | + NULL as active, | |
| 382 | + position, | |
| 383 | + parent_group_id, | |
| 384 | + workspace_id, | |
| 385 | + flexes | |
| 386 | + FROM pane_groups | |
| 374 | 387 | UNION |
| 375 | − SELECT | |
| 376 | − NULL, | |
| 377 | − NULL, | |
| 378 | − center_panes.pane_id, | |
| 379 | − panes.active as active, | |
| 380 | − position, | |
| 381 | − parent_group_id, | |
| 382 | − panes.workspace_id as workspace_id | |
| 383 | − FROM center_panes | |
| 384 | − JOIN panes ON center_panes.pane_id = panes.pane_id) | |
| 388 | + SELECT | |
| 389 | + NULL, | |
| 390 | + NULL, | |
| 391 | + center_panes.pane_id, | |
| 392 | + panes.active as active, | |
| 393 | + position, | |
| 394 | + parent_group_id, | |
| 395 | + panes.workspace_id as workspace_id, | |
| 396 | + NULL | |
| 397 | + FROM center_panes | |
| 398 | + JOIN panes ON center_panes.pane_id = panes.pane_id) | |
| 385 | 399 | WHERE parent_group_id IS ? AND workspace_id = ? |
| 386 | 400 | ORDER BY position |
| 387 | 401 | ))?((group_id, workspace_id))? |
| 388 | 402 | .into_iter() |
| 389 | − .map(|(group_id, axis, pane_id, active)| { | |
| 403 | + .map(|(group_id, axis, pane_id, active, flexes)| { | |
| 390 | 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 | 409 | Ok(SerializedPaneGroup::Group { |
| 392 | 410 | axis, |
| 393 | 411 | children: self.get_pane_group(workspace_id, Some(group_id))?, |
| 412 | + flexes, | |
| 394 | 413 | }) |
| 395 | 414 | } else if let Some((pane_id, active)) = pane_id.zip(active) { |
| 396 | 415 | Ok(SerializedPaneGroup::Pane(SerializedPane::new( |
| @@ -417,14 +436,34 @@ impl WorkspaceDb { · 20 unmodified lines | ||
| 417 | 436 | parent: Option<(GroupId, usize)>, |
| 418 | 437 | ) -> Result<()> { |
| 419 | 438 | match pane_group { |
| 420 | − SerializedPaneGroup::Group { axis, children } => { | |
| 439 | + SerializedPaneGroup::Group { | |
| 440 | + axis, | |
| 441 | + children, | |
| 442 | + flexes, | |
| 443 | + } => { | |
| 421 | 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 | 450 | let group_id = conn.select_row_bound::<_, i64>(sql!( |
| 424 | − INSERT INTO pane_groups(workspace_id, parent_group_id, position, axis) | |
| 425 | − VALUES (?, ?, ?, ?) | |
| 451 | + INSERT INTO pane_groups( | |
| 452 | + workspace_id, | |
| 453 | + parent_group_id, | |
| 454 | + position, | |
| 455 | + axis, | |
| 456 | + flexes | |
| 457 | + ) | |
| 458 | + VALUES (?, ?, ?, ?, ?) | |
| 426 | 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 | 467 | .ok_or_else(|| anyhow!("Couldn't retrieve group_id from inserted pane_group"))?; |
| 429 | 468 | |
| 430 | 469 | for (position, group) in children.iter().enumerate() { |
| @@ -641,6 +680,14 @@ mod tests { · 210 unmodified lines | ||
| 641 | 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 | 691 | #[gpui::test] |
| 645 | 692 | async fn test_full_workspace_serialization() { |
| 646 | 693 | env_logger::try_init().ok(); |
| @@ -652,12 +699,12 @@ mod tests { · 5 unmodified lines | ||
| 652 | 699 | // | - - - | | |
| 653 | 700 | // | 3,4 | | |
| 654 | 701 | // ----------------- |
| 655 | − let center_group = SerializedPaneGroup::Group { | |
| 656 | − axis: gpui::Axis::Horizontal, | |
| 657 | − children: vec![ | |
| 658 | − SerializedPaneGroup::Group { | |
| 659 | − axis: gpui::Axis::Vertical, | |
| 660 | − children: vec![ | |
| 702 | + let center_group = group( | |
| 703 | + gpui::Axis::Horizontal, | |
| 704 | + vec![ | |
| 705 | + group( | |
| 706 | + gpui::Axis::Vertical, | |
| 707 | + vec![ | |
| 661 | 708 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 662 | 709 | vec![ |
| 663 | 710 | SerializedItem::new("Terminal", 5, false), |
| @@ -673,7 +720,7 @@ mod tests { · 9 unmodified lines | ||
| 673 | 720 | false, |
| 674 | 721 | )), |
| 675 | 722 | ], |
| 676 | − }, | |
| 723 | + ), | |
| 677 | 724 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 678 | 725 | vec![ |
| 679 | 726 | SerializedItem::new("Terminal", 9, false), |
| @@ -682,7 +729,7 @@ mod tests { · 2 unmodified lines | ||
| 682 | 729 | false, |
| 683 | 730 | )), |
| 684 | 731 | ], |
| 685 | − }; | |
| 732 | + ); | |
| 686 | 733 | |
| 687 | 734 | let workspace = SerializedWorkspace { |
| 688 | 735 | id: 5, |
| @@ -811,12 +858,12 @@ mod tests { · 122 unmodified lines | ||
| 811 | 858 | // | - - - | | |
| 812 | 859 | // | 3,4 | | |
| 813 | 860 | // ----------------- |
| 814 | − let center_pane = SerializedPaneGroup::Group { | |
| 815 | − axis: gpui::Axis::Horizontal, | |
| 816 | − children: vec![ | |
| 817 | − SerializedPaneGroup::Group { | |
| 818 | − axis: gpui::Axis::Vertical, | |
| 819 | − children: vec![ | |
| 861 | + let center_pane = group( | |
| 862 | + gpui::Axis::Horizontal, | |
| 863 | + vec![ | |
| 864 | + group( | |
| 865 | + gpui::Axis::Vertical, | |
| 866 | + vec![ | |
| 820 | 867 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 821 | 868 | vec![ |
| 822 | 869 | SerializedItem::new("Terminal", 1, false), |
| @@ -832,7 +879,7 @@ mod tests { · 9 unmodified lines | ||
| 832 | 879 | true, |
| 833 | 880 | )), |
| 834 | 881 | ], |
| 835 | − }, | |
| 882 | + ), | |
| 836 | 883 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 837 | 884 | vec![ |
| 838 | 885 | SerializedItem::new("Terminal", 5, true), |
| @@ -841,7 +888,7 @@ mod tests { · 2 unmodified lines | ||
| 841 | 888 | false, |
| 842 | 889 | )), |
| 843 | 890 | ], |
| 844 | − }; | |
| 891 | + ); | |
| 845 | 892 | |
| 846 | 893 | let workspace = default_workspace(&["/tmp"], ¢er_pane); |
| 847 | 894 | |
| @@ -858,12 +905,12 @@ mod tests { · 10 unmodified lines | ||
| 858 | 905 | |
| 859 | 906 | let db = WorkspaceDb(open_test_db("test_cleanup_panes").await); |
| 860 | 907 | |
| 861 | − let center_pane = SerializedPaneGroup::Group { | |
| 862 | − axis: gpui::Axis::Horizontal, | |
| 863 | − children: vec![ | |
| 864 | − SerializedPaneGroup::Group { | |
| 865 | − axis: gpui::Axis::Vertical, | |
| 866 | − children: vec![ | |
| 908 | + let center_pane = group( | |
| 909 | + gpui::Axis::Horizontal, | |
| 910 | + vec![ | |
| 911 | + group( | |
| 912 | + gpui::Axis::Vertical, | |
| 913 | + vec![ | |
| 867 | 914 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 868 | 915 | vec![ |
| 869 | 916 | SerializedItem::new("Terminal", 1, false), |
| @@ -879,7 +926,7 @@ mod tests { · 9 unmodified lines | ||
| 879 | 926 | true, |
| 880 | 927 | )), |
| 881 | 928 | ], |
| 882 | − }, | |
| 929 | + ), | |
| 883 | 930 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 884 | 931 | vec![ |
| 885 | 932 | SerializedItem::new("Terminal", 5, false), |
| @@ -888,7 +935,7 @@ mod tests { · 2 unmodified lines | ||
| 888 | 935 | false, |
| 889 | 936 | )), |
| 890 | 937 | ], |
| 891 | − }; | |
| 938 | + ); | |
| 892 | 939 | |
| 893 | 940 | let id = &["/tmp"]; |
| 894 | 941 | |
| @@ -896,9 +943,9 @@ mod tests { · 1 unmodified line | ||
| 896 | 943 | |
| 897 | 944 | db.save_workspace(workspace.clone()).await; |
| 898 | 945 | |
| 899 | − workspace.center_group = SerializedPaneGroup::Group { | |
| 900 | − axis: gpui::Axis::Vertical, | |
| 901 | − children: vec![ | |
| 946 | + workspace.center_group = group( | |
| 947 | + gpui::Axis::Vertical, | |
| 948 | + vec![ | |
| 902 | 949 | SerializedPaneGroup::Pane(SerializedPane::new( |
| 903 | 950 | vec![ |
| 904 | 951 | SerializedItem::new("Terminal", 1, false), |
| @@ -914,7 +961,7 @@ mod tests { · 9 unmodified lines | ||
| 914 | 961 | true, |
| 915 | 962 | )), |
| 916 | 963 | ], |
| 917 | − }; | |
| 964 | + ); | |
| 918 | 965 | |
| 919 | 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 | 131 | pub enum SerializedPaneGroup { |
| 132 | 132 | Group { |
| 133 | 133 | axis: Axis, |
| 134 | + flexes: Option<Vec<f32>>, | |
| 134 | 135 | children: Vec<SerializedPaneGroup>, |
| 135 | 136 | }, |
| 136 | 137 | Pane(SerializedPane), |
| @@ -149,7 +150,7 @@ impl Default for SerializedPaneGroup { · 12 unmodified lines | ||
| 149 | 150 | impl SerializedPaneGroup { |
| 150 | 151 | #[async_recursion(?Send)] |
| 151 | 152 | pub(crate) async fn deserialize( |
| 152 | − &self, | |
| 153 | + self, | |
| 153 | 154 | project: &ModelHandle<Project>, |
| 154 | 155 | workspace_id: WorkspaceId, |
| 155 | 156 | workspace: &WeakViewHandle<Workspace>, |
| @@ -160,7 +161,11 @@ impl SerializedPaneGroup { · 4 unmodified lines | ||
| 160 | 161 | Vec<Option<Box<dyn ItemHandle>>>, |
| 161 | 162 | )> { |
| 162 | 163 | match self { |
| 163 | − SerializedPaneGroup::Group { axis, children } => { | |
| 164 | + SerializedPaneGroup::Group { | |
| 165 | + axis, | |
| 166 | + children, | |
| 167 | + flexes, | |
| 168 | + } => { | |
| 164 | 169 | let mut current_active_pane = None; |
| 165 | 170 | let mut members = Vec::new(); |
| 166 | 171 | let mut items = Vec::new(); |
| @@ -184,10 +189,7 @@ impl SerializedPaneGroup { · 17 unmodified lines | ||
| 184 | 189 | } |
| 185 | 190 | |
| 186 | 191 | Some(( |
| 187 | − Member::Axis(PaneAxis { | |
| 188 | − axis: *axis, | |
| 189 | − members, | |
| 190 | − }), | |
| 192 | + Member::Axis(PaneAxis::load(axis, members, flexes)), | |
| 191 | 193 | current_active_pane, |
| 192 | 194 | items, |
| 193 | 195 | )) |
| @@ -37,7 +37,11 @@ pub trait SearchableItem: Item { · 36 unmodified lines | ||
| 37 | 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 | 45 | fn clear_matches(&mut self, cx: &mut ViewContext<Self>); |
| 42 | 46 | fn update_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>); |
| 43 | 47 | fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String; |
| @@ -47,6 +51,7 @@ pub trait SearchableItem: Item { · 3 unmodified lines | ||
| 47 | 51 | matches: Vec<Self::Match>, |
| 48 | 52 | cx: &mut ViewContext<Self>, |
| 49 | 53 | ); |
| 54 | + fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>); | |
| 50 | 55 | fn match_index_for_direction( |
| 51 | 56 | &mut self, |
| 52 | 57 | matches: &Vec<Self::Match>, |
| @@ -102,6 +107,7 @@ pub trait SearchableItemHandle: ItemHandle { · 49 unmodified lines | ||
| 102 | 107 | matches: &Vec<Box<dyn Any + Send>>, |
| 103 | 108 | cx: &mut WindowContext, |
| 104 | 109 | ); |
| 110 | + fn select_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut WindowContext); | |
| 105 | 111 | fn match_index_for_direction( |
| 106 | 112 | &self, |
| 107 | 113 | matches: &Vec<Box<dyn Any + Send>>, |
| @@ -139,8 +145,9 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> { · 31 unmodified lines | ||
| 139 | 145 | cx: &mut WindowContext, |
| 140 | 146 | handler: Box<dyn Fn(SearchEvent, &mut WindowContext)>, |
| 141 | 147 | ) -> Subscription { |
| 142 | − cx.subscribe(self, move |_, event, cx| { | |
| 143 | − if let Some(search_event) = T::to_search_event(event) { | |
| 148 | + cx.subscribe(self, move |handle, event, cx| { | |
| 149 | + let search_event = handle.update(cx, |handle, cx| handle.to_search_event(event, cx)); | |
| 150 | + if let Some(search_event) = search_event { | |
| 144 | 151 | handler(search_event, cx) |
| 145 | 152 | } |
| 146 | 153 | }) |
| @@ -165,6 +172,12 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> { · 18 unmodified lines | ||
| 165 | 172 | let matches = downcast_matches(matches); |
| 166 | 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 | 181 | fn match_index_for_direction( |
| 169 | 182 | &self, |
| 170 | 183 | matches: &Vec<Box<dyn Any + Send>>, |
| @@ -1,8 +1,4 @@ | ||
| 1 | 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 | 2 | pub mod item; |
| 7 | 3 | pub mod notifications; |
| 8 | 4 | pub mod pane; |
| @@ -207,6 +203,7 @@ pub type WorkspaceId = i64; · 198 unmodified lines | ||
| 207 | 203 | |
| 208 | 204 | pub fn init_settings(cx: &mut AppContext) { |
| 209 | 205 | settings::register::<WorkspaceSettings>(cx); |
| 206 | + settings::register::<item::ItemSettings>(cx); | |
| 210 | 207 | } |
| 211 | 208 | |
| 212 | 209 | pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) { |
| @@ -508,6 +505,7 @@ pub struct Workspace { · 295 unmodified lines | ||
| 508 | 505 | subscriptions: Vec<Subscription>, |
| 509 | 506 | _apply_leader_updates: Task<Result<()>>, |
| 510 | 507 | _observe_current_user: Task<Result<()>>, |
| 508 | + _schedule_serialize: Option<Task<()>>, | |
| 511 | 509 | pane_history_timestamp: Arc<AtomicUsize>, |
| 512 | 510 | } |
| 513 | 511 | |
| @@ -722,6 +720,7 @@ impl Workspace { · 208 unmodified lines | ||
| 722 | 720 | app_state, |
| 723 | 721 | _observe_current_user, |
| 724 | 722 | _apply_leader_updates, |
| 723 | + _schedule_serialize: None, | |
| 725 | 724 | leader_updates_tx, |
| 726 | 725 | subscriptions, |
| 727 | 726 | pane_history_timestamp, |
| @@ -1823,6 +1822,13 @@ impl Workspace { · 1095 unmodified lines | ||
| 1823 | 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 | 1832 | pub fn open_abs_path( |
| 1827 | 1833 | &mut self, |
| 1828 | 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 | 1877 | pub fn open_path( |
| 1857 | 1878 | &mut self, |
| 1858 | 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 | 1934 | pub(crate) fn load_path( |
| 1882 | 1935 | &mut self, |
| 1883 | 1936 | path: ProjectPath, |
| @@ -1928,6 +1981,30 @@ impl Workspace { · 44 unmodified lines | ||
| 1928 | 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 | 2008 | pub fn open_shared_screen(&mut self, peer_id: PeerId, cx: &mut ViewContext<Self>) { |
| 1932 | 2009 | if let Some(shared_screen) = self.shared_screen_for_peer(peer_id, &self.active_pane, cx) { |
| 1933 | 2010 | self.active_pane.update(cx, |pane, cx| { |
| @@ -1955,7 +2032,7 @@ impl Workspace { · 21 unmodified lines | ||
| 1955 | 2032 | if let Some(pane) = panes.get(action.0).map(|p| (*p).clone()) { |
| 1956 | 2033 | cx.focus(&pane); |
| 1957 | 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 | 2085 | match event { |
| 2009 | 2086 | pane::Event::AddItem { item } => item.added_to_pane(self, pane, cx), |
| 2010 | 2087 | pane::Event::Split(direction) => { |
| 2011 | − self.split_pane(pane, *direction, cx); | |
| 2088 | + self.split_and_clone(pane, *direction, cx); | |
| 2012 | 2089 | } |
| 2013 | 2090 | pane::Event::Remove => self.remove_pane(pane, cx), |
| 2014 | 2091 | pane::Event::ActivateItem { local } => { |
| @@ -2059,6 +2136,20 @@ impl Workspace { · 44 unmodified lines | ||
| 2059 | 2136 | } |
| 2060 | 2137 | |
| 2061 | 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 | 2153 | &mut self, |
| 2063 | 2154 | pane: ViewHandle<Pane>, |
| 2064 | 2155 | direction: SplitDirection, |
| @@ -2897,6 +2988,14 @@ impl Workspace { · 832 unmodified lines | ||
| 2897 | 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 | 2999 | fn serialize_workspace(&self, cx: &ViewContext<Self>) { |
| 2901 | 3000 | fn serialize_pane_handle( |
| 2902 | 3001 | pane_handle: &ViewHandle<Pane>, |
| @@ -2927,12 +3026,17 @@ impl Workspace { · 24 unmodified lines | ||
| 2927 | 3026 | cx: &AppContext, |
| 2928 | 3027 | ) -> SerializedPaneGroup { |
| 2929 | 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 | 3034 | axis: *axis, |
| 2932 | 3035 | children: members |
| 2933 | 3036 | .iter() |
| 2934 | 3037 | .map(|member| build_serialized_pane_group(member, cx)) |
| 2935 | 3038 | .collect::<Vec<_>>(), |
| 3039 | + flexes: Some(flexes.borrow().clone()), | |
| 2936 | 3040 | }, |
| 2937 | 3041 | Member::Pane(pane_handle) => { |
| 2938 | 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 | 3503 | if (*db::ALL_FILE_DB_FAILED).load(std::sync::atomic::Ordering::Acquire) { |
| 3400 | 3504 | workspace.show_notification_once(0, cx, |cx| { |
| 3401 | 3505 | cx.add_view(|_| { |
| 3402 | − MessageNotification::new("Failed to load any database file.") | |
| 3506 | + MessageNotification::new("Failed to load the database file.") | |
| 3403 | 3507 | .with_click_message("Click to let us know about this error") |
| 3404 | 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 | 3513 | .log_err(); |
| @@ -4235,7 +4323,7 @@ mod tests { · 809 unmodified lines | ||
| 4235 | 4323 | }); |
| 4236 | 4324 | |
| 4237 | 4325 | workspace |
| 4238 | − .split_pane(left_pane.clone(), SplitDirection::Right, cx) | |
| 4326 | + .split_and_clone(left_pane.clone(), SplitDirection::Right, cx) | |
| 4239 | 4327 | .unwrap(); |
| 4240 | 4328 | |
| 4241 | 4329 | left_pane |
| @@ -104,25 +104,28 @@ thiserror.workspace = true · 103 unmodified lines | ||
| 104 | 104 | tiny_http = "0.8" |
| 105 | 105 | toml.workspace = true |
| 106 | 106 | tree-sitter.workspace = true |
| 107 | −tree-sitter-c = "0.20.1" | |
| 108 | −tree-sitter-cpp = "0.20.0" | |
| 109 | −tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } | |
| 110 | −tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" } | |
| 111 | −tree-sitter-embedded-template = "0.20.0" | |
| 112 | −tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "aeb2f33b366fd78d5789ff104956ce23508b85db" } | |
| 113 | −tree-sitter-heex = { git = "https://github.com/phoenixframework/tree-sitter-heex", rev = "2e1348c3cf2c9323e87c2744796cf3f3868aa82a" } | |
| 114 | −tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "40a81c01a40ac48744e0c8ccabbaba1920441199" } | |
| 115 | −tree-sitter-rust = "0.20.3" | |
| 116 | −tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" } | |
| 117 | −tree-sitter-python = "0.20.2" | |
| 118 | −tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" } | |
| 119 | −tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" } | |
| 120 | −tree-sitter-ruby = "0.20.0" | |
| 121 | −tree-sitter-html = "0.19.0" | |
| 122 | −tree-sitter-scheme = { git = "https://github.com/6cdh/tree-sitter-scheme", rev = "af0fd1fa452cb2562dc7b5c8a8c55551c39273b9"} | |
| 123 | −tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a"} | |
| 124 | −tree-sitter-yaml = { git = "https://github.com/zed-industries/tree-sitter-yaml", rev = "f545a41f57502e1b5ddf2a6668896c1b0620f930"} | |
| 125 | −tree-sitter-lua = "0.0.14" | |
| 107 | +tree-sitter-c.workspace = true | |
| 108 | +tree-sitter-cpp.workspace = true | |
| 109 | +tree-sitter-css.workspace = true | |
| 110 | +tree-sitter-elixir.workspace = true | |
| 111 | +tree-sitter-embedded-template.workspace = true | |
| 112 | +tree-sitter-go.workspace = true | |
| 113 | +tree-sitter-heex.workspace = true | |
| 114 | +tree-sitter-json.workspace = true | |
| 115 | +tree-sitter-rust.workspace = true | |
| 116 | +tree-sitter-markdown.workspace = true | |
| 117 | +tree-sitter-python.workspace = true | |
| 118 | +tree-sitter-toml.workspace = true | |
| 119 | +tree-sitter-typescript.workspace = true | |
| 120 | +tree-sitter-ruby.workspace = true | |
| 121 | +tree-sitter-html.workspace = true | |
| 122 | +tree-sitter-php.workspace = true | |
| 123 | +tree-sitter-scheme.workspace = true | |
| 124 | +tree-sitter-svelte.workspace = true | |
| 125 | +tree-sitter-racket.workspace = true | |
| 126 | +tree-sitter-yaml.workspace = true | |
| 127 | +tree-sitter-lua.workspace = true | |
| 128 | + | |
| 126 | 129 | url = "2.2" |
| 127 | 130 | urlencoding = "2.1.2" |
| 128 | 131 | uuid = { version = "1.1.2", features = ["v4"] } |
| @@ -13,9 +13,11 @@ mod json; · 12 unmodified lines | ||
| 13 | 13 | #[cfg(feature = "plugin_runtime")] |
| 14 | 14 | mod language_plugin; |
| 15 | 15 | mod lua; |
| 16 | +mod php; | |
| 16 | 17 | mod python; |
| 17 | 18 | mod ruby; |
| 18 | 19 | mod rust; |
| 20 | +mod svelte; | |
| 19 | 21 | mod typescript; |
| 20 | 22 | mod yaml; |
| 21 | 23 | |
| @@ -135,7 +137,19 @@ pub fn init(languages: Arc<LanguageRegistry>, node_runtime: Arc<NodeRuntime>) { · 113 unmodified lines | ||
| 135 | 137 | language( |
| 136 | 138 | "yaml", |
| 137 | 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 | 4 | brackets = [ |
| 5 | 5 | { start = "<", end = ">", close = true, newline = true }, |
| 6 | 6 | ] |
| 7 | −block_comment = ["<%#", "%>"] | |
| 7 | +block_comment = ["<%!-- ", " --%>"] | |
| @@ -1,10 +1,7 @@ | ||
| 1 | 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 | 24 | ] @keyword |
| 25 | 25 | |
| 26 | 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 | 6 | (function_definition |
| 7 | 7 | "async"? @context |
| 8 | 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 | 36 | path::{Path, PathBuf}, |
| 37 | 37 | str, |
| 38 | 38 | sync::{ |
| 39 | − atomic::{AtomicBool, Ordering}, | |
| 39 | + atomic::{AtomicBool, AtomicU32, Ordering}, | |
| 40 | 40 | Arc, Weak, |
| 41 | 41 | }, |
| 42 | 42 | thread, |
| @@ -405,11 +405,18 @@ struct PanicRequest { · 362 unmodified lines | ||
| 405 | 405 | token: String, |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | +static PANIC_COUNT: AtomicU32 = AtomicU32::new(0); | |
| 409 | + | |
| 408 | 410 | fn init_panic_hook(app: &App, installation_id: Option<String>) { |
| 409 | 411 | let is_pty = stdout_is_a_pty(); |
| 410 | 412 | let platform = app.platform(); |
| 411 | 413 | |
| 412 | 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 | 420 | let app_version = ZED_APP_VERSION |
| 414 | 421 | .or_else(|| platform.app_version().ok()) |
| 415 | 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 | 471 | if is_pty { |
| 465 | 472 | if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() { |
| 466 | 473 | eprintln!("{}", panic_data_json); |
| 467 | − return; | |
| 468 | 474 | } |
| 469 | 475 | } else { |
| 470 | 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 | 517 | let mut settings_subscription = None; |
| 518 | 518 | while let Some(user_keymap_content) = user_keymap_file_rx.next().await { |
| 519 | 519 | if let Ok(keymap_content) = KeymapFile::parse(&user_keymap_content) { |
| 520 | − cx.update(|cx| { | |
| 521 | − cx.clear_bindings(); | |
| 522 | − load_default_keymap(cx); | |
| 523 | − keymap_content.clone().add_to_cx(cx).log_err(); | |
| 524 | − }); | |
| 520 | + cx.update(|cx| reload_keymaps(cx, &keymap_content)); | |
| 525 | 521 | |
| 526 | 522 | let mut old_base_keymap = cx.read(|cx| *settings::get::<BaseKeymap>(cx)); |
| 527 | 523 | drop(settings_subscription); |
| @@ -530,10 +526,7 @@ pub fn handle_keymap_file_changes( · 2 unmodified lines | ||
| 530 | 526 | let new_base_keymap = *settings::get::<BaseKeymap>(cx); |
| 531 | 527 | if new_base_keymap != old_base_keymap { |
| 532 | 528 | old_base_keymap = new_base_keymap.clone(); |
| 533 | − | |
| 534 | − cx.clear_bindings(); | |
| 535 | − load_default_keymap(cx); | |
| 536 | − keymap_content.clone().add_to_cx(cx).log_err(); | |
| 529 | + reload_keymaps(cx, &keymap_content); | |
| 537 | 530 | } |
| 538 | 531 | }) |
| 539 | 532 | .detach(); |
| @@ -544,6 +537,13 @@ pub fn handle_keymap_file_changes( · 4 unmodified lines | ||
| 544 | 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 | 547 | fn open_local_settings_file( |
| 548 | 548 | workspace: &mut Workspace, |
| 549 | 549 | _: &OpenLocalSettings, |
| @@ -1021,7 +1021,7 @@ mod tests { · 471 unmodified lines | ||
| 1021 | 1021 | // Split the pane with the first entry, then open the second entry again. |
| 1022 | 1022 | workspace |
| 1023 | 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 | 1025 | w.open_path(file2.clone(), None, true, cx) |
| 1026 | 1026 | }) |
| 1027 | 1027 | .await |
| @@ -1344,7 +1344,11 @@ mod tests { · 316 unmodified lines | ||
| 1344 | 1344 | cx.dispatch_action(window_id, NewFile); |
| 1345 | 1345 | workspace |
| 1346 | 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 | 1352 | workspace.open_path((worktree.read(cx).id(), "the-new-name.rs"), None, true, cx) |
| 1349 | 1353 | }) |
| 1350 | 1354 | .await |
| @@ -114,7 +114,7 @@ export default function editor(): any { · 113 unmodified lines | ||
| 114 | 114 | color: foreground(layer, "default"), |
| 115 | 115 | }, |
| 116 | 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 | 33 | background: background(theme.highest, "on", "hovered"), |
| 34 | 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 | 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 | 115 | editor, |
| 87 | 116 | invalid_editor: { |
| 88 | 117 | ...editor, |
| @@ -6,6 +6,8 @@ import { useTheme } from "../common" · 5 unmodified lines | ||
| 6 | 6 | export default function tab_bar(): any { |
| 7 | 7 | const theme = useTheme() |
| 8 | 8 | |
| 9 | + const { is_light } = theme | |
| 10 | + | |
| 9 | 11 | const height = 32 |
| 10 | 12 | |
| 11 | 13 | const active_layer = theme.highest |
| @@ -38,6 +40,18 @@ export default function tab_bar(): any { · 26 unmodified lines | ||
| 38 | 40 | icon_conflict: foreground(layer, "warning"), |
| 39 | 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 | 55 | // When two tabs of the same name are open, a label appears next to them |
| 42 | 56 | description: { |
| 43 | 57 | margin: { left: 8 }, |