Merge branch 'main' into cursors

Conrad Irwin created

Change summary

.github/workflows/ci.yml                                                      |   9 
.gitignore                                                                    |   1 
CONTRIBUTING.md                                                               |  57 
Cargo.lock                                                                    |  79 
Procfile                                                                      |   2 
README.md                                                                     | 109 
assets/keymaps/vim.json                                                       |   8 
assets/screenshots/staff_usage_of_channels.png                                |   0 
crates/ai/src/prompts/base.rs                                                 |  10 
crates/ai/src/prompts/repository_context.rs                                   |   6 
crates/ai/src/providers/open_ai/completion.rs                                 |   2 
crates/assistant/src/assistant_panel.rs                                       |  25 
crates/auto_update/src/auto_update.rs                                         |  47 
crates/auto_update/src/update_notification.rs                                 |   4 
crates/client/src/telemetry.rs                                                |   8 
crates/collab/.admins.default.json                                            |   1 
crates/collab/Cargo.toml                                                      |   2 
crates/collab/migrations.sqlite/20221109000000_test_schema.sql                |   1 
crates/collab/migrations/20240117150300_add_impersonator_to_access_tokens.sql |   1 
crates/collab/src/api.rs                                                      |   9 
crates/collab/src/auth.rs                                                     | 104 
crates/collab/src/bin/seed.rs                                                 | 121 
crates/collab/src/db.rs                                                       |  26 
crates/collab/src/db/ids.rs                                                   |  20 
crates/collab/src/db/queries/access_tokens.rs                                 |   4 
crates/collab/src/db/queries/buffers.rs                                       |  14 
crates/collab/src/db/queries/channels.rs                                      |  28 
crates/collab/src/db/queries/contacts.rs                                      |   8 
crates/collab/src/db/queries/messages.rs                                      |  11 
crates/collab/src/db/queries/notifications.rs                                 |   4 
crates/collab/src/db/queries/projects.rs                                      |  18 
crates/collab/src/db/queries/rooms.rs                                         |   6 
crates/collab/src/db/queries/servers.rs                                       |   6 
crates/collab/src/db/queries/users.rs                                         |  21 
crates/collab/src/db/tables/access_token.rs                                   |   1 
crates/collab/src/db/tables/user.rs                                           |   1 
crates/collab/src/db/tests/db_tests.rs                                        | 104 
crates/collab/src/rpc.rs                                                      |  82 
crates/collab/src/tests/channel_tests.rs                                      |   2 
crates/collab/src/tests/editor_tests.rs                                       | 100 
crates/collab/src/tests/following_tests.rs                                    |  13 
crates/collab/src/tests/integration_tests.rs                                  |  44 
crates/collab/src/tests/test_server.rs                                        |   1 
crates/collab_ui/src/chat_panel.rs                                            |  17 
crates/collab_ui/src/collab_panel.rs                                          |   4 
crates/collab_ui/src/collab_panel/channel_modal.rs                            |   4 
crates/collab_ui/src/collab_titlebar_item.rs                                  |  53 
crates/color/Cargo.toml                                                       |  32 
crates/color/src/color.rs                                                     | 234 
crates/copilot/src/copilot.rs                                                 |   9 
crates/copilot_ui/src/copilot_button.rs                                       |   2 
crates/copilot_ui/src/sign_in.rs                                              |   4 
crates/diagnostics/src/diagnostics.rs                                         |   2 
crates/diagnostics/src/items.rs                                               |   2 
crates/editor/src/actions.rs                                                  | 218 
crates/editor/src/display_map.rs                                              |  51 
crates/editor/src/display_map/block_map.rs                                    |   2 
crates/editor/src/display_map/fold_map.rs                                     |  12 
crates/editor/src/display_map/inlay_map.rs                                    |   6 
crates/editor/src/display_map/wrap_map.rs                                     |   2 
crates/editor/src/editor.rs                                                   | 277 
crates/editor/src/element.rs                                                  |  11 
crates/editor/src/hover_popover.rs                                            |   1 
crates/editor/src/inlay_hint_cache.rs                                         |  71 
crates/editor/src/link_go_to_definition.rs                                    |   2 
crates/editor/src/movement.rs                                                 |  72 
crates/editor/src/scroll.rs                                                   |  13 
crates/editor/src/scroll/autoscroll.rs                                        |   2 
crates/editor/src/selections_collection.rs                                    |  14 
crates/feature_flags/src/feature_flags.rs                                     |  16 
crates/file_finder/src/file_finder.rs                                         |   2 
crates/fs/src/repository.rs                                                   |   2 
crates/go_to_line/src/go_to_line.rs                                           |   2 
crates/gpui/examples/ownership_post.rs                                        |  35 
crates/gpui/src/app.rs                                                        |  81 
crates/gpui/src/app/async_context.rs                                          |  31 
crates/gpui/src/app/entity_map.rs                                             |  35 
crates/gpui/src/app/model_context.rs                                          |  17 
crates/gpui/src/app/test_context.rs                                           |  74 
crates/gpui/src/element.rs                                                    |   6 
crates/gpui/src/elements/div.rs                                               |  23 
crates/gpui/src/elements/list.rs                                              |  69 
crates/gpui/src/executor.rs                                                   |   7 
crates/gpui/src/interactive.rs                                                | 175 
crates/gpui/src/keymap/matcher.rs                                             |   5 
crates/gpui/src/platform.rs                                                   |  35 
crates/gpui/src/platform/keystroke.rs                                         |   2 
crates/gpui/src/platform/mac.rs                                               |   2 
crates/gpui/src/platform/mac/display.rs                                       |   5 
crates/gpui/src/platform/mac/events.rs                                        |   8 
crates/gpui/src/platform/mac/metal_atlas.rs                                   |  14 
crates/gpui/src/platform/mac/metal_renderer.rs                                |  34 
crates/gpui/src/platform/mac/platform.rs                                      |  10 
crates/gpui/src/platform/mac/text_system.rs                                   |  15 
crates/gpui/src/platform/mac/window.rs                                        |  56 
crates/gpui/src/platform/mac/window_appearance.rs                             |   0 
crates/gpui/src/platform/test/display.rs                                      |   4 
crates/gpui/src/platform/test/platform.rs                                     |   2 
crates/gpui/src/platform/test/window.rs                                       |  20 
crates/gpui/src/scene.rs                                                      |  28 
crates/gpui/src/style.rs                                                      |  12 
crates/gpui/src/text_system.rs                                                |  21 
crates/gpui/src/text_system/line_wrapper.rs                                   |   2 
crates/gpui/src/view.rs                                                       |  30 
crates/gpui/src/window.rs                                                     |  93 
crates/gpui_macros/src/gpui_macros.rs                                         |   2 
crates/journal/src/journal.rs                                                 |   2 
crates/language/src/buffer_tests.rs                                           |   2 
crates/language/src/language.rs                                               |   2 
crates/language_tools/src/lsp_log.rs                                          |   2 
crates/language_tools/src/syntax_tree_view.rs                                 |   2 
crates/live_kit_client/LiveKitBridge/Package.resolved                         |   8 
crates/live_kit_client/LiveKitBridge/Package.swift                            |   2 
crates/live_kit_client/examples/test_app.rs                                   |   4 
crates/lsp/src/lsp.rs                                                         | 108 
crates/multi_buffer/src/multi_buffer.rs                                       |  16 
crates/outline/src/outline.rs                                                 |   4 
crates/picker/src/picker.rs                                                   |   6 
crates/project/src/lsp_command.rs                                             |   2 
crates/project/src/project.rs                                                 |   4 
crates/project/src/project_settings.rs                                        |   2 
crates/project_panel/src/file_associations.rs                                 |   8 
crates/project_panel/src/project_panel.rs                                     |   2 
crates/project_symbols/src/project_symbols.rs                                 |   2 
crates/quick_action_bar/src/quick_action_bar.rs                               |   4 
crates/recent_projects/src/recent_projects.rs                                 |   2 
crates/refineable/derive_refineable/src/derive_refineable.rs                  |  12 
crates/search/src/buffer_search.rs                                            | 144 
crates/search/src/history.rs                                                  |   2 
crates/search/src/project_search.rs                                           | 223 
crates/semantic_index/README.md                                               |   2 
crates/semantic_index/src/parsing.rs                                          |   2 
crates/semantic_index/src/semantic_index.rs                                   |   7 
crates/semantic_index/src/semantic_index_tests.rs                             |  10 
crates/sqlez/src/migrations.rs                                                |   2 
crates/storybook/src/stories/auto_height_editor.rs                            |   6 
crates/storybook/src/stories/text.rs                                          |   4 
crates/storybook/src/storybook.rs                                             |   3 
crates/terminal/src/terminal.rs                                               |  35 
crates/terminal_view/src/terminal_element.rs                                  | 111 
crates/terminal_view/src/terminal_panel.rs                                    |   2 
crates/terminal_view/src/terminal_view.rs                                     |   8 
crates/theme/Cargo.toml                                                       |   1 
crates/theme/src/styles/syntax.rs                                             |   2 
crates/theme_importer/src/main.rs                                             |   4 
crates/ui/src/components/button/button_like.rs                                |   4 
crates/ui/src/components/button/icon_button.rs                                |  23 
crates/ui/src/components/context_menu.rs                                      |   2 
crates/ui/src/components/popover.rs                                           |   2 
crates/ui/src/components/right_click_menu.rs                                  |  12 
crates/ui/src/components/stories/icon_button.rs                               |  33 
crates/ui/src/components/stories/toggle_button.rs                             |   2 
crates/ui/src/components/tab.rs                                               |   5 
crates/ui/src/styles/elevation.rs                                             |   2 
crates/vcs_menu/src/lib.rs                                                    |   2 
crates/vim/src/command.rs                                                     |  32 
crates/vim/src/insert.rs                                                      |   2 
crates/vim/src/mode_indicator.rs                                              |  16 
crates/vim/src/motion.rs                                                      |   5 
crates/vim/src/normal.rs                                                      |   2 
crates/vim/src/normal/case.rs                                                 |   2 
crates/vim/src/normal/change.rs                                               |   7 
crates/vim/src/normal/delete.rs                                               |   2 
crates/vim/src/normal/increment.rs                                            |   2 
crates/vim/src/normal/paste.rs                                                |   3 
crates/vim/src/normal/repeat.rs                                               |   4 
crates/vim/src/normal/scroll.rs                                               |   2 
crates/vim/src/normal/search.rs                                               |   6 
crates/vim/src/object.rs                                                      |   5 
crates/vim/src/test.rs                                                        |  24 
crates/vim/src/test/neovim_connection.rs                                      |   2 
crates/vim/src/vim.rs                                                         |  24 
crates/vim/src/visual.rs                                                      |  14 
crates/welcome/src/base_keymap_setting.rs                                     |   2 
crates/welcome/src/welcome.rs                                                 | 361 
crates/workspace/src/item.rs                                                  |  22 
crates/workspace/src/pane.rs                                                  |   7 
crates/workspace/src/pane_group.rs                                            |  78 
crates/workspace/src/workspace.rs                                             |  21 
crates/zed/Cargo.toml                                                         |   1 
crates/zed/src/app_menus.rs                                                   |  49 
crates/zed/src/main.rs                                                        |  18 
crates/zed/src/open_listener.rs                                               |   2 
crates/zed/src/zed.rs                                                         |   8 
docs/old/building-zed.md                                                      |   2 
docs/old/release-process.md                                                   |  14 
docs/old/zed/syntax-highlighting.md                                           |   2 
docs/src/SUMMARY.md                                                           |   3 
docs/src/configuring_zed.md                                                   |   2 
docs/src/developing_zed__adding_languages.md                                  |   2 
docs/src/developing_zed__building_zed.md                                      | 146 
docs/src/developing_zed__local_collaboration.md                               |  52 
script/deploy-collab                                                          |   2 
script/lib/squawk.toml                                                        |   4 
script/seed-db                                                                |   4 
script/squawk                                                                 |   5 
script/what-is-deployed                                                       |   7 
script/zed-local                                                              |  39 
typos.toml                                                                    |  22 
199 files changed, 3,361 insertions(+), 1,731 deletions(-)

Detailed changes

.github/workflows/ci.yml πŸ”—

@@ -23,7 +23,7 @@ env:
 
 jobs:
     style:
-        name: Check formatting and Clippy lints
+        name: Check formatting, Clippy lints, and spelling
         runs-on:
             - self-hosted
             - test
@@ -38,6 +38,13 @@ jobs:
             - name: Set up default .cargo/config.toml
               run: cp ./.cargo/ci-config.toml ~/.cargo/config.toml
 
+            - name: Check spelling
+              run: |
+                  if ! which typos > /dev/null; then
+                    cargo install typos-cli
+                  fi
+                  typos
+
             - name: Run style checks
               uses: ./.github/actions/check_style
 

.gitignore πŸ”—

@@ -9,6 +9,7 @@
 /styles/src/types/zed.ts
 /crates/theme/schemas/theme.json
 /crates/collab/static/styles.css
+/crates/collab/.admins.json
 /vendor/bin
 /assets/themes/*.json
 /assets/*licenses.md

CONTRIBUTING.md πŸ”—

@@ -0,0 +1,57 @@
+# CONTRIBUTING
+
+Thanks for your interest in contributing to Zed, the collaborative platform that is also a code editor!
+
+We want to ensure that no one ends up spending time on a pull request that may not be accepted, so we ask that you discuss your ideas with the team and community before starting on a contribution.
+
+All activity in Zed communities is subject to our [Code of Conduct](https://docs.zed.dev/community/code-of-conduct). Contributors to Zed must sign our Contributor License Agreement (link coming soon) before their contributions can be merged.
+
+## Contribution ideas
+
+If you already have an idea of what you'd like to contribute, you can skip this section, otherwise, here are a few resources to help you find something to work on:
+
+- Our public roadmap (link coming soon!) details what features we plan to add to Zed.
+- Our [Top-Ranking Issues issue](https://github.com/zed-industries/community/issues/52) shows the most popular feature requests and issues, as voted on by the community.
+
+At the moment, we are generally not looking to extend Zed's language or theme support by directly adding these features to Zed - we really want to build a plugin system to handle making the editor extensible going forward.
+
+If you are passionate about shipping new languages or themes we suggest contributing to the extension system to help us get there faster.
+
+## Resources
+
+### Bird-eye's view of Zed
+
+Zed is made up of several smaller crates - let's go over those you're most likely to interact with:
+
+- [gpui](/crates/gpui) is a GPU-accelerated UI framework which provides all of the building blocks for Zed. **We recommend familiarizing yourself with the root level GPUI documentation**
+- [editor](/crates/editor) contains the core `Editor` type that drives both the code editor and all various input fields within Zed. It also handles a display layer for LSP features such as Inlay Hints or code completions.
+- [project](/crates/project) manages files and navigation within the filetree. It is also Zed's side of communication with LSP.
+- [workspace](/crates/workspace) handles local state serialization and groups projects together.
+- [vim](/crates/vim) is a thin implementation of Vim workflow over `editor`.
+- [lsp](/crates/lsp) handles communication with external LSP server.
+- [language](/crates/language) drives `editor`'s understanding of language - from providing a list of symbols to the syntax map.
+- [collab](/crates/collab) is the collaboration server itself, driving the collaboration features such as project sharing.
+- [rpc](/crates/rpc) defines messages to be exchanged with collaboration server.
+- [theme](/crates/theme) defines the theme system and provides a default theme.
+- [ui](/crates/ui) is a collection of UI components and common patterns used throughout Zed.
+
+### Proposal & Discussion
+
+Before starting on a contribution, we ask that you look to see if there is any existing PRs, or in-Zed discussions about the thing you want to implement. If there is no existing work, find a public channel that is relevant to your contribution, check the channel notes to see which Zed team members typically work in that channel, and post a message in the chat. If you're not sure which channel is best, you can start a discussion, ask a team member or another contributor.
+
+*Please remember contributions not discussed with the team ahead of time likely have a lower chance of being merged or looked at in a timely manner.*
+
+## Implementation & Help
+
+When you start working on your contribution if you find you are struggling with something specific feel free to reach out to the team for help.
+
+Remember the team is more likely to be available to help if you have already discussed your contribution or are working on something that is higher priority, like something on the roadmap or a top-ranking issue.
+
+We're happy to pair with you to help you learn the codebase and get your contribution merged.
+
+**Zed makes heavy use of unit and integration testing, it is highly likely that contributions without any unit tests will be rejected**
+
+Reviewing code in a pull request, after the fact, is hard and tedious - the team generally likes to build trust and review code through pair programming.
+We'd prefer have conversations about the code, through Zed, while it is being written, so decisions can be made in real-time and less time is spent on fixing things after the fact. Ideally, GitHub is only used to merge code that has already been discussed and reviewed in Zed.
+
+Remember that smaller, incremental PRs are easier to review and merge than large PRs.

Cargo.lock πŸ”—

@@ -1452,7 +1452,7 @@ dependencies = [
 
 [[package]]
 name = "collab"
-version = "0.36.1"
+version = "0.37.0"
 dependencies = [
  "anyhow",
  "async-trait",
@@ -1580,6 +1580,28 @@ dependencies = [
  "rustc-hash",
 ]
 
+[[package]]
+name = "color"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "fs",
+ "indexmap 1.9.3",
+ "itertools 0.11.0",
+ "palette",
+ "parking_lot 0.11.2",
+ "refineable",
+ "schemars",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "settings",
+ "story",
+ "toml 0.5.11",
+ "util",
+ "uuid 1.4.1",
+]
+
 [[package]]
 name = "color_quant"
 version = "1.1.0"
@@ -4977,6 +4999,7 @@ dependencies = [
  "approx",
  "fast-srgb8",
  "palette_derive",
+ "phf",
 ]
 
 [[package]]
@@ -5165,6 +5188,48 @@ dependencies = [
  "indexmap 2.0.0",
 ]
 
+[[package]]
+name = "phf"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
+dependencies = [
+ "phf_macros",
+ "phf_shared",
+]
+
+[[package]]
+name = "phf_generator"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
+dependencies = [
+ "phf_shared",
+ "rand 0.8.5",
+]
+
+[[package]]
+name = "phf_macros"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b"
+dependencies = [
+ "phf_generator",
+ "phf_shared",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.37",
+]
+
+[[package]]
+name = "phf_shared"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
+dependencies = [
+ "siphasher 0.3.11",
+]
+
 [[package]]
 name = "picker"
 version = "0.1.0"
@@ -7074,6 +7139,12 @@ version = "0.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
 
+[[package]]
+name = "siphasher"
+version = "0.3.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
+
 [[package]]
 name = "slab"
 version = "0.4.9"
@@ -7644,7 +7715,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9c536faaff1a10837cfe373142583f6e27d81e96beba339147e77b67c9f260ff"
 dependencies = [
  "float-cmp",
- "siphasher",
+ "siphasher 0.2.3",
 ]
 
 [[package]]
@@ -7855,6 +7926,7 @@ name = "theme"
 version = "0.1.0"
 dependencies = [
  "anyhow",
+ "color",
  "fs",
  "gpui",
  "indexmap 1.9.3",
@@ -8858,7 +8930,7 @@ dependencies = [
  "roxmltree",
  "rustybuzz",
  "simplecss",
- "siphasher",
+ "siphasher 0.2.3",
  "svgtypes",
  "ttf-parser 0.12.3",
  "unicode-bidi",
@@ -9650,6 +9722,7 @@ dependencies = [
  "client",
  "collab_ui",
  "collections",
+ "color",
  "command_palette",
  "copilot",
  "copilot_ui",

Procfile πŸ”—

@@ -1,4 +1,2 @@
-web: cd ../zed.dev && PORT=3000 npm run dev
 collab: cd crates/collab && RUST_LOG=${RUST_LOG:-warn,collab=info} cargo run serve
 livekit: livekit-server --dev
-postgrest: postgrest crates/collab/admin_api.conf

README.md πŸ”—

@@ -1,110 +1,27 @@
-# Zed
-
-[![CI](https://github.com/zed-industries/zed/actions/workflows/ci.yml/badge.svg)](https://github.com/zed-industries/zed/actions/workflows/ci.yml)
-
-Welcome to Zed, a lightning-fast, collaborative code editor that makes your dreams come true.
-
-## Development tips
-
-### Dependencies
-
-* Install Xcode from https://apps.apple.com/us/app/xcode/id497799835?mt=12, and accept the license:
-  ```
-  sudo xcodebuild -license
-  ```
-
-* Install homebrew, node and rustup-init (rustup, rust, cargo, etc.)
-  ```
-  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-  brew install node rustup-init
-  rustup-init # follow the installation steps
-  ```
-
-* Install postgres and configure the database
-  ```
-  brew install postgresql@15
-  brew services start postgresql@15
-  psql -c "CREATE ROLE postgres SUPERUSER LOGIN" postgres
-  psql -U postgres -c "CREATE DATABASE zed"
-  ```
-
-* Install the `LiveKit` server, the `PostgREST` API server, and the `foreman` process supervisor:
-
-    ```
-    brew install livekit
-    brew install postgrest
-    brew install foreman
-    ```
-
-* Ensure the Zed.dev website is checked out in a sibling directory and install its dependencies:
-
-    ```
-    cd ..
-    git clone https://github.com/zed-industries/zed.dev
-    cd zed.dev && npm install
-    npm install -g vercel
-    ```
-
-* Return to Zed project directory and Initialize submodules
-
-    ```
-    cd zed
-    git submodule update --init --recursive
-    ```
+# 🚧 TODO 🚧
 
-* Set up a local `zed` database and seed it with some initial users:
+- [ ] Add intro
+- [ ] Add link to contributing guide
+- [ ] Add barebones running zed from source instructions
+- [ ] Link out to further dev docs
 
-    [Create a personal GitHub token](https://github.com/settings/tokens/new) to run `script/bootstrap` once successfully: the token needs to have an access to private repositories for the script to work (`repo` OAuth scope).
-    Then delete that token.
-
-    ```
-    GITHUB_TOKEN=<$token> script/bootstrap
-    ```
-
-* Now try running zed with collaboration disabled:
-  ```
-  cargo run
-  ```
-
-### Common errors
-
-* `xcrun: error: unable to find utility "metal", not a developer tool or in PATH`
-  * You need to install Xcode and then run: `xcode-select --switch /Applications/Xcode.app/Contents/Developer`
-  * (see https://github.com/gfx-rs/gfx/issues/2309)
-
-### Testing against locally-running servers
-
-Start the web and collab servers:
-
-```
-foreman start
-```
+# Zed
 
-If you want to run Zed pointed at the local servers, you can run:
+[![CI](https://github.com/zed-industries/zed/actions/workflows/ci.yml/badge.svg)](https://github.com/zed-industries/zed/actions/workflows/ci.yml)
 
-```
-script/zed-local
-```
+Welcome to Zed, a high-performance, multiplayer code editor from the creators of [Atom](https://github.com/atom/atom) and [Tree-sitter](https://github.com/tree-sitter/tree-sitter).
 
-### Dump element JSON
+## Developing Zed
 
-If you trigger `cmd-alt-i`, Zed will copy a JSON representation of the current window contents to the clipboard. You can paste this in a tool like [DJSON](https://chrome.google.com/webstore/detail/djson-json-viewer-formatt/chaeijjekipecdajnijdldjjipaegdjc?hl=en) to navigate the state of on-screen elements in a structured way.
+- [Building Zed](./docs/src/developing_zed__building_zed.md)
+- [Running Collaboration Locally](./docs/src/developing_zed__local_collaboration.md)
 
 ### Licensing
 
+License information for third party dependencies must be correctly provided for CI to pass.
+
 We use [`cargo-about`](https://github.com/EmbarkStudios/cargo-about) to automatically comply with open source licenses. If CI is failing, check the following:
 
 - Is it showing a `no license specified` error for a crate you've created? If so, add `publish = false` under `[package]` in your crate's Cargo.toml.
 - Is the error `failed to satisfy license requirements` for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the `accepted` array in `script/licenses/zed-licenses.toml`.
 - Is `cargo-about` unable to find the license for a dependency? If so, add a clarification field at the end of `script/licenses/zed-licenses.toml`, as specified in the [cargo-about book](https://embarkstudios.github.io/cargo-about/cli/generate/config.html#crate-configuration).
-
-
-### Wasm Plugins
-
-Zed has a Wasm-based plugin runtime which it currently uses to embed plugins. To compile Zed, you'll need to have the `wasm32-wasi` toolchain installed on your system. To install this toolchain, run:
-
-```bash
-rustup target add wasm32-wasi
-```
-
-Plugins can be found in the `plugins` folder in the root. For more information about how plugins work, check the [Plugin Guide](./crates/plugin_runtime/README.md) in `crates/plugin_runtime/README.md`.

assets/keymaps/vim.json πŸ”—

@@ -99,7 +99,7 @@
       "ctrl-i": "pane::GoForward",
       "ctrl-]": "editor::GoToDefinition",
       "escape": ["vim::SwitchMode", "Normal"],
-      "ctrl+[": ["vim::SwitchMode", "Normal"],
+      "ctrl-[": ["vim::SwitchMode", "Normal"],
       "v": "vim::ToggleVisual",
       "shift-v": "vim::ToggleVisualLine",
       "ctrl-v": "vim::ToggleVisualBlock",
@@ -288,7 +288,7 @@
     "context": "Editor && vim_mode == normal && vim_operator == none && !VimWaiting",
     "bindings": {
       "escape": "editor::Cancel",
-      "ctrl+[": "editor::Cancel"
+      "ctrl-[": "editor::Cancel"
     }
   },
   {
@@ -441,7 +441,7 @@
       "r": ["vim::PushOperator", "Replace"],
       "ctrl-c": ["vim::SwitchMode", "Normal"],
       "escape": ["vim::SwitchMode", "Normal"],
-      "ctrl+[": ["vim::SwitchMode", "Normal"],
+      "ctrl-[": ["vim::SwitchMode", "Normal"],
       ">": "editor::Indent",
       "<": "editor::Outdent",
       "i": [
@@ -481,7 +481,7 @@
       "tab": "vim::Tab",
       "enter": "vim::Enter",
       "escape": ["vim::SwitchMode", "Normal"],
-      "ctrl+[": ["vim::SwitchMode", "Normal"]
+      "ctrl-[": ["vim::SwitchMode", "Normal"]
     }
   },
   {

crates/ai/src/prompts/base.rs πŸ”—

@@ -81,8 +81,8 @@ impl PromptChain {
 
     pub fn generate(&self, truncate: bool) -> anyhow::Result<(String, usize)> {
         // Argsort based on Prompt Priority
-        let seperator = "\n";
-        let seperator_tokens = self.args.model.count_tokens(seperator)?;
+        let separator = "\n";
+        let separator_tokens = self.args.model.count_tokens(separator)?;
         let mut sorted_indices = (0..self.templates.len()).collect::<Vec<_>>();
         sorted_indices.sort_by_key(|&i| Reverse(&self.templates[i].0));
 
@@ -104,7 +104,7 @@ impl PromptChain {
                     prompts[idx] = template_prompt;
 
                     if let Some(remaining_tokens) = tokens_outstanding {
-                        let new_tokens = prompt_token_count + seperator_tokens;
+                        let new_tokens = prompt_token_count + separator_tokens;
                         tokens_outstanding = if remaining_tokens > new_tokens {
                             Some(remaining_tokens - new_tokens)
                         } else {
@@ -117,9 +117,9 @@ impl PromptChain {
 
         prompts.retain(|x| x != "");
 
-        let full_prompt = prompts.join(seperator);
+        let full_prompt = prompts.join(separator);
         let total_token_count = self.args.model.count_tokens(&full_prompt)?;
-        anyhow::Ok((prompts.join(seperator), total_token_count))
+        anyhow::Ok((prompts.join(separator), total_token_count))
     }
 }
 

crates/ai/src/prompts/repository_context.rs πŸ”—

@@ -68,7 +68,7 @@ impl PromptTemplate for RepositoryContext {
         let mut prompt = String::new();
 
         let mut remaining_tokens = max_token_length.clone();
-        let seperator_token_length = args.model.count_tokens("\n")?;
+        let separator_token_length = args.model.count_tokens("\n")?;
         for snippet in &args.snippets {
             let mut snippet_prompt = template.to_string();
             let content = snippet.to_string();
@@ -79,9 +79,9 @@ impl PromptTemplate for RepositoryContext {
                 if let Some(tokens_left) = remaining_tokens {
                     if tokens_left >= token_count {
                         writeln!(prompt, "{snippet_prompt}").unwrap();
-                        remaining_tokens = if tokens_left >= (token_count + seperator_token_length)
+                        remaining_tokens = if tokens_left >= (token_count + separator_token_length)
                         {
-                            Some(tokens_left - token_count - seperator_token_length)
+                            Some(tokens_left - token_count - separator_token_length)
                         } else {
                             Some(0)
                         };

crates/ai/src/providers/open_ai/completion.rs πŸ”—

@@ -273,7 +273,7 @@ impl CompletionProvider for OpenAICompletionProvider {
     ) -> BoxFuture<'static, Result<BoxStream<'static, Result<String>>>> {
         // Currently the CompletionRequest for OpenAI, includes a 'model' parameter
         // This means that the model is determined by the CompletionRequest and not the CompletionProvider,
-        // which is currently model based, due to the langauge model.
+        // which is currently model based, due to the language model.
         // At some point in the future we should rectify this.
         let credential = self.credential.read().clone();
         let request = stream_completion(credential, self.executor.clone(), prompt);

crates/assistant/src/assistant_panel.rs πŸ”—

@@ -19,12 +19,13 @@ use chrono::{DateTime, Local};
 use client::telemetry::AssistantKind;
 use collections::{hash_map, HashMap, HashSet, VecDeque};
 use editor::{
+    actions::{MoveDown, MoveUp},
     display_map::{
         BlockContext, BlockDisposition, BlockId, BlockProperties, BlockStyle, ToDisplayPoint,
     },
-    scroll::autoscroll::{Autoscroll, AutoscrollStrategy},
-    Anchor, Editor, EditorElement, EditorEvent, EditorStyle, MoveDown, MoveUp, MultiBufferSnapshot,
-    ToOffset, ToPoint,
+    scroll::{Autoscroll, AutoscrollStrategy},
+    Anchor, Editor, EditorElement, EditorEvent, EditorStyle, MultiBufferSnapshot, ToOffset,
+    ToPoint,
 };
 use fs::Fs;
 use futures::StreamExt;
@@ -479,7 +480,7 @@ impl AssistantPanel {
 
     fn cancel_last_inline_assist(
         workspace: &mut Workspace,
-        _: &editor::Cancel,
+        _: &editor::actions::Cancel,
         cx: &mut ViewContext<Workspace>,
     ) {
         if let Some(panel) = workspace.panel::<AssistantPanel>(cx) {
@@ -891,7 +892,7 @@ impl AssistantPanel {
         }
     }
 
-    fn handle_editor_cancel(&mut self, _: &editor::Cancel, cx: &mut ViewContext<Self>) {
+    fn handle_editor_cancel(&mut self, _: &editor::actions::Cancel, cx: &mut ViewContext<Self>) {
         if let Some(search_bar) = self.toolbar.read(cx).item_of_type::<BufferSearchBar>() {
             if !search_bar.read(cx).is_dismissed() {
                 search_bar.update(cx, |search_bar, cx| {
@@ -1148,7 +1149,7 @@ impl Render for AssistantPanel {
                     |panel, cx| panel.toolbar.read(cx).item_of_type::<BufferSearchBar>(),
                     cx,
                 );
-                BufferSearchBar::register_inner(&mut registrar);
+                BufferSearchBar::register(&mut registrar);
                 registrar.into_div()
             } else {
                 div()
@@ -2158,7 +2159,7 @@ impl ConversationEditor {
         }
     }
 
-    fn cancel_last_assist(&mut self, _: &editor::Cancel, cx: &mut ViewContext<Self>) {
+    fn cancel_last_assist(&mut self, _: &editor::actions::Cancel, cx: &mut ViewContext<Self>) {
         if !self
             .conversation
             .update(cx, |conversation, _| conversation.cancel_last_assist())
@@ -2311,8 +2312,7 @@ impl ConversationEditor {
                                     }
                                 });
 
-                            div()
-                                .h_flex()
+                            h_flex()
                                 .id(("message_header", message_id.0))
                                 .h_11()
                                 .relative()
@@ -2328,6 +2328,7 @@ impl ConversationEditor {
                                         .add_suffix(true)
                                         .to_string(),
                                     )
+                                    .size(LabelSize::XSmall)
                                     .color(Color::Muted),
                                 )
                                 .children(
@@ -2417,7 +2418,7 @@ impl ConversationEditor {
         }
     }
 
-    fn copy(&mut self, _: &editor::Copy, cx: &mut ViewContext<Self>) {
+    fn copy(&mut self, _: &editor::actions::Copy, cx: &mut ViewContext<Self>) {
         let editor = self.editor.read(cx);
         let conversation = self.conversation.read(cx);
         if editor.selections.count() == 1 {
@@ -2828,7 +2829,7 @@ impl InlineAssistant {
         cx.notify();
     }
 
-    fn cancel(&mut self, _: &editor::Cancel, cx: &mut ViewContext<Self>) {
+    fn cancel(&mut self, _: &editor::actions::Cancel, cx: &mut ViewContext<Self>) {
         cx.emit(InlineAssistantEvent::Canceled);
     }
 
@@ -2917,7 +2918,7 @@ impl InlineAssistant {
         let semantic_permissioned = self.semantic_permissioned(cx);
         if let Some(semantic_index) = SemanticIndex::global(cx) {
             cx.spawn(|_, mut cx| async move {
-                // This has to be updated to accomodate for semantic_permissions
+                // This has to be updated to accommodate for semantic_permissions
                 if semantic_permissioned.await.unwrap_or(false) {
                     semantic_index
                         .update(&mut cx, |index, cx| index.index_project(project, cx))?

crates/auto_update/src/auto_update.rs πŸ”—

@@ -93,7 +93,9 @@ pub fn init(http_client: Arc<dyn HttpClient>, server_url: String, cx: &mut AppCo
     cx.observe_new_views(|workspace: &mut Workspace, _cx| {
         workspace.register_action(|_, action: &Check, cx| check(action, cx));
 
-        workspace.register_action(|_, action, cx| view_release_notes(action, cx));
+        workspace.register_action(|_, action, cx| {
+            view_release_notes(action, cx);
+        });
 
         // @nate - code to trigger update notification on launch
         // todo!("remove this when Nate is done")
@@ -140,24 +142,23 @@ pub fn check(_: &Check, cx: &mut WindowContext) {
     }
 }
 
-pub fn view_release_notes(_: &ViewReleaseNotes, cx: &mut AppContext) {
-    if let Some(auto_updater) = AutoUpdater::get(cx) {
+pub fn view_release_notes(_: &ViewReleaseNotes, cx: &mut AppContext) -> Option<()> {
+    let auto_updater = AutoUpdater::get(cx)?;
+    let release_channel = cx.try_global::<ReleaseChannel>()?;
+
+    if matches!(
+        release_channel,
+        ReleaseChannel::Stable | ReleaseChannel::Preview
+    ) {
         let auto_updater = auto_updater.read(cx);
         let server_url = &auto_updater.server_url;
+        let release_channel = release_channel.dev_name();
         let current_version = auto_updater.current_version;
-        if cx.has_global::<ReleaseChannel>() {
-            match cx.global::<ReleaseChannel>() {
-                ReleaseChannel::Dev => {}
-                ReleaseChannel::Nightly => {}
-                ReleaseChannel::Preview => {
-                    cx.open_url(&format!("{server_url}/releases/preview/{current_version}"))
-                }
-                ReleaseChannel::Stable => {
-                    cx.open_url(&format!("{server_url}/releases/stable/{current_version}"))
-                }
-            }
-        }
+        let url = format!("{server_url}/releases/{release_channel}/{current_version}");
+        cx.open_url(&url);
     }
+
+    None
 }
 
 pub fn notify_of_any_new_update(cx: &mut ViewContext<Workspace>) -> Option<()> {
@@ -257,11 +258,13 @@ impl AutoUpdater {
             "{server_url}/api/releases/latest?token={ZED_SECRET_CLIENT_TOKEN}&asset=Zed.dmg"
         );
         cx.update(|cx| {
-            if cx.has_global::<ReleaseChannel>() {
-                if let Some(param) = cx.global::<ReleaseChannel>().release_query_param() {
-                    url_string += "&";
-                    url_string += param;
-                }
+            if let Some(param) = cx
+                .try_global::<ReleaseChannel>()
+                .map(|release_channel| release_channel.release_query_param())
+                .flatten()
+            {
+                url_string += "&";
+                url_string += param;
             }
         })?;
 
@@ -313,8 +316,8 @@ impl AutoUpdater {
         let (installation_id, release_channel, telemetry) = cx.update(|cx| {
             let installation_id = cx.global::<Arc<Client>>().telemetry().installation_id();
             let release_channel = cx
-                .has_global::<ReleaseChannel>()
-                .then(|| cx.global::<ReleaseChannel>().display_name());
+                .try_global::<ReleaseChannel>()
+                .map(|release_channel| release_channel.display_name());
             let telemetry = TelemetrySettings::get_global(cx).metrics;
 
             (installation_id, release_channel, telemetry)

crates/auto_update/src/update_notification.rs πŸ”—

@@ -40,7 +40,9 @@ impl Render for UpdateNotification {
                     .id("notes")
                     .child(Label::new("View the release notes"))
                     .cursor_pointer()
-                    .on_click(|_, cx| crate::view_release_notes(&Default::default(), cx)),
+                    .on_click(|_, cx| {
+                        crate::view_release_notes(&Default::default(), cx);
+                    }),
             )
     }
 }

crates/client/src/telemetry.rs πŸ”—

@@ -150,11 +150,9 @@ const FLUSH_INTERVAL: Duration = Duration::from_secs(60 * 5);
 
 impl Telemetry {
     pub fn new(client: Arc<dyn HttpClient>, cx: &mut AppContext) -> Arc<Self> {
-        let release_channel = if cx.has_global::<ReleaseChannel>() {
-            Some(cx.global::<ReleaseChannel>().display_name())
-        } else {
-            None
-        };
+        let release_channel = cx
+            .try_global::<ReleaseChannel>()
+            .map(|release_channel| release_channel.display_name());
 
         TelemetrySettings::register(cx);
 

crates/collab/Cargo.toml πŸ”—

@@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathan@zed.dev>"]
 default-run = "collab"
 edition = "2021"
 name = "collab"
-version = "0.36.1"
+version = "0.37.0"
 publish = false
 
 [[bin]]

crates/collab/migrations.sqlite/20221109000000_test_schema.sql πŸ”—

@@ -19,6 +19,7 @@ CREATE INDEX "index_users_on_github_user_id" ON "users" ("github_user_id");
 CREATE TABLE "access_tokens" (
     "id" INTEGER PRIMARY KEY AUTOINCREMENT,
     "user_id" INTEGER REFERENCES users (id),
+    "impersonated_user_id" INTEGER REFERENCES users (id),
     "hash" VARCHAR(128)
 );
 CREATE INDEX "index_access_tokens_user_id" ON "access_tokens" ("user_id");

crates/collab/src/api.rs πŸ”—

@@ -156,11 +156,11 @@ async fn create_access_token(
         .await?
         .ok_or_else(|| anyhow!("user not found"))?;
 
-    let mut user_id = user.id;
+    let mut impersonated_user_id = None;
     if let Some(impersonate) = params.impersonate {
         if user.admin {
             if let Some(impersonated_user) = app.db.get_user_by_github_login(&impersonate).await? {
-                user_id = impersonated_user.id;
+                impersonated_user_id = Some(impersonated_user.id);
             } else {
                 return Err(Error::Http(
                     StatusCode::UNPROCESSABLE_ENTITY,
@@ -175,12 +175,13 @@ async fn create_access_token(
         }
     }
 
-    let access_token = auth::create_access_token(app.db.as_ref(), user_id).await?;
+    let access_token =
+        auth::create_access_token(app.db.as_ref(), user_id, impersonated_user_id).await?;
     let encrypted_access_token =
         auth::encrypt_access_token(&access_token, params.public_key.clone())?;
 
     Ok(Json(CreateAccessTokenResponse {
-        user_id,
+        user_id: impersonated_user_id.unwrap_or(user_id),
         encrypted_access_token,
     }))
 }

crates/collab/src/auth.rs πŸ”—

@@ -27,6 +27,11 @@ lazy_static! {
     .unwrap();
 }
 
+#[derive(Clone, Debug, Default, PartialEq, Eq)]
+pub struct Impersonator(pub Option<db::User>);
+
+/// Validates the authorization header. This has two mechanisms, one for the ADMIN_TOKEN
+/// and one for the access tokens that we issue.
 pub async fn validate_header<B>(mut req: Request<B>, next: Next<B>) -> impl IntoResponse {
     let mut auth_header = req
         .headers()
@@ -55,28 +60,50 @@ pub async fn validate_header<B>(mut req: Request<B>, next: Next<B>) -> impl Into
     })?;
 
     let state = req.extensions().get::<Arc<AppState>>().unwrap();
-    let credentials_valid = if let Some(admin_token) = access_token.strip_prefix("ADMIN_TOKEN:") {
-        state.config.api_token == admin_token
+
+    // In development, allow impersonation using the admin API token.
+    // Don't allow this in production because we can't tell who is doing
+    // the impersonating.
+    let validate_result = if let (Some(admin_token), true) = (
+        access_token.strip_prefix("ADMIN_TOKEN:"),
+        state.config.is_development(),
+    ) {
+        Ok(VerifyAccessTokenResult {
+            is_valid: state.config.api_token == admin_token,
+            impersonator_id: None,
+        })
     } else {
-        verify_access_token(&access_token, user_id, &state.db)
-            .await
-            .unwrap_or(false)
+        verify_access_token(&access_token, user_id, &state.db).await
     };
 
-    if credentials_valid {
-        let user = state
-            .db
-            .get_user_by_id(user_id)
-            .await?
-            .ok_or_else(|| anyhow!("user {} not found", user_id))?;
-        req.extensions_mut().insert(user);
-        Ok::<_, Error>(next.run(req).await)
-    } else {
-        Err(Error::Http(
-            StatusCode::UNAUTHORIZED,
-            "invalid credentials".to_string(),
-        ))
+    if let Ok(validate_result) = validate_result {
+        if validate_result.is_valid {
+            let user = state
+                .db
+                .get_user_by_id(user_id)
+                .await?
+                .ok_or_else(|| anyhow!("user {} not found", user_id))?;
+
+            let impersonator = if let Some(impersonator_id) = validate_result.impersonator_id {
+                let impersonator = state
+                    .db
+                    .get_user_by_id(impersonator_id)
+                    .await?
+                    .ok_or_else(|| anyhow!("user {} not found", impersonator_id))?;
+                Some(impersonator)
+            } else {
+                None
+            };
+            req.extensions_mut().insert(user);
+            req.extensions_mut().insert(Impersonator(impersonator));
+            return Ok::<_, Error>(next.run(req).await);
+        }
     }
+
+    Err(Error::Http(
+        StatusCode::UNAUTHORIZED,
+        "invalid credentials".to_string(),
+    ))
 }
 
 const MAX_ACCESS_TOKENS_TO_STORE: usize = 8;
@@ -88,13 +115,24 @@ struct AccessTokenJson {
     token: String,
 }
 
-pub async fn create_access_token(db: &db::Database, user_id: UserId) -> Result<String> {
+/// Creates a new access token to identify the given user. before returning it, you should
+/// encrypt it with the user's public key.
+pub async fn create_access_token(
+    db: &db::Database,
+    user_id: UserId,
+    impersonated_user_id: Option<UserId>,
+) -> Result<String> {
     const VERSION: usize = 1;
     let access_token = rpc::auth::random_token();
     let access_token_hash =
         hash_access_token(&access_token).context("failed to hash access token")?;
     let id = db
-        .create_access_token(user_id, &access_token_hash, MAX_ACCESS_TOKENS_TO_STORE)
+        .create_access_token(
+            user_id,
+            impersonated_user_id,
+            &access_token_hash,
+            MAX_ACCESS_TOKENS_TO_STORE,
+        )
         .await?;
     Ok(serde_json::to_string(&AccessTokenJson {
         version: VERSION,
@@ -122,6 +160,8 @@ fn hash_access_token(token: &str) -> Result<String> {
         .to_string())
 }
 
+/// Encrypts the given access token with the given public key to avoid leaking it on the way
+/// to the client.
 pub fn encrypt_access_token(access_token: &str, public_key: String) -> Result<String> {
     let native_app_public_key =
         rpc::auth::PublicKey::try_from(public_key).context("failed to parse app public key")?;
@@ -131,11 +171,22 @@ pub fn encrypt_access_token(access_token: &str, public_key: String) -> Result<St
     Ok(encrypted_access_token)
 }
 
-pub async fn verify_access_token(token: &str, user_id: UserId, db: &Arc<Database>) -> Result<bool> {
+pub struct VerifyAccessTokenResult {
+    pub is_valid: bool,
+    pub impersonator_id: Option<UserId>,
+}
+
+/// Checks that the given access token is valid for the given user.
+pub async fn verify_access_token(
+    token: &str,
+    user_id: UserId,
+    db: &Arc<Database>,
+) -> Result<VerifyAccessTokenResult> {
     let token: AccessTokenJson = serde_json::from_str(&token)?;
 
     let db_token = db.get_access_token(token.id).await?;
-    if db_token.user_id != user_id {
+    let token_user_id = db_token.impersonated_user_id.unwrap_or(db_token.user_id);
+    if token_user_id != user_id {
         return Err(anyhow!("no such access token"))?;
     }
 
@@ -147,5 +198,12 @@ pub async fn verify_access_token(token: &str, user_id: UserId, db: &Arc<Database
     let duration = t0.elapsed();
     log::info!("hashed access token in {:?}", duration);
     METRIC_ACCESS_TOKEN_HASHING_TIME.observe(duration.as_millis() as f64);
-    Ok(is_valid)
+    Ok(VerifyAccessTokenResult {
+        is_valid,
+        impersonator_id: if db_token.impersonated_user_id.is_some() {
+            Some(db_token.user_id)
+        } else {
+            None
+        },
+    })
 }

crates/collab/src/bin/seed.rs πŸ”—

@@ -1,7 +1,11 @@
-use collab::{db, executor::Executor};
+use collab::{
+    db::{self, NewUserParams},
+    env::load_dotenv,
+    executor::Executor,
+};
 use db::{ConnectOptions, Database};
 use serde::{de::DeserializeOwned, Deserialize};
-use std::fmt::Write;
+use std::{fmt::Write, fs};
 
 #[derive(Debug, Deserialize)]
 struct GitHubUser {
@@ -12,90 +16,75 @@ struct GitHubUser {
 
 #[tokio::main]
 async fn main() {
+    load_dotenv().expect("failed to load .env.toml file");
+
+    let mut admin_logins =
+        load_admins("./.admins.default.json").expect("failed to load default admins file");
+    if let Ok(other_admins) = load_admins("./.admins.json") {
+        admin_logins.extend(other_admins);
+    }
+
     let database_url = std::env::var("DATABASE_URL").expect("missing DATABASE_URL env var");
     let db = Database::new(ConnectOptions::new(database_url), Executor::Production)
         .await
         .expect("failed to connect to postgres database");
-    let github_token = std::env::var("GITHUB_TOKEN").expect("missing GITHUB_TOKEN env var");
     let client = reqwest::Client::new();
 
-    let mut current_user =
-        fetch_github::<GitHubUser>(&client, &github_token, "https://api.github.com/user").await;
-    current_user
-        .email
-        .get_or_insert_with(|| "placeholder@example.com".to_string());
-    let staff_users = fetch_github::<Vec<GitHubUser>>(
-        &client,
-        &github_token,
-        "https://api.github.com/orgs/zed-industries/teams/staff/members",
-    )
-    .await;
-
-    let mut zed_users = Vec::new();
-    zed_users.push((current_user, true));
-    zed_users.extend(staff_users.into_iter().map(|user| (user, true)));
+    // Create admin users for all of the users in `.admins.toml` or `.admins.default.toml`.
+    for admin_login in admin_logins {
+        let user = fetch_github::<GitHubUser>(
+            &client,
+            &format!("https://api.github.com/users/{admin_login}"),
+        )
+        .await;
+        db.create_user(
+            &user.email.unwrap_or(format!("{admin_login}@example.com")),
+            true,
+            NewUserParams {
+                github_login: user.login,
+                github_user_id: user.id,
+            },
+        )
+        .await
+        .expect("failed to create admin user");
+    }
 
-    let user_count = db
+    // Fetch 100 other random users from GitHub and insert them into the database.
+    let mut user_count = db
         .get_all_users(0, 200)
         .await
         .expect("failed to load users from db")
         .len();
-    if user_count < 100 {
-        let mut last_user_id = None;
-        for _ in 0..10 {
-            let mut uri = "https://api.github.com/users?per_page=100".to_string();
-            if let Some(last_user_id) = last_user_id {
-                write!(&mut uri, "&since={}", last_user_id).unwrap();
-            }
-            let users = fetch_github::<Vec<GitHubUser>>(&client, &github_token, &uri).await;
-            if let Some(last_user) = users.last() {
-                last_user_id = Some(last_user.id);
-                zed_users.extend(users.into_iter().map(|user| (user, false)));
-            } else {
-                break;
-            }
+    let mut last_user_id = None;
+    while user_count < 100 {
+        let mut uri = "https://api.github.com/users?per_page=100".to_string();
+        if let Some(last_user_id) = last_user_id {
+            write!(&mut uri, "&since={}", last_user_id).unwrap();
         }
-    }
+        let users = fetch_github::<Vec<GitHubUser>>(&client, &uri).await;
 
-    for (github_user, admin) in zed_users {
-        if db
-            .get_user_by_github_login(&github_user.login)
+        for github_user in users {
+            last_user_id = Some(github_user.id);
+            user_count += 1;
+            db.get_or_create_user_by_github_account(
+                &github_user.login,
+                Some(github_user.id),
+                github_user.email.as_deref(),
+            )
             .await
-            .expect("failed to fetch user")
-            .is_none()
-        {
-            if admin {
-                db.create_user(
-                    &format!("{}@zed.dev", github_user.login),
-                    admin,
-                    db::NewUserParams {
-                        github_login: github_user.login,
-                        github_user_id: github_user.id,
-                    },
-                )
-                .await
-                .expect("failed to insert user");
-            } else {
-                db.get_or_create_user_by_github_account(
-                    &github_user.login,
-                    Some(github_user.id),
-                    github_user.email.as_deref(),
-                )
-                .await
-                .expect("failed to insert user");
-            }
+            .expect("failed to insert user");
         }
     }
 }
 
-async fn fetch_github<T: DeserializeOwned>(
-    client: &reqwest::Client,
-    access_token: &str,
-    url: &str,
-) -> T {
+fn load_admins(path: &str) -> anyhow::Result<Vec<String>> {
+    let file_content = fs::read_to_string(path)?;
+    Ok(serde_json::from_str(&file_content)?)
+}
+
+async fn fetch_github<T: DeserializeOwned>(client: &reqwest::Client, url: &str) -> T {
     let response = client
         .get(url)
-        .bearer_auth(&access_token)
         .header("user-agent", "zed")
         .send()
         .await

crates/collab/src/db.rs πŸ”—

@@ -47,6 +47,8 @@ pub use ids::*;
 pub use sea_orm::ConnectOptions;
 pub use tables::user::Model as User;
 
+/// Database gives you a handle that lets you access the database.
+/// It handles pooling internally.
 pub struct Database {
     options: ConnectOptions,
     pool: DatabaseConnection,
@@ -62,6 +64,7 @@ pub struct Database {
 // The `Database` type has so many methods that its impl blocks are split into
 // separate files in the `queries` folder.
 impl Database {
+    /// Connects to the database with the given options
     pub async fn new(options: ConnectOptions, executor: Executor) -> Result<Self> {
         sqlx::any::install_default_drivers();
         Ok(Self {
@@ -82,6 +85,7 @@ impl Database {
         self.rooms.clear();
     }
 
+    /// Runs the database migrations.
     pub async fn migrate(
         &self,
         migrations_path: &Path,
@@ -123,11 +127,15 @@ impl Database {
         Ok(new_migrations)
     }
 
+    /// Initializes static data that resides in the database by upserting it.
     pub async fn initialize_static_data(&mut self) -> Result<()> {
         self.initialize_notification_kinds().await?;
         Ok(())
     }
 
+    /// Transaction runs things in a transaction. If you want to call other methods
+    /// and pass the transaction around you need to reborrow the transaction at each
+    /// call site with: `&*tx`.
     pub async fn transaction<F, Fut, T>(&self, f: F) -> Result<T>
     where
         F: Send + Fn(TransactionHandle) -> Fut,
@@ -160,6 +168,7 @@ impl Database {
         self.run(body).await
     }
 
+    /// The same as room_transaction, but if you need to only optionally return a Room.
     async fn optional_room_transaction<F, Fut, T>(&self, f: F) -> Result<Option<RoomGuard<T>>>
     where
         F: Send + Fn(TransactionHandle) -> Fut,
@@ -210,6 +219,9 @@ impl Database {
         self.run(body).await
     }
 
+    /// room_transaction runs the block in a transaction. It returns a RoomGuard, that keeps
+    /// the database locked until it is dropped. This ensures that updates sent to clients are
+    /// properly serialized with respect to database changes.
     async fn room_transaction<F, Fut, T>(&self, room_id: RoomId, f: F) -> Result<RoomGuard<T>>
     where
         F: Send + Fn(TransactionHandle) -> Fut,
@@ -330,6 +342,7 @@ fn is_serialization_error(error: &Error) -> bool {
     }
 }
 
+/// A handle to a [`DatabaseTransaction`].
 pub struct TransactionHandle(Arc<Option<DatabaseTransaction>>);
 
 impl Deref for TransactionHandle {
@@ -340,6 +353,8 @@ impl Deref for TransactionHandle {
     }
 }
 
+/// [`RoomGuard`] keeps a database transaction alive until it is dropped.
+/// so that updates to rooms are serialized.
 pub struct RoomGuard<T> {
     data: T,
     _guard: OwnedMutexGuard<()>,
@@ -361,6 +376,7 @@ impl<T> DerefMut for RoomGuard<T> {
 }
 
 impl<T> RoomGuard<T> {
+    /// Returns the inner value of the guard.
     pub fn into_inner(self) -> T {
         self.data
     }
@@ -420,12 +436,14 @@ pub struct WaitlistSummary {
     pub unknown_count: i64,
 }
 
+/// The parameters to create a new user.
 #[derive(Debug, Serialize, Deserialize)]
 pub struct NewUserParams {
     pub github_login: String,
     pub github_user_id: i32,
 }
 
+/// The result of creating a new user.
 #[derive(Debug)]
 pub struct NewUserResult {
     pub user_id: UserId,
@@ -434,6 +452,7 @@ pub struct NewUserResult {
     pub signup_device_id: Option<String>,
 }
 
+/// The result of moving a channel.
 #[derive(Debug)]
 pub struct MoveChannelResult {
     pub participants_to_update: HashMap<UserId, ChannelsForUser>,
@@ -441,18 +460,21 @@ pub struct MoveChannelResult {
     pub moved_channels: HashSet<ChannelId>,
 }
 
+/// The result of renaming a channel.
 #[derive(Debug)]
 pub struct RenameChannelResult {
     pub channel: Channel,
     pub participants_to_update: HashMap<UserId, Channel>,
 }
 
+/// The result of creating a channel.
 #[derive(Debug)]
 pub struct CreateChannelResult {
     pub channel: Channel,
     pub participants_to_update: Vec<(UserId, ChannelsForUser)>,
 }
 
+/// The result of setting a channel's visibility.
 #[derive(Debug)]
 pub struct SetChannelVisibilityResult {
     pub participants_to_update: HashMap<UserId, ChannelsForUser>,
@@ -460,6 +482,7 @@ pub struct SetChannelVisibilityResult {
     pub channels_to_remove: Vec<ChannelId>,
 }
 
+/// The result of updating a channel membership.
 #[derive(Debug)]
 pub struct MembershipUpdated {
     pub channel_id: ChannelId,
@@ -467,12 +490,14 @@ pub struct MembershipUpdated {
     pub removed_channels: Vec<ChannelId>,
 }
 
+/// The result of setting a member's role.
 #[derive(Debug)]
 pub enum SetMemberRoleResult {
     InviteUpdated(Channel),
     MembershipUpdated(MembershipUpdated),
 }
 
+/// The result of inviting a member to a channel.
 #[derive(Debug)]
 pub struct InviteMemberResult {
     pub channel: Channel,
@@ -497,6 +522,7 @@ pub struct Channel {
     pub name: String,
     pub visibility: ChannelVisibility,
     pub role: ChannelRole,
+    /// parent_path is the channel ids from the root to this one (not including this one)
     pub parent_path: Vec<ChannelId>,
 }
 

crates/collab/src/db/ids.rs πŸ”—

@@ -19,19 +19,23 @@ macro_rules! id_type {
             Deserialize,
             DeriveValueType,
         )]
+        #[allow(missing_docs)]
         #[serde(transparent)]
         pub struct $name(pub i32);
 
         impl $name {
             #[allow(unused)]
+            #[allow(missing_docs)]
             pub const MAX: Self = Self(i32::MAX);
 
             #[allow(unused)]
+            #[allow(missing_docs)]
             pub fn from_proto(value: u64) -> Self {
                 Self(value as i32)
             }
 
             #[allow(unused)]
+            #[allow(missing_docs)]
             pub fn to_proto(self) -> u64 {
                 self.0 as u64
             }
@@ -84,21 +88,28 @@ id_type!(FlagId);
 id_type!(NotificationId);
 id_type!(NotificationKindId);
 
+/// ChannelRole gives you permissions for both channels and calls.
 #[derive(Eq, PartialEq, Copy, Clone, Debug, EnumIter, DeriveActiveEnum, Default, Hash)]
 #[sea_orm(rs_type = "String", db_type = "String(None)")]
 pub enum ChannelRole {
+    /// Admin can read/write and change permissions.
     #[sea_orm(string_value = "admin")]
     Admin,
+    /// Member can read/write, but not change pemissions.
     #[sea_orm(string_value = "member")]
     #[default]
     Member,
+    /// Guest can read, but not write.
+    /// (thought they can use the channel chat)
     #[sea_orm(string_value = "guest")]
     Guest,
+    /// Banned may not read.
     #[sea_orm(string_value = "banned")]
     Banned,
 }
 
 impl ChannelRole {
+    /// Returns true if this role is more powerful than the other role.
     pub fn should_override(&self, other: Self) -> bool {
         use ChannelRole::*;
         match self {
@@ -109,6 +120,7 @@ impl ChannelRole {
         }
     }
 
+    /// Returns the maximal role between the two
     pub fn max(&self, other: Self) -> Self {
         if self.should_override(other) {
             *self
@@ -117,6 +129,7 @@ impl ChannelRole {
         }
     }
 
+    /// True if the role allows access to all descendant channels
     pub fn can_see_all_descendants(&self) -> bool {
         use ChannelRole::*;
         match self {
@@ -125,6 +138,7 @@ impl ChannelRole {
         }
     }
 
+    /// True if the role only allows access to public descendant channels
     pub fn can_only_see_public_descendants(&self) -> bool {
         use ChannelRole::*;
         match self {
@@ -133,6 +147,7 @@ impl ChannelRole {
         }
     }
 
+    /// True if the role can share screen/microphone/projects into rooms.
     pub fn can_publish_to_rooms(&self) -> bool {
         use ChannelRole::*;
         match self {
@@ -141,6 +156,7 @@ impl ChannelRole {
         }
     }
 
+    /// True if the role can edit shared projects.
     pub fn can_edit_projects(&self) -> bool {
         use ChannelRole::*;
         match self {
@@ -149,6 +165,7 @@ impl ChannelRole {
         }
     }
 
+    /// True if the role can read shared projects.
     pub fn can_read_projects(&self) -> bool {
         use ChannelRole::*;
         match self {
@@ -187,11 +204,14 @@ impl Into<i32> for ChannelRole {
     }
 }
 
+/// ChannelVisibility controls whether channels are public or private.
 #[derive(Eq, PartialEq, Copy, Clone, Debug, EnumIter, DeriveActiveEnum, Default, Hash)]
 #[sea_orm(rs_type = "String", db_type = "String(None)")]
 pub enum ChannelVisibility {
+    /// Public channels are visible to anyone with the link. People join with the Guest role by default.
     #[sea_orm(string_value = "public")]
     Public,
+    /// Members channels are only visible to members of this channel or its parents.
     #[sea_orm(string_value = "members")]
     #[default]
     Members,

crates/collab/src/db/queries/access_tokens.rs πŸ”—

@@ -2,9 +2,11 @@ use super::*;
 use sea_orm::sea_query::Query;
 
 impl Database {
+    /// Creates a new access token for the given user.
     pub async fn create_access_token(
         &self,
         user_id: UserId,
+        impersonated_user_id: Option<UserId>,
         access_token_hash: &str,
         max_access_token_count: usize,
     ) -> Result<AccessTokenId> {
@@ -13,6 +15,7 @@ impl Database {
 
             let token = access_token::ActiveModel {
                 user_id: ActiveValue::set(user_id),
+                impersonated_user_id: ActiveValue::set(impersonated_user_id),
                 hash: ActiveValue::set(access_token_hash.into()),
                 ..Default::default()
             }
@@ -39,6 +42,7 @@ impl Database {
         .await
     }
 
+    /// Retrieves the access token with the given ID.
     pub async fn get_access_token(
         &self,
         access_token_id: AccessTokenId,

crates/collab/src/db/queries/buffers.rs πŸ”—

@@ -9,6 +9,8 @@ pub struct LeftChannelBuffer {
 }
 
 impl Database {
+    /// Open a channel buffer. Returns the current contents, and adds you to the list of people
+    /// to notify on changes.
     pub async fn join_channel_buffer(
         &self,
         channel_id: ChannelId,
@@ -121,6 +123,7 @@ impl Database {
         .await
     }
 
+    /// Rejoin a channel buffer (after a connection interruption)
     pub async fn rejoin_channel_buffers(
         &self,
         buffers: &[proto::ChannelBufferVersion],
@@ -149,7 +152,7 @@ impl Database {
                     .await?;
 
                 // If the buffer epoch hasn't changed since the client lost
-                // connection, then the client's buffer can be syncronized with
+                // connection, then the client's buffer can be synchronized with
                 // the server's buffer.
                 if buffer.epoch as u64 != client_buffer.epoch {
                     log::info!("can't rejoin buffer, epoch has changed");
@@ -232,6 +235,7 @@ impl Database {
         .await
     }
 
+    /// Clear out any buffer collaborators who are no longer collaborating.
     pub async fn clear_stale_channel_buffer_collaborators(
         &self,
         channel_id: ChannelId,
@@ -274,6 +278,7 @@ impl Database {
         .await
     }
 
+    /// Close the channel buffer, and stop receiving updates for it.
     pub async fn leave_channel_buffer(
         &self,
         channel_id: ChannelId,
@@ -286,6 +291,7 @@ impl Database {
         .await
     }
 
+    /// Close the channel buffer, and stop receiving updates for it.
     pub async fn channel_buffer_connection_lost(
         &self,
         connection: ConnectionId,
@@ -309,6 +315,7 @@ impl Database {
         Ok(())
     }
 
+    /// Close all open channel buffers
     pub async fn leave_channel_buffers(
         &self,
         connection: ConnectionId,
@@ -342,7 +349,7 @@ impl Database {
         .await
     }
 
-    pub async fn leave_channel_buffer_internal(
+    async fn leave_channel_buffer_internal(
         &self,
         channel_id: ChannelId,
         connection: ConnectionId,
@@ -798,6 +805,7 @@ impl Database {
         Ok(changes)
     }
 
+    /// Returns the latest operations for the buffers with the specified IDs.
     pub async fn get_latest_operations_for_buffers(
         &self,
         buffer_ids: impl IntoIterator<Item = BufferId>,
@@ -962,7 +970,7 @@ fn version_from_storage(version: &Vec<storage::VectorClockEntry>) -> Vec<proto::
         .collect()
 }
 
-// This is currently a manual copy of the deserialization code in the client's langauge crate
+// This is currently a manual copy of the deserialization code in the client's language crate
 pub fn operation_from_wire(operation: proto::Operation) -> Option<text::Operation> {
     match operation.variant? {
         proto::operation::Variant::Edit(edit) => Some(text::Operation::Edit(EditOperation {

crates/collab/src/db/queries/channels.rs πŸ”—

@@ -40,6 +40,7 @@ impl Database {
             .id)
     }
 
+    /// Creates a new channel.
     pub async fn create_channel(
         &self,
         name: &str,
@@ -97,6 +98,7 @@ impl Database {
         .await
     }
 
+    /// Adds a user to the specified channel.
     pub async fn join_channel(
         &self,
         channel_id: ChannelId,
@@ -179,6 +181,7 @@ impl Database {
         .await
     }
 
+    /// Sets the visibiltity of the given channel.
     pub async fn set_channel_visibility(
         &self,
         channel_id: ChannelId,
@@ -258,6 +261,7 @@ impl Database {
         .await
     }
 
+    /// Deletes the channel with the specified ID.
     pub async fn delete_channel(
         &self,
         channel_id: ChannelId,
@@ -294,6 +298,7 @@ impl Database {
         .await
     }
 
+    /// Invites a user to a channel as a member.
     pub async fn invite_channel_member(
         &self,
         channel_id: ChannelId,
@@ -349,6 +354,7 @@ impl Database {
         Ok(new_name)
     }
 
+    /// Renames the specified channel.
     pub async fn rename_channel(
         &self,
         channel_id: ChannelId,
@@ -387,6 +393,7 @@ impl Database {
         .await
     }
 
+    /// accept or decline an invite to join a channel
     pub async fn respond_to_channel_invite(
         &self,
         channel_id: ChannelId,
@@ -486,6 +493,7 @@ impl Database {
         })
     }
 
+    /// Removes a channel member.
     pub async fn remove_channel_member(
         &self,
         channel_id: ChannelId,
@@ -530,6 +538,7 @@ impl Database {
         .await
     }
 
+    /// Returns all channel invites for the user with the given ID.
     pub async fn get_channel_invites_for_user(&self, user_id: UserId) -> Result<Vec<Channel>> {
         self.transaction(|tx| async move {
             let mut role_for_channel: HashMap<ChannelId, ChannelRole> = HashMap::default();
@@ -565,6 +574,7 @@ impl Database {
         .await
     }
 
+    /// Returns all channels for the user with the given ID.
     pub async fn get_channels_for_user(&self, user_id: UserId) -> Result<ChannelsForUser> {
         self.transaction(|tx| async move {
             let tx = tx;
@@ -574,6 +584,8 @@ impl Database {
         .await
     }
 
+    /// Returns all channels for the user with the given ID that are descendants
+    /// of the specified ancestor channel.
     pub async fn get_user_channels(
         &self,
         user_id: UserId,
@@ -743,6 +755,7 @@ impl Database {
         Ok(results)
     }
 
+    /// Sets the role for the specified channel member.
     pub async fn set_channel_member_role(
         &self,
         channel_id: ChannelId,
@@ -786,6 +799,7 @@ impl Database {
         .await
     }
 
+    /// Returns the details for the specified channel member.
     pub async fn get_channel_participant_details(
         &self,
         channel_id: ChannelId,
@@ -911,6 +925,7 @@ impl Database {
             .collect())
     }
 
+    /// Returns the participants in the given channel.
     pub async fn get_channel_participants(
         &self,
         channel: &channel::Model,
@@ -925,6 +940,7 @@ impl Database {
             .collect())
     }
 
+    /// Returns whether the given user is an admin in the specified channel.
     pub async fn check_user_is_channel_admin(
         &self,
         channel: &channel::Model,
@@ -943,6 +959,7 @@ impl Database {
         }
     }
 
+    /// Returns whether the given user is a member of the specified channel.
     pub async fn check_user_is_channel_member(
         &self,
         channel: &channel::Model,
@@ -958,6 +975,7 @@ impl Database {
         }
     }
 
+    /// Returns whether the given user is a participant in the specified channel.
     pub async fn check_user_is_channel_participant(
         &self,
         channel: &channel::Model,
@@ -975,6 +993,7 @@ impl Database {
         }
     }
 
+    /// Returns a user's pending invite for the given channel, if one exists.
     pub async fn pending_invite_for_channel(
         &self,
         channel: &channel::Model,
@@ -991,7 +1010,7 @@ impl Database {
         Ok(row)
     }
 
-    pub async fn public_parent_channel(
+    async fn public_parent_channel(
         &self,
         channel: &channel::Model,
         tx: &DatabaseTransaction,
@@ -1003,7 +1022,7 @@ impl Database {
         Ok(path.pop())
     }
 
-    pub async fn public_ancestors_including_self(
+    pub(crate) async fn public_ancestors_including_self(
         &self,
         channel: &channel::Model,
         tx: &DatabaseTransaction,
@@ -1018,6 +1037,7 @@ impl Database {
         Ok(visible_channels)
     }
 
+    /// Returns the role for a user in the given channel.
     pub async fn channel_role_for_user(
         &self,
         channel: &channel::Model,
@@ -1143,7 +1163,7 @@ impl Database {
             .await?)
     }
 
-    /// Returns the channel with the given ID
+    /// Returns the channel with the given ID.
     pub async fn get_channel(&self, channel_id: ChannelId, user_id: UserId) -> Result<Channel> {
         self.transaction(|tx| async move {
             let channel = self.get_channel_internal(channel_id, &*tx).await?;
@@ -1156,7 +1176,7 @@ impl Database {
         .await
     }
 
-    pub async fn get_channel_internal(
+    pub(crate) async fn get_channel_internal(
         &self,
         channel_id: ChannelId,
         tx: &DatabaseTransaction,

crates/collab/src/db/queries/contacts.rs πŸ”—

@@ -1,6 +1,7 @@
 use super::*;
 
 impl Database {
+    /// Retrieves the contacts for the user with the given ID.
     pub async fn get_contacts(&self, user_id: UserId) -> Result<Vec<Contact>> {
         #[derive(Debug, FromQueryResult)]
         struct ContactWithUserBusyStatuses {
@@ -86,6 +87,7 @@ impl Database {
         .await
     }
 
+    /// Returns whether the given user is a busy (on a call).
     pub async fn is_user_busy(&self, user_id: UserId) -> Result<bool> {
         self.transaction(|tx| async move {
             let participant = room_participant::Entity::find()
@@ -97,6 +99,9 @@ impl Database {
         .await
     }
 
+    /// Returns whether the user with `user_id_1` has the user with `user_id_2` as a contact.
+    ///
+    /// In order for this to return `true`, `user_id_2` must have an accepted invite from `user_id_1`.
     pub async fn has_contact(&self, user_id_1: UserId, user_id_2: UserId) -> Result<bool> {
         self.transaction(|tx| async move {
             let (id_a, id_b) = if user_id_1 < user_id_2 {
@@ -119,6 +124,7 @@ impl Database {
         .await
     }
 
+    /// Invite the user with `receiver_id` to be a contact of the user with `sender_id`.
     pub async fn send_contact_request(
         &self,
         sender_id: UserId,
@@ -231,6 +237,7 @@ impl Database {
         .await
     }
 
+    /// Dismisses a contact notification for the given user.
     pub async fn dismiss_contact_notification(
         &self,
         user_id: UserId,
@@ -272,6 +279,7 @@ impl Database {
         .await
     }
 
+    /// Accept or decline a contact request
     pub async fn respond_to_contact_request(
         &self,
         responder_id: UserId,

crates/collab/src/db/queries/messages.rs πŸ”—

@@ -4,6 +4,7 @@ use sea_orm::TryInsertResult;
 use time::OffsetDateTime;
 
 impl Database {
+    /// Inserts a record representing a user joining the chat for a given channel.
     pub async fn join_channel_chat(
         &self,
         channel_id: ChannelId,
@@ -28,6 +29,7 @@ impl Database {
         .await
     }
 
+    /// Removes `channel_chat_participant` records associated with the given connection ID.
     pub async fn channel_chat_connection_lost(
         &self,
         connection_id: ConnectionId,
@@ -47,6 +49,8 @@ impl Database {
         Ok(())
     }
 
+    /// Removes `channel_chat_participant` records associated with the given user ID so they
+    /// will no longer get chat notifications.
     pub async fn leave_channel_chat(
         &self,
         channel_id: ChannelId,
@@ -72,6 +76,9 @@ impl Database {
         .await
     }
 
+    /// Retrieves the messages in the specified channel.
+    ///
+    /// Use `before_message_id` to paginate through the channel's messages.
     pub async fn get_channel_messages(
         &self,
         channel_id: ChannelId,
@@ -103,6 +110,7 @@ impl Database {
         .await
     }
 
+    /// Returns the channel messages with the given IDs.
     pub async fn get_channel_messages_by_id(
         &self,
         user_id: UserId,
@@ -190,6 +198,7 @@ impl Database {
         Ok(messages)
     }
 
+    /// Creates a new channel message.
     pub async fn create_channel_message(
         &self,
         channel_id: ChannelId,
@@ -376,6 +385,7 @@ impl Database {
         Ok(())
     }
 
+    /// Returns the unseen messages for the given user in the specified channels.
     pub async fn unseen_channel_messages(
         &self,
         user_id: UserId,
@@ -449,6 +459,7 @@ impl Database {
         Ok(changes)
     }
 
+    /// Removes the channel message with the given ID.
     pub async fn remove_channel_message(
         &self,
         channel_id: ChannelId,

crates/collab/src/db/queries/notifications.rs πŸ”—

@@ -2,6 +2,7 @@ use super::*;
 use rpc::Notification;
 
 impl Database {
+    /// Initializes the different kinds of notifications by upserting records for them.
     pub async fn initialize_notification_kinds(&mut self) -> Result<()> {
         notification_kind::Entity::insert_many(Notification::all_variant_names().iter().map(
             |kind| notification_kind::ActiveModel {
@@ -28,6 +29,7 @@ impl Database {
         Ok(())
     }
 
+    /// Returns the notifications for the given recipient.
     pub async fn get_notifications(
         &self,
         recipient_id: UserId,
@@ -140,6 +142,7 @@ impl Database {
             .await
     }
 
+    /// Marks the given notification as read.
     pub async fn mark_notification_as_read(
         &self,
         recipient_id: UserId,
@@ -150,6 +153,7 @@ impl Database {
             .await
     }
 
+    /// Marks the notification with the given ID as read.
     pub async fn mark_notification_as_read_by_id(
         &self,
         recipient_id: UserId,

crates/collab/src/db/queries/projects.rs πŸ”—

@@ -1,6 +1,7 @@
 use super::*;
 
 impl Database {
+    /// Returns the count of all projects, excluding ones marked as admin.
     pub async fn project_count_excluding_admins(&self) -> Result<usize> {
         #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
         enum QueryAs {
@@ -21,6 +22,7 @@ impl Database {
         .await
     }
 
+    /// Shares a project with the given room.
     pub async fn share_project(
         &self,
         room_id: RoomId,
@@ -100,6 +102,7 @@ impl Database {
         .await
     }
 
+    /// Unshares the given project.
     pub async fn unshare_project(
         &self,
         project_id: ProjectId,
@@ -126,6 +129,7 @@ impl Database {
         .await
     }
 
+    /// Updates the worktrees associated with the given project.
     pub async fn update_project(
         &self,
         project_id: ProjectId,
@@ -346,6 +350,7 @@ impl Database {
         .await
     }
 
+    /// Updates the diagnostic summary for the given connection.
     pub async fn update_diagnostic_summary(
         &self,
         update: &proto::UpdateDiagnosticSummary,
@@ -401,6 +406,7 @@ impl Database {
         .await
     }
 
+    /// Starts the language server for the given connection.
     pub async fn start_language_server(
         &self,
         update: &proto::StartLanguageServer,
@@ -447,6 +453,7 @@ impl Database {
         .await
     }
 
+    /// Updates the worktree settings for the given connection.
     pub async fn update_worktree_settings(
         &self,
         update: &proto::UpdateWorktreeSettings,
@@ -499,6 +506,7 @@ impl Database {
         .await
     }
 
+    /// Adds the given connection to the specified project.
     pub async fn join_project(
         &self,
         project_id: ProjectId,
@@ -704,6 +712,7 @@ impl Database {
         .await
     }
 
+    /// Removes the given connection from the specified project.
     pub async fn leave_project(
         &self,
         project_id: ProjectId,
@@ -805,6 +814,7 @@ impl Database {
         .map(|guard| guard.into_inner())
     }
 
+    /// Returns the host connection for a read-only request to join a shared project.
     pub async fn host_for_read_only_project_request(
         &self,
         project_id: ProjectId,
@@ -842,6 +852,7 @@ impl Database {
         .map(|guard| guard.into_inner())
     }
 
+    /// Returns the host connection for a request to join a shared project.
     pub async fn host_for_mutating_project_request(
         &self,
         project_id: ProjectId,
@@ -927,6 +938,10 @@ impl Database {
         .await
     }
 
+    /// Returns the connection IDs in the given project.
+    ///
+    /// The provided `connection_id` must also be a collaborator in the project,
+    /// otherwise an error will be returned.
     pub async fn project_connection_ids(
         &self,
         project_id: ProjectId,
@@ -976,6 +991,7 @@ impl Database {
         Ok(guest_connection_ids)
     }
 
+    /// Returns the [`RoomId`] for the given project.
     pub async fn room_id_for_project(&self, project_id: ProjectId) -> Result<RoomId> {
         self.transaction(|tx| async move {
             let project = project::Entity::find_by_id(project_id)
@@ -1020,6 +1036,7 @@ impl Database {
         .await
     }
 
+    /// Adds the given follower connection as a follower of the given leader connection.
     pub async fn follow(
         &self,
         room_id: RoomId,
@@ -1050,6 +1067,7 @@ impl Database {
         .await
     }
 
+    /// Removes the given follower connection as a follower of the given leader connection.
     pub async fn unfollow(
         &self,
         room_id: RoomId,

crates/collab/src/db/queries/rooms.rs πŸ”—

@@ -1,6 +1,7 @@
 use super::*;
 
 impl Database {
+    /// Clears all room participants in rooms attached to a stale server.
     pub async fn clear_stale_room_participants(
         &self,
         room_id: RoomId,
@@ -78,6 +79,7 @@ impl Database {
         .await
     }
 
+    /// Returns the incoming calls for user with the given ID.
     pub async fn incoming_call_for_user(
         &self,
         user_id: UserId,
@@ -102,6 +104,7 @@ impl Database {
         .await
     }
 
+    /// Creates a new room.
     pub async fn create_room(
         &self,
         user_id: UserId,
@@ -394,6 +397,7 @@ impl Database {
         Ok(participant_index)
     }
 
+    /// Returns the channel ID for the given room, if it has one.
     pub async fn channel_id_for_room(&self, room_id: RoomId) -> Result<Option<ChannelId>> {
         self.transaction(|tx| async move {
             let room: Option<room::Model> = room::Entity::find()
@@ -944,6 +948,7 @@ impl Database {
         .await
     }
 
+    /// Updates the location of a participant in the given room.
     pub async fn update_room_participant_location(
         &self,
         room_id: RoomId,
@@ -1004,6 +1009,7 @@ impl Database {
         .await
     }
 
+    /// Sets the role of a participant in the given room.
     pub async fn set_room_participant_role(
         &self,
         admin_id: UserId,

crates/collab/src/db/queries/servers.rs πŸ”—

@@ -1,6 +1,7 @@
 use super::*;
 
 impl Database {
+    /// Creates a new server in the given environment.
     pub async fn create_server(&self, environment: &str) -> Result<ServerId> {
         self.transaction(|tx| async move {
             let server = server::ActiveModel {
@@ -14,6 +15,10 @@ impl Database {
         .await
     }
 
+    /// Returns the IDs of resources associated with stale servers.
+    ///
+    /// A server is stale if it is in the specified `environment` and does not
+    /// match the provided `new_server_id`.
     pub async fn stale_server_resource_ids(
         &self,
         environment: &str,
@@ -61,6 +66,7 @@ impl Database {
         .await
     }
 
+    /// Deletes any stale servers in the environment that don't match the `new_server_id`.
     pub async fn delete_stale_servers(
         &self,
         environment: &str,

crates/collab/src/db/queries/users.rs πŸ”—

@@ -1,6 +1,7 @@
 use super::*;
 
 impl Database {
+    /// Creates a new user.
     pub async fn create_user(
         &self,
         email_address: &str,
@@ -19,7 +20,11 @@ impl Database {
             })
             .on_conflict(
                 OnConflict::column(user::Column::GithubLogin)
-                    .update_column(user::Column::GithubLogin)
+                    .update_columns([
+                        user::Column::Admin,
+                        user::Column::EmailAddress,
+                        user::Column::GithubUserId,
+                    ])
                     .to_owned(),
             )
             .exec_with_returning(&*tx)
@@ -35,11 +40,13 @@ impl Database {
         .await
     }
 
+    /// Returns a user by ID. There are no access checks here, so this should only be used internally.
     pub async fn get_user_by_id(&self, id: UserId) -> Result<Option<user::Model>> {
         self.transaction(|tx| async move { Ok(user::Entity::find_by_id(id).one(&*tx).await?) })
             .await
     }
 
+    /// Returns all users by ID. There are no access checks here, so this should only be used internally.
     pub async fn get_users_by_ids(&self, ids: Vec<UserId>) -> Result<Vec<user::Model>> {
         self.transaction(|tx| async {
             let tx = tx;
@@ -51,6 +58,7 @@ impl Database {
         .await
     }
 
+    /// Returns a user by GitHub login. There are no access checks here, so this should only be used internally.
     pub async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> {
         self.transaction(|tx| async move {
             Ok(user::Entity::find()
@@ -111,6 +119,8 @@ impl Database {
         .await
     }
 
+    /// get_all_users returns the next page of users. To get more call again with
+    /// the same limit and the page incremented by 1.
     pub async fn get_all_users(&self, page: u32, limit: u32) -> Result<Vec<User>> {
         self.transaction(|tx| async move {
             Ok(user::Entity::find()
@@ -123,6 +133,7 @@ impl Database {
         .await
     }
 
+    /// Returns the metrics id for the user.
     pub async fn get_user_metrics_id(&self, id: UserId) -> Result<String> {
         #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
         enum QueryAs {
@@ -142,6 +153,7 @@ impl Database {
         .await
     }
 
+    /// Set "connected_once" on the user for analytics.
     pub async fn set_user_connected_once(&self, id: UserId, connected_once: bool) -> Result<()> {
         self.transaction(|tx| async move {
             user::Entity::update_many()
@@ -157,6 +169,7 @@ impl Database {
         .await
     }
 
+    /// hard delete the user.
     pub async fn destroy_user(&self, id: UserId) -> Result<()> {
         self.transaction(|tx| async move {
             access_token::Entity::delete_many()
@@ -169,6 +182,7 @@ impl Database {
         .await
     }
 
+    /// Find users where github_login ILIKE name_query.
     pub async fn fuzzy_search_users(&self, name_query: &str, limit: u32) -> Result<Vec<User>> {
         self.transaction(|tx| async {
             let tx = tx;
@@ -193,6 +207,8 @@ impl Database {
         .await
     }
 
+    /// fuzzy_like_string creates a string for matching in-order using fuzzy_search_users.
+    /// e.g. "cir" would become "%c%i%r%"
     pub fn fuzzy_like_string(string: &str) -> String {
         let mut result = String::with_capacity(string.len() * 2 + 1);
         for c in string.chars() {
@@ -205,6 +221,7 @@ impl Database {
         result
     }
 
+    /// Creates a new feature flag.
     pub async fn create_user_flag(&self, flag: &str) -> Result<FlagId> {
         self.transaction(|tx| async move {
             let flag = feature_flag::Entity::insert(feature_flag::ActiveModel {
@@ -220,6 +237,7 @@ impl Database {
         .await
     }
 
+    /// Add the given user to the feature flag
     pub async fn add_user_flag(&self, user: UserId, flag: FlagId) -> Result<()> {
         self.transaction(|tx| async move {
             user_feature::Entity::insert(user_feature::ActiveModel {
@@ -234,6 +252,7 @@ impl Database {
         .await
     }
 
+    /// Return the active flags for the user.
     pub async fn get_user_flags(&self, user: UserId) -> Result<Vec<String>> {
         self.transaction(|tx| async move {
             #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]

crates/collab/src/db/tables/user.rs πŸ”—

@@ -2,6 +2,7 @@ use crate::db::UserId;
 use sea_orm::entity::prelude::*;
 use serde::Serialize;
 
+/// A user model.
 #[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel, Serialize)]
 #[sea_orm(table_name = "users")]
 pub struct Model {

crates/collab/src/db/tests/db_tests.rs πŸ”—

@@ -146,7 +146,7 @@ test_both_dbs!(
 );
 
 async fn test_create_access_tokens(db: &Arc<Database>) {
-    let user = db
+    let user_1 = db
         .create_user(
             "u1@example.com",
             false,
@@ -158,14 +158,27 @@ async fn test_create_access_tokens(db: &Arc<Database>) {
         .await
         .unwrap()
         .user_id;
+    let user_2 = db
+        .create_user(
+            "u2@example.com",
+            false,
+            NewUserParams {
+                github_login: "u2".into(),
+                github_user_id: 2,
+            },
+        )
+        .await
+        .unwrap()
+        .user_id;
 
-    let token_1 = db.create_access_token(user, "h1", 2).await.unwrap();
-    let token_2 = db.create_access_token(user, "h2", 2).await.unwrap();
+    let token_1 = db.create_access_token(user_1, None, "h1", 2).await.unwrap();
+    let token_2 = db.create_access_token(user_1, None, "h2", 2).await.unwrap();
     assert_eq!(
         db.get_access_token(token_1).await.unwrap(),
         access_token::Model {
             id: token_1,
-            user_id: user,
+            user_id: user_1,
+            impersonated_user_id: None,
             hash: "h1".into(),
         }
     );
@@ -173,17 +186,19 @@ async fn test_create_access_tokens(db: &Arc<Database>) {
         db.get_access_token(token_2).await.unwrap(),
         access_token::Model {
             id: token_2,
-            user_id: user,
+            user_id: user_1,
+            impersonated_user_id: None,
             hash: "h2".into()
         }
     );
 
-    let token_3 = db.create_access_token(user, "h3", 2).await.unwrap();
+    let token_3 = db.create_access_token(user_1, None, "h3", 2).await.unwrap();
     assert_eq!(
         db.get_access_token(token_3).await.unwrap(),
         access_token::Model {
             id: token_3,
-            user_id: user,
+            user_id: user_1,
+            impersonated_user_id: None,
             hash: "h3".into()
         }
     );
@@ -191,18 +206,20 @@ async fn test_create_access_tokens(db: &Arc<Database>) {
         db.get_access_token(token_2).await.unwrap(),
         access_token::Model {
             id: token_2,
-            user_id: user,
+            user_id: user_1,
+            impersonated_user_id: None,
             hash: "h2".into()
         }
     );
     assert!(db.get_access_token(token_1).await.is_err());
 
-    let token_4 = db.create_access_token(user, "h4", 2).await.unwrap();
+    let token_4 = db.create_access_token(user_1, None, "h4", 2).await.unwrap();
     assert_eq!(
         db.get_access_token(token_4).await.unwrap(),
         access_token::Model {
             id: token_4,
-            user_id: user,
+            user_id: user_1,
+            impersonated_user_id: None,
             hash: "h4".into()
         }
     );
@@ -210,12 +227,77 @@ async fn test_create_access_tokens(db: &Arc<Database>) {
         db.get_access_token(token_3).await.unwrap(),
         access_token::Model {
             id: token_3,
-            user_id: user,
+            user_id: user_1,
+            impersonated_user_id: None,
             hash: "h3".into()
         }
     );
     assert!(db.get_access_token(token_2).await.is_err());
     assert!(db.get_access_token(token_1).await.is_err());
+
+    // An access token for user 2 impersonating user 1 does not
+    // count against user 1's access token limit (of 2).
+    let token_5 = db
+        .create_access_token(user_2, Some(user_1), "h5", 2)
+        .await
+        .unwrap();
+    assert_eq!(
+        db.get_access_token(token_5).await.unwrap(),
+        access_token::Model {
+            id: token_5,
+            user_id: user_2,
+            impersonated_user_id: Some(user_1),
+            hash: "h5".into()
+        }
+    );
+    assert_eq!(
+        db.get_access_token(token_3).await.unwrap(),
+        access_token::Model {
+            id: token_3,
+            user_id: user_1,
+            impersonated_user_id: None,
+            hash: "h3".into()
+        }
+    );
+
+    // Only a limited number (2) of access tokens are stored for user 2
+    // impersonating other users.
+    let token_6 = db
+        .create_access_token(user_2, Some(user_1), "h6", 2)
+        .await
+        .unwrap();
+    let token_7 = db
+        .create_access_token(user_2, Some(user_1), "h7", 2)
+        .await
+        .unwrap();
+    assert_eq!(
+        db.get_access_token(token_6).await.unwrap(),
+        access_token::Model {
+            id: token_6,
+            user_id: user_2,
+            impersonated_user_id: Some(user_1),
+            hash: "h6".into()
+        }
+    );
+    assert_eq!(
+        db.get_access_token(token_7).await.unwrap(),
+        access_token::Model {
+            id: token_7,
+            user_id: user_2,
+            impersonated_user_id: Some(user_1),
+            hash: "h7".into()
+        }
+    );
+    assert!(db.get_access_token(token_5).await.is_err());
+    assert_eq!(
+        db.get_access_token(token_3).await.unwrap(),
+        access_token::Model {
+            id: token_3,
+            user_id: user_1,
+            impersonated_user_id: None,
+            hash: "h3".into()
+        }
+    );
 }
 
 test_both_dbs!(

crates/collab/src/rpc.rs πŸ”—

@@ -1,7 +1,7 @@
 mod connection_pool;
 
 use crate::{
-    auth,
+    auth::{self, Impersonator},
     db::{
         self, BufferId, ChannelId, ChannelRole, ChannelsForUser, CreateChannelResult,
         CreatedChannelMessage, Database, InviteMemberResult, MembershipUpdated, MessageId,
@@ -65,7 +65,7 @@ use std::{
 use time::OffsetDateTime;
 use tokio::sync::{watch, Semaphore};
 use tower::ServiceBuilder;
-use tracing::{info_span, instrument, Instrument};
+use tracing::{field, info_span, instrument, Instrument};
 
 pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30);
 pub const CLEANUP_TIMEOUT: Duration = Duration::from_secs(10);
@@ -561,13 +561,17 @@ impl Server {
         connection: Connection,
         address: String,
         user: User,
+        impersonator: Option<User>,
         mut send_connection_id: Option<oneshot::Sender<ConnectionId>>,
         executor: Executor,
     ) -> impl Future<Output = Result<()>> {
         let this = self.clone();
         let user_id = user.id;
         let login = user.github_login;
-        let span = info_span!("handle connection", %user_id, %login, %address);
+        let span = info_span!("handle connection", %user_id, %login, %address, impersonator = field::Empty);
+        if let Some(impersonator) = impersonator {
+            span.record("impersonator", &impersonator.github_login);
+        }
         let mut teardown = self.teardown.subscribe();
         async move {
             let (connection_id, handle_io, mut incoming_rx) = this
@@ -839,6 +843,7 @@ pub async fn handle_websocket_request(
     ConnectInfo(socket_address): ConnectInfo<SocketAddr>,
     Extension(server): Extension<Arc<Server>>,
     Extension(user): Extension<User>,
+    Extension(impersonator): Extension<Impersonator>,
     ws: WebSocketUpgrade,
 ) -> axum::response::Response {
     if protocol_version != rpc::PROTOCOL_VERSION {
@@ -858,7 +863,14 @@ pub async fn handle_websocket_request(
         let connection = Connection::new(Box::pin(socket));
         async move {
             server
-                .handle_connection(connection, socket_address, user, None, Executor::Production)
+                .handle_connection(
+                    connection,
+                    socket_address,
+                    user,
+                    impersonator.0,
+                    None,
+                    Executor::Production,
+                )
                 .await
                 .log_err();
         }
@@ -932,11 +944,13 @@ async fn connection_lost(
     Ok(())
 }
 
+/// Acknowledges a ping from a client, used to keep the connection alive.
 async fn ping(_: proto::Ping, response: Response<proto::Ping>, _session: Session) -> Result<()> {
     response.send(proto::Ack {})?;
     Ok(())
 }
 
+/// Create a new room for calling (outside of channels)
 async fn create_room(
     _request: proto::CreateRoom,
     response: Response<proto::CreateRoom>,
@@ -984,6 +998,7 @@ async fn create_room(
     Ok(())
 }
 
+/// Join a room from an invitation. Equivalent to joining a channel if there is one.
 async fn join_room(
     request: proto::JoinRoom,
     response: Response<proto::JoinRoom>,
@@ -1058,6 +1073,7 @@ async fn join_room(
     Ok(())
 }
 
+/// Rejoin room is used to reconnect to a room after connection errors.
 async fn rejoin_room(
     request: proto::RejoinRoom,
     response: Response<proto::RejoinRoom>,
@@ -1249,6 +1265,7 @@ async fn rejoin_room(
     Ok(())
 }
 
+/// leave room disonnects from the room.
 async fn leave_room(
     _: proto::LeaveRoom,
     response: Response<proto::LeaveRoom>,
@@ -1259,6 +1276,7 @@ async fn leave_room(
     Ok(())
 }
 
+/// Update the permissions of someone else in the room.
 async fn set_room_participant_role(
     request: proto::SetRoomParticipantRole,
     response: Response<proto::SetRoomParticipantRole>,
@@ -1303,6 +1321,7 @@ async fn set_room_participant_role(
     Ok(())
 }
 
+/// Call someone else into the current room
 async fn call(
     request: proto::Call,
     response: Response<proto::Call>,
@@ -1371,6 +1390,7 @@ async fn call(
     Err(anyhow!("failed to ring user"))?
 }
 
+/// Cancel an outgoing call.
 async fn cancel_call(
     request: proto::CancelCall,
     response: Response<proto::CancelCall>,
@@ -1408,6 +1428,7 @@ async fn cancel_call(
     Ok(())
 }
 
+/// Decline an incoming call.
 async fn decline_call(message: proto::DeclineCall, session: Session) -> Result<()> {
     let room_id = RoomId::from_proto(message.room_id);
     {
@@ -1439,6 +1460,7 @@ async fn decline_call(message: proto::DeclineCall, session: Session) -> Result<(
     Ok(())
 }
 
+/// Update other participants in the room with your current location.
 async fn update_participant_location(
     request: proto::UpdateParticipantLocation,
     response: Response<proto::UpdateParticipantLocation>,
@@ -1459,6 +1481,7 @@ async fn update_participant_location(
     Ok(())
 }
 
+/// Share a project into the room.
 async fn share_project(
     request: proto::ShareProject,
     response: Response<proto::ShareProject>,
@@ -1481,6 +1504,7 @@ async fn share_project(
     Ok(())
 }
 
+/// Unshare a project from the room.
 async fn unshare_project(message: proto::UnshareProject, session: Session) -> Result<()> {
     let project_id = ProjectId::from_proto(message.project_id);
 
@@ -1500,6 +1524,7 @@ async fn unshare_project(message: proto::UnshareProject, session: Session) -> Re
     Ok(())
 }
 
+/// Join someone elses shared project.
 async fn join_project(
     request: proto::JoinProject,
     response: Response<proto::JoinProject>,
@@ -1625,6 +1650,7 @@ async fn join_project(
     Ok(())
 }
 
+/// Leave someone elses shared project.
 async fn leave_project(request: proto::LeaveProject, session: Session) -> Result<()> {
     let sender_id = session.connection_id;
     let project_id = ProjectId::from_proto(request.project_id);
@@ -1647,6 +1673,7 @@ async fn leave_project(request: proto::LeaveProject, session: Session) -> Result
     Ok(())
 }
 
+/// Update other participants with changes to the project
 async fn update_project(
     request: proto::UpdateProject,
     response: Response<proto::UpdateProject>,
@@ -1673,6 +1700,7 @@ async fn update_project(
     Ok(())
 }
 
+/// Update other participants with changes to the worktree
 async fn update_worktree(
     request: proto::UpdateWorktree,
     response: Response<proto::UpdateWorktree>,
@@ -1697,6 +1725,7 @@ async fn update_worktree(
     Ok(())
 }
 
+/// Update other participants with changes to the diagnostics
 async fn update_diagnostic_summary(
     message: proto::UpdateDiagnosticSummary,
     session: Session,
@@ -1720,6 +1749,7 @@ async fn update_diagnostic_summary(
     Ok(())
 }
 
+/// Update other participants with changes to the worktree settings
 async fn update_worktree_settings(
     message: proto::UpdateWorktreeSettings,
     session: Session,
@@ -1743,6 +1773,7 @@ async fn update_worktree_settings(
     Ok(())
 }
 
+/// Notify other participants that a  language server has started.
 async fn start_language_server(
     request: proto::StartLanguageServer,
     session: Session,
@@ -1765,6 +1796,7 @@ async fn start_language_server(
     Ok(())
 }
 
+/// Notify other participants that a language server has changed.
 async fn update_language_server(
     request: proto::UpdateLanguageServer,
     session: Session,
@@ -1787,6 +1819,8 @@ async fn update_language_server(
     Ok(())
 }
 
+/// forward a project request to the host. These requests should be read only
+/// as guests are allowed to send them.
 async fn forward_read_only_project_request<T>(
     request: T,
     response: Response<T>,
@@ -1809,6 +1843,8 @@ where
     Ok(())
 }
 
+/// forward a project request to the host. These requests are disallowed
+/// for guests.
 async fn forward_mutating_project_request<T>(
     request: T,
     response: Response<T>,
@@ -1831,6 +1867,7 @@ where
     Ok(())
 }
 
+/// Notify other participants that a new buffer has been created
 async fn create_buffer_for_peer(
     request: proto::CreateBufferForPeer,
     session: Session,
@@ -1850,6 +1887,8 @@ async fn create_buffer_for_peer(
     Ok(())
 }
 
+/// Notify other participants that a buffer has been updated. This is
+/// allowed for guests as long as the update is limited to selections.
 async fn update_buffer(
     request: proto::UpdateBuffer,
     response: Response<proto::UpdateBuffer>,
@@ -1909,6 +1948,7 @@ async fn update_buffer(
     Ok(())
 }
 
+/// Notify other participants that a project has been updated.
 async fn broadcast_project_message_from_host<T: EntityMessage<Entity = ShareProject>>(
     request: T,
     session: Session,
@@ -1932,6 +1972,7 @@ async fn broadcast_project_message_from_host<T: EntityMessage<Entity = ShareProj
     Ok(())
 }
 
+/// Start following another user in a call.
 async fn follow(
     request: proto::Follow,
     response: Response<proto::Follow>,
@@ -1969,6 +2010,7 @@ async fn follow(
     Ok(())
 }
 
+/// Stop following another user in a call.
 async fn unfollow(request: proto::Unfollow, session: Session) -> Result<()> {
     let room_id = RoomId::from_proto(request.room_id);
     let project_id = request.project_id.map(ProjectId::from_proto);
@@ -2000,6 +2042,7 @@ async fn unfollow(request: proto::Unfollow, session: Session) -> Result<()> {
     Ok(())
 }
 
+/// Notify everyone following you of your current location.
 async fn update_followers(request: proto::UpdateFollowers, session: Session) -> Result<()> {
     let room_id = RoomId::from_proto(request.room_id);
     let database = session.db.lock().await;
@@ -2036,6 +2079,7 @@ async fn update_followers(request: proto::UpdateFollowers, session: Session) ->
     Ok(())
 }
 
+/// Get public data about users.
 async fn get_users(
     request: proto::GetUsers,
     response: Response<proto::GetUsers>,
@@ -2062,6 +2106,7 @@ async fn get_users(
     Ok(())
 }
 
+/// Search for users (to invite) buy Github login
 async fn fuzzy_search_users(
     request: proto::FuzzySearchUsers,
     response: Response<proto::FuzzySearchUsers>,
@@ -2092,6 +2137,7 @@ async fn fuzzy_search_users(
     Ok(())
 }
 
+/// Send a contact request to another user.
 async fn request_contact(
     request: proto::RequestContact,
     response: Response<proto::RequestContact>,
@@ -2138,6 +2184,7 @@ async fn request_contact(
     Ok(())
 }
 
+/// Accept or decline a contact request
 async fn respond_to_contact_request(
     request: proto::RespondToContactRequest,
     response: Response<proto::RespondToContactRequest>,
@@ -2195,6 +2242,7 @@ async fn respond_to_contact_request(
     Ok(())
 }
 
+/// Remove a contact.
 async fn remove_contact(
     request: proto::RemoveContact,
     response: Response<proto::RemoveContact>,
@@ -2245,6 +2293,7 @@ async fn remove_contact(
     Ok(())
 }
 
+/// Create a new channel.
 async fn create_channel(
     request: proto::CreateChannel,
     response: Response<proto::CreateChannel>,
@@ -2279,6 +2328,7 @@ async fn create_channel(
     Ok(())
 }
 
+/// Delete a channel
 async fn delete_channel(
     request: proto::DeleteChannel,
     response: Response<proto::DeleteChannel>,
@@ -2308,6 +2358,7 @@ async fn delete_channel(
     Ok(())
 }
 
+/// Invite someone to join a channel.
 async fn invite_channel_member(
     request: proto::InviteChannelMember,
     response: Response<proto::InviteChannelMember>,
@@ -2344,6 +2395,7 @@ async fn invite_channel_member(
     Ok(())
 }
 
+/// remove someone from a channel
 async fn remove_channel_member(
     request: proto::RemoveChannelMember,
     response: Response<proto::RemoveChannelMember>,
@@ -2385,6 +2437,7 @@ async fn remove_channel_member(
     Ok(())
 }
 
+/// Toggle the channel between public and private
 async fn set_channel_visibility(
     request: proto::SetChannelVisibility,
     response: Response<proto::SetChannelVisibility>,
@@ -2423,6 +2476,7 @@ async fn set_channel_visibility(
     Ok(())
 }
 
+/// Alter the role for a user in the channel
 async fn set_channel_member_role(
     request: proto::SetChannelMemberRole,
     response: Response<proto::SetChannelMemberRole>,
@@ -2470,6 +2524,7 @@ async fn set_channel_member_role(
     Ok(())
 }
 
+/// Change the name of a channel
 async fn rename_channel(
     request: proto::RenameChannel,
     response: Response<proto::RenameChannel>,
@@ -2503,6 +2558,7 @@ async fn rename_channel(
     Ok(())
 }
 
+/// Move a channel to a new parent.
 async fn move_channel(
     request: proto::MoveChannel,
     response: Response<proto::MoveChannel>,
@@ -2555,6 +2611,7 @@ async fn notify_channel_moved(result: Option<MoveChannelResult>, session: Sessio
     Ok(())
 }
 
+/// Get the list of channel members
 async fn get_channel_members(
     request: proto::GetChannelMembers,
     response: Response<proto::GetChannelMembers>,
@@ -2569,6 +2626,7 @@ async fn get_channel_members(
     Ok(())
 }
 
+/// Accept or decline a channel invitation.
 async fn respond_to_channel_invite(
     request: proto::RespondToChannelInvite,
     response: Response<proto::RespondToChannelInvite>,
@@ -2609,6 +2667,7 @@ async fn respond_to_channel_invite(
     Ok(())
 }
 
+/// Join the channels' room
 async fn join_channel(
     request: proto::JoinChannel,
     response: Response<proto::JoinChannel>,
@@ -2713,6 +2772,7 @@ async fn join_channel_internal(
     Ok(())
 }
 
+/// Start editing the channel notes
 async fn join_channel_buffer(
     request: proto::JoinChannelBuffer,
     response: Response<proto::JoinChannelBuffer>,
@@ -2744,6 +2804,7 @@ async fn join_channel_buffer(
     Ok(())
 }
 
+/// Edit the channel notes
 async fn update_channel_buffer(
     request: proto::UpdateChannelBuffer,
     session: Session,
@@ -2790,6 +2851,7 @@ async fn update_channel_buffer(
     Ok(())
 }
 
+/// Rejoin the channel notes after a connection blip
 async fn rejoin_channel_buffers(
     request: proto::RejoinChannelBuffers,
     response: Response<proto::RejoinChannelBuffers>,
@@ -2824,6 +2886,7 @@ async fn rejoin_channel_buffers(
     Ok(())
 }
 
+/// Stop editing the channel notes
 async fn leave_channel_buffer(
     request: proto::LeaveChannelBuffer,
     response: Response<proto::LeaveChannelBuffer>,
@@ -2885,6 +2948,7 @@ fn send_notifications(
     }
 }
 
+/// Send a message to the channel
 async fn send_channel_message(
     request: proto::SendChannelMessage,
     response: Response<proto::SendChannelMessage>,
@@ -2973,6 +3037,7 @@ async fn send_channel_message(
     Ok(())
 }
 
+/// Delete a channel message
 async fn remove_channel_message(
     request: proto::RemoveChannelMessage,
     response: Response<proto::RemoveChannelMessage>,
@@ -2992,6 +3057,7 @@ async fn remove_channel_message(
     Ok(())
 }
 
+/// Mark a channel message as read
 async fn acknowledge_channel_message(
     request: proto::AckChannelMessage,
     session: Session,
@@ -3011,6 +3077,7 @@ async fn acknowledge_channel_message(
     Ok(())
 }
 
+/// Mark a buffer version as synced
 async fn acknowledge_buffer_version(
     request: proto::AckBufferOperation,
     session: Session,
@@ -3029,6 +3096,7 @@ async fn acknowledge_buffer_version(
     Ok(())
 }
 
+/// Start receiving chat updates for a channel
 async fn join_channel_chat(
     request: proto::JoinChannelChat,
     response: Response<proto::JoinChannelChat>,
@@ -3049,6 +3117,7 @@ async fn join_channel_chat(
     Ok(())
 }
 
+/// Stop receiving chat updates for a channel
 async fn leave_channel_chat(request: proto::LeaveChannelChat, session: Session) -> Result<()> {
     let channel_id = ChannelId::from_proto(request.channel_id);
     session
@@ -3059,6 +3128,7 @@ async fn leave_channel_chat(request: proto::LeaveChannelChat, session: Session)
     Ok(())
 }
 
+/// Retrieve the chat history for a channel
 async fn get_channel_messages(
     request: proto::GetChannelMessages,
     response: Response<proto::GetChannelMessages>,
@@ -3082,6 +3152,7 @@ async fn get_channel_messages(
     Ok(())
 }
 
+/// Retrieve specific chat messages
 async fn get_channel_messages_by_id(
     request: proto::GetChannelMessagesById,
     response: Response<proto::GetChannelMessagesById>,
@@ -3104,6 +3175,7 @@ async fn get_channel_messages_by_id(
     Ok(())
 }
 
+/// Retrieve the current users notifications
 async fn get_notifications(
     request: proto::GetNotifications,
     response: Response<proto::GetNotifications>,
@@ -3127,6 +3199,7 @@ async fn get_notifications(
     Ok(())
 }
 
+/// Mark notifications as read
 async fn mark_notification_as_read(
     request: proto::MarkNotificationRead,
     response: Response<proto::MarkNotificationRead>,
@@ -3148,6 +3221,7 @@ async fn mark_notification_as_read(
     Ok(())
 }
 
+/// Get the current users information
 async fn get_private_user_info(
     _request: proto::GetPrivateUserInfo,
     response: Response<proto::GetPrivateUserInfo>,

crates/collab/src/tests/channel_tests.rs πŸ”—

@@ -203,7 +203,7 @@ async fn test_core_channels(
     executor.run_until_parked();
 
     // Observe that client B is now an admin of channel A, and that
-    // their admin priveleges extend to subchannels of channel A.
+    // their admin privileges extend to subchannels of channel A.
     assert_channel_invitations(client_b.channel_store(), cx_b, &[]);
     assert_channels(
         client_b.channel_store(),

crates/collab/src/tests/editor_tests.rs πŸ”—

@@ -8,9 +8,11 @@ use std::{
 
 use call::ActiveCall;
 use editor::{
+    actions::{
+        ConfirmCodeAction, ConfirmCompletion, ConfirmRename, Redo, Rename, ToggleCodeActions, Undo,
+    },
     test::editor_test_context::{AssertionContextManager, EditorTestContext},
-    ConfirmCodeAction, ConfirmCompletion, ConfirmRename, Editor, Redo, Rename, ToggleCodeActions,
-    Undo,
+    Editor,
 };
 use futures::StreamExt;
 use gpui::{TestAppContext, VisualContext, VisualTestContext};
@@ -185,31 +187,27 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
         .update(cx_a, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
         .await
         .unwrap();
-    let window_a = cx_a.add_empty_window();
-    let editor_a =
-        window_a.build_view(cx_a, |cx| Editor::for_buffer(buffer_a, Some(project_a), cx));
+    let cx_a = cx_a.add_empty_window();
+    let editor_a = cx_a.new_view(|cx| Editor::for_buffer(buffer_a, Some(project_a), cx));
 
     let mut editor_cx_a = EditorTestContext {
-        cx: VisualTestContext::from_window(window_a, cx_a),
-        window: window_a.into(),
+        cx: cx_a.clone(),
+        window: cx_a.handle(),
         editor: editor_a,
         assertion_cx: AssertionContextManager::new(),
     };
 
-    let window_b = cx_b.add_empty_window();
-    let mut cx_b = VisualTestContext::from_window(window_b, cx_b);
-
+    let cx_b = cx_b.add_empty_window();
     // Open a buffer as client B
     let buffer_b = project_b
-        .update(&mut cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
+        .update(cx_b, |p, cx| p.open_buffer((worktree_id, "a.txt"), cx))
         .await
         .unwrap();
-    let editor_b = window_b.build_view(&mut cx_b, |cx| {
-        Editor::for_buffer(buffer_b, Some(project_b), cx)
-    });
+    let editor_b = cx_b.new_view(|cx| Editor::for_buffer(buffer_b, Some(project_b), cx));
+
     let mut editor_cx_b = EditorTestContext {
-        cx: cx_b,
-        window: window_b.into(),
+        cx: cx_b.clone(),
+        window: cx_b.handle(),
         editor: editor_b,
         assertion_cx: AssertionContextManager::new(),
     };
@@ -221,7 +219,8 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
     editor_cx_b.set_selections_state(indoc! {"
         Some textˇ
     "});
-    editor_cx_a.update_editor(|editor, cx| editor.newline_above(&editor::NewlineAbove, cx));
+    editor_cx_a
+        .update_editor(|editor, cx| editor.newline_above(&editor::actions::NewlineAbove, cx));
     executor.run_until_parked();
     editor_cx_a.assert_editor_state(indoc! {"
         Λ‡
@@ -241,7 +240,8 @@ async fn test_newline_above_or_below_does_not_move_guest_cursor(
 
         Some textˇ
     "});
-    editor_cx_a.update_editor(|editor, cx| editor.newline_below(&editor::NewlineBelow, cx));
+    editor_cx_a
+        .update_editor(|editor, cx| editor.newline_below(&editor::actions::NewlineBelow, cx));
     executor.run_until_parked();
     editor_cx_a.assert_editor_state(indoc! {"
 
@@ -311,10 +311,9 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
         .update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
         .await
         .unwrap();
-    let window_b = cx_b.add_empty_window();
-    let editor_b = window_b.build_view(cx_b, |cx| {
-        Editor::for_buffer(buffer_b.clone(), Some(project_b.clone()), cx)
-    });
+    let cx_b = cx_b.add_empty_window();
+    let editor_b =
+        cx_b.new_view(|cx| Editor::for_buffer(buffer_b.clone(), Some(project_b.clone()), cx));
 
     let fake_language_server = fake_language_servers.next().await.unwrap();
     cx_a.background_executor.run_until_parked();
@@ -323,10 +322,8 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
         assert!(!buffer.completion_triggers().is_empty())
     });
 
-    let mut cx_b = VisualTestContext::from_window(window_b, cx_b);
-
     // Type a completion trigger character as the guest.
-    editor_b.update(&mut cx_b, |editor, cx| {
+    editor_b.update(cx_b, |editor, cx| {
         editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
         editor.handle_input(".", cx);
     });
@@ -392,8 +389,7 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
     });
 
     // Confirm a completion on the guest.
-
-    editor_b.update(&mut cx_b, |editor, cx| {
+    editor_b.update(cx_b, |editor, cx| {
         assert!(editor.context_menu_visible());
         editor.confirm_completion(&ConfirmCompletion { item_ix: Some(0) }, cx);
         assert_eq!(editor.text(cx), "fn main() { a.first_method() }");
@@ -431,7 +427,7 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
         );
     });
 
-    buffer_b.read_with(&mut cx_b, |buffer, _| {
+    buffer_b.read_with(cx_b, |buffer, _| {
         assert_eq!(
             buffer.text(),
             "use d::SomeTrait;\nfn main() { a.first_method() }"
@@ -960,7 +956,7 @@ async fn test_share_project(
     cx_c: &mut TestAppContext,
 ) {
     let executor = cx_a.executor();
-    let window_b = cx_b.add_empty_window();
+    let cx_b = cx_b.add_empty_window();
     let mut server = TestServer::start(executor.clone()).await;
     let client_a = server.create_client(cx_a, "user_a").await;
     let client_b = server.create_client(cx_b, "user_b").await;
@@ -1075,7 +1071,7 @@ async fn test_share_project(
         .await
         .unwrap();
 
-    let editor_b = window_b.build_view(cx_b, |cx| Editor::for_buffer(buffer_b, None, cx));
+    let editor_b = cx_b.new_view(|cx| Editor::for_buffer(buffer_b, None, cx));
 
     // Client A sees client B's selection
     executor.run_until_parked();
@@ -1089,8 +1085,7 @@ async fn test_share_project(
     });
 
     // Edit the buffer as client B and see that edit as client A.
-    let mut cx_b = VisualTestContext::from_window(window_b, cx_b);
-    editor_b.update(&mut cx_b, |editor, cx| editor.handle_input("ok, ", cx));
+    editor_b.update(cx_b, |editor, cx| editor.handle_input("ok, ", cx));
     executor.run_until_parked();
 
     buffer_a.read_with(cx_a, |buffer, _| {
@@ -1099,7 +1094,7 @@ async fn test_share_project(
 
     // Client B can invite client C on a project shared by client A.
     active_call_b
-        .update(&mut cx_b, |call, cx| {
+        .update(cx_b, |call, cx| {
             call.invite(client_c.user_id().unwrap(), Some(project_b.clone()), cx)
         })
         .await
@@ -1190,18 +1185,14 @@ async fn test_on_input_format_from_host_to_guest(
         .update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
         .await
         .unwrap();
-    let window_a = cx_a.add_empty_window();
-    let editor_a = window_a
-        .update(cx_a, |_, cx| {
-            cx.new_view(|cx| Editor::for_buffer(buffer_a, Some(project_a.clone()), cx))
-        })
-        .unwrap();
+    let cx_a = cx_a.add_empty_window();
+    let editor_a = cx_a.new_view(|cx| Editor::for_buffer(buffer_a, Some(project_a.clone()), cx));
 
     let fake_language_server = fake_language_servers.next().await.unwrap();
     executor.run_until_parked();
 
     // Receive an OnTypeFormatting request as the host's language server.
-    // Return some formattings from the host's language server.
+    // Return some formatting from the host's language server.
     fake_language_server.handle_request::<lsp::request::OnTypeFormatting, _, _>(
         |params, _| async move {
             assert_eq!(
@@ -1220,16 +1211,15 @@ async fn test_on_input_format_from_host_to_guest(
         },
     );
 
-    // Open the buffer on the guest and see that the formattings worked
+    // Open the buffer on the guest and see that the formatting worked
     let buffer_b = project_b
         .update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
         .await
         .unwrap();
 
-    let mut cx_a = VisualTestContext::from_window(window_a, cx_a);
     // Type a on type formatting trigger character as the guest.
     cx_a.focus_view(&editor_a);
-    editor_a.update(&mut cx_a, |editor, cx| {
+    editor_a.update(cx_a, |editor, cx| {
         editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
         editor.handle_input(">", cx);
     });
@@ -1241,7 +1231,7 @@ async fn test_on_input_format_from_host_to_guest(
     });
 
     // Undo should remove LSP edits first
-    editor_a.update(&mut cx_a, |editor, cx| {
+    editor_a.update(cx_a, |editor, cx| {
         assert_eq!(editor.text(cx), "fn main() { a>~< }");
         editor.undo(&Undo, cx);
         assert_eq!(editor.text(cx), "fn main() { a> }");
@@ -1252,7 +1242,7 @@ async fn test_on_input_format_from_host_to_guest(
         assert_eq!(buffer.text(), "fn main() { a> }")
     });
 
-    editor_a.update(&mut cx_a, |editor, cx| {
+    editor_a.update(cx_a, |editor, cx| {
         assert_eq!(editor.text(cx), "fn main() { a> }");
         editor.undo(&Undo, cx);
         assert_eq!(editor.text(cx), "fn main() { a }");
@@ -1323,23 +1313,21 @@ async fn test_on_input_format_from_guest_to_host(
         .update(cx_b, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
         .await
         .unwrap();
-    let window_b = cx_b.add_empty_window();
-    let editor_b = window_b.build_view(cx_b, |cx| {
-        Editor::for_buffer(buffer_b, Some(project_b.clone()), cx)
-    });
+    let cx_b = cx_b.add_empty_window();
+    let editor_b = cx_b.new_view(|cx| Editor::for_buffer(buffer_b, Some(project_b.clone()), cx));
 
     let fake_language_server = fake_language_servers.next().await.unwrap();
     executor.run_until_parked();
-    let mut cx_b = VisualTestContext::from_window(window_b, cx_b);
+
     // Type a on type formatting trigger character as the guest.
     cx_b.focus_view(&editor_b);
-    editor_b.update(&mut cx_b, |editor, cx| {
+    editor_b.update(cx_b, |editor, cx| {
         editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
         editor.handle_input(":", cx);
     });
 
     // Receive an OnTypeFormatting request as the host's language server.
-    // Return some formattings from the host's language server.
+    // Return some formatting from the host's language server.
     executor.start_waiting();
     fake_language_server
         .handle_request::<lsp::request::OnTypeFormatting, _, _>(|params, _| async move {
@@ -1362,7 +1350,7 @@ async fn test_on_input_format_from_guest_to_host(
         .unwrap();
     executor.finish_waiting();
 
-    // Open the buffer on the host and see that the formattings worked
+    // Open the buffer on the host and see that the formatting worked
     let buffer_a = project_a
         .update(cx_a, |p, cx| p.open_buffer((worktree_id, "main.rs"), cx))
         .await
@@ -1374,7 +1362,7 @@ async fn test_on_input_format_from_guest_to_host(
     });
 
     // Undo should remove LSP edits first
-    editor_b.update(&mut cx_b, |editor, cx| {
+    editor_b.update(cx_b, |editor, cx| {
         assert_eq!(editor.text(cx), "fn main() { a:~: }");
         editor.undo(&Undo, cx);
         assert_eq!(editor.text(cx), "fn main() { a: }");
@@ -1385,7 +1373,7 @@ async fn test_on_input_format_from_guest_to_host(
         assert_eq!(buffer.text(), "fn main() { a: }")
     });
 
-    editor_b.update(&mut cx_b, |editor, cx| {
+    editor_b.update(cx_b, |editor, cx| {
         assert_eq!(editor.text(cx), "fn main() { a: }");
         editor.undo(&Undo, cx);
         assert_eq!(editor.text(cx), "fn main() { a }");
@@ -1836,7 +1824,7 @@ async fn test_inlay_hint_refresh_is_forwarded(
         assert_eq!(
             inlay_cache.version(),
             1,
-            "Should update cache verison after first hints"
+            "Should update cache version after first hints"
         );
     });
 

crates/collab/src/tests/following_tests.rs πŸ”—

@@ -249,7 +249,7 @@ async fn test_basic_following(
     executor.run_until_parked();
     cx_c.cx.update(|_| {});
 
-    weak_workspace_c.assert_dropped();
+    weak_workspace_c.assert_released();
 
     // Clients A and B see that client B is following A, and client C is not present in the followers.
     executor.run_until_parked();
@@ -1229,7 +1229,9 @@ async fn test_auto_unfollowing(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
     });
 
     // When client B moves, it automatically stops following client A.
-    editor_b2.update(cx_b, |editor, cx| editor.move_right(&editor::MoveRight, cx));
+    editor_b2.update(cx_b, |editor, cx| {
+        editor.move_right(&editor::actions::MoveRight, cx)
+    });
     assert_eq!(
         workspace_b.update(cx_b, |workspace, _| workspace.leader_for_pane(&pane_b)),
         None
@@ -1735,6 +1737,11 @@ async fn test_following_into_excluded_file(
         vec![18..17]
     );
 
+    editor_for_excluded_a.update(cx_a, |editor, cx| {
+        editor.select_right(&Default::default(), cx);
+    });
+    executor.run_until_parked();
+
     // Changes from B to the excluded file are replicated in A's editor
     editor_for_excluded_b.update(cx_b, |editor, cx| {
         editor.handle_input("\nCo-Authored-By: B <b@b.b>", cx);
@@ -1743,7 +1750,7 @@ async fn test_following_into_excluded_file(
     editor_for_excluded_a.update(cx_a, |editor, cx| {
         assert_eq!(
             editor.text(cx),
-            "new commit messag\nCo-Authored-By: B <b@b.b>"
+            "new commit message\nCo-Authored-By: B <b@b.b>"
         );
     });
 }

crates/collab/src/tests/integration_tests.rs πŸ”—

@@ -7,7 +7,10 @@ use client::{User, RECEIVE_TIMEOUT};
 use collections::{HashMap, HashSet};
 use fs::{repository::GitFileStatus, FakeFs, Fs as _, RemoveOptions};
 use futures::StreamExt as _;
-use gpui::{AppContext, BackgroundExecutor, Model, TestAppContext};
+use gpui::{
+    px, size, AppContext, BackgroundExecutor, Model, Modifiers, MouseButton, MouseDownEvent,
+    TestAppContext,
+};
 use language::{
     language_settings::{AllLanguageSettings, Formatter},
     tree_sitter_rust, Diagnostic, DiagnosticEntry, FakeLspAdapter, Language, LanguageConfig,
@@ -5903,3 +5906,42 @@ async fn test_join_call_after_screen_was_shared(
         );
     });
 }
+
+#[gpui::test]
+async fn test_right_click_menu_behind_collab_panel(cx: &mut TestAppContext) {
+    let mut server = TestServer::start(cx.executor().clone()).await;
+    let client_a = server.create_client(cx, "user_a").await;
+    let (_workspace_a, cx) = client_a.build_test_workspace(cx).await;
+
+    cx.simulate_resize(size(px(300.), px(300.)));
+
+    cx.simulate_keystrokes("cmd-n cmd-n cmd-n");
+    cx.update(|cx| cx.refresh());
+
+    let tab_bounds = cx.debug_bounds("TAB-2").unwrap();
+    let new_tab_button_bounds = cx.debug_bounds("ICON-Plus").unwrap();
+
+    assert!(
+        tab_bounds.intersects(&new_tab_button_bounds),
+        "Tab should overlap with the new tab button, if this is failing check if there's been a redesign!"
+    );
+
+    cx.simulate_event(MouseDownEvent {
+        button: MouseButton::Right,
+        position: new_tab_button_bounds.center(),
+        modifiers: Modifiers::default(),
+        click_count: 1,
+    });
+
+    // regression test that the right click menu for tabs does not open.
+    assert!(cx.debug_bounds("MENU_ITEM-Close").is_none());
+
+    let tab_bounds = cx.debug_bounds("TAB-1").unwrap();
+    cx.simulate_event(MouseDownEvent {
+        button: MouseButton::Right,
+        position: tab_bounds.center(),
+        modifiers: Modifiers::default(),
+        click_count: 1,
+    });
+    assert!(cx.debug_bounds("MENU_ITEM-Close").is_some());
+}

crates/collab_ui/src/chat_panel.rs πŸ”—

@@ -125,6 +125,23 @@ impl ChatPanel {
                 open_context_menu: None,
             };
 
+            if let Some(channel_id) = ActiveCall::global(cx)
+                .read(cx)
+                .room()
+                .and_then(|room| room.read(cx).channel_id())
+            {
+                this.select_channel(channel_id, None, cx)
+                    .detach_and_log_err(cx);
+
+                if ActiveCall::global(cx)
+                    .read(cx)
+                    .room()
+                    .is_some_and(|room| room.read(cx).contains_guests())
+                {
+                    cx.emit(PanelEvent::Activate)
+                }
+            }
+
             this.subscriptions.push(cx.subscribe(
                 &ActiveCall::global(cx),
                 move |this: &mut Self, call, event: &room::Event, cx| match event {

crates/collab_ui/src/collab_panel.rs πŸ”—

@@ -2314,7 +2314,7 @@ impl CollabPanel {
                             .child(
                                 IconButton::new("channel_chat", IconName::MessageBubbles)
                                     .style(ButtonStyle::Filled)
-                                    .size(ButtonSize::Compact)
+                                    .shape(ui::IconButtonShape::Square)
                                     .icon_size(IconSize::Small)
                                     .icon_color(if has_messages_notification {
                                         Color::Default
@@ -2332,7 +2332,7 @@ impl CollabPanel {
                             .child(
                                 IconButton::new("channel_notes", IconName::File)
                                     .style(ButtonStyle::Filled)
-                                    .size(ButtonSize::Compact)
+                                    .shape(ui::IconButtonShape::Square)
                                     .icon_size(IconSize::Small)
                                     .icon_color(if has_notes_notification {
                                         Color::Default

crates/collab_ui/src/collab_panel/channel_modal.rs πŸ”—

@@ -111,7 +111,7 @@ impl ChannelModal {
         .detach();
     }
 
-    fn set_channel_visiblity(&mut self, selection: &Selection, cx: &mut ViewContext<Self>) {
+    fn set_channel_visibility(&mut self, selection: &Selection, cx: &mut ViewContext<Self>) {
         self.channel_store.update(cx, |channel_store, cx| {
             channel_store
                 .set_channel_visibility(
@@ -189,7 +189,7 @@ impl Render for ChannelModal {
                                                 ui::Selection::Unselected
                                             },
                                         )
-                                        .on_click(cx.listener(Self::set_channel_visiblity)),
+                                        .on_click(cx.listener(Self::set_channel_visibility)),
                                     )
                                     .child(Label::new("Public").size(LabelSize::Small)),
                             )

crates/collab_ui/src/collab_titlebar_item.rs πŸ”—

@@ -3,7 +3,7 @@ use auto_update::AutoUpdateStatus;
 use call::{ActiveCall, ParticipantLocation, Room};
 use client::{proto::PeerId, Client, User, UserStore};
 use gpui::{
-    actions, canvas, div, point, px, rems, Action, AnyElement, AppContext, Element, Hsla,
+    actions, canvas, div, point, px, Action, AnyElement, AppContext, Element, Hsla,
     InteractiveElement, IntoElement, Model, ParentElement, Path, Render,
     StatefulInteractiveElement, Styled, Subscription, View, ViewContext, VisualContext, WeakView,
     WindowBounds,
@@ -19,7 +19,7 @@ use ui::{
 };
 use util::ResultExt;
 use vcs_menu::{build_branch_list, BranchList, OpenRecent as ToggleVcsMenu};
-use workspace::{notifications::NotifyResultExt, Workspace};
+use workspace::{notifications::NotifyResultExt, titlebar_height, Workspace};
 
 const MAX_PROJECT_NAME_LENGTH: usize = 40;
 const MAX_BRANCH_NAME_LENGTH: usize = 40;
@@ -62,10 +62,7 @@ impl Render for CollabTitlebarItem {
             .id("titlebar")
             .justify_between()
             .w_full()
-            .h(rems(1.75))
-            // Set a non-scaling min-height here to ensure the titlebar is
-            // always at least the height of the traffic lights.
-            .min_h(px(32.))
+            .h(titlebar_height(cx))
             .map(|this| {
                 if matches!(cx.window_bounds(), WindowBounds::Fullscreen) {
                     this.pl_2()
@@ -480,14 +477,16 @@ impl CollabTitlebarItem {
             return None;
         }
 
+        const FACEPILE_LIMIT: usize = 3;
         let followers = project_id.map_or(&[] as &[_], |id| room.followers_for(peer_id, id));
+        let extra_count = followers.len().saturating_sub(FACEPILE_LIMIT);
 
         let pile = FacePile::default()
             .child(
                 Avatar::new(user.avatar_uri.clone())
                     .grayscale(!is_present)
                     .border_color(if is_speaking {
-                        cx.theme().status().info_border
+                        cx.theme().status().info
                     } else {
                         // We draw the border in a transparent color rather to avoid
                         // the layout shift that would come with adding/removing the border.
@@ -502,18 +501,34 @@ impl CollabTitlebarItem {
                         )
                     }),
             )
-            .children(followers.iter().filter_map(|follower_peer_id| {
-                let follower = room
-                    .remote_participants()
-                    .values()
-                    .find_map(|p| (p.peer_id == *follower_peer_id).then_some(&p.user))
-                    .or_else(|| {
-                        (self.client.peer_id() == Some(*follower_peer_id)).then_some(current_user)
-                    })?
-                    .clone();
-
-                Some(Avatar::new(follower.avatar_uri.clone()))
-            }));
+            .children(
+                followers
+                    .iter()
+                    .take(FACEPILE_LIMIT)
+                    .filter_map(|follower_peer_id| {
+                        let follower = room
+                            .remote_participants()
+                            .values()
+                            .find_map(|p| (p.peer_id == *follower_peer_id).then_some(&p.user))
+                            .or_else(|| {
+                                (self.client.peer_id() == Some(*follower_peer_id))
+                                    .then_some(current_user)
+                            })?
+                            .clone();
+
+                        Some(Avatar::new(follower.avatar_uri.clone()))
+                    }),
+            )
+            .children(if extra_count > 0 {
+                Some(
+                    div()
+                        .ml_1()
+                        .child(Label::new(format!("+{extra_count}")))
+                        .into_any_element(),
+                )
+            } else {
+                None
+            });
 
         Some(pile)
     }

crates/color/Cargo.toml πŸ”—

@@ -0,0 +1,32 @@
+[package]
+name = "color"
+version = "0.1.0"
+edition = "2021"
+publish = false
+
+[features]
+default = []
+stories = ["dep:itertools", "dep:story"]
+
+[lib]
+path = "src/color.rs"
+doctest = true
+
+[dependencies]
+# TODO: Clean up dependencies
+anyhow.workspace = true
+fs = { path = "../fs" }
+indexmap = "1.6.2"
+parking_lot.workspace = true
+refineable.workspace = true
+schemars.workspace = true
+serde.workspace = true
+serde_derive.workspace = true
+serde_json.workspace = true
+settings = { path = "../settings" }
+story = { path = "../story", optional = true }
+toml.workspace = true
+uuid.workspace = true
+util = { path = "../util" }
+itertools = { version = "0.11.0", optional = true }
+palette = "0.7.3"

crates/color/src/color.rs πŸ”—

@@ -0,0 +1,234 @@
+//! # Color
+//!
+//! The `color` crate provides a set utilities for working with colors. It is a wrapper around the [`palette`](https://docs.rs/palette) crate with some additional functionality.
+//!
+//! It is used to create a manipulate colors when building themes.
+//!
+//! === In development note ===
+//!
+//! This crate is meant to sit between gpui and the theme/ui for all the color related stuff.
+//!
+//! It could be folded into gpui, ui or theme potentially but for now we'll continue
+//! to develop it in isolation.
+//!
+//! Once we have a good idea of the needs of the theme system and color in gpui in general I see 3 paths:
+//! 1. Use `palette` (or another color library) directly in gpui and everywhere else, rather than rolling our own color system.
+//! 2. Keep this crate as a thin wrapper around `palette` and use it everywhere except gpui, and convert to gpui's color system when needed.
+//! 3. Build the needed functionality into gpui and keep using it's color system everywhere.
+//!
+//! I'm leaning towards 2 in the short term and 1 in the long term, but we'll need to discuss it more.
+//!
+//! === End development note ===
+use palette::{
+    blend::Blend, convert::FromColorUnclamped, encoding, rgb::Rgb, Clamp, Mix, Srgb, WithAlpha,
+};
+
+/// The types of blend modes supported
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub enum BlendMode {
+    /// Multiplies the colors, resulting in a darker color. This mode is useful for creating shadows.
+    Multiply,
+    /// Lightens the color by adding the source and destination colors. It results in a lighter color.
+    Screen,
+    /// Combines Multiply and Screen blend modes. Parts of the image that are lighter than 50% gray are lightened, and parts that are darker are darkened.
+    Overlay,
+    /// Selects the darker of the base or blend color as the resulting color. Useful for darkening images without affecting the overall contrast.
+    Darken,
+    /// Selects the lighter of the base or blend color as the resulting color. Useful for lightening images without affecting the overall contrast.
+    Lighten,
+    /// Brightens the base color to reflect the blend color. The result is a lightened image.
+    Dodge,
+    /// Darkens the base color to reflect the blend color. The result is a darkened image.
+    Burn,
+    /// Similar to Overlay, but with a stronger effect. Hard Light can either multiply or screen colors, depending on the blend color.
+    HardLight,
+    /// A softer version of Hard Light. Soft Light either darkens or lightens colors, depending on the blend color.
+    SoftLight,
+    /// Subtracts the darker of the two constituent colors from the lighter color. Difference mode is useful for creating more vivid colors.
+    Difference,
+    /// Similar to Difference, but with a lower contrast. Exclusion mode produces an effect similar to Difference but with less intensity.
+    Exclusion,
+}
+
+/// Converts a hexadecimal color string to a `palette::Hsla` color.
+///
+/// This function supports the following hex formats:
+/// `#RGB`, `#RGBA`, `#RRGGBB`, `#RRGGBBAA`.
+pub fn hex_to_hsla(s: &str) -> Result<RGBAColor, String> {
+    let hex = s.trim_start_matches('#');
+
+    // Expand shorthand formats #RGB and #RGBA to #RRGGBB and #RRGGBBAA
+    let hex = match hex.len() {
+        3 => hex
+            .chars()
+            .map(|c| c.to_string().repeat(2))
+            .collect::<String>(),
+        4 => {
+            let (rgb, alpha) = hex.split_at(3);
+            let rgb = rgb
+                .chars()
+                .map(|c| c.to_string().repeat(2))
+                .collect::<String>();
+            let alpha = alpha.chars().next().unwrap().to_string().repeat(2);
+            format!("{}{}", rgb, alpha)
+        }
+        6 => format!("{}ff", hex), // Add alpha if missing
+        8 => hex.to_string(),      // Already in full format
+        _ => return Err("Invalid hexadecimal string length".to_string()),
+    };
+
+    let hex_val =
+        u32::from_str_radix(&hex, 16).map_err(|_| format!("Invalid hexadecimal string: {}", s))?;
+
+    let r = ((hex_val >> 24) & 0xFF) as f32 / 255.0;
+    let g = ((hex_val >> 16) & 0xFF) as f32 / 255.0;
+    let b = ((hex_val >> 8) & 0xFF) as f32 / 255.0;
+    let a = (hex_val & 0xFF) as f32 / 255.0;
+
+    let color = RGBAColor { r, g, b, a };
+
+    Ok(color)
+}
+
+// These derives implement to and from palette's color types.
+#[derive(FromColorUnclamped, WithAlpha, Debug, Clone)]
+#[palette(skip_derives(Rgb), rgb_standard = "encoding::Srgb")]
+pub struct RGBAColor {
+    r: f32,
+    g: f32,
+    b: f32,
+    // Let Palette know this is our alpha channel.
+    #[palette(alpha)]
+    a: f32,
+}
+
+impl FromColorUnclamped<RGBAColor> for RGBAColor {
+    fn from_color_unclamped(color: RGBAColor) -> RGBAColor {
+        color
+    }
+}
+
+impl<S> FromColorUnclamped<Rgb<S, f32>> for RGBAColor
+where
+    Srgb: FromColorUnclamped<Rgb<S, f32>>,
+{
+    fn from_color_unclamped(color: Rgb<S, f32>) -> RGBAColor {
+        let srgb = Srgb::from_color_unclamped(color);
+        RGBAColor {
+            r: srgb.red,
+            g: srgb.green,
+            b: srgb.blue,
+            a: 1.0,
+        }
+    }
+}
+
+impl<S> FromColorUnclamped<RGBAColor> for Rgb<S, f32>
+where
+    Rgb<S, f32>: FromColorUnclamped<Srgb>,
+{
+    fn from_color_unclamped(color: RGBAColor) -> Self {
+        let srgb = Srgb::new(color.r, color.g, color.b);
+        Self::from_color_unclamped(srgb)
+    }
+}
+
+impl Clamp for RGBAColor {
+    fn clamp(self) -> Self {
+        RGBAColor {
+            r: self.r.min(1.0).max(0.0),
+            g: self.g.min(1.0).max(0.0),
+            b: self.b.min(1.0).max(0.0),
+            a: self.a.min(1.0).max(0.0),
+        }
+    }
+}
+
+impl RGBAColor {
+    /// Creates a new color from the given RGBA values.
+    ///
+    /// This color can be used to convert to any [`palette::Color`] type.
+    pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self {
+        RGBAColor { r, g, b, a }
+    }
+
+    /// Returns a set of states for this color.
+    pub fn states(self, is_light: bool) -> ColorStates {
+        states_for_color(self, is_light)
+    }
+
+    /// Mixes this color with another [`palette::Hsl`] color at the given `mix_ratio`.
+    pub fn mixed(&self, other: RGBAColor, mix_ratio: f32) -> Self {
+        let srgb_self = Srgb::new(self.r, self.g, self.b);
+        let srgb_other = Srgb::new(other.r, other.g, other.b);
+
+        // Directly mix the colors as sRGB values
+        let mixed = srgb_self.mix(srgb_other, mix_ratio);
+        RGBAColor::from_color_unclamped(mixed)
+    }
+
+    pub fn blend(&self, other: RGBAColor, blend_mode: BlendMode) -> Self {
+        let srgb_self = Srgb::new(self.r, self.g, self.b);
+        let srgb_other = Srgb::new(other.r, other.g, other.b);
+
+        let blended = match blend_mode {
+            // replace hsl methods with the respective sRGB methods
+            BlendMode::Multiply => srgb_self.multiply(srgb_other),
+            _ => unimplemented!(),
+        };
+
+        Self {
+            r: blended.red,
+            g: blended.green,
+            b: blended.blue,
+            a: self.a,
+        }
+    }
+}
+
+/// A set of colors for different states of an element.
+#[derive(Debug, Clone)]
+pub struct ColorStates {
+    /// The default color.
+    pub default: RGBAColor,
+    /// The color when the mouse is hovering over the element.
+    pub hover: RGBAColor,
+    /// The color when the mouse button is held down on the element.
+    pub active: RGBAColor,
+    /// The color when the element is focused with the keyboard.
+    pub focused: RGBAColor,
+    /// The color when the element is disabled.
+    pub disabled: RGBAColor,
+}
+
+/// Returns a set of colors for different states of an element.
+///
+/// todo!("This should take a theme and use appropriate colors from it")
+pub fn states_for_color(color: RGBAColor, is_light: bool) -> ColorStates {
+    let adjustment_factor = if is_light { 0.1 } else { -0.1 };
+    let hover_adjustment = 1.0 - adjustment_factor;
+    let active_adjustment = 1.0 - 2.0 * adjustment_factor;
+    let focused_adjustment = 1.0 - 3.0 * adjustment_factor;
+    let disabled_adjustment = 1.0 - 4.0 * adjustment_factor;
+
+    let make_adjustment = |color: RGBAColor, adjustment: f32| -> RGBAColor {
+        // Adjust lightness for each state
+        // Note: Adjustment logic may differ; simplify as needed for sRGB
+        RGBAColor::new(
+            color.r * adjustment,
+            color.g * adjustment,
+            color.b * adjustment,
+            color.a,
+        )
+    };
+
+    let color = color.clamp();
+
+    ColorStates {
+        default: color.clone(),
+        hover: make_adjustment(color.clone(), hover_adjustment),
+        active: make_adjustment(color.clone(), active_adjustment),
+        focused: make_adjustment(color.clone(), focused_adjustment),
+        disabled: make_adjustment(color.clone(), disabled_adjustment),
+    }
+}

crates/copilot/src/copilot.rs πŸ”—

@@ -308,11 +308,7 @@ impl EventEmitter<Event> for Copilot {}
 
 impl Copilot {
     pub fn global(cx: &AppContext) -> Option<Model<Self>> {
-        if cx.has_global::<Model<Self>>() {
-            Some(cx.global::<Model<Self>>().clone())
-        } else {
-            None
-        }
+        cx.try_global::<Model<Self>>().map(|model| model.clone())
     }
 
     fn start(
@@ -373,10 +369,11 @@ impl Copilot {
 
     #[cfg(any(test, feature = "test-support"))]
     pub fn fake(cx: &mut gpui::TestAppContext) -> (Model<Self>, lsp::FakeLanguageServer) {
+        use lsp::FakeLanguageServer;
         use node_runtime::FakeNodeRuntime;
 
         let (server, fake_server) =
-            LanguageServer::fake("copilot".into(), Default::default(), cx.to_async());
+            FakeLanguageServer::new("copilot".into(), Default::default(), cx.to_async());
         let http = util::http::FakeHttpClient::create(|_| async { unreachable!() });
         let node_runtime = FakeNodeRuntime::new();
         let this = cx.new_model(|cx| Self {

crates/copilot_ui/src/copilot_button.rs πŸ”—

@@ -1,7 +1,7 @@
 use crate::sign_in::CopilotCodeVerification;
 use anyhow::Result;
 use copilot::{Copilot, SignOut, Status};
-use editor::{scroll::autoscroll::Autoscroll, Editor};
+use editor::{scroll::Autoscroll, Editor};
 use fs::Fs;
 use gpui::{
     div, Action, AnchorCorner, AppContext, AsyncWindowContext, Entity, IntoElement, ParentElement,

crates/copilot_ui/src/sign_in.rs πŸ”—

@@ -96,7 +96,7 @@ impl CopilotCodeVerification {
             .items_center()
             .child(Headline::new("Use Github Copilot in Zed.").size(HeadlineSize::Large))
             .child(
-                Label::new("Using Copilot requres an active subscription on Github.")
+                Label::new("Using Copilot requires an active subscription on Github.")
                     .color(Color::Muted),
             )
             .child(Self::render_device_code(data, cx))
@@ -139,7 +139,7 @@ impl CopilotCodeVerification {
                 "You can enable Copilot by connecting your existing license once you have subscribed or renewed your subscription.",
             ).color(Color::Warning))
             .child(
-                Button::new("copilot-subscribe-button", "Subscibe on Github")
+                Button::new("copilot-subscribe-button", "Subscribe on Github")
                     .full_width()
                     .on_click(|_, cx| cx.open_url(COPILOT_SIGN_UP_URL)),
             )

crates/diagnostics/src/diagnostics.rs πŸ”—

@@ -8,7 +8,7 @@ use editor::{
     diagnostic_block_renderer,
     display_map::{BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock},
     highlight_diagnostic_message,
-    scroll::autoscroll::Autoscroll,
+    scroll::Autoscroll,
     Editor, EditorEvent, ExcerptId, ExcerptRange, MultiBuffer, ToOffset,
 };
 use futures::future::try_join_all;

crates/diagnostics/src/items.rs πŸ”—

@@ -80,7 +80,7 @@ impl Render for DiagnosticIndicator {
                 Button::new("diagnostic_message", message)
                     .label_size(LabelSize::Small)
                     .tooltip(|cx| {
-                        Tooltip::for_action("Next Diagnostic", &editor::GoToDiagnostic, cx)
+                        Tooltip::for_action("Next Diagnostic", &editor::actions::GoToDiagnostic, cx)
                     })
                     .on_click(cx.listener(|this, _, cx| {
                         this.go_to_next_diagnostic(cx);

crates/editor/src/actions.rs πŸ”—

@@ -0,0 +1,218 @@
+//! This module contains all actions supported by [`Editor`].
+use super::*;
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct SelectNext {
+    #[serde(default)]
+    pub replace_newest: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct SelectPrevious {
+    #[serde(default)]
+    pub replace_newest: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct SelectAllMatches {
+    #[serde(default)]
+    pub replace_newest: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct SelectToBeginningOfLine {
+    #[serde(default)]
+    pub(super) stop_at_soft_wraps: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct MovePageUp {
+    #[serde(default)]
+    pub(super) center_cursor: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct MovePageDown {
+    #[serde(default)]
+    pub(super) center_cursor: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct SelectToEndOfLine {
+    #[serde(default)]
+    pub(super) stop_at_soft_wraps: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct ToggleCodeActions {
+    #[serde(default)]
+    pub deployed_from_indicator: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct ConfirmCompletion {
+    #[serde(default)]
+    pub item_ix: Option<usize>,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct ConfirmCodeAction {
+    #[serde(default)]
+    pub item_ix: Option<usize>,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct ToggleComments {
+    #[serde(default)]
+    pub advance_downwards: bool,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct FoldAt {
+    pub buffer_row: u32,
+}
+
+#[derive(PartialEq, Clone, Deserialize, Default)]
+pub struct UnfoldAt {
+    pub buffer_row: u32,
+}
+impl_actions!(
+    editor,
+    [
+        SelectNext,
+        SelectPrevious,
+        SelectAllMatches,
+        SelectToBeginningOfLine,
+        MovePageUp,
+        MovePageDown,
+        SelectToEndOfLine,
+        ToggleCodeActions,
+        ConfirmCompletion,
+        ConfirmCodeAction,
+        ToggleComments,
+        FoldAt,
+        UnfoldAt
+    ]
+);
+
+gpui::actions!(
+    editor,
+    [
+        AddSelectionAbove,
+        AddSelectionBelow,
+        Backspace,
+        Cancel,
+        ConfirmRename,
+        ContextMenuFirst,
+        ContextMenuLast,
+        ContextMenuNext,
+        ContextMenuPrev,
+        ConvertToKebabCase,
+        ConvertToLowerCamelCase,
+        ConvertToLowerCase,
+        ConvertToSnakeCase,
+        ConvertToTitleCase,
+        ConvertToUpperCamelCase,
+        ConvertToUpperCase,
+        Copy,
+        CopyHighlightJson,
+        CopyPath,
+        CopyRelativePath,
+        Cut,
+        CutToEndOfLine,
+        Delete,
+        DeleteLine,
+        DeleteToBeginningOfLine,
+        DeleteToEndOfLine,
+        DeleteToNextSubwordEnd,
+        DeleteToNextWordEnd,
+        DeleteToPreviousSubwordStart,
+        DeleteToPreviousWordStart,
+        DuplicateLine,
+        ExpandMacroRecursively,
+        FindAllReferences,
+        Fold,
+        FoldSelectedRanges,
+        Format,
+        GoToDefinition,
+        GoToDefinitionSplit,
+        GoToDiagnostic,
+        GoToHunk,
+        GoToPrevDiagnostic,
+        GoToPrevHunk,
+        GoToTypeDefinition,
+        GoToTypeDefinitionSplit,
+        HalfPageDown,
+        HalfPageUp,
+        Hover,
+        Indent,
+        JoinLines,
+        LineDown,
+        LineUp,
+        MoveDown,
+        MoveLeft,
+        MoveLineDown,
+        MoveLineUp,
+        MoveRight,
+        MoveToBeginning,
+        MoveToBeginningOfLine,
+        MoveToEnclosingBracket,
+        MoveToEnd,
+        MoveToEndOfLine,
+        MoveToEndOfParagraph,
+        MoveToNextSubwordEnd,
+        MoveToNextWordEnd,
+        MoveToPreviousSubwordStart,
+        MoveToPreviousWordStart,
+        MoveToStartOfParagraph,
+        MoveUp,
+        Newline,
+        NewlineAbove,
+        NewlineBelow,
+        NextScreen,
+        OpenExcerpts,
+        Outdent,
+        PageDown,
+        PageUp,
+        Paste,
+        Redo,
+        RedoSelection,
+        Rename,
+        RestartLanguageServer,
+        RevealInFinder,
+        ReverseLines,
+        ScrollCursorBottom,
+        ScrollCursorCenter,
+        ScrollCursorTop,
+        SelectAll,
+        SelectDown,
+        SelectLargerSyntaxNode,
+        SelectLeft,
+        SelectLine,
+        SelectRight,
+        SelectSmallerSyntaxNode,
+        SelectToBeginning,
+        SelectToEnd,
+        SelectToEndOfParagraph,
+        SelectToNextSubwordEnd,
+        SelectToNextWordEnd,
+        SelectToPreviousSubwordStart,
+        SelectToPreviousWordStart,
+        SelectToStartOfParagraph,
+        SelectUp,
+        ShowCharacterPalette,
+        ShowCompletions,
+        ShuffleLines,
+        SortLinesCaseInsensitive,
+        SortLinesCaseSensitive,
+        SplitSelectionIntoLines,
+        Tab,
+        TabPrev,
+        ToggleInlayHints,
+        ToggleSoftWrap,
+        Transpose,
+        Undo,
+        UndoSelection,
+        UnfoldLines,
+    ]
+);

crates/editor/src/display_map.rs πŸ”—

@@ -1,3 +1,22 @@
+//! This module defines where the text should be displayed in an [`Editor`][Editor].
+//!
+//! Not literally though - rendering, layout and all that jazz is a responsibility of [`EditorElement`][EditorElement].
+//! Instead, [`DisplayMap`] decides where Inlays/Inlay hints are displayed, when
+//! to apply a soft wrap, where to add fold indicators, whether there are any tabs in the buffer that
+//! we display as spaces and where to display custom blocks (like diagnostics).
+//! Seems like a lot? That's because it is. [`DisplayMap`] is conceptually made up
+//! of several smaller structures that form a hierarchy (starting at the bottom):
+//! - [`InlayMap`] that decides where the [`Inlay`]s should be displayed.
+//! - [`FoldMap`] that decides where the fold indicators should be; it also tracks parts of a source file that are currently folded.
+//! - [`TabMap`] that keeps track of hard tabs in a buffer.
+//! - [`WrapMap`] that handles soft wrapping.
+//! - [`BlockMap`] that tracks custom blocks such as diagnostics that should be displayed within buffer.
+//! - [`DisplayMap`] that adds background highlights to the regions of text.
+//! Each one of those builds on top of preceding map.
+//!
+//! [Editor]: crate::Editor
+//! [EditorElement]: crate::element::EditorElement
+
 mod block_map;
 mod fold_map;
 mod inlay_map;
@@ -30,7 +49,8 @@ pub use block_map::{
 };
 
 pub use self::fold_map::{Fold, FoldPoint};
-pub use self::inlay_map::{Inlay, InlayOffset, InlayPoint};
+pub use self::inlay_map::{InlayOffset, InlayPoint};
+pub(crate) use inlay_map::Inlay;
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
 pub enum FoldStatus {
@@ -220,7 +240,7 @@ impl DisplayMap {
             .insert(Some(type_id), Arc::new((style, ranges)));
     }
 
-    pub fn highlight_inlays(
+    pub(crate) fn highlight_inlays(
         &mut self,
         type_id: TypeId,
         highlights: Vec<InlayHighlight>,
@@ -258,11 +278,11 @@ impl DisplayMap {
             .update(cx, |map, cx| map.set_wrap_width(width, cx))
     }
 
-    pub fn current_inlays(&self) -> impl Iterator<Item = &Inlay> {
+    pub(crate) fn current_inlays(&self) -> impl Iterator<Item = &Inlay> {
         self.inlay_map.current_inlays()
     }
 
-    pub fn splice_inlays(
+    pub(crate) fn splice_inlays(
         &mut self,
         to_remove: Vec<InlayId>,
         to_insert: Vec<Inlay>,
@@ -306,7 +326,7 @@ impl DisplayMap {
 }
 
 #[derive(Debug, Default)]
-pub struct Highlights<'a> {
+pub(crate) struct Highlights<'a> {
     pub text_highlights: Option<&'a TextHighlights>,
     pub inlay_highlights: Option<&'a InlayHighlights>,
     pub inlay_highlight_style: Option<HighlightStyle>,
@@ -880,8 +900,9 @@ impl DisplaySnapshot {
         self.text_highlights.get(&Some(type_id)).cloned()
     }
 
+    #[allow(unused)]
     #[cfg(any(test, feature = "test-support"))]
-    pub fn inlay_highlights<Tag: ?Sized + 'static>(
+    pub(crate) fn inlay_highlights<Tag: ?Sized + 'static>(
         &self,
     ) -> Option<&HashMap<InlayId, (HighlightStyle, InlayHighlight)>> {
         let type_id = TypeId::of::<Tag>();
@@ -969,24 +990,6 @@ impl ToDisplayPoint for Anchor {
     }
 }
 
-pub fn next_rows(display_row: u32, display_map: &DisplaySnapshot) -> impl Iterator<Item = u32> {
-    let max_row = display_map.max_point().row();
-    let start_row = display_row + 1;
-    let mut current = None;
-    std::iter::from_fn(move || {
-        if current == None {
-            current = Some(start_row);
-        } else {
-            current = Some(current.unwrap() + 1)
-        }
-        if current.unwrap() > max_row {
-            None
-        } else {
-            current
-        }
-    })
-}
-
 #[cfg(test)]
 pub mod tests {
     use super::*;

crates/editor/src/display_map/fold_map.rs πŸ”—

@@ -71,10 +71,10 @@ impl<'a> sum_tree::Dimension<'a, TransformSummary> for FoldPoint {
     }
 }
 
-pub struct FoldMapWriter<'a>(&'a mut FoldMap);
+pub(crate) struct FoldMapWriter<'a>(&'a mut FoldMap);
 
 impl<'a> FoldMapWriter<'a> {
-    pub fn fold<T: ToOffset>(
+    pub(crate) fn fold<T: ToOffset>(
         &mut self,
         ranges: impl IntoIterator<Item = Range<T>>,
     ) -> (FoldSnapshot, Vec<FoldEdit>) {
@@ -129,7 +129,7 @@ impl<'a> FoldMapWriter<'a> {
         (self.0.snapshot.clone(), edits)
     }
 
-    pub fn unfold<T: ToOffset>(
+    pub(crate) fn unfold<T: ToOffset>(
         &mut self,
         ranges: impl IntoIterator<Item = Range<T>>,
         inclusive: bool,
@@ -178,14 +178,14 @@ impl<'a> FoldMapWriter<'a> {
     }
 }
 
-pub struct FoldMap {
+pub(crate) struct FoldMap {
     snapshot: FoldSnapshot,
     ellipses_color: Option<Hsla>,
     next_fold_id: FoldId,
 }
 
 impl FoldMap {
-    pub fn new(inlay_snapshot: InlaySnapshot) -> (Self, FoldSnapshot) {
+    pub(crate) fn new(inlay_snapshot: InlaySnapshot) -> (Self, FoldSnapshot) {
         let this = Self {
             snapshot: FoldSnapshot {
                 folds: Default::default(),
@@ -655,7 +655,7 @@ impl FoldSnapshot {
         }
     }
 
-    pub fn chunks<'a>(
+    pub(crate) fn chunks<'a>(
         &'a self,
         range: Range<FoldOffset>,
         language_aware: bool,

crates/editor/src/display_map/inlay_map.rs πŸ”—

@@ -35,8 +35,8 @@ enum Transform {
 }
 
 #[derive(Debug, Clone)]
-pub struct Inlay {
-    pub id: InlayId,
+pub(crate) struct Inlay {
+    pub(crate) id: InlayId,
     pub position: Anchor,
     pub text: text::Rope,
 }
@@ -1016,7 +1016,7 @@ impl InlaySnapshot {
         (line_end - line_start) as u32
     }
 
-    pub fn chunks<'a>(
+    pub(crate) fn chunks<'a>(
         &'a self,
         range: Range<InlayOffset>,
         language_aware: bool,

crates/editor/src/editor.rs πŸ”—

@@ -1,3 +1,18 @@
+#![allow(rustdoc::private_intra_doc_links)]
+//! This is the place where everything editor-related is stored (data-wise) and displayed (ui-wise).
+//! The main point of interest in this crate is [`Editor`] type, which is used in every other Zed part as a user input element.
+//! It comes in different flavors: single line, multiline and a fixed height one.
+//!
+//! Editor contains of multiple large submodules:
+//! * [`element`] β€” the place where all rendering happens
+//! * [`display_map`] - chunks up text in the editor into the logical blocks, establishes coordinates and mapping between each of them.
+//!   Contains all metadata related to text transformations (folds, fake inlay text insertions, soft wraps, tab markup, etc.).
+//! * [`inlay_hint_cache`] - is a storage of inlay hints out of LSP requests, responsible for querying LSP and updating `display_map`'s state accordingly.
+//!
+//! All other submodules and structs are mostly concerned with holding editor data about the way it displays current buffer region(s).
+//!
+//! If you're looking to improve Vim mode, you should check out Vim crate that wraps Editor and overrides it's behaviour.
+pub mod actions;
 mod blink_manager;
 pub mod display_map;
 mod editor_settings;
@@ -14,13 +29,14 @@ pub mod movement;
 mod persistence;
 mod rust_analyzer_ext;
 pub mod scroll;
-pub mod selections_collection;
+mod selections_collection;
 
 #[cfg(test)]
 mod editor_tests;
 #[cfg(any(test, feature = "test-support"))]
 pub mod test;
 use ::git::diff::DiffHunk;
+pub(crate) use actions::*;
 use aho_corasick::AhoCorasick;
 use anyhow::{anyhow, Context as _, Result};
 use blink_manager::BlinkManager;
@@ -32,14 +48,13 @@ use copilot::Copilot;
 pub use display_map::DisplayPoint;
 use display_map::*;
 pub use editor_settings::EditorSettings;
-pub use element::{
-    Cursor, EditorElement, HighlightedRange, HighlightedRangeLine, LineWithInvisibles,
-};
+use element::LineWithInvisibles;
+pub use element::{Cursor, EditorElement, HighlightedRange, HighlightedRangeLine};
 use futures::FutureExt;
 use fuzzy::{StringMatch, StringMatchCandidate};
 use git::diff_hunk_to_display;
 use gpui::{
-    actions, div, impl_actions, point, prelude::*, px, relative, rems, size, uniform_list, Action,
+    div, impl_actions, point, prelude::*, px, relative, rems, size, uniform_list, Action,
     AnyElement, AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Context,
     DispatchPhase, ElementId, EventEmitter, FocusHandle, FocusableView, FontStyle, FontWeight,
     HighlightStyle, Hsla, InputHandler, InteractiveText, KeyContext, Model, MouseButton,
@@ -51,7 +66,7 @@ use hover_popover::{hide_hover, HoverState};
 use inlay_hint_cache::{InlayHintCache, InlaySplice, InvalidationStrategy};
 pub use items::MAX_TAB_TITLE_LEN;
 use itertools::Itertools;
-pub use language::{char_kind, CharKind};
+use language::{char_kind, CharKind};
 use language::{
     language_settings::{self, all_language_settings, InlayHintSettings},
     markdown, point_from_lsp, AutoindentMode, BracketPair, Buffer, Capability, CodeAction,
@@ -74,9 +89,7 @@ use parking_lot::RwLock;
 use project::{FormatTrigger, Location, Project, ProjectPath, ProjectTransaction};
 use rand::prelude::*;
 use rpc::proto::{self, *};
-use scroll::{
-    autoscroll::Autoscroll, OngoingScroll, ScrollAnchor, ScrollManager, ScrollbarAutoHide,
-};
+use scroll::{Autoscroll, OngoingScroll, ScrollAnchor, ScrollManager, ScrollbarAutoHide};
 use selections_collection::{resolve_multiple, MutableSelectionsCollection, SelectionsCollection};
 use serde::{Deserialize, Serialize};
 use settings::{Settings, SettingsStore};
@@ -113,10 +126,12 @@ const MAX_LINE_LEN: usize = 1024;
 const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
 const MAX_SELECTION_HISTORY_LEN: usize = 1024;
 const COPILOT_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
+#[doc(hidden)]
 pub const CODE_ACTIONS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(250);
+#[doc(hidden)]
 pub const DOCUMENT_HIGHLIGHTS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
 
-pub const FORMAT_TIMEOUT: Duration = Duration::from_secs(2);
+pub(crate) const FORMAT_TIMEOUT: Duration = Duration::from_secs(2);
 
 pub fn render_parsed_markdown(
     element_id: impl Into<ElementId>,
@@ -181,103 +196,8 @@ pub fn render_parsed_markdown(
     })
 }
 
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct SelectNext {
-    #[serde(default)]
-    pub replace_newest: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct SelectPrevious {
-    #[serde(default)]
-    pub replace_newest: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct SelectAllMatches {
-    #[serde(default)]
-    pub replace_newest: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct SelectToBeginningOfLine {
-    #[serde(default)]
-    stop_at_soft_wraps: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct MovePageUp {
-    #[serde(default)]
-    center_cursor: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct MovePageDown {
-    #[serde(default)]
-    center_cursor: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct SelectToEndOfLine {
-    #[serde(default)]
-    stop_at_soft_wraps: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct ToggleCodeActions {
-    #[serde(default)]
-    pub deployed_from_indicator: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct ConfirmCompletion {
-    #[serde(default)]
-    pub item_ix: Option<usize>,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct ConfirmCodeAction {
-    #[serde(default)]
-    pub item_ix: Option<usize>,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct ToggleComments {
-    #[serde(default)]
-    pub advance_downwards: bool,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct FoldAt {
-    pub buffer_row: u32,
-}
-
-#[derive(PartialEq, Clone, Deserialize, Default)]
-pub struct UnfoldAt {
-    pub buffer_row: u32,
-}
-
-impl_actions!(
-    editor,
-    [
-        SelectNext,
-        SelectPrevious,
-        SelectAllMatches,
-        SelectToBeginningOfLine,
-        MovePageUp,
-        MovePageDown,
-        SelectToEndOfLine,
-        ToggleCodeActions,
-        ConfirmCompletion,
-        ConfirmCodeAction,
-        ToggleComments,
-        FoldAt,
-        UnfoldAt
-    ]
-);
-
 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub enum InlayId {
+pub(crate) enum InlayId {
     Suggestion(usize),
     Hint(usize),
 }
@@ -291,128 +211,6 @@ impl InlayId {
     }
 }
 
-actions!(
-    editor,
-    [
-        AddSelectionAbove,
-        AddSelectionBelow,
-        Backspace,
-        Cancel,
-        ConfirmRename,
-        ContextMenuFirst,
-        ContextMenuLast,
-        ContextMenuNext,
-        ContextMenuPrev,
-        ConvertToKebabCase,
-        ConvertToLowerCamelCase,
-        ConvertToLowerCase,
-        ConvertToSnakeCase,
-        ConvertToTitleCase,
-        ConvertToUpperCamelCase,
-        ConvertToUpperCase,
-        Copy,
-        CopyHighlightJson,
-        CopyPath,
-        CopyRelativePath,
-        Cut,
-        CutToEndOfLine,
-        Delete,
-        DeleteLine,
-        DeleteToBeginningOfLine,
-        DeleteToEndOfLine,
-        DeleteToNextSubwordEnd,
-        DeleteToNextWordEnd,
-        DeleteToPreviousSubwordStart,
-        DeleteToPreviousWordStart,
-        DuplicateLine,
-        ExpandMacroRecursively,
-        FindAllReferences,
-        Fold,
-        FoldSelectedRanges,
-        Format,
-        GoToDefinition,
-        GoToDefinitionSplit,
-        GoToDiagnostic,
-        GoToHunk,
-        GoToPrevDiagnostic,
-        GoToPrevHunk,
-        GoToTypeDefinition,
-        GoToTypeDefinitionSplit,
-        HalfPageDown,
-        HalfPageUp,
-        Hover,
-        Indent,
-        JoinLines,
-        LineDown,
-        LineUp,
-        MoveDown,
-        MoveLeft,
-        MoveLineDown,
-        MoveLineUp,
-        MoveRight,
-        MoveToBeginning,
-        MoveToBeginningOfLine,
-        MoveToEnclosingBracket,
-        MoveToEnd,
-        MoveToEndOfLine,
-        MoveToEndOfParagraph,
-        MoveToNextSubwordEnd,
-        MoveToNextWordEnd,
-        MoveToPreviousSubwordStart,
-        MoveToPreviousWordStart,
-        MoveToStartOfParagraph,
-        MoveUp,
-        Newline,
-        NewlineAbove,
-        NewlineBelow,
-        NextScreen,
-        OpenExcerpts,
-        Outdent,
-        PageDown,
-        PageUp,
-        Paste,
-        Redo,
-        RedoSelection,
-        Rename,
-        RestartLanguageServer,
-        RevealInFinder,
-        ReverseLines,
-        ScrollCursorBottom,
-        ScrollCursorCenter,
-        ScrollCursorTop,
-        SelectAll,
-        SelectDown,
-        SelectLargerSyntaxNode,
-        SelectLeft,
-        SelectLine,
-        SelectRight,
-        SelectSmallerSyntaxNode,
-        SelectToBeginning,
-        SelectToEnd,
-        SelectToEndOfParagraph,
-        SelectToNextSubwordEnd,
-        SelectToNextWordEnd,
-        SelectToPreviousSubwordStart,
-        SelectToPreviousWordStart,
-        SelectToStartOfParagraph,
-        SelectUp,
-        ShowCharacterPalette,
-        ShowCompletions,
-        ShuffleLines,
-        SortLinesCaseInsensitive,
-        SortLinesCaseSensitive,
-        SplitSelectionIntoLines,
-        Tab,
-        TabPrev,
-        ToggleInlayHints,
-        ToggleSoftWrap,
-        Transpose,
-        Undo,
-        UndoSelection,
-        UnfoldLines,
-    ]
-);
-
 enum DocumentHighlightRead {}
 enum DocumentHighlightWrite {}
 enum InputComposition {}
@@ -489,7 +287,7 @@ pub enum SelectPhase {
 }
 
 #[derive(Clone, Debug)]
-pub enum SelectMode {
+pub(crate) enum SelectMode {
     Character,
     Word(Range<Anchor>),
     Line(Range<Anchor>),
@@ -763,6 +561,7 @@ struct SnippetState {
     active_index: usize,
 }
 
+#[doc(hidden)]
 pub struct RenameState {
     pub range: Range<Anchor>,
     pub old_name: Arc<str>,
@@ -1502,7 +1301,7 @@ impl CodeActionsMenu {
     }
 }
 
-pub struct CopilotState {
+pub(crate) struct CopilotState {
     excerpt_id: Option<ExcerptId>,
     pending_refresh: Task<Option<()>>,
     pending_cycling_refresh: Task<Option<()>>,
@@ -1622,15 +1421,13 @@ pub struct ClipboardSelection {
 }
 
 #[derive(Debug)]
-pub struct NavigationData {
+pub(crate) struct NavigationData {
     cursor_anchor: Anchor,
     cursor_position: Point,
     scroll_anchor: ScrollAnchor,
     scroll_top_row: u32,
 }
 
-pub struct EditorCreated(pub View<Editor>);
-
 enum GotoDefinitionKind {
     Symbol,
     Type,
@@ -8130,7 +7927,7 @@ impl Editor {
         }
     }
 
-    pub fn fold(&mut self, _: &Fold, cx: &mut ViewContext<Self>) {
+    pub fn fold(&mut self, _: &actions::Fold, cx: &mut ViewContext<Self>) {
         let mut fold_ranges = Vec::new();
 
         let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
@@ -8489,7 +8286,7 @@ impl Editor {
         cx.notify();
     }
 
-    pub fn highlight_inlay_background<T: 'static>(
+    pub(crate) fn highlight_inlay_background<T: 'static>(
         &mut self,
         ranges: Vec<InlayHighlight>,
         color_fetcher: fn(&ThemeColors) -> Hsla,
@@ -8696,7 +8493,7 @@ impl Editor {
         cx.notify();
     }
 
-    pub fn highlight_inlays<T: 'static>(
+    pub(crate) fn highlight_inlays<T: 'static>(
         &mut self,
         highlights: Vec<InlayHighlight>,
         style: HighlightStyle,
@@ -8741,7 +8538,7 @@ impl Editor {
     ) {
         match event {
             multi_buffer::Event::Edited {
-                sigleton_buffer_edited,
+                singleton_buffer_edited,
             } => {
                 self.refresh_active_diagnostics(cx);
                 self.refresh_code_actions(cx);
@@ -8751,7 +8548,7 @@ impl Editor {
                 cx.emit(EditorEvent::BufferEdited);
                 cx.emit(SearchEvent::MatchesInvalidated);
 
-                if *sigleton_buffer_edited {
+                if *singleton_buffer_edited {
                     if let Some(project) = &self.project {
                         let project = project.read(cx);
                         let languages_affected = multibuffer
@@ -9926,7 +9723,7 @@ pub fn highlight_diagnostic_message(diagnostic: &Diagnostic) -> (SharedString, V
     (text_without_backticks.into(), code_ranges)
 }
 
-pub fn diagnostic_style(severity: DiagnosticSeverity, valid: bool, colors: &StatusColors) -> Hsla {
+fn diagnostic_style(severity: DiagnosticSeverity, valid: bool, colors: &StatusColors) -> Hsla {
     match (severity, valid) {
         (DiagnosticSeverity::ERROR, true) => colors.error,
         (DiagnosticSeverity::ERROR, false) => colors.error,
@@ -9985,7 +9782,7 @@ pub fn styled_runs_for_code_label<'a>(
         })
 }
 
-pub fn split_words<'a>(text: &'a str) -> impl std::iter::Iterator<Item = &'a str> + 'a {
+pub(crate) fn split_words<'a>(text: &'a str) -> impl std::iter::Iterator<Item = &'a str> + 'a {
     let mut index = 0;
     let mut codepoints = text.char_indices().peekable();
 

crates/editor/src/element.rs πŸ”—

@@ -459,6 +459,7 @@ impl EditorElement {
         event: &MouseUpEvent,
         position_map: &PositionMap,
         text_bounds: Bounds<Pixels>,
+        interactive_bounds: &InteractiveBounds,
         stacking_order: &StackingOrder,
         cx: &mut ViewContext<Editor>,
     ) {
@@ -469,7 +470,8 @@ impl EditorElement {
             editor.select(SelectPhase::End, cx);
         }
 
-        if !pending_nonempty_selections
+        if interactive_bounds.visibly_contains(&event.position, cx)
+            && !pending_nonempty_selections
             && event.modifiers.command
             && text_bounds.contains(&event.position)
             && cx.was_top_layer(&event.position, stacking_order)
@@ -2590,15 +2592,14 @@ impl EditorElement {
             let interactive_bounds = interactive_bounds.clone();
 
             move |event: &MouseUpEvent, phase, cx| {
-                if phase == DispatchPhase::Bubble
-                    && interactive_bounds.visibly_contains(&event.position, cx)
-                {
+                if phase == DispatchPhase::Bubble {
                     editor.update(cx, |editor, cx| {
                         Self::mouse_up(
                             editor,
                             event,
                             &position_map,
                             text_bounds,
+                            &interactive_bounds,
                             &stacking_order,
                             cx,
                         )
@@ -2647,7 +2648,7 @@ impl EditorElement {
 }
 
 #[derive(Debug)]
-pub struct LineWithInvisibles {
+pub(crate) struct LineWithInvisibles {
     pub line: ShapedLine,
     invisibles: Vec<Invisible>,
 }

crates/editor/src/inlay_hint_cache.rs πŸ”—

@@ -1,3 +1,11 @@
+/// Stores and updates all data received from LSP <a href="https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint">textDocument/inlayHint</a> requests.
+/// Has nothing to do with other inlays, e.g. copilot suggestions β€”Β those are stored elsewhere.
+/// On every update, cache may query for more inlay hints and update inlays on the screen.
+///
+/// Inlays stored on screen are in [`crate::display_map::inlay_map`] and this cache is the only way to update any inlay hint data in the visible hints in the inlay map.
+/// For determining the update to the `inlay_map`, the cache requires a list of visible inlay hints β€” all other hints are not relevant and their separate updates are not influencing the cache work.
+///
+/// Due to the way the data is stored for both visible inlays and the cache, every inlay (and inlay hint) collection is editor-specific, so a single buffer may have multiple sets of inlays of open on different panes.
 use std::{
     cmp,
     ops::{ControlFlow, Range},
@@ -39,7 +47,7 @@ struct TasksForRanges {
 }
 
 #[derive(Debug)]
-pub struct CachedExcerptHints {
+struct CachedExcerptHints {
     version: usize,
     buffer_version: Global,
     buffer_id: u64,
@@ -47,15 +55,30 @@ pub struct CachedExcerptHints {
     hints_by_id: HashMap<InlayId, InlayHint>,
 }
 
+/// A logic to apply when querying for new inlay hints and deciding what to do with the old entries in the cache in case of conflicts.
 #[derive(Debug, Clone, Copy)]
-pub enum InvalidationStrategy {
+pub(super) enum InvalidationStrategy {
+    /// Hints reset is <a href="https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_inlayHint_refresh">requested</a> by the LSP server.
+    /// Demands to re-query all inlay hints needed and invalidate all cached entries, but does not require instant update with invalidation.
+    ///
+    /// Despite nothing forbids language server from sending this request on every edit, it is expected to be sent only when certain internal server state update, invisible for the editor otherwise.
     RefreshRequested,
+    /// Multibuffer excerpt(s) and/or singleton buffer(s) were edited at least on one place.
+    /// Neither editor nor LSP is able to tell which open file hints' are not affected, so all of them have to be invalidated, re-queried and do that fast enough to avoid being slow, but also debounce to avoid loading hints on every fast keystroke sequence.
     BufferEdited,
+    /// A new file got opened/new excerpt was added to a multibuffer/a [multi]buffer was scrolled to a new position.
+    /// No invalidation should be done at all, all new hints are added to the cache.
+    ///
+    /// A special case is the settings change: in addition to LSP capabilities, Zed allows omitting certain hint kinds (defined by the corresponding LSP part: type/parameter/other).
+    /// This does not lead to cache invalidation, but would require cache usage for determining which hints are not displayed and issuing an update to inlays on the screen.
     None,
 }
 
-#[derive(Debug, Default)]
-pub struct InlaySplice {
+/// A splice to send into the `inlay_map` for updating the visible inlays on the screen.
+/// "Visible" inlays may not be displayed in the buffer right away, but those are ready to be displayed on further buffer scroll, pane item activations, etc. right away without additional LSP queries or settings changes.
+/// The data in the cache is never used directly for displaying inlays on the screen, to avoid races with updates from LSP queries and sync overhead.
+/// Splice is picked to help avoid extra hint flickering and "jumps" on the screen.
+pub(super) struct InlaySplice {
     pub to_remove: Vec<InlayId>,
     pub to_insert: Vec<Inlay>,
 }
@@ -237,7 +260,7 @@ impl TasksForRanges {
 }
 
 impl InlayHintCache {
-    pub fn new(inlay_hint_settings: InlayHintSettings) -> Self {
+    pub(super) fn new(inlay_hint_settings: InlayHintSettings) -> Self {
         Self {
             allowed_hint_kinds: inlay_hint_settings.enabled_inlay_hint_kinds(),
             enabled: inlay_hint_settings.enabled,
@@ -248,7 +271,10 @@ impl InlayHintCache {
         }
     }
 
-    pub fn update_settings(
+    /// Checks inlay hint settings for enabled hint kinds and general enabled state.
+    /// Generates corresponding inlay_map splice updates on settings changes.
+    /// Does not update inlay hint cache state on disabling or inlay hint kinds change: only reenabling forces new LSP queries.
+    pub(super) fn update_settings(
         &mut self,
         multi_buffer: &Model<MultiBuffer>,
         new_hint_settings: InlayHintSettings,
@@ -299,7 +325,11 @@ impl InlayHintCache {
         }
     }
 
-    pub fn spawn_hint_refresh(
+    /// If needed, queries LSP for new inlay hints, using the invalidation strategy given.
+    /// To reduce inlay hint jumping, attempts to query a visible range of the editor(s) first,
+    /// followed by the delayed queries of the same range above and below the visible one.
+    /// This way, concequent refresh invocations are less likely to trigger LSP queries for the invisible ranges.
+    pub(super) fn spawn_hint_refresh(
         &mut self,
         reason: &'static str,
         excerpts_to_query: HashMap<ExcerptId, (Model<Buffer>, Global, Range<usize>)>,
@@ -460,7 +490,11 @@ impl InlayHintCache {
         }
     }
 
-    pub fn remove_excerpts(&mut self, excerpts_removed: Vec<ExcerptId>) -> Option<InlaySplice> {
+    /// Completely forget of certain excerpts that were removed from the multibuffer.
+    pub(super) fn remove_excerpts(
+        &mut self,
+        excerpts_removed: Vec<ExcerptId>,
+    ) -> Option<InlaySplice> {
         let mut to_remove = Vec::new();
         for excerpt_to_remove in excerpts_removed {
             self.update_tasks.remove(&excerpt_to_remove);
@@ -480,7 +514,7 @@ impl InlayHintCache {
         }
     }
 
-    pub fn clear(&mut self) {
+    pub(super) fn clear(&mut self) {
         if !self.update_tasks.is_empty() || !self.hints.is_empty() {
             self.version += 1;
         }
@@ -488,7 +522,7 @@ impl InlayHintCache {
         self.hints.clear();
     }
 
-    pub fn hint_by_id(&self, excerpt_id: ExcerptId, hint_id: InlayId) -> Option<InlayHint> {
+    pub(super) fn hint_by_id(&self, excerpt_id: ExcerptId, hint_id: InlayId) -> Option<InlayHint> {
         self.hints
             .get(&excerpt_id)?
             .read()
@@ -516,7 +550,8 @@ impl InlayHintCache {
         self.version
     }
 
-    pub fn spawn_hint_resolve(
+    /// Queries a certain hint from the cache for extra data via the LSP <a href="https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#inlayHint_resolve">resolve</a> request.
+    pub(super) fn spawn_hint_resolve(
         &self,
         buffer_id: u64,
         excerpt_id: ExcerptId,
@@ -925,14 +960,14 @@ async fn fetch_and_update_hints(
     log::trace!("Fetched hints: {new_hints:?}");
 
     let background_task_buffer_snapshot = buffer_snapshot.clone();
-    let backround_fetch_range = fetch_range.clone();
+    let background_fetch_range = fetch_range.clone();
     let new_update = cx
         .background_executor()
         .spawn(async move {
             calculate_hint_updates(
                 query.excerpt_id,
                 invalidate,
-                backround_fetch_range,
+                background_fetch_range,
                 new_hints,
                 &background_task_buffer_snapshot,
                 cached_excerpt_hints,
@@ -1199,7 +1234,7 @@ pub mod tests {
     use std::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering};
 
     use crate::{
-        scroll::{autoscroll::Autoscroll, scroll_amount::ScrollAmount},
+        scroll::{scroll_amount::ScrollAmount, Autoscroll},
         ExcerptRange,
     };
     use futures::StreamExt;
@@ -1449,7 +1484,7 @@ pub mod tests {
             assert_eq!(
                 editor.inlay_hint_cache().version,
                 edits_made,
-                "Cache version should udpate once after the work task is done"
+                "Cache version should update once after the work task is done"
             );
         });
     }
@@ -1599,7 +1634,7 @@ pub mod tests {
             assert_eq!(
                 expected_hints,
                 cached_hint_labels(editor),
-                "Markdown editor should have a separate verison, repeating Rust editor rules"
+                "Markdown editor should have a separate version, repeating Rust editor rules"
             );
             assert_eq!(expected_hints, visible_hint_labels(editor, cx));
             assert_eq!(editor.inlay_hint_cache().version, 1);
@@ -2612,7 +2647,7 @@ pub mod tests {
                     "When scroll is at the edge of a multibuffer, its visible excerpts only should be queried for inlay hints"
                 );
                 assert_eq!(expected_hints, visible_hint_labels(editor, cx));
-                assert_eq!(editor.inlay_hint_cache().version, expected_hints.len(), "Every visible excerpt hints should bump the verison");
+                assert_eq!(editor.inlay_hint_cache().version, expected_hints.len(), "Every visible excerpt hints should bump the version");
             });
 
         _ = editor.update(cx, |editor, cx| {
@@ -2728,7 +2763,7 @@ pub mod tests {
                 expected_hints,
                 cached_hint_labels(editor),
                 "After multibuffer edit, editor gets scolled back to the last selection; \
-    all hints should be invalidated and requeried for all of its visible excerpts"
+    all hints should be invalidated and required for all of its visible excerpts"
             );
             assert_eq!(expected_hints, visible_hint_labels(editor, cx));
 
@@ -69,7 +69,7 @@ pub enum GoToDefinitionLink {
 }
 
 #[derive(Debug, Clone, PartialEq, Eq)]
-pub struct InlayHighlight {
+pub(crate) struct InlayHighlight {
     pub inlay: InlayId,
     pub inlay_position: Anchor,
     pub range: Range<usize>,

crates/editor/src/movement.rs πŸ”—

@@ -1,3 +1,6 @@
+//! Movement module contains helper functions for calculating intended position
+//! in editor given a given motion (e.g. it handles converting a "move left" command into coordinates in editor). It is exposed mostly for use by vim crate.
+
 use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
 use crate::{char_kind, CharKind, EditorStyle, ToOffset, ToPoint};
 use gpui::{px, Pixels, TextSystem};
@@ -5,6 +8,9 @@ use language::Point;
 
 use std::{ops::Range, sync::Arc};
 
+/// Defines search strategy for items in `movement` module.
+/// `FindRange::SingeLine` only looks for a match on a single line at a time, whereas
+/// `FindRange::MultiLine` keeps going until the end of a string.
 #[derive(Debug, PartialEq)]
 pub enum FindRange {
     SingleLine,
@@ -14,11 +20,13 @@ pub enum FindRange {
 /// TextLayoutDetails encompasses everything we need to move vertically
 /// taking into account variable width characters.
 pub struct TextLayoutDetails {
-    pub text_system: Arc<TextSystem>,
-    pub editor_style: EditorStyle,
-    pub rem_size: Pixels,
+    pub(crate) text_system: Arc<TextSystem>,
+    pub(crate) editor_style: EditorStyle,
+    pub(crate) rem_size: Pixels,
 }
 
+/// Returns a column to the left of the current point, wrapping
+/// to the previous line if that point is at the start of line.
 pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
     if point.column() > 0 {
         *point.column_mut() -= 1;
@@ -29,6 +37,8 @@ pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
     map.clip_point(point, Bias::Left)
 }
 
+/// Returns a column to the left of the current point, doing nothing if
+/// that point is already at the start of line.
 pub fn saturating_left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
     if point.column() > 0 {
         *point.column_mut() -= 1;
@@ -36,6 +46,8 @@ pub fn saturating_left(map: &DisplaySnapshot, mut point: DisplayPoint) -> Displa
     map.clip_point(point, Bias::Left)
 }
 
+/// Returns a column to the right of the current point, wrapping
+/// to the next line if that point is at the end of line.
 pub fn right(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
     let max_column = map.line_len(point.row());
     if point.column() < max_column {
@@ -47,11 +59,14 @@ pub fn right(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
     map.clip_point(point, Bias::Right)
 }
 
+/// Returns a column to the right of the current point, not performing any wrapping
+/// if that point is already at the end of line.
 pub fn saturating_right(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
     *point.column_mut() += 1;
     map.clip_point(point, Bias::Right)
 }
 
+/// Returns a display point for the preceding displayed line (which might be a soft-wrapped line).
 pub fn up(
     map: &DisplaySnapshot,
     start: DisplayPoint,
@@ -69,6 +84,7 @@ pub fn up(
     )
 }
 
+/// Returns a display point for the next displayed line (which might be a soft-wrapped line).
 pub fn down(
     map: &DisplaySnapshot,
     start: DisplayPoint,
@@ -86,7 +102,7 @@ pub fn down(
     )
 }
 
-pub fn up_by_rows(
+pub(crate) fn up_by_rows(
     map: &DisplaySnapshot,
     start: DisplayPoint,
     row_count: u32,
@@ -125,7 +141,7 @@ pub fn up_by_rows(
     )
 }
 
-pub fn down_by_rows(
+pub(crate) fn down_by_rows(
     map: &DisplaySnapshot,
     start: DisplayPoint,
     row_count: u32,
@@ -161,6 +177,10 @@ pub fn down_by_rows(
     )
 }
 
+/// Returns a position of the start of line.
+/// If `stop_at_soft_boundaries` is true, the returned position is that of the
+/// displayed line (e.g. it could actually be in the middle of a text line if that line is soft-wrapped).
+/// Otherwise it's always going to be the start of a logical line.
 pub fn line_beginning(
     map: &DisplaySnapshot,
     display_point: DisplayPoint,
@@ -177,6 +197,10 @@ pub fn line_beginning(
     }
 }
 
+/// Returns the last indented position on a given line.
+/// If `stop_at_soft_boundaries` is true, the returned [`DisplayPoint`] is that of a
+/// displayed line (e.g. if there's soft wrap it's gonna be returned),
+/// otherwise it's always going to be a start of a logical line.
 pub fn indented_line_beginning(
     map: &DisplaySnapshot,
     display_point: DisplayPoint,
@@ -201,6 +225,11 @@ pub fn indented_line_beginning(
     }
 }
 
+/// Returns a position of the end of line.
+
+/// If `stop_at_soft_boundaries` is true, the returned position is that of the
+/// displayed line (e.g. it could actually be in the middle of a text line if that line is soft-wrapped).
+/// Otherwise it's always going to be the end of a logical line.
 pub fn line_end(
     map: &DisplaySnapshot,
     display_point: DisplayPoint,
@@ -217,6 +246,8 @@ pub fn line_end(
     }
 }
 
+/// Returns a position of the previous word boundary, where a word character is defined as either
+/// uppercase letter, lowercase letter, '_' character or language-specific word character (like '-' in CSS).
 pub fn previous_word_start(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
     let raw_point = point.to_point(map);
     let scope = map.buffer_snapshot.language_scope_at(raw_point);
@@ -227,6 +258,9 @@ pub fn previous_word_start(map: &DisplaySnapshot, point: DisplayPoint) -> Displa
     })
 }
 
+/// Returns a position of the previous subword boundary, where a subword is defined as a run of
+/// word characters of the same "subkind" - where subcharacter kinds are '_' character,
+/// lowerspace characters and uppercase characters.
 pub fn previous_subword_start(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
     let raw_point = point.to_point(map);
     let scope = map.buffer_snapshot.language_scope_at(raw_point);
@@ -240,6 +274,8 @@ pub fn previous_subword_start(map: &DisplaySnapshot, point: DisplayPoint) -> Dis
     })
 }
 
+/// Returns a position of the next word boundary, where a word character is defined as either
+/// uppercase letter, lowercase letter, '_' character or language-specific word character (like '-' in CSS).
 pub fn next_word_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
     let raw_point = point.to_point(map);
     let scope = map.buffer_snapshot.language_scope_at(raw_point);
@@ -250,6 +286,9 @@ pub fn next_word_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint
     })
 }
 
+/// Returns a position of the next subword boundary, where a subword is defined as a run of
+/// word characters of the same "subkind" - where subcharacter kinds are '_' character,
+/// lowerspace characters and uppercase characters.
 pub fn next_subword_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
     let raw_point = point.to_point(map);
     let scope = map.buffer_snapshot.language_scope_at(raw_point);
@@ -263,6 +302,8 @@ pub fn next_subword_end(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPo
     })
 }
 
+/// Returns a position of the start of the current paragraph, where a paragraph
+/// is defined as a run of non-blank lines.
 pub fn start_of_paragraph(
     map: &DisplaySnapshot,
     display_point: DisplayPoint,
@@ -290,6 +331,8 @@ pub fn start_of_paragraph(
     DisplayPoint::zero()
 }
 
+/// Returns a position of the end of the current paragraph, where a paragraph
+/// is defined as a run of non-blank lines.
 pub fn end_of_paragraph(
     map: &DisplaySnapshot,
     display_point: DisplayPoint,
@@ -376,6 +419,9 @@ pub fn find_boundary(
     map.clip_point(offset.to_display_point(map), Bias::Right)
 }
 
+/// Returns an iterator over the characters following a given offset in the [`DisplaySnapshot`].
+/// The returned value also contains a range of the start/end of a returned character in
+/// the [`DisplaySnapshot`]. The offsets are relative to the start of a buffer.
 pub fn chars_after(
     map: &DisplaySnapshot,
     mut offset: usize,
@@ -387,6 +433,9 @@ pub fn chars_after(
     })
 }
 
+/// Returns a reverse iterator over the characters following a given offset in the [`DisplaySnapshot`].
+/// The returned value also contains a range of the start/end of a returned character in
+/// the [`DisplaySnapshot`]. The offsets are relative to the start of a buffer.
 pub fn chars_before(
     map: &DisplaySnapshot,
     mut offset: usize,
@@ -400,7 +449,7 @@ pub fn chars_before(
         })
 }
 
-pub fn is_inside_word(map: &DisplaySnapshot, point: DisplayPoint) -> bool {
+pub(crate) fn is_inside_word(map: &DisplaySnapshot, point: DisplayPoint) -> bool {
     let raw_point = point.to_point(map);
     let scope = map.buffer_snapshot.language_scope_at(raw_point);
     let ix = map.clip_point(point, Bias::Left).to_offset(map, Bias::Left);
@@ -413,7 +462,10 @@ pub fn is_inside_word(map: &DisplaySnapshot, point: DisplayPoint) -> bool {
     prev_char_kind.zip(next_char_kind) == Some((CharKind::Word, CharKind::Word))
 }
 
-pub fn surrounding_word(map: &DisplaySnapshot, position: DisplayPoint) -> Range<DisplayPoint> {
+pub(crate) fn surrounding_word(
+    map: &DisplaySnapshot,
+    position: DisplayPoint,
+) -> Range<DisplayPoint> {
     let position = map
         .clip_point(position, Bias::Left)
         .to_offset(map, Bias::Left);
@@ -429,6 +481,12 @@ pub fn surrounding_word(map: &DisplaySnapshot, position: DisplayPoint) -> Range<
     start..end
 }
 
+/// Returns a list of lines (represented as a [`DisplayPoint`] range) contained
+/// within a passed range.
+///
+/// The line ranges are **always* going to be in bounds of a requested range, which means that
+/// the first and the last lines might not necessarily represent the
+/// full range of a logical line (as their `.start`/`.end` values are clipped to those of a passed in range).
 pub fn split_display_range_by_lines(
     map: &DisplaySnapshot,
     range: Range<DisplayPoint>,

crates/editor/src/scroll.rs πŸ”—

@@ -1,6 +1,6 @@
-pub mod actions;
-pub mod autoscroll;
-pub mod scroll_amount;
+mod actions;
+pub(crate) mod autoscroll;
+pub(crate) mod scroll_amount;
 
 use crate::{
     display_map::{DisplaySnapshot, ToDisplayPoint},
@@ -9,8 +9,10 @@ use crate::{
     Anchor, DisplayPoint, Editor, EditorEvent, EditorMode, InlayHintRefreshReason,
     MultiBufferSnapshot, ToPoint,
 };
+pub use autoscroll::{Autoscroll, AutoscrollStrategy};
 use gpui::{point, px, AppContext, Entity, Pixels, Task, ViewContext};
 use language::{Bias, Point};
+pub use scroll_amount::ScrollAmount;
 use std::{
     cmp::Ordering,
     time::{Duration, Instant},
@@ -18,11 +20,6 @@ use std::{
 use util::ResultExt;
 use workspace::{ItemId, WorkspaceId};
 
-use self::{
-    autoscroll::{Autoscroll, AutoscrollStrategy},
-    scroll_amount::ScrollAmount,
-};
-
 pub const SCROLL_EVENT_SEPARATION: Duration = Duration::from_millis(28);
 pub const VERTICAL_SCROLL_MARGIN: f32 = 3.;
 const SCROLLBAR_SHOW_INTERVAL: Duration = Duration::from_secs(1);

crates/editor/src/selections_collection.rs πŸ”—

@@ -99,7 +99,7 @@ impl SelectionsCollection {
             .map(|pending| pending.map(|p| p.summary::<D>(&self.buffer(cx))))
     }
 
-    pub fn pending_mode(&self) -> Option<SelectMode> {
+    pub(crate) fn pending_mode(&self) -> Option<SelectMode> {
         self.pending.as_ref().map(|pending| pending.mode.clone())
     }
 
@@ -398,7 +398,7 @@ impl<'a> MutableSelectionsCollection<'a> {
         }
     }
 
-    pub fn set_pending_anchor_range(&mut self, range: Range<Anchor>, mode: SelectMode) {
+    pub(crate) fn set_pending_anchor_range(&mut self, range: Range<Anchor>, mode: SelectMode) {
         self.collection.pending = Some(PendingSelection {
             selection: Selection {
                 id: post_inc(&mut self.collection.next_selection_id),
@@ -412,7 +412,11 @@ impl<'a> MutableSelectionsCollection<'a> {
         self.selections_changed = true;
     }
 
-    pub fn set_pending_display_range(&mut self, range: Range<DisplayPoint>, mode: SelectMode) {
+    pub(crate) fn set_pending_display_range(
+        &mut self,
+        range: Range<DisplayPoint>,
+        mode: SelectMode,
+    ) {
         let (start, end, reversed) = {
             let display_map = self.display_map();
             let buffer = self.buffer();
@@ -448,7 +452,7 @@ impl<'a> MutableSelectionsCollection<'a> {
         self.selections_changed = true;
     }
 
-    pub fn set_pending(&mut self, selection: Selection<Anchor>, mode: SelectMode) {
+    pub(crate) fn set_pending(&mut self, selection: Selection<Anchor>, mode: SelectMode) {
         self.collection.pending = Some(PendingSelection { selection, mode });
         self.selections_changed = true;
     }
@@ -855,7 +859,7 @@ impl<'a> DerefMut for MutableSelectionsCollection<'a> {
 }
 
 // Panics if passed selections are not in order
-pub fn resolve_multiple<'a, D, I>(
+pub(crate) fn resolve_multiple<'a, D, I>(
     selections: I,
     snapshot: &MultiBufferSnapshot,
 ) -> impl 'a + Iterator<Item = Selection<D>>

crates/feature_flags/src/feature_flags.rs πŸ”—

@@ -57,18 +57,14 @@ impl FeatureFlagAppExt for AppContext {
     }
 
     fn has_flag<T: FeatureFlag>(&self) -> bool {
-        if self.has_global::<FeatureFlags>() {
-            self.global::<FeatureFlags>().has_flag(T::NAME)
-        } else {
-            false
-        }
+        self.try_global::<FeatureFlags>()
+            .map(|flags| flags.has_flag(T::NAME))
+            .unwrap_or(false)
     }
 
     fn is_staff(&self) -> bool {
-        if self.has_global::<FeatureFlags>() {
-            return self.global::<FeatureFlags>().staff;
-        } else {
-            false
-        }
+        self.try_global::<FeatureFlags>()
+            .map(|flags| flags.staff)
+            .unwrap_or(false)
     }
 }

crates/file_finder/src/file_finder.rs πŸ”—

@@ -1,5 +1,5 @@
 use collections::HashMap;
-use editor::{scroll::autoscroll::Autoscroll, Bias, Editor};
+use editor::{scroll::Autoscroll, Bias, Editor};
 use fuzzy::{CharBag, PathMatch, PathMatchCandidate};
 use gpui::{
     actions, rems, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, Model,

crates/fs/src/repository.rs πŸ”—

@@ -29,7 +29,7 @@ pub trait GitRepository: Send {
     fn branch_name(&self) -> Option<String>;
 
     /// Get the statuses of all of the files in the index that start with the given
-    /// path and have changes with resepect to the HEAD commit. This is fast because
+    /// path and have changes with respect to the HEAD commit. This is fast because
     /// the index stores hashes of trees, so that unchanged directories can be skipped.
     fn staged_statuses(&self, path_prefix: &Path) -> TreeMap<RepoPath, GitFileStatus>;
 

crates/go_to_line/src/go_to_line.rs πŸ”—

@@ -1,4 +1,4 @@
-use editor::{display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Editor};
+use editor::{display_map::ToDisplayPoint, scroll::Autoscroll, Editor};
 use gpui::{
     actions, div, prelude::*, AnyWindowHandle, AppContext, DismissEvent, EventEmitter, FocusHandle,
     FocusableView, Render, SharedString, Styled, Subscription, View, ViewContext, VisualContext,

crates/gpui/examples/ownership_post.rs πŸ”—

@@ -0,0 +1,35 @@
+use gpui::{prelude::*, App, AppContext, EventEmitter, Model, ModelContext};
+
+struct Counter {
+    count: usize,
+}
+
+struct Change {
+    increment: usize,
+}
+
+impl EventEmitter<Change> for Counter {}
+
+fn main() {
+    App::new().run(|cx: &mut AppContext| {
+        let counter: Model<Counter> = cx.new_model(|_cx| Counter { count: 0 });
+        let subscriber = cx.new_model(|cx: &mut ModelContext<Counter>| {
+            cx.subscribe(&counter, |subscriber, _emitter, event, _cx| {
+                subscriber.count += event.increment * 2;
+            })
+            .detach();
+
+            Counter {
+                count: counter.read(cx).count * 2,
+            }
+        });
+
+        counter.update(cx, |counter, cx| {
+            counter.count += 2;
+            cx.notify();
+            cx.emit(Change { increment: 2 });
+        });
+
+        assert_eq!(subscriber.read(cx).count, 4);
+    });
+}

crates/gpui/src/app.rs πŸ”—

@@ -1,3 +1,5 @@
+#![deny(missing_docs)]
+
 mod async_context;
 mod entity_map;
 mod model_context;
@@ -43,6 +45,9 @@ use util::{
     ResultExt,
 };
 
+/// The duration for which futures returned from [AppContext::on_app_context] or [ModelContext::on_app_quit] can run before the application fully quits.
+pub const SHUTDOWN_TIMEOUT: Duration = Duration::from_millis(100);
+
 /// Temporary(?) wrapper around [`RefCell<AppContext>`] to help us debug any double borrows.
 /// Strongly consider removing after stabilization.
 #[doc(hidden)]
@@ -106,14 +111,24 @@ pub struct App(Rc<AppCell>);
 /// configured, you'll start the app with `App::run`.
 impl App {
     /// Builds an app with the given asset source.
-    pub fn production(asset_source: Arc<dyn AssetSource>) -> Self {
+    pub fn new() -> Self {
         Self(AppContext::new(
             current_platform(),
-            asset_source,
+            Arc::new(()),
             http::client(),
         ))
     }
 
+    /// Assign
+    pub fn with_assets(self, asset_source: impl AssetSource) -> Self {
+        let mut context_lock = self.0.borrow_mut();
+        let asset_source = Arc::new(asset_source);
+        context_lock.asset_source = asset_source.clone();
+        context_lock.svg_renderer = SvgRenderer::new(asset_source);
+        drop(context_lock);
+        self
+    }
+
     /// Start the application. The provided callback will be called once the
     /// app is fully launched.
     pub fn run<F>(self, on_finish_launching: F)
@@ -187,6 +202,9 @@ type QuitHandler = Box<dyn FnOnce(&mut AppContext) -> LocalBoxFuture<'static, ()
 type ReleaseListener = Box<dyn FnOnce(&mut dyn Any, &mut AppContext) + 'static>;
 type NewViewListener = Box<dyn FnMut(AnyView, &mut WindowContext) + 'static>;
 
+/// Contains the state of the full application, and passed as a reference to a variety of callbacks.
+/// Other contexts such as [ModelContext], [WindowContext], and [ViewContext] deref to this type, making it the most general context type.
+/// You need a reference to an `AppContext` to access the state of a [Model].
 pub struct AppContext {
     pub(crate) this: Weak<AppCell>,
     pub(crate) platform: Rc<dyn Platform>,
@@ -312,7 +330,7 @@ impl AppContext {
         let futures = futures::future::join_all(futures);
         if self
             .background_executor
-            .block_with_timeout(Duration::from_millis(100), futures)
+            .block_with_timeout(SHUTDOWN_TIMEOUT, futures)
             .is_err()
         {
             log::error!("timed out waiting on app_will_quit");
@@ -446,6 +464,7 @@ impl AppContext {
             .collect()
     }
 
+    /// Returns a handle to the window that is currently focused at the platform level, if one exists.
     pub fn active_window(&self) -> Option<AnyWindowHandle> {
         self.platform.active_window()
     }
@@ -474,14 +493,17 @@ impl AppContext {
         self.platform.activate(ignoring_other_apps);
     }
 
+    /// Hide the application at the platform level.
     pub fn hide(&self) {
         self.platform.hide();
     }
 
+    /// Hide other applications at the platform level.
     pub fn hide_other_apps(&self) {
         self.platform.hide_other_apps();
     }
 
+    /// Unhide other applications at the platform level.
     pub fn unhide_other_apps(&self) {
         self.platform.unhide_other_apps();
     }
@@ -521,18 +543,25 @@ impl AppContext {
         self.platform.open_url(url);
     }
 
+    /// Returns the full pathname of the current app bundle.
+    /// If the app is not being run from a bundle, returns an error.
     pub fn app_path(&self) -> Result<PathBuf> {
         self.platform.app_path()
     }
 
+    /// Returns the file URL of the executable with the specified name in the application bundle
     pub fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf> {
         self.platform.path_for_auxiliary_executable(name)
     }
 
+    /// Returns the maximum duration in which a second mouse click must occur for an event to be a double-click event.
     pub fn double_click_interval(&self) -> Duration {
         self.platform.double_click_interval()
     }
 
+    /// Displays a platform modal for selecting paths.
+    /// When one or more paths are selected, they'll be relayed asynchronously via the returned oneshot channel.
+    /// If cancelled, a `None` will be relayed instead.
     pub fn prompt_for_paths(
         &self,
         options: PathPromptOptions,
@@ -540,22 +569,30 @@ impl AppContext {
         self.platform.prompt_for_paths(options)
     }
 
+    /// Displays a platform modal for selecting a new path where a file can be saved.
+    /// The provided directory will be used to set the iniital location.
+    /// When a path is selected, it is relayed asynchronously via the returned oneshot channel.
+    /// If cancelled, a `None` will be relayed instead.
     pub fn prompt_for_new_path(&self, directory: &Path) -> oneshot::Receiver<Option<PathBuf>> {
         self.platform.prompt_for_new_path(directory)
     }
 
+    /// Reveals the specified path at the platform level, such as in Finder on macOS.
     pub fn reveal_path(&self, path: &Path) {
         self.platform.reveal_path(path)
     }
 
+    /// Returns whether the user has configured scrollbars to auto-hide at the platform level.
     pub fn should_auto_hide_scrollbars(&self) -> bool {
         self.platform.should_auto_hide_scrollbars()
     }
 
+    /// Restart the application.
     pub fn restart(&self) {
         self.platform.restart()
     }
 
+    /// Returns the local timezone at the platform level.
     pub fn local_timezone(&self) -> UtcOffset {
         self.platform.local_timezone()
     }
@@ -745,7 +782,7 @@ impl AppContext {
     }
 
     /// Spawns the future returned by the given function on the thread pool. The closure will be invoked
-    /// with AsyncAppContext, which allows the application state to be accessed across await points.
+    /// with [AsyncAppContext], which allows the application state to be accessed across await points.
     pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut) -> Task<R>
     where
         Fut: Future<Output = R> + 'static,
@@ -896,6 +933,8 @@ impl AppContext {
         self.globals_by_type.insert(global_type, lease.global);
     }
 
+    /// Arrange for the given function to be invoked whenever a view of the specified type is created.
+    /// The function will be passed a mutable reference to the view along with an appropriate context.
     pub fn observe_new_views<V: 'static>(
         &mut self,
         on_new: impl 'static + Fn(&mut V, &mut ViewContext<V>),
@@ -915,6 +954,8 @@ impl AppContext {
         subscription
     }
 
+    /// Observe the release of a model or view. The callback is invoked after the model or view
+    /// has no more strong references but before it has been dropped.
     pub fn observe_release<E, T>(
         &mut self,
         handle: &E,
@@ -935,6 +976,9 @@ impl AppContext {
         subscription
     }
 
+    /// Register a callback to be invoked when a keystroke is received by the application
+    /// in any window. Note that this fires after all other action and event mechanisms have resolved
+    /// and that this API will not be invoked if the event's propagation is stopped.
     pub fn observe_keystrokes(
         &mut self,
         f: impl FnMut(&KeystrokeEvent, &mut WindowContext) + 'static,
@@ -958,6 +1002,7 @@ impl AppContext {
         self.pending_effects.push_back(Effect::Refresh);
     }
 
+    /// Clear all key bindings in the app.
     pub fn clear_key_bindings(&mut self) {
         self.keymap.lock().clear();
         self.pending_effects.push_back(Effect::Refresh);
@@ -992,6 +1037,7 @@ impl AppContext {
         self.propagate_event = true;
     }
 
+    /// Build an action from some arbitrary data, typically a keymap entry.
     pub fn build_action(
         &self,
         name: &str,
@@ -1000,10 +1046,16 @@ impl AppContext {
         self.actions.build_action(name, data)
     }
 
+    /// Get a list of all action names that have been registered.
+    /// in the application. Note that registration only allows for
+    /// actions to be built dynamically, and is unrelated to binding
+    /// actions in the element tree.
     pub fn all_action_names(&self) -> &[SharedString] {
         self.actions.all_action_names()
     }
 
+    /// Register a callback to be invoked when the application is about to quit.
+    /// It is not possible to cancel the quit event at this point.
     pub fn on_app_quit<Fut>(
         &mut self,
         mut on_quit: impl FnMut(&mut AppContext) -> Fut + 'static,
@@ -1039,6 +1091,8 @@ impl AppContext {
         }
     }
 
+    /// Checks if the given action is bound in the current context, as defined by the app's current focus,
+    /// the bindings in the element tree, and any global action listeners.
     pub fn is_action_available(&mut self, action: &dyn Action) -> bool {
         if let Some(window) = self.active_window() {
             if let Ok(window_action_available) =
@@ -1052,10 +1106,13 @@ impl AppContext {
             .contains_key(&action.as_any().type_id())
     }
 
+    /// Set the menu bar for this application. This will replace any existing menu bar.
     pub fn set_menus(&mut self, menus: Vec<Menu>) {
         self.platform.set_menus(menus, &self.keymap.lock());
     }
 
+    /// Dispatch an action to the currently active window or global action handler
+    /// See [action::Action] for more information on how actions work
     pub fn dispatch_action(&mut self, action: &dyn Action) {
         if let Some(active_window) = self.active_window() {
             active_window
@@ -1110,6 +1167,7 @@ impl AppContext {
         }
     }
 
+    /// Is there currently something being dragged?
     pub fn has_active_drag(&self) -> bool {
         self.active_drag.is_some()
     }
@@ -1119,7 +1177,7 @@ impl Context for AppContext {
     type Result<T> = T;
 
     /// Build an entity that is owned by the application. The given function will be invoked with
-    /// a `ModelContext` and must return an object representing the entity. A `Model` will be returned
+    /// a `ModelContext` and must return an object representing the entity. A `Model` handle will be returned,
     /// which can be used to access the entity in a context.
     fn new_model<T: 'static>(
         &mut self,
@@ -1262,8 +1320,14 @@ impl<G: 'static> DerefMut for GlobalLease<G> {
 /// Contains state associated with an active drag operation, started by dragging an element
 /// within the window or by dragging into the app from the underlying platform.
 pub struct AnyDrag {
+    /// The view used to render this drag
     pub view: AnyView,
+
+    /// The value of the dragged item, to be dropped
     pub value: Box<dyn Any>,
+
+    /// This is used to render the dragged item in the same place
+    /// on the original element that the drag was initiated
     pub cursor_offset: Point<Pixels>,
 }
 
@@ -1271,12 +1335,19 @@ pub struct AnyDrag {
 /// tooltip behavior on a custom element. Otherwise, use [Div::tooltip].
 #[derive(Clone)]
 pub struct AnyTooltip {
+    /// The view used to display the tooltip
     pub view: AnyView,
+
+    /// The offset from the cursor to use, relative to the parent view
     pub cursor_offset: Point<Pixels>,
 }
 
+/// A keystroke event, and potentially the associated action
 #[derive(Debug)]
 pub struct KeystrokeEvent {
+    /// The keystroke that occurred
     pub keystroke: Keystroke,
+
+    /// The action that was resolved for the keystroke, if any
     pub action: Option<Box<dyn Action>>,
 }

crates/gpui/src/app/async_context.rs πŸ”—

@@ -7,6 +7,9 @@ use anyhow::{anyhow, Context as _};
 use derive_more::{Deref, DerefMut};
 use std::{future::Future, rc::Weak};
 
+/// An async-friendly version of [AppContext] with a static lifetime so it can be held across `await` points in async code.
+/// You're provided with an instance when calling [AppContext::spawn], and you can also create one with [AppContext::to_async].
+/// Internally, this holds a weak reference to an `AppContext`, so its methods are fallible to protect against cases where the [AppContext] is dropped.
 #[derive(Clone)]
 pub struct AsyncAppContext {
     pub(crate) app: Weak<AppCell>,
@@ -139,6 +142,8 @@ impl AsyncAppContext {
         self.foreground_executor.spawn(f(self.clone()))
     }
 
+    /// Determine whether global state of the specified type has been assigned.
+    /// Returns an error if the `AppContext` has been dropped.
     pub fn has_global<G: 'static>(&self) -> Result<bool> {
         let app = self
             .app
@@ -148,6 +153,9 @@ impl AsyncAppContext {
         Ok(app.has_global::<G>())
     }
 
+    /// Reads the global state of the specified type, passing it to the given callback.
+    /// Panics if no global state of the specified type has been assigned.
+    /// Returns an error if the `AppContext` has been dropped.
     pub fn read_global<G: 'static, R>(&self, read: impl FnOnce(&G, &AppContext) -> R) -> Result<R> {
         let app = self
             .app
@@ -157,6 +165,9 @@ impl AsyncAppContext {
         Ok(read(app.global(), &app))
     }
 
+    /// Reads the global state of the specified type, passing it to the given callback.
+    /// Similar to [read_global], but returns an error instead of panicking if no state of the specified type has been assigned.
+    /// Returns an error if no state of the specified type has been assigned the `AppContext` has been dropped.
     pub fn try_read_global<G: 'static, R>(
         &self,
         read: impl FnOnce(&G, &AppContext) -> R,
@@ -166,6 +177,8 @@ impl AsyncAppContext {
         Some(read(app.try_global()?, &app))
     }
 
+    /// A convenience method for [AppContext::update_global]
+    /// for updating the global state of the specified type.
     pub fn update_global<G: 'static, R>(
         &mut self,
         update: impl FnOnce(&mut G, &mut AppContext) -> R,
@@ -179,6 +192,8 @@ impl AsyncAppContext {
     }
 }
 
+/// A cloneable, owned handle to the application context,
+/// composed with the window associated with the current task.
 #[derive(Clone, Deref, DerefMut)]
 pub struct AsyncWindowContext {
     #[deref]
@@ -188,14 +203,16 @@ pub struct AsyncWindowContext {
 }
 
 impl AsyncWindowContext {
-    pub fn window_handle(&self) -> AnyWindowHandle {
-        self.window
-    }
-
     pub(crate) fn new(app: AsyncAppContext, window: AnyWindowHandle) -> Self {
         Self { app, window }
     }
 
+    /// Get the handle of the window this context is associated with.
+    pub fn window_handle(&self) -> AnyWindowHandle {
+        self.window
+    }
+
+    /// A convenience method for [WindowContext::update()]
     pub fn update<R>(
         &mut self,
         update: impl FnOnce(AnyView, &mut WindowContext) -> R,
@@ -203,10 +220,12 @@ impl AsyncWindowContext {
         self.app.update_window(self.window, update)
     }
 
+    /// A convenience method for [WindowContext::on_next_frame()]
     pub fn on_next_frame(&mut self, f: impl FnOnce(&mut WindowContext) + 'static) {
         self.window.update(self, |_, cx| cx.on_next_frame(f)).ok();
     }
 
+    /// A convenience method for [AppContext::global()]
     pub fn read_global<G: 'static, R>(
         &mut self,
         read: impl FnOnce(&G, &WindowContext) -> R,
@@ -214,6 +233,8 @@ impl AsyncWindowContext {
         self.window.update(self, |_, cx| read(cx.global(), cx))
     }
 
+    /// A convenience method for [AppContext::update_global()]
+    /// for updating the global state of the specified type.
     pub fn update_global<G, R>(
         &mut self,
         update: impl FnOnce(&mut G, &mut WindowContext) -> R,
@@ -224,6 +245,8 @@ impl AsyncWindowContext {
         self.window.update(self, |_, cx| cx.update_global(update))
     }
 
+    /// Schedule a future to be executed on the main thread. This is used for collecting
+    /// the results of background tasks and updating the UI.
     pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncWindowContext) -> Fut) -> Task<R>
     where
         Fut: Future<Output = R> + 'static,

crates/gpui/src/app/entity_map.rs πŸ”—

@@ -31,6 +31,7 @@ impl From<u64> for EntityId {
 }
 
 impl EntityId {
+    /// Converts this entity id to a [u64]
     pub fn as_u64(self) -> u64 {
         self.0.as_ffi()
     }
@@ -140,7 +141,7 @@ impl EntityMap {
     }
 }
 
-pub struct Lease<'a, T> {
+pub(crate) struct Lease<'a, T> {
     entity: Option<Box<dyn Any>>,
     pub model: &'a Model<T>,
     entity_type: PhantomData<T>,
@@ -169,8 +170,9 @@ impl<'a, T> Drop for Lease<'a, T> {
 }
 
 #[derive(Deref, DerefMut)]
-pub struct Slot<T>(Model<T>);
+pub(crate) struct Slot<T>(Model<T>);
 
+/// A dynamically typed reference to a model, which can be downcast into a `Model<T>`.
 pub struct AnyModel {
     pub(crate) entity_id: EntityId,
     pub(crate) entity_type: TypeId,
@@ -195,14 +197,17 @@ impl AnyModel {
         }
     }
 
+    /// Returns the id associated with this model.
     pub fn entity_id(&self) -> EntityId {
         self.entity_id
     }
 
+    /// Returns the [TypeId] associated with this model.
     pub fn entity_type(&self) -> TypeId {
         self.entity_type
     }
 
+    /// Converts this model handle into a weak variant, which does not prevent it from being released.
     pub fn downgrade(&self) -> AnyWeakModel {
         AnyWeakModel {
             entity_id: self.entity_id,
@@ -211,6 +216,8 @@ impl AnyModel {
         }
     }
 
+    /// Converts this model handle into a strongly-typed model handle of the given type.
+    /// If this model handle is not of the specified type, returns itself as an error variant.
     pub fn downcast<T: 'static>(self) -> Result<Model<T>, AnyModel> {
         if TypeId::of::<T>() == self.entity_type {
             Ok(Model {
@@ -274,7 +281,7 @@ impl Drop for AnyModel {
             entity_map
                 .write()
                 .leak_detector
-                .handle_dropped(self.entity_id, self.handle_id)
+                .handle_released(self.entity_id, self.handle_id)
         }
     }
 }
@@ -307,6 +314,8 @@ impl std::fmt::Debug for AnyModel {
     }
 }
 
+/// A strong, well typed reference to a struct which is managed
+/// by GPUI
 #[derive(Deref, DerefMut)]
 pub struct Model<T> {
     #[deref]
@@ -368,10 +377,12 @@ impl<T: 'static> Model<T> {
         self.any_model
     }
 
+    /// Grab a reference to this entity from the context.
     pub fn read<'a>(&self, cx: &'a AppContext) -> &'a T {
         cx.entities.read(self)
     }
 
+    /// Read the entity referenced by this model with the given function.
     pub fn read_with<R, C: Context>(
         &self,
         cx: &C,
@@ -437,6 +448,7 @@ impl<T> PartialEq<WeakModel<T>> for Model<T> {
     }
 }
 
+/// A type erased, weak reference to a model.
 #[derive(Clone)]
 pub struct AnyWeakModel {
     pub(crate) entity_id: EntityId,
@@ -445,10 +457,12 @@ pub struct AnyWeakModel {
 }
 
 impl AnyWeakModel {
+    /// Get the entity ID associated with this weak reference.
     pub fn entity_id(&self) -> EntityId {
         self.entity_id
     }
 
+    /// Check if this weak handle can be upgraded, or if the model has already been dropped
     pub fn is_upgradable(&self) -> bool {
         let ref_count = self
             .entity_ref_counts
@@ -458,6 +472,7 @@ impl AnyWeakModel {
         ref_count > 0
     }
 
+    /// Upgrade this weak model reference to a strong reference.
     pub fn upgrade(&self) -> Option<AnyModel> {
         let ref_counts = &self.entity_ref_counts.upgrade()?;
         let ref_counts = ref_counts.read();
@@ -485,14 +500,15 @@ impl AnyWeakModel {
         })
     }
 
+    /// Assert that model referenced by this weak handle has been released.
     #[cfg(any(test, feature = "test-support"))]
-    pub fn assert_dropped(&self) {
+    pub fn assert_released(&self) {
         self.entity_ref_counts
             .upgrade()
             .unwrap()
             .write()
             .leak_detector
-            .assert_dropped(self.entity_id);
+            .assert_released(self.entity_id);
 
         if self
             .entity_ref_counts
@@ -527,6 +543,7 @@ impl PartialEq for AnyWeakModel {
 
 impl Eq for AnyWeakModel {}
 
+/// A weak reference to a model of the given type.
 #[derive(Deref, DerefMut)]
 pub struct WeakModel<T> {
     #[deref]
@@ -617,12 +634,12 @@ lazy_static::lazy_static! {
 
 #[cfg(any(test, feature = "test-support"))]
 #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq)]
-pub struct HandleId {
+pub(crate) struct HandleId {
     id: u64, // id of the handle itself, not the pointed at object
 }
 
 #[cfg(any(test, feature = "test-support"))]
-pub struct LeakDetector {
+pub(crate) struct LeakDetector {
     next_handle_id: u64,
     entity_handles: HashMap<EntityId, HashMap<HandleId, Option<backtrace::Backtrace>>>,
 }
@@ -641,12 +658,12 @@ impl LeakDetector {
         handle_id
     }
 
-    pub fn handle_dropped(&mut self, entity_id: EntityId, handle_id: HandleId) {
+    pub fn handle_released(&mut self, entity_id: EntityId, handle_id: HandleId) {
         let handles = self.entity_handles.entry(entity_id).or_default();
         handles.remove(&handle_id);
     }
 
-    pub fn assert_dropped(&mut self, entity_id: EntityId) {
+    pub fn assert_released(&mut self, entity_id: EntityId) {
         let handles = self.entity_handles.entry(entity_id).or_default();
         if !handles.is_empty() {
             for (_, backtrace) in handles {

crates/gpui/src/app/model_context.rs πŸ”—

@@ -11,6 +11,7 @@ use std::{
     future::Future,
 };
 
+/// The app context, with specialized behavior for the given model.
 #[derive(Deref, DerefMut)]
 pub struct ModelContext<'a, T> {
     #[deref]
@@ -24,20 +25,24 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         Self { app, model_state }
     }
 
+    /// The entity id of the model backing this context.
     pub fn entity_id(&self) -> EntityId {
         self.model_state.entity_id
     }
 
+    /// Returns a handle to the model belonging to this context.
     pub fn handle(&self) -> Model<T> {
         self.weak_model()
             .upgrade()
             .expect("The entity must be alive if we have a model context")
     }
 
+    /// Returns a weak handle to the model belonging to this context.
     pub fn weak_model(&self) -> WeakModel<T> {
         self.model_state.clone()
     }
 
+    /// Arranges for the given function to be called whenever [ModelContext::notify] or [ViewContext::notify] is called with the given model or view.
     pub fn observe<W, E>(
         &mut self,
         entity: &E,
@@ -59,6 +64,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         })
     }
 
+    /// Subscribe to an event type from another model or view
     pub fn subscribe<T2, E, Evt>(
         &mut self,
         entity: &E,
@@ -81,6 +87,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         })
     }
 
+    /// Register a callback to be invoked when GPUI releases this model.
     pub fn on_release(
         &mut self,
         on_release: impl FnOnce(&mut T, &mut AppContext) + 'static,
@@ -99,6 +106,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         subscription
     }
 
+    /// Register a callback to be run on the release of another model or view
     pub fn observe_release<T2, E>(
         &mut self,
         entity: &E,
@@ -124,6 +132,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         subscription
     }
 
+    /// Register a callback to for updates to the given global
     pub fn observe_global<G: 'static>(
         &mut self,
         mut f: impl FnMut(&mut T, &mut ModelContext<'_, T>) + 'static,
@@ -140,6 +149,8 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         subscription
     }
 
+    /// Arrange for the given function to be invoked whenever the application is quit.
+    /// The future returned from this callback will be polled for up to [gpui::SHUTDOWN_TIMEOUT] until the app fully quits.
     pub fn on_app_quit<Fut>(
         &mut self,
         mut on_quit: impl FnMut(&mut T, &mut ModelContext<T>) -> Fut + 'static,
@@ -165,6 +176,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         subscription
     }
 
+    /// Tell GPUI that this model has changed and observers of it should be notified.
     pub fn notify(&mut self) {
         if self
             .app
@@ -177,6 +189,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         }
     }
 
+    /// Update the given global
     pub fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
     where
         G: 'static,
@@ -187,6 +200,9 @@ impl<'a, T: 'static> ModelContext<'a, T> {
         result
     }
 
+    /// Spawn the future returned by the given function.
+    /// The function is provided a weak handle to the model owned by this context and a context that can be held across await points.
+    /// The returned task must be held or detached.
     pub fn spawn<Fut, R>(&self, f: impl FnOnce(WeakModel<T>, AsyncAppContext) -> Fut) -> Task<R>
     where
         T: 'static,
@@ -199,6 +215,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
 }
 
 impl<'a, T> ModelContext<'a, T> {
+    /// Emit an event of the specified type, which can be handled by other entities that have subscribed via `subscribe` methods on their respective contexts.
     pub fn emit<Evt>(&mut self, event: Evt)
     where
         T: EventEmitter<Evt>,

crates/gpui/src/app/test_context.rs πŸ”—

@@ -1,11 +1,11 @@
 #![deny(missing_docs)]
 
 use crate::{
-    div, Action, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
-    BackgroundExecutor, ClipboardItem, Context, Entity, EventEmitter, ForegroundExecutor,
-    IntoElement, Keystroke, Model, ModelContext, Pixels, Platform, Render, Result, Size, Task,
-    TestDispatcher, TestPlatform, TestWindow, TextSystem, View, ViewContext, VisualContext,
-    WindowContext, WindowHandle, WindowOptions,
+    Action, AnyElement, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
+    AvailableSpace, BackgroundExecutor, Bounds, ClipboardItem, Context, Entity, EventEmitter,
+    ForegroundExecutor, InputEvent, Keystroke, Model, ModelContext, Pixels, Platform, Point,
+    Render, Result, Size, Task, TestDispatcher, TestPlatform, TestWindow, TextSystem, View,
+    ViewContext, VisualContext, WindowContext, WindowHandle, WindowOptions,
 };
 use anyhow::{anyhow, bail};
 use futures::{Stream, StreamExt};
@@ -167,10 +167,14 @@ impl TestAppContext {
     }
 
     /// Adds a new window with no content.
-    pub fn add_empty_window(&mut self) -> AnyWindowHandle {
+    pub fn add_empty_window(&mut self) -> &mut VisualTestContext {
         let mut cx = self.app.borrow_mut();
-        cx.open_window(WindowOptions::default(), |cx| cx.new_view(|_| EmptyView {}))
-            .any_handle
+        let window = cx.open_window(WindowOptions::default(), |cx| cx.new_view(|_| ()));
+        drop(cx);
+        let cx = Box::new(VisualTestContext::from_window(*window.deref(), self));
+        cx.run_until_parked();
+        // it might be nice to try and cleanup these at the end of each test.
+        Box::leak(cx)
     }
 
     /// Adds a new window, and returns its root view and a `VisualTestContext` which can be used
@@ -564,6 +568,11 @@ pub struct VisualTestContext {
 }
 
 impl<'a> VisualTestContext {
+    /// Get the underlying window handle underlying this context.
+    pub fn handle(&self) -> AnyWindowHandle {
+        self.window
+    }
+
     /// Provides the `WindowContext` for the duration of the closure.
     pub fn update<R>(&mut self, f: impl FnOnce(&mut WindowContext) -> R) -> R {
         self.cx.update_window(self.window, |_, cx| f(cx)).unwrap()
@@ -609,6 +618,46 @@ impl<'a> VisualTestContext {
         self.cx.simulate_input(self.window, input)
     }
 
+    /// Simulates the user resizing the window to the new size.
+    pub fn simulate_resize(&self, size: Size<Pixels>) {
+        self.simulate_window_resize(self.window, size)
+    }
+
+    /// debug_bounds returns the bounds of the element with the given selector.
+    pub fn debug_bounds(&mut self, selector: &'static str) -> Option<Bounds<Pixels>> {
+        self.update(|cx| cx.window.rendered_frame.debug_bounds.get(selector).copied())
+    }
+
+    /// Draw an element to the window. Useful for simulating events or actions
+    pub fn draw(
+        &mut self,
+        origin: Point<Pixels>,
+        space: Size<AvailableSpace>,
+        f: impl FnOnce(&mut WindowContext) -> AnyElement,
+    ) {
+        self.update(|cx| {
+            let entity_id = cx
+                .window
+                .root_view
+                .as_ref()
+                .expect("Can't draw to this window without a root view")
+                .entity_id();
+            cx.with_view_id(entity_id, |cx| {
+                f(cx).draw(origin, space, cx);
+            });
+
+            cx.refresh();
+        })
+    }
+
+    /// Simulate an event from the platform, e.g. a SrollWheelEvent
+    /// Make sure you've called [VisualTestContext::draw] first!
+    pub fn simulate_event<E: InputEvent>(&mut self, event: E) {
+        self.test_window(self.window)
+            .simulate_input(event.to_platform_input());
+        self.background_executor.run_until_parked();
+    }
+
     /// Simulates the user blurring the window.
     pub fn deactivate_window(&mut self) {
         if Some(self.window) == self.test_platform.active_window() {
@@ -763,12 +812,3 @@ impl AnyWindowHandle {
         self.update(cx, |_, cx| cx.new_view(build_view)).unwrap()
     }
 }
-
-/// An EmptyView for testing.
-pub struct EmptyView {}
-
-impl Render for EmptyView {
-    fn render(&mut self, _cx: &mut crate::ViewContext<Self>) -> impl IntoElement {
-        div()
-    }
-}

crates/gpui/src/element.rs πŸ”—

@@ -115,6 +115,12 @@ pub trait Render: 'static + Sized {
     fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement;
 }
 
+impl Render for () {
+    fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
+        ()
+    }
+}
+
 /// You can derive [`IntoElement`] on any type that implements this trait.
 /// It is used to allow views to be expressed in terms of abstract data.
 pub trait RenderOnce: 'static {

crates/gpui/src/elements/div.rs πŸ”—

@@ -416,6 +416,18 @@ pub trait InteractiveElement: Sized {
         self
     }
 
+    #[cfg(any(test, feature = "test-support"))]
+    fn debug_selector(mut self, f: impl FnOnce() -> String) -> Self {
+        self.interactivity().debug_selector = Some(f());
+        self
+    }
+
+    #[cfg(not(any(test, feature = "test-support")))]
+    #[inline]
+    fn debug_selector(self, _: impl FnOnce() -> String) -> Self {
+        self
+    }
+
     fn capture_any_mouse_down(
         mut self,
         listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@@ -911,6 +923,9 @@ pub struct Interactivity {
 
     #[cfg(debug_assertions)]
     pub location: Option<core::panic::Location<'static>>,
+
+    #[cfg(any(test, feature = "test-support"))]
+    pub debug_selector: Option<String>,
 }
 
 #[derive(Clone, Debug)]
@@ -980,6 +995,14 @@ impl Interactivity {
         let style = self.compute_style(Some(bounds), element_state, cx);
         let z_index = style.z_index.unwrap_or(0);
 
+        #[cfg(any(feature = "test-support", test))]
+        if let Some(debug_selector) = &self.debug_selector {
+            cx.window
+                .next_frame
+                .debug_bounds
+                .insert(debug_selector.clone(), bounds);
+        }
+
         let paint_hover_group_handler = |cx: &mut WindowContext| {
             let hover_group_bounds = self
                 .group_hover_style

crates/gpui/src/elements/list.rs πŸ”—

@@ -30,6 +30,7 @@ struct StateInner {
     logical_scroll_top: Option<ListOffset>,
     alignment: ListAlignment,
     overdraw: Pixels,
+    reset: bool,
     #[allow(clippy::type_complexity)]
     scroll_handler: Option<Box<dyn FnMut(&ListScrollEvent, &mut WindowContext)>>,
 }
@@ -92,11 +93,17 @@ impl ListState {
             alignment: orientation,
             overdraw,
             scroll_handler: None,
+            reset: false,
         })))
     }
 
+    /// Reset this instantiation of the list state.
+    ///
+    /// Note that this will cause scroll events to be dropped until the next paint.
     pub fn reset(&self, element_count: usize) {
         let state = &mut *self.0.borrow_mut();
+        state.reset = true;
+
         state.logical_scroll_top = None;
         state.items = SumTree::new();
         state
@@ -152,11 +159,13 @@ impl ListState {
             scroll_top.item_ix = item_count;
             scroll_top.offset_in_item = px(0.);
         }
+
         state.logical_scroll_top = Some(scroll_top);
     }
 
     pub fn scroll_to_reveal_item(&self, ix: usize) {
         let state = &mut *self.0.borrow_mut();
+
         let mut scroll_top = state.logical_scroll_top();
         let height = state
             .last_layout_bounds
@@ -187,9 +196,9 @@ impl ListState {
     /// Get the bounds for the given item in window coordinates.
     pub fn bounds_for_item(&self, ix: usize) -> Option<Bounds<Pixels>> {
         let state = &*self.0.borrow();
+
         let bounds = state.last_layout_bounds.unwrap_or_default();
         let scroll_top = state.logical_scroll_top();
-
         if ix < scroll_top.item_ix {
             return None;
         }
@@ -230,6 +239,12 @@ impl StateInner {
         delta: Point<Pixels>,
         cx: &mut WindowContext,
     ) {
+        // Drop scroll events after a reset, since we can't calculate
+        // the new logical scroll top without the item heights
+        if self.reset {
+            return;
+        }
+
         let scroll_max = (self.items.summary().height - height).max(px(0.));
         let new_scroll_top = (self.scroll_top(scroll_top) - delta.y)
             .max(px(0.))
@@ -325,6 +340,8 @@ impl Element for List {
     ) {
         let state = &mut *self.state.0.borrow_mut();
 
+        state.reset = false;
+
         // If the width of the list has changed, invalidate all cached item heights
         if state.last_layout_bounds.map_or(true, |last_bounds| {
             last_bounds.size.width != bounds.size.width
@@ -346,8 +363,9 @@ impl Element for List {
             height: AvailableSpace::MinContent,
         };
 
-        // Render items after the scroll top, including those in the trailing overdraw
         let mut cursor = old_items.cursor::<Count>();
+
+        // Render items after the scroll top, including those in the trailing overdraw
         cursor.seek(&Count(scroll_top.item_ix), Bias::Right, &());
         for (ix, item) in cursor.by_ref().enumerate() {
             let visible_height = rendered_height - scroll_top.offset_in_item;
@@ -461,6 +479,7 @@ impl Element for List {
 
         let list_state = self.state.clone();
         let height = bounds.size.height;
+
         cx.on_mouse_event(move |event: &ScrollWheelEvent, phase, cx| {
             if phase == DispatchPhase::Bubble
                 && bounds.contains(&event.position)
@@ -562,3 +581,49 @@ impl<'a> sum_tree::SeekTarget<'a, ListItemSummary, ListItemSummary> for Height {
         self.0.partial_cmp(&other.height).unwrap()
     }
 }
+
+#[cfg(test)]
+mod test {
+
+    use gpui::{ScrollDelta, ScrollWheelEvent};
+
+    use crate::{self as gpui, TestAppContext};
+
+    #[gpui::test]
+    fn test_reset_after_paint_before_scroll(cx: &mut TestAppContext) {
+        use crate::{div, list, point, px, size, Element, ListState, Styled};
+
+        let cx = cx.add_empty_window();
+
+        let state = ListState::new(5, crate::ListAlignment::Top, px(10.), |_, _| {
+            div().h(px(10.)).w_full().into_any()
+        });
+
+        // Ensure that the list is scrolled to the top
+        state.scroll_to(gpui::ListOffset {
+            item_ix: 0,
+            offset_in_item: px(0.0),
+        });
+
+        // Paint
+        cx.draw(
+            point(px(0.), px(0.)),
+            size(px(100.), px(20.)).into(),
+            |_| list(state.clone()).w_full().h_full().z_index(10).into_any(),
+        );
+
+        // Reset
+        state.reset(5);
+
+        // And then receive a scroll event _before_ the next paint
+        cx.simulate_event(ScrollWheelEvent {
+            position: point(px(1.), px(1.)),
+            delta: ScrollDelta::Pixels(point(px(0.), px(-500.))),
+            ..Default::default()
+        });
+
+        // Scroll position should stay at the top of the list
+        assert_eq!(state.logical_scroll_top().item_ix, 0);
+        assert_eq!(state.logical_scroll_top().offset_in_item, px(0.));
+    }
+}

crates/gpui/src/executor.rs πŸ”—

@@ -109,9 +109,10 @@ type AnyFuture<R> = Pin<Box<dyn 'static + Send + Future<Output = R>>>;
 
 /// BackgroundExecutor lets you run things on background threads.
 /// In production this is a thread pool with no ordering guarantees.
-/// In tests this is simalated by running tasks one by one in a deterministic
+/// In tests this is simulated by running tasks one by one in a deterministic
 /// (but arbitrary) order controlled by the `SEED` environment variable.
 impl BackgroundExecutor {
+    #[doc(hidden)]
     pub fn new(dispatcher: Arc<dyn PlatformDispatcher>) -> Self {
         Self { dispatcher }
     }
@@ -149,7 +150,7 @@ impl BackgroundExecutor {
         Task::Spawned(task)
     }
 
-    /// Used by the test harness to run an async test in a syncronous fashion.
+    /// Used by the test harness to run an async test in a synchronous fashion.
     #[cfg(any(test, feature = "test-support"))]
     #[track_caller]
     pub fn block_test<R>(&self, future: impl Future<Output = R>) -> R {
@@ -276,7 +277,7 @@ impl BackgroundExecutor {
 
     /// Returns a task that will complete after the given duration.
     /// Depending on other concurrent tasks the elapsed duration may be longer
-    /// than reqested.
+    /// than requested.
     pub fn timer(&self, duration: Duration) -> Task<()> {
         let (runnable, task) = async_task::spawn(async move {}, {
             let dispatcher = self.dispatcher.clone();

crates/gpui/src/interactive.rs πŸ”—

@@ -1,8 +1,14 @@
 use crate::{
-    div, point, Element, IntoElement, Keystroke, Modifiers, Pixels, Point, Render, ViewContext,
+    point, seal::Sealed, IntoElement, Keystroke, Modifiers, Pixels, Point, Render, ViewContext,
 };
 use smallvec::SmallVec;
-use std::{any::Any, fmt::Debug, marker::PhantomData, ops::Deref, path::PathBuf};
+use std::{any::Any, fmt::Debug, ops::Deref, path::PathBuf};
+
+pub trait InputEvent: Sealed + 'static {
+    fn to_platform_input(self) -> PlatformInput;
+}
+pub trait KeyEvent: InputEvent {}
+pub trait MouseEvent: InputEvent {}
 
 #[derive(Clone, Debug, Eq, PartialEq)]
 pub struct KeyDownEvent {
@@ -10,16 +16,40 @@ pub struct KeyDownEvent {
     pub is_held: bool,
 }
 
+impl Sealed for KeyDownEvent {}
+impl InputEvent for KeyDownEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::KeyDown(self)
+    }
+}
+impl KeyEvent for KeyDownEvent {}
+
 #[derive(Clone, Debug)]
 pub struct KeyUpEvent {
     pub keystroke: Keystroke,
 }
 
+impl Sealed for KeyUpEvent {}
+impl InputEvent for KeyUpEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::KeyUp(self)
+    }
+}
+impl KeyEvent for KeyUpEvent {}
+
 #[derive(Clone, Debug, Default)]
 pub struct ModifiersChangedEvent {
     pub modifiers: Modifiers,
 }
 
+impl Sealed for ModifiersChangedEvent {}
+impl InputEvent for ModifiersChangedEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::ModifiersChanged(self)
+    }
+}
+impl KeyEvent for ModifiersChangedEvent {}
+
 impl Deref for ModifiersChangedEvent {
     type Target = Modifiers;
 
@@ -30,9 +60,10 @@ impl Deref for ModifiersChangedEvent {
 
 /// The phase of a touch motion event.
 /// Based on the winit enum of the same name.
-#[derive(Clone, Copy, Debug)]
+#[derive(Clone, Copy, Debug, Default)]
 pub enum TouchPhase {
     Started,
+    #[default]
     Moved,
     Ended,
 }
@@ -45,6 +76,14 @@ pub struct MouseDownEvent {
     pub click_count: usize,
 }
 
+impl Sealed for MouseDownEvent {}
+impl InputEvent for MouseDownEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::MouseDown(self)
+    }
+}
+impl MouseEvent for MouseDownEvent {}
+
 #[derive(Clone, Debug, Default)]
 pub struct MouseUpEvent {
     pub button: MouseButton,
@@ -53,38 +92,20 @@ pub struct MouseUpEvent {
     pub click_count: usize,
 }
 
+impl Sealed for MouseUpEvent {}
+impl InputEvent for MouseUpEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::MouseUp(self)
+    }
+}
+impl MouseEvent for MouseUpEvent {}
+
 #[derive(Clone, Debug, Default)]
 pub struct ClickEvent {
     pub down: MouseDownEvent,
     pub up: MouseUpEvent,
 }
 
-pub struct Drag<S, R, V, E>
-where
-    R: Fn(&mut V, &mut ViewContext<V>) -> E,
-    V: 'static,
-    E: IntoElement,
-{
-    pub state: S,
-    pub render_drag_handle: R,
-    view_element_types: PhantomData<(V, E)>,
-}
-
-impl<S, R, V, E> Drag<S, R, V, E>
-where
-    R: Fn(&mut V, &mut ViewContext<V>) -> E,
-    V: 'static,
-    E: Element,
-{
-    pub fn new(state: S, render_drag_handle: R) -> Self {
-        Drag {
-            state,
-            render_drag_handle,
-            view_element_types: Default::default(),
-        }
-    }
-}
-
 #[derive(Hash, PartialEq, Eq, Copy, Clone, Debug)]
 pub enum MouseButton {
     Left,
@@ -130,13 +151,21 @@ pub struct MouseMoveEvent {
     pub modifiers: Modifiers,
 }
 
+impl Sealed for MouseMoveEvent {}
+impl InputEvent for MouseMoveEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::MouseMove(self)
+    }
+}
+impl MouseEvent for MouseMoveEvent {}
+
 impl MouseMoveEvent {
     pub fn dragging(&self) -> bool {
         self.pressed_button == Some(MouseButton::Left)
     }
 }
 
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, Default)]
 pub struct ScrollWheelEvent {
     pub position: Point<Pixels>,
     pub delta: ScrollDelta,
@@ -144,6 +173,14 @@ pub struct ScrollWheelEvent {
     pub touch_phase: TouchPhase,
 }
 
+impl Sealed for ScrollWheelEvent {}
+impl InputEvent for ScrollWheelEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::ScrollWheel(self)
+    }
+}
+impl MouseEvent for ScrollWheelEvent {}
+
 impl Deref for ScrollWheelEvent {
     type Target = Modifiers;
 
@@ -201,6 +238,14 @@ pub struct MouseExitEvent {
     pub modifiers: Modifiers,
 }
 
+impl Sealed for MouseExitEvent {}
+impl InputEvent for MouseExitEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::MouseExited(self)
+    }
+}
+impl MouseEvent for MouseExitEvent {}
+
 impl Deref for MouseExitEvent {
     type Target = Modifiers;
 
@@ -220,7 +265,7 @@ impl ExternalPaths {
 
 impl Render for ExternalPaths {
     fn render(&mut self, _: &mut ViewContext<Self>) -> impl IntoElement {
-        div() // Intentionally left empty because the platform will render icons for the dragged files
+        () // Intentionally left empty because the platform will render icons for the dragged files
     }
 }
 
@@ -239,8 +284,16 @@ pub enum FileDropEvent {
     Exited,
 }
 
+impl Sealed for FileDropEvent {}
+impl InputEvent for FileDropEvent {
+    fn to_platform_input(self) -> PlatformInput {
+        PlatformInput::FileDrop(self)
+    }
+}
+impl MouseEvent for FileDropEvent {}
+
 #[derive(Clone, Debug)]
-pub enum InputEvent {
+pub enum PlatformInput {
     KeyDown(KeyDownEvent),
     KeyUp(KeyUpEvent),
     ModifiersChanged(ModifiersChangedEvent),
@@ -252,19 +305,19 @@ pub enum InputEvent {
     FileDrop(FileDropEvent),
 }
 
-impl InputEvent {
+impl PlatformInput {
     pub fn position(&self) -> Option<Point<Pixels>> {
         match self {
-            InputEvent::KeyDown { .. } => None,
-            InputEvent::KeyUp { .. } => None,
-            InputEvent::ModifiersChanged { .. } => None,
-            InputEvent::MouseDown(event) => Some(event.position),
-            InputEvent::MouseUp(event) => Some(event.position),
-            InputEvent::MouseMove(event) => Some(event.position),
-            InputEvent::MouseExited(event) => Some(event.position),
-            InputEvent::ScrollWheel(event) => Some(event.position),
-            InputEvent::FileDrop(FileDropEvent::Exited) => None,
-            InputEvent::FileDrop(
+            PlatformInput::KeyDown { .. } => None,
+            PlatformInput::KeyUp { .. } => None,
+            PlatformInput::ModifiersChanged { .. } => None,
+            PlatformInput::MouseDown(event) => Some(event.position),
+            PlatformInput::MouseUp(event) => Some(event.position),
+            PlatformInput::MouseMove(event) => Some(event.position),
+            PlatformInput::MouseExited(event) => Some(event.position),
+            PlatformInput::ScrollWheel(event) => Some(event.position),
+            PlatformInput::FileDrop(FileDropEvent::Exited) => None,
+            PlatformInput::FileDrop(
                 FileDropEvent::Entered { position, .. }
                 | FileDropEvent::Pending { position, .. }
                 | FileDropEvent::Submit { position, .. },
@@ -274,29 +327,29 @@ impl InputEvent {
 
     pub fn mouse_event(&self) -> Option<&dyn Any> {
         match self {
-            InputEvent::KeyDown { .. } => None,
-            InputEvent::KeyUp { .. } => None,
-            InputEvent::ModifiersChanged { .. } => None,
-            InputEvent::MouseDown(event) => Some(event),
-            InputEvent::MouseUp(event) => Some(event),
-            InputEvent::MouseMove(event) => Some(event),
-            InputEvent::MouseExited(event) => Some(event),
-            InputEvent::ScrollWheel(event) => Some(event),
-            InputEvent::FileDrop(event) => Some(event),
+            PlatformInput::KeyDown { .. } => None,
+            PlatformInput::KeyUp { .. } => None,
+            PlatformInput::ModifiersChanged { .. } => None,
+            PlatformInput::MouseDown(event) => Some(event),
+            PlatformInput::MouseUp(event) => Some(event),
+            PlatformInput::MouseMove(event) => Some(event),
+            PlatformInput::MouseExited(event) => Some(event),
+            PlatformInput::ScrollWheel(event) => Some(event),
+            PlatformInput::FileDrop(event) => Some(event),
         }
     }
 
     pub fn keyboard_event(&self) -> Option<&dyn Any> {
         match self {
-            InputEvent::KeyDown(event) => Some(event),
-            InputEvent::KeyUp(event) => Some(event),
-            InputEvent::ModifiersChanged(event) => Some(event),
-            InputEvent::MouseDown(_) => None,
-            InputEvent::MouseUp(_) => None,
-            InputEvent::MouseMove(_) => None,
-            InputEvent::MouseExited(_) => None,
-            InputEvent::ScrollWheel(_) => None,
-            InputEvent::FileDrop(_) => None,
+            PlatformInput::KeyDown(event) => Some(event),
+            PlatformInput::KeyUp(event) => Some(event),
+            PlatformInput::ModifiersChanged(event) => Some(event),
+            PlatformInput::MouseDown(_) => None,
+            PlatformInput::MouseUp(_) => None,
+            PlatformInput::MouseMove(_) => None,
+            PlatformInput::MouseExited(_) => None,
+            PlatformInput::ScrollWheel(_) => None,
+            PlatformInput::FileDrop(_) => None,
         }
     }
 }

crates/gpui/src/keymap/matcher.rs πŸ”—

@@ -209,7 +209,6 @@ mod tests {
         );
         assert!(!matcher.has_pending_keystrokes());
 
-        eprintln!("PROBLEM AREA");
         // If a is prefixed, C will not be dispatched because there
         // was a pending binding for it
         assert_eq!(
@@ -445,7 +444,7 @@ mod tests {
             KeyMatch::Some(vec![Box::new(Dollar)])
         );
 
-        // handle Brazillian quote (quote key then space key)
+        // handle Brazilian quote (quote key then space key)
         assert_eq!(
             matcher.match_keystroke(
                 &Keystroke::parse("space->\"").unwrap(),
@@ -454,7 +453,7 @@ mod tests {
             KeyMatch::Some(vec![Box::new(Quote)])
         );
 
-        // handle ctrl+` on a brazillian keyboard
+        // handle ctrl+` on a brazilian keyboard
         assert_eq!(
             matcher.match_keystroke(&Keystroke::parse("ctrl-->`").unwrap(), &[context_a.clone()]),
             KeyMatch::Some(vec![Box::new(Backtick)])

crates/gpui/src/platform.rs πŸ”—

@@ -7,7 +7,7 @@ mod test;
 
 use crate::{
     Action, AnyWindowHandle, BackgroundExecutor, Bounds, DevicePixels, Font, FontId, FontMetrics,
-    FontRun, ForegroundExecutor, GlobalPixels, GlyphId, InputEvent, Keymap, LineLayout, Pixels,
+    FontRun, ForegroundExecutor, GlobalPixels, GlyphId, Keymap, LineLayout, Pixels, PlatformInput,
     Point, RenderGlyphParams, RenderImageParams, RenderSvgParams, Result, Scene, SharedString,
     Size, TaskLabel,
 };
@@ -88,7 +88,7 @@ pub(crate) trait Platform: 'static {
     fn on_resign_active(&self, callback: Box<dyn FnMut()>);
     fn on_quit(&self, callback: Box<dyn FnMut()>);
     fn on_reopen(&self, callback: Box<dyn FnMut()>);
-    fn on_event(&self, callback: Box<dyn FnMut(InputEvent) -> bool>);
+    fn on_event(&self, callback: Box<dyn FnMut(PlatformInput) -> bool>);
 
     fn set_menus(&self, menus: Vec<Menu>, keymap: &Keymap);
     fn on_app_menu_action(&self, callback: Box<dyn FnMut(&dyn Action)>);
@@ -114,15 +114,20 @@ pub(crate) trait Platform: 'static {
     fn delete_credentials(&self, url: &str) -> Result<()>;
 }
 
+/// A handle to a platform's display, e.g. a monitor or laptop screen.
 pub trait PlatformDisplay: Send + Sync + Debug {
+    /// Get the ID for this display
     fn id(&self) -> DisplayId;
+
     /// Returns a stable identifier for this display that can be persisted and used
     /// across system restarts.
     fn uuid(&self) -> Result<Uuid>;
-    fn as_any(&self) -> &dyn Any;
+
+    /// Get the bounds for this display
     fn bounds(&self) -> Bounds<GlobalPixels>;
 }
 
+/// An opaque identifier for a hardware display
 #[derive(PartialEq, Eq, Hash, Copy, Clone)]
 pub struct DisplayId(pub(crate) u32);
 
@@ -134,7 +139,7 @@ impl Debug for DisplayId {
 
 unsafe impl Send for DisplayId {}
 
-pub trait PlatformWindow {
+pub(crate) trait PlatformWindow {
     fn bounds(&self) -> WindowBounds;
     fn content_size(&self) -> Size<Pixels>;
     fn scale_factor(&self) -> f32;
@@ -155,7 +160,7 @@ pub trait PlatformWindow {
     fn zoom(&self);
     fn toggle_full_screen(&self);
     fn on_request_frame(&self, callback: Box<dyn FnMut()>);
-    fn on_input(&self, callback: Box<dyn FnMut(InputEvent) -> bool>);
+    fn on_input(&self, callback: Box<dyn FnMut(PlatformInput) -> bool>);
     fn on_active_status_change(&self, callback: Box<dyn FnMut(bool)>);
     fn on_resize(&self, callback: Box<dyn FnMut(Size<Pixels>, f32)>);
     fn on_fullscreen(&self, callback: Box<dyn FnMut(bool)>);
@@ -175,6 +180,9 @@ pub trait PlatformWindow {
     }
 }
 
+/// This type is public so that our test macro can generate and use it, but it should not
+/// be considered part of our public API.
+#[doc(hidden)]
 pub trait PlatformDispatcher: Send + Sync {
     fn is_main_thread(&self) -> bool;
     fn dispatch(&self, runnable: Runnable, label: Option<TaskLabel>);
@@ -190,9 +198,10 @@ pub trait PlatformDispatcher: Send + Sync {
     }
 }
 
-pub trait PlatformTextSystem: Send + Sync {
+pub(crate) trait PlatformTextSystem: Send + Sync {
     fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()>;
     fn all_font_names(&self) -> Vec<String>;
+    fn all_font_families(&self) -> Vec<String>;
     fn font_id(&self, descriptor: &Font) -> Result<FontId>;
     fn font_metrics(&self, font_id: FontId) -> FontMetrics;
     fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>>;
@@ -214,15 +223,21 @@ pub trait PlatformTextSystem: Send + Sync {
     ) -> Vec<usize>;
 }
 
+/// Basic metadata about the current application and operating system.
 #[derive(Clone, Debug)]
 pub struct AppMetadata {
+    /// The name of the current operating system
     pub os_name: &'static str,
+
+    /// The operating system's version
     pub os_version: Option<SemanticVersion>,
+
+    /// The current version of the application
     pub app_version: Option<SemanticVersion>,
 }
 
 #[derive(PartialEq, Eq, Hash, Clone)]
-pub enum AtlasKey {
+pub(crate) enum AtlasKey {
     Glyph(RenderGlyphParams),
     Svg(RenderSvgParams),
     Image(RenderImageParams),
@@ -262,19 +277,17 @@ impl From<RenderImageParams> for AtlasKey {
     }
 }
 
-pub trait PlatformAtlas: Send + Sync {
+pub(crate) trait PlatformAtlas: Send + Sync {
     fn get_or_insert_with<'a>(
         &self,
         key: &AtlasKey,
         build: &mut dyn FnMut() -> Result<(Size<DevicePixels>, Cow<'a, [u8]>)>,
     ) -> Result<AtlasTile>;
-
-    fn clear(&self);
 }
 
 #[derive(Clone, Debug, PartialEq, Eq)]
 #[repr(C)]
-pub struct AtlasTile {
+pub(crate) struct AtlasTile {
     pub(crate) texture_id: AtlasTextureId,
     pub(crate) tile_id: TileId,
     pub(crate) bounds: Bounds<DevicePixels>,

crates/gpui/src/platform/keystroke.rs πŸ”—

@@ -19,7 +19,7 @@ impl Keystroke {
     // the ime_key or the key. On some non-US keyboards keys we use in our
     // bindings are behind option (for example `$` is typed `alt-Γ§` on a Czech keyboard),
     // and on some keyboards the IME handler converts a sequence of keys into a
-    // specific character (for example `"` is typed as `" space` on a brazillian keyboard).
+    // specific character (for example `"` is typed as `" space` on a brazilian keyboard).
     pub fn match_candidates(&self) -> SmallVec<[Keystroke; 2]> {
         let mut possibilities = SmallVec::new();
         match self.ime_key.as_ref() {

crates/gpui/src/platform/mac.rs πŸ”—

@@ -10,7 +10,7 @@ mod open_type;
 mod platform;
 mod text_system;
 mod window;
-mod window_appearence;
+mod window_appearance;
 
 use crate::{px, size, GlobalPixels, Pixels, Size};
 use cocoa::{

crates/gpui/src/platform/mac/display.rs πŸ”—

@@ -11,7 +11,6 @@ use core_graphics::{
     geometry::{CGPoint, CGRect, CGSize},
 };
 use objc::{msg_send, sel, sel_impl};
-use std::any::Any;
 use uuid::Uuid;
 
 #[derive(Debug)]
@@ -154,10 +153,6 @@ impl PlatformDisplay for MacDisplay {
         ]))
     }
 
-    fn as_any(&self) -> &dyn Any {
-        self
-    }
-
     fn bounds(&self) -> Bounds<GlobalPixels> {
         unsafe {
             let native_bounds = CGDisplayBounds(self.0);

crates/gpui/src/platform/mac/events.rs πŸ”—

@@ -1,7 +1,7 @@
 use crate::{
-    point, px, InputEvent, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers, ModifiersChangedEvent,
-    MouseButton, MouseDownEvent, MouseExitEvent, MouseMoveEvent, MouseUpEvent, NavigationDirection,
-    Pixels, ScrollDelta, ScrollWheelEvent, TouchPhase,
+    point, px, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers, ModifiersChangedEvent, MouseButton,
+    MouseDownEvent, MouseExitEvent, MouseMoveEvent, MouseUpEvent, NavigationDirection, Pixels,
+    PlatformInput, ScrollDelta, ScrollWheelEvent, TouchPhase,
 };
 use cocoa::{
     appkit::{NSEvent, NSEventModifierFlags, NSEventPhase, NSEventType},
@@ -82,7 +82,7 @@ unsafe fn read_modifiers(native_event: id) -> Modifiers {
     }
 }
 
-impl InputEvent {
+impl PlatformInput {
     pub unsafe fn from_native(native_event: id, window_height: Option<Pixels>) -> Option<Self> {
         let event_type = native_event.eventType();
 

crates/gpui/src/platform/mac/metal_atlas.rs πŸ”—

@@ -74,20 +74,6 @@ impl PlatformAtlas for MetalAtlas {
             Ok(tile)
         }
     }
-
-    fn clear(&self) {
-        let mut lock = self.0.lock();
-        lock.tiles_by_key.clear();
-        for texture in &mut lock.monochrome_textures {
-            texture.clear();
-        }
-        for texture in &mut lock.polychrome_textures {
-            texture.clear();
-        }
-        for texture in &mut lock.path_textures {
-            texture.clear();
-        }
-    }
 }
 
 impl MetalAtlasState {

crates/gpui/src/platform/mac/metal_renderer.rs πŸ”—

@@ -14,6 +14,7 @@ use foreign_types::ForeignType;
 use media::core_video::CVMetalTextureCache;
 use metal::{CommandQueue, MTLPixelFormat, MTLResourceOptions, NSRange};
 use objc::{self, msg_send, sel, sel_impl};
+use smallvec::SmallVec;
 use std::{ffi::c_void, mem, ptr, sync::Arc};
 
 const SHADERS_METALLIB: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/shaders.metallib"));
@@ -81,7 +82,7 @@ impl MetalRenderer {
         ];
         let unit_vertices = device.new_buffer_with_data(
             unit_vertices.as_ptr() as *const c_void,
-            (unit_vertices.len() * mem::size_of::<u64>()) as u64,
+            mem::size_of_val(&unit_vertices) as u64,
             MTLResourceOptions::StorageModeManaged,
         );
         let instances = device.new_buffer(
@@ -339,7 +340,8 @@ impl MetalRenderer {
 
         for (texture_id, vertices) in vertices_by_texture_id {
             align_offset(offset);
-            let next_offset = *offset + vertices.len() * mem::size_of::<PathVertex<ScaledPixels>>();
+            let vertices_bytes_len = mem::size_of_val(vertices.as_slice());
+            let next_offset = *offset + vertices_bytes_len;
             if next_offset > INSTANCE_BUFFER_SIZE {
                 return None;
             }
@@ -372,7 +374,6 @@ impl MetalRenderer {
                 &texture_size as *const Size<DevicePixels> as *const _,
             );
 
-            let vertices_bytes_len = mem::size_of::<PathVertex<ScaledPixels>>() * vertices.len();
             let buffer_contents = unsafe { (self.instances.contents() as *mut u8).add(*offset) };
             unsafe {
                 ptr::copy_nonoverlapping(
@@ -429,7 +430,7 @@ impl MetalRenderer {
             &viewport_size as *const Size<DevicePixels> as *const _,
         );
 
-        let shadow_bytes_len = std::mem::size_of_val(shadows);
+        let shadow_bytes_len = mem::size_of_val(shadows);
         let buffer_contents = unsafe { (self.instances.contents() as *mut u8).add(*offset) };
 
         let next_offset = *offset + shadow_bytes_len;
@@ -490,7 +491,7 @@ impl MetalRenderer {
             &viewport_size as *const Size<DevicePixels> as *const _,
         );
 
-        let quad_bytes_len = std::mem::size_of_val(quads);
+        let quad_bytes_len = mem::size_of_val(quads);
         let buffer_contents = unsafe { (self.instances.contents() as *mut u8).add(*offset) };
 
         let next_offset = *offset + quad_bytes_len;
@@ -537,7 +538,7 @@ impl MetalRenderer {
         );
 
         let mut prev_texture_id = None;
-        let mut sprites = Vec::new();
+        let mut sprites = SmallVec::<[_; 1]>::new();
         let mut paths_and_tiles = paths
             .iter()
             .map(|path| (path, tiles_by_path_id.get(&path.id).unwrap()))
@@ -590,7 +591,7 @@ impl MetalRenderer {
                 command_encoder
                     .set_fragment_texture(SpriteInputIndex::AtlasTexture as u64, Some(&texture));
 
-                let sprite_bytes_len = mem::size_of::<MonochromeSprite>() * sprites.len();
+                let sprite_bytes_len = mem::size_of_val(sprites.as_slice());
                 let next_offset = *offset + sprite_bytes_len;
                 if next_offset > INSTANCE_BUFFER_SIZE {
                     return false;
@@ -655,21 +656,22 @@ impl MetalRenderer {
             &viewport_size as *const Size<DevicePixels> as *const _,
         );
 
-        let quad_bytes_len = std::mem::size_of_val(underlines);
+        let underline_bytes_len = mem::size_of_val(underlines);
         let buffer_contents = unsafe { (self.instances.contents() as *mut u8).add(*offset) };
+
+        let next_offset = *offset + underline_bytes_len;
+        if next_offset > INSTANCE_BUFFER_SIZE {
+            return false;
+        }
+
         unsafe {
             ptr::copy_nonoverlapping(
                 underlines.as_ptr() as *const u8,
                 buffer_contents,
-                quad_bytes_len,
+                underline_bytes_len,
             );
         }
 
-        let next_offset = *offset + quad_bytes_len;
-        if next_offset > INSTANCE_BUFFER_SIZE {
-            return false;
-        }
-
         command_encoder.draw_primitives_instanced(
             metal::MTLPrimitiveType::Triangle,
             0,
@@ -726,7 +728,7 @@ impl MetalRenderer {
         );
         command_encoder.set_fragment_texture(SpriteInputIndex::AtlasTexture as u64, Some(&texture));
 
-        let sprite_bytes_len = std::mem::size_of_val(sprites);
+        let sprite_bytes_len = mem::size_of_val(sprites);
         let buffer_contents = unsafe { (self.instances.contents() as *mut u8).add(*offset) };
 
         let next_offset = *offset + sprite_bytes_len;
@@ -798,7 +800,7 @@ impl MetalRenderer {
         );
         command_encoder.set_fragment_texture(SpriteInputIndex::AtlasTexture as u64, Some(&texture));
 
-        let sprite_bytes_len = std::mem::size_of_val(sprites);
+        let sprite_bytes_len = mem::size_of_val(sprites);
         let buffer_contents = unsafe { (self.instances.contents() as *mut u8).add(*offset) };
 
         let next_offset = *offset + sprite_bytes_len;

crates/gpui/src/platform/mac/platform.rs πŸ”—

@@ -1,8 +1,8 @@
 use super::{events::key_to_native, BoolExt};
 use crate::{
     Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DisplayId,
-    ForegroundExecutor, InputEvent, Keymap, MacDispatcher, MacDisplay, MacDisplayLinker,
-    MacTextSystem, MacWindow, Menu, MenuItem, PathPromptOptions, Platform, PlatformDisplay,
+    ForegroundExecutor, Keymap, MacDispatcher, MacDisplay, MacDisplayLinker, MacTextSystem,
+    MacWindow, Menu, MenuItem, PathPromptOptions, Platform, PlatformDisplay, PlatformInput,
     PlatformTextSystem, PlatformWindow, Result, SemanticVersion, VideoTimestamp, WindowOptions,
 };
 use anyhow::anyhow;
@@ -153,7 +153,7 @@ pub struct MacPlatformState {
     resign_active: Option<Box<dyn FnMut()>>,
     reopen: Option<Box<dyn FnMut()>>,
     quit: Option<Box<dyn FnMut()>>,
-    event: Option<Box<dyn FnMut(InputEvent) -> bool>>,
+    event: Option<Box<dyn FnMut(PlatformInput) -> bool>>,
     menu_command: Option<Box<dyn FnMut(&dyn Action)>>,
     validate_menu_command: Option<Box<dyn FnMut(&dyn Action) -> bool>>,
     will_open_menu: Option<Box<dyn FnMut()>>,
@@ -637,7 +637,7 @@ impl Platform for MacPlatform {
         self.0.lock().reopen = Some(callback);
     }
 
-    fn on_event(&self, callback: Box<dyn FnMut(InputEvent) -> bool>) {
+    fn on_event(&self, callback: Box<dyn FnMut(PlatformInput) -> bool>) {
         self.0.lock().event = Some(callback);
     }
 
@@ -976,7 +976,7 @@ unsafe fn get_mac_platform(object: &mut Object) -> &MacPlatform {
 
 extern "C" fn send_event(this: &mut Object, _sel: Sel, native_event: id) {
     unsafe {
-        if let Some(event) = InputEvent::from_native(native_event, None) {
+        if let Some(event) = PlatformInput::from_native(native_event, None) {
             let platform = get_mac_platform(this);
             let mut lock = platform.0.lock();
             if let Some(mut callback) = lock.event.take() {

crates/gpui/src/platform/mac/text_system.rs πŸ”—

@@ -85,11 +85,24 @@ impl PlatformTextSystem for MacTextSystem {
         };
         let mut names = BTreeSet::new();
         for descriptor in descriptors.into_iter() {
-            names.insert(descriptor.display_name());
+            names.insert(descriptor.font_name());
+            names.insert(descriptor.family_name());
+            names.insert(descriptor.style_name());
+        }
+        if let Ok(fonts_in_memory) = self.0.read().memory_source.all_families() {
+            names.extend(fonts_in_memory);
         }
         names.into_iter().collect()
     }
 
+    fn all_font_families(&self) -> Vec<String> {
+        self.0
+            .read()
+            .system_source
+            .all_families()
+            .expect("core text should never return an error")
+    }
+
     fn font_id(&self, font: &Font) -> Result<FontId> {
         let lock = self.0.upgradable_read();
         if let Some(font_id) = lock.font_selections.get(font) {

crates/gpui/src/platform/mac/window.rs πŸ”—

@@ -1,9 +1,9 @@
 use super::{display_bounds_from_native, ns_string, MacDisplay, MetalRenderer, NSRange};
 use crate::{
     display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, ExternalPaths,
-    FileDropEvent, ForegroundExecutor, GlobalPixels, InputEvent, KeyDownEvent, Keystroke,
-    Modifiers, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
-    Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point,
+    FileDropEvent, ForegroundExecutor, GlobalPixels, KeyDownEvent, Keystroke, Modifiers,
+    ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
+    PlatformAtlas, PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow, Point,
     PromptLevel, Size, Timer, WindowAppearance, WindowBounds, WindowKind, WindowOptions,
 };
 use block::ConcreteBlock;
@@ -319,7 +319,7 @@ struct MacWindowState {
     renderer: MetalRenderer,
     kind: WindowKind,
     request_frame_callback: Option<Box<dyn FnMut()>>,
-    event_callback: Option<Box<dyn FnMut(InputEvent) -> bool>>,
+    event_callback: Option<Box<dyn FnMut(PlatformInput) -> bool>>,
     activate_callback: Option<Box<dyn FnMut(bool)>>,
     resize_callback: Option<Box<dyn FnMut(Size<Pixels>, f32)>>,
     fullscreen_callback: Option<Box<dyn FnMut(bool)>>,
@@ -333,7 +333,7 @@ struct MacWindowState {
     synthetic_drag_counter: usize,
     last_fresh_keydown: Option<Keystroke>,
     traffic_light_position: Option<Point<Pixels>>,
-    previous_modifiers_changed_event: Option<InputEvent>,
+    previous_modifiers_changed_event: Option<PlatformInput>,
     // State tracking what the IME did after the last request
     ime_state: ImeState,
     // Retains the last IME Text
@@ -928,7 +928,7 @@ impl PlatformWindow for MacWindow {
         self.0.as_ref().lock().request_frame_callback = Some(callback);
     }
 
-    fn on_input(&self, callback: Box<dyn FnMut(InputEvent) -> bool>) {
+    fn on_input(&self, callback: Box<dyn FnMut(PlatformInput) -> bool>) {
         self.0.as_ref().lock().event_callback = Some(callback);
     }
 
@@ -1053,9 +1053,9 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
     let mut lock = window_state.as_ref().lock();
 
     let window_height = lock.content_size().height;
-    let event = unsafe { InputEvent::from_native(native_event, Some(window_height)) };
+    let event = unsafe { PlatformInput::from_native(native_event, Some(window_height)) };
 
-    if let Some(InputEvent::KeyDown(event)) = event {
+    if let Some(PlatformInput::KeyDown(event)) = event {
         // For certain keystrokes, macOS will first dispatch a "key equivalent" event.
         // If that event isn't handled, it will then dispatch a "key down" event. GPUI
         // makes no distinction between these two types of events, so we need to ignore
@@ -1102,7 +1102,7 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
                         .flatten()
                         .is_some();
                 if !is_composing {
-                    handled = callback(InputEvent::KeyDown(event));
+                    handled = callback(PlatformInput::KeyDown(event));
                 }
 
                 if !handled {
@@ -1146,11 +1146,11 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
     let is_active = unsafe { lock.native_window.isKeyWindow() == YES };
 
     let window_height = lock.content_size().height;
-    let event = unsafe { InputEvent::from_native(native_event, Some(window_height)) };
+    let event = unsafe { PlatformInput::from_native(native_event, Some(window_height)) };
 
     if let Some(mut event) = event {
         match &mut event {
-            InputEvent::MouseDown(
+            PlatformInput::MouseDown(
                 event @ MouseDownEvent {
                     button: MouseButton::Left,
                     modifiers: Modifiers { control: true, .. },
@@ -1172,7 +1172,7 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
             // Because we map a ctrl-left_down to a right_down -> right_up let's ignore
             // the ctrl-left_up to avoid having a mismatch in button down/up events if the
             // user is still holding ctrl when releasing the left mouse button
-            InputEvent::MouseUp(
+            PlatformInput::MouseUp(
                 event @ MouseUpEvent {
                     button: MouseButton::Left,
                     modifiers: Modifiers { control: true, .. },
@@ -1194,7 +1194,7 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
         };
 
         match &event {
-            InputEvent::MouseMove(
+            PlatformInput::MouseMove(
                 event @ MouseMoveEvent {
                     pressed_button: Some(_),
                     ..
@@ -1216,15 +1216,15 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
                 }
             }
 
-            InputEvent::MouseMove(_) if !(is_active || lock.kind == WindowKind::PopUp) => return,
+            PlatformInput::MouseMove(_) if !(is_active || lock.kind == WindowKind::PopUp) => return,
 
-            InputEvent::MouseUp(MouseUpEvent { .. }) => {
+            PlatformInput::MouseUp(MouseUpEvent { .. }) => {
                 lock.synthetic_drag_counter += 1;
             }
 
-            InputEvent::ModifiersChanged(ModifiersChangedEvent { modifiers }) => {
+            PlatformInput::ModifiersChanged(ModifiersChangedEvent { modifiers }) => {
                 // Only raise modifiers changed event when they have actually changed
-                if let Some(InputEvent::ModifiersChanged(ModifiersChangedEvent {
+                if let Some(PlatformInput::ModifiersChanged(ModifiersChangedEvent {
                     modifiers: prev_modifiers,
                 })) = &lock.previous_modifiers_changed_event
                 {
@@ -1258,7 +1258,7 @@ extern "C" fn cancel_operation(this: &Object, _sel: Sel, _sender: id) {
         key: ".".into(),
         ime_key: None,
     };
-    let event = InputEvent::KeyDown(KeyDownEvent {
+    let event = PlatformInput::KeyDown(KeyDownEvent {
         keystroke: keystroke.clone(),
         is_held: false,
     });
@@ -1655,7 +1655,7 @@ extern "C" fn dragging_entered(this: &Object, _: Sel, dragging_info: id) -> NSDr
     if send_new_event(&window_state, {
         let position = drag_event_position(&window_state, dragging_info);
         let paths = external_paths_from_event(dragging_info);
-        InputEvent::FileDrop(FileDropEvent::Entered { position, paths })
+        PlatformInput::FileDrop(FileDropEvent::Entered { position, paths })
     }) {
         window_state.lock().external_files_dragged = true;
         NSDragOperationCopy
@@ -1669,7 +1669,7 @@ extern "C" fn dragging_updated(this: &Object, _: Sel, dragging_info: id) -> NSDr
     let position = drag_event_position(&window_state, dragging_info);
     if send_new_event(
         &window_state,
-        InputEvent::FileDrop(FileDropEvent::Pending { position }),
+        PlatformInput::FileDrop(FileDropEvent::Pending { position }),
     ) {
         NSDragOperationCopy
     } else {
@@ -1679,7 +1679,10 @@ extern "C" fn dragging_updated(this: &Object, _: Sel, dragging_info: id) -> NSDr
 
 extern "C" fn dragging_exited(this: &Object, _: Sel, _: id) {
     let window_state = unsafe { get_window_state(this) };
-    send_new_event(&window_state, InputEvent::FileDrop(FileDropEvent::Exited));
+    send_new_event(
+        &window_state,
+        PlatformInput::FileDrop(FileDropEvent::Exited),
+    );
     window_state.lock().external_files_dragged = false;
 }
 
@@ -1688,7 +1691,7 @@ extern "C" fn perform_drag_operation(this: &Object, _: Sel, dragging_info: id) -
     let position = drag_event_position(&window_state, dragging_info);
     if send_new_event(
         &window_state,
-        InputEvent::FileDrop(FileDropEvent::Submit { position }),
+        PlatformInput::FileDrop(FileDropEvent::Submit { position }),
     ) {
         YES
     } else {
@@ -1712,7 +1715,10 @@ fn external_paths_from_event(dragging_info: *mut Object) -> ExternalPaths {
 
 extern "C" fn conclude_drag_operation(this: &Object, _: Sel, _: id) {
     let window_state = unsafe { get_window_state(this) };
-    send_new_event(&window_state, InputEvent::FileDrop(FileDropEvent::Exited));
+    send_new_event(
+        &window_state,
+        PlatformInput::FileDrop(FileDropEvent::Exited),
+    );
 }
 
 async fn synthetic_drag(
@@ -1727,7 +1733,7 @@ async fn synthetic_drag(
             if lock.synthetic_drag_counter == drag_id {
                 if let Some(mut callback) = lock.event_callback.take() {
                     drop(lock);
-                    callback(InputEvent::MouseMove(event.clone()));
+                    callback(PlatformInput::MouseMove(event.clone()));
                     window_state.lock().event_callback = Some(callback);
                 }
             } else {
@@ -1737,7 +1743,7 @@ async fn synthetic_drag(
     }
 }
 
-fn send_new_event(window_state_lock: &Mutex<MacWindowState>, e: InputEvent) -> bool {
+fn send_new_event(window_state_lock: &Mutex<MacWindowState>, e: PlatformInput) -> bool {
     let window_state = window_state_lock.lock().event_callback.take();
     if let Some(mut callback) = window_state {
         callback(e);

crates/gpui/src/platform/test/display.rs πŸ”—

@@ -31,10 +31,6 @@ impl PlatformDisplay for TestDisplay {
         Ok(self.uuid)
     }
 
-    fn as_any(&self) -> &dyn std::any::Any {
-        unimplemented!()
-    }
-
     fn bounds(&self) -> crate::Bounds<crate::GlobalPixels> {
         self.bounds
     }

crates/gpui/src/platform/test/platform.rs πŸ”—

@@ -239,7 +239,7 @@ impl Platform for TestPlatform {
         unimplemented!()
     }
 
-    fn on_event(&self, _callback: Box<dyn FnMut(crate::InputEvent) -> bool>) {
+    fn on_event(&self, _callback: Box<dyn FnMut(crate::PlatformInput) -> bool>) {
         unimplemented!()
     }
 

crates/gpui/src/platform/test/window.rs πŸ”—

@@ -1,7 +1,7 @@
 use crate::{
-    px, AnyWindowHandle, AtlasKey, AtlasTextureId, AtlasTile, Bounds, InputEvent, KeyDownEvent,
-    Keystroke, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point,
-    Size, TestPlatform, TileId, WindowAppearance, WindowBounds, WindowOptions,
+    px, AnyWindowHandle, AtlasKey, AtlasTextureId, AtlasTile, Bounds, KeyDownEvent, Keystroke,
+    Pixels, PlatformAtlas, PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow,
+    Point, Size, TestPlatform, TileId, WindowAppearance, WindowBounds, WindowOptions,
 };
 use collections::HashMap;
 use parking_lot::Mutex;
@@ -19,7 +19,7 @@ pub struct TestWindowState {
     platform: Weak<TestPlatform>,
     sprite_atlas: Arc<dyn PlatformAtlas>,
     pub(crate) should_close_handler: Option<Box<dyn FnMut() -> bool>>,
-    input_callback: Option<Box<dyn FnMut(InputEvent) -> bool>>,
+    input_callback: Option<Box<dyn FnMut(PlatformInput) -> bool>>,
     active_status_change_callback: Option<Box<dyn FnMut(bool)>>,
     resize_callback: Option<Box<dyn FnMut(Size<Pixels>, f32)>>,
     moved_callback: Option<Box<dyn FnMut()>>,
@@ -85,7 +85,7 @@ impl TestWindow {
         self.0.lock().active_status_change_callback = Some(callback);
     }
 
-    pub fn simulate_input(&mut self, event: InputEvent) -> bool {
+    pub fn simulate_input(&mut self, event: PlatformInput) -> bool {
         let mut lock = self.0.lock();
         let Some(mut callback) = lock.input_callback.take() else {
             return false;
@@ -97,7 +97,7 @@ impl TestWindow {
     }
 
     pub fn simulate_keystroke(&mut self, keystroke: Keystroke, is_held: bool) {
-        if self.simulate_input(InputEvent::KeyDown(KeyDownEvent {
+        if self.simulate_input(PlatformInput::KeyDown(KeyDownEvent {
             keystroke: keystroke.clone(),
             is_held,
         })) {
@@ -220,7 +220,7 @@ impl PlatformWindow for TestWindow {
 
     fn on_request_frame(&self, _callback: Box<dyn FnMut()>) {}
 
-    fn on_input(&self, callback: Box<dyn FnMut(crate::InputEvent) -> bool>) {
+    fn on_input(&self, callback: Box<dyn FnMut(crate::PlatformInput) -> bool>) {
         self.0.lock().input_callback = Some(callback)
     }
 
@@ -325,10 +325,4 @@ impl PlatformAtlas for TestAtlas {
 
         Ok(state.tiles[key].clone())
     }
-
-    fn clear(&self) {
-        let mut state = self.0.lock();
-        state.tiles = HashMap::default();
-        state.next_id = 0;
-    }
 }

crates/gpui/src/scene.rs πŸ”—

@@ -93,7 +93,7 @@ impl Scene {
         }
     }
 
-    pub fn insert(&mut self, order: &StackingOrder, primitive: impl Into<Primitive>) {
+    pub(crate) fn insert(&mut self, order: &StackingOrder, primitive: impl Into<Primitive>) {
         let primitive = primitive.into();
         let clipped_bounds = primitive
             .bounds()
@@ -299,8 +299,8 @@ impl<'a> Iterator for BatchIterator<'a> {
 
         let first = orders_and_kinds[0];
         let second = orders_and_kinds[1];
-        let (batch_kind, max_order) = if first.0.is_some() {
-            (first.1, second.0.unwrap_or(u32::MAX))
+        let (batch_kind, max_order_and_kind) = if first.0.is_some() {
+            (first.1, (second.0.unwrap_or(u32::MAX), second.1))
         } else {
             return None;
         };
@@ -312,7 +312,7 @@ impl<'a> Iterator for BatchIterator<'a> {
                 self.shadows_iter.next();
                 while self
                     .shadows_iter
-                    .next_if(|shadow| shadow.order < max_order)
+                    .next_if(|shadow| (shadow.order, batch_kind) < max_order_and_kind)
                     .is_some()
                 {
                     shadows_end += 1;
@@ -328,7 +328,7 @@ impl<'a> Iterator for BatchIterator<'a> {
                 self.quads_iter.next();
                 while self
                     .quads_iter
-                    .next_if(|quad| quad.order < max_order)
+                    .next_if(|quad| (quad.order, batch_kind) < max_order_and_kind)
                     .is_some()
                 {
                     quads_end += 1;
@@ -342,7 +342,7 @@ impl<'a> Iterator for BatchIterator<'a> {
                 self.paths_iter.next();
                 while self
                     .paths_iter
-                    .next_if(|path| path.order < max_order)
+                    .next_if(|path| (path.order, batch_kind) < max_order_and_kind)
                     .is_some()
                 {
                     paths_end += 1;
@@ -356,7 +356,7 @@ impl<'a> Iterator for BatchIterator<'a> {
                 self.underlines_iter.next();
                 while self
                     .underlines_iter
-                    .next_if(|underline| underline.order < max_order)
+                    .next_if(|underline| (underline.order, batch_kind) < max_order_and_kind)
                     .is_some()
                 {
                     underlines_end += 1;
@@ -374,7 +374,8 @@ impl<'a> Iterator for BatchIterator<'a> {
                 while self
                     .monochrome_sprites_iter
                     .next_if(|sprite| {
-                        sprite.order < max_order && sprite.tile.texture_id == texture_id
+                        (sprite.order, batch_kind) < max_order_and_kind
+                            && sprite.tile.texture_id == texture_id
                     })
                     .is_some()
                 {
@@ -394,7 +395,8 @@ impl<'a> Iterator for BatchIterator<'a> {
                 while self
                     .polychrome_sprites_iter
                     .next_if(|sprite| {
-                        sprite.order < max_order && sprite.tile.texture_id == texture_id
+                        (sprite.order, batch_kind) < max_order_and_kind
+                            && sprite.tile.texture_id == texture_id
                     })
                     .is_some()
                 {
@@ -412,7 +414,7 @@ impl<'a> Iterator for BatchIterator<'a> {
                 self.surfaces_iter.next();
                 while self
                     .surfaces_iter
-                    .next_if(|surface| surface.order < max_order)
+                    .next_if(|surface| (surface.order, batch_kind) < max_order_and_kind)
                     .is_some()
                 {
                     surfaces_end += 1;
@@ -438,7 +440,7 @@ pub enum PrimitiveKind {
     Surface,
 }
 
-pub enum Primitive {
+pub(crate) enum Primitive {
     Shadow(Shadow),
     Quad(Quad),
     Path(Path<ScaledPixels>),
@@ -587,7 +589,7 @@ impl From<Shadow> for Primitive {
 
 #[derive(Clone, Debug, Eq, PartialEq)]
 #[repr(C)]
-pub struct MonochromeSprite {
+pub(crate) struct MonochromeSprite {
     pub view_id: ViewId,
     pub layer_id: LayerId,
     pub order: DrawOrder,
@@ -620,7 +622,7 @@ impl From<MonochromeSprite> for Primitive {
 
 #[derive(Clone, Debug, Eq, PartialEq)]
 #[repr(C)]
-pub struct PolychromeSprite {
+pub(crate) struct PolychromeSprite {
     pub view_id: ViewId,
     pub layer_id: LayerId,
     pub order: DrawOrder,

crates/gpui/src/style.rs πŸ”—

@@ -42,7 +42,7 @@ pub struct Style {
     #[refineable]
     pub inset: Edges<Length>,
 
-    // Size properies
+    // Size properties
     /// Sets the initial size of the item
     #[refineable]
     pub size: Size<Length>,
@@ -79,7 +79,7 @@ pub struct Style {
     #[refineable]
     pub gap: Size<DefiniteLength>,
 
-    // Flexbox properies
+    // Flexbox properties
     /// Which direction does the main axis flow in?
     pub flex_direction: FlexDirection,
     /// Should elements wrap, or stay in a single line?
@@ -386,7 +386,7 @@ impl Style {
 
         let background_color = self.background.as_ref().and_then(Fill::color);
         if background_color.map_or(false, |color| !color.is_transparent()) {
-            cx.with_z_index(1, |cx| {
+            cx.with_z_index(0, |cx| {
                 let mut border_color = background_color.unwrap_or_default();
                 border_color.a = 0.;
                 cx.paint_quad(quad(
@@ -399,12 +399,12 @@ impl Style {
             });
         }
 
-        cx.with_z_index(2, |cx| {
+        cx.with_z_index(0, |cx| {
             continuation(cx);
         });
 
         if self.is_border_visible() {
-            cx.with_z_index(3, |cx| {
+            cx.with_z_index(0, |cx| {
                 let corner_radii = self.corner_radii.to_pixels(bounds.size, rem_size);
                 let border_widths = self.border_widths.to_pixels(rem_size);
                 let max_border_width = border_widths.max();
@@ -502,7 +502,7 @@ impl Default for Style {
             max_size: Size::auto(),
             aspect_ratio: None,
             gap: Size::default(),
-            // Aligment
+            // Alignment
             align_items: None,
             align_self: None,
             align_content: None,

crates/gpui/src/text_system.rs πŸ”—

@@ -13,7 +13,7 @@ use crate::{
     SharedString, Size, UnderlineStyle,
 };
 use anyhow::anyhow;
-use collections::{FxHashMap, FxHashSet};
+use collections::{BTreeSet, FxHashMap, FxHashSet};
 use core::fmt;
 use itertools::Itertools;
 use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
@@ -47,7 +47,7 @@ pub struct TextSystem {
 }
 
 impl TextSystem {
-    pub fn new(platform_text_system: Arc<dyn PlatformTextSystem>) -> Self {
+    pub(crate) fn new(platform_text_system: Arc<dyn PlatformTextSystem>) -> Self {
         TextSystem {
             line_layout_cache: Arc::new(LineLayoutCache::new(platform_text_system.clone())),
             platform_text_system,
@@ -66,15 +66,18 @@ impl TextSystem {
     }
 
     pub fn all_font_names(&self) -> Vec<String> {
-        let mut families = self.platform_text_system.all_font_names();
-        families.append(
-            &mut self
-                .fallback_font_stack
+        let mut names: BTreeSet<_> = self
+            .platform_text_system
+            .all_font_names()
+            .into_iter()
+            .collect();
+        names.extend(self.platform_text_system.all_font_families().into_iter());
+        names.extend(
+            self.fallback_font_stack
                 .iter()
-                .map(|font| font.family.to_string())
-                .collect(),
+                .map(|font| font.family.to_string()),
         );
-        families
+        names.into_iter().collect()
     }
     pub fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()> {
         self.platform_text_system.add_fonts(fonts)

crates/gpui/src/text_system/line_wrapper.rs πŸ”—

@@ -13,7 +13,7 @@ pub struct LineWrapper {
 impl LineWrapper {
     pub const MAX_INDENT: u32 = 256;
 
-    pub fn new(
+    pub(crate) fn new(
         font_id: FontId,
         font_size: Pixels,
         text_system: Arc<dyn PlatformTextSystem>,

crates/gpui/src/view.rs πŸ”—

@@ -1,3 +1,5 @@
+#![deny(missing_docs)]
+
 use crate::{
     seal::Sealed, AnyElement, AnyModel, AnyWeakModel, AppContext, AvailableSpace, BorrowWindow,
     Bounds, ContentMask, Element, ElementId, Entity, EntityId, Flatten, FocusHandle, FocusableView,
@@ -11,12 +13,16 @@ use std::{
     hash::{Hash, Hasher},
 };
 
+/// A view is a piece of state that can be presented on screen by implementing the [Render] trait.
+/// Views implement [Element] and can composed with other views, and every window is created with a root view.
 pub struct View<V> {
+    /// A view is just a [Model] whose type implements `Render`, and the model is accessible via this field.
     pub model: Model<V>,
 }
 
 impl<V> Sealed for View<V> {}
 
+#[doc(hidden)]
 pub struct AnyViewState {
     root_style: Style,
     cache_key: Option<ViewCacheKey>,
@@ -58,6 +64,7 @@ impl<V: 'static> View<V> {
         Entity::downgrade(self)
     }
 
+    /// Update the view's state with the given function, which is passed a mutable reference and a context.
     pub fn update<C, R>(
         &self,
         cx: &mut C,
@@ -69,10 +76,12 @@ impl<V: 'static> View<V> {
         cx.update_view(self, f)
     }
 
+    /// Obtain a read-only reference to this view's state.
     pub fn read<'a>(&self, cx: &'a AppContext) -> &'a V {
         self.model.read(cx)
     }
 
+    /// Gets a [FocusHandle] for this view when its state implements [FocusableView].
     pub fn focus_handle(&self, cx: &AppContext) -> FocusHandle
     where
         V: FocusableView,
@@ -131,19 +140,24 @@ impl<V> PartialEq for View<V> {
 
 impl<V> Eq for View<V> {}
 
+/// A weak variant of [View] which does not prevent the view from being released.
 pub struct WeakView<V> {
     pub(crate) model: WeakModel<V>,
 }
 
 impl<V: 'static> WeakView<V> {
+    /// Gets the entity id associated with this handle.
     pub fn entity_id(&self) -> EntityId {
         self.model.entity_id
     }
 
+    /// Obtain a strong handle for the view if it hasn't been released.
     pub fn upgrade(&self) -> Option<View<V>> {
         Entity::upgrade_from(self)
     }
 
+    /// Update this view's state if it hasn't been released.
+    /// Returns an error if this view has been released.
     pub fn update<C, R>(
         &self,
         cx: &mut C,
@@ -157,9 +171,10 @@ impl<V: 'static> WeakView<V> {
         Ok(view.update(cx, f)).flatten()
     }
 
+    /// Assert that the view referenced by this handle has been released.
     #[cfg(any(test, feature = "test-support"))]
-    pub fn assert_dropped(&self) {
-        self.model.assert_dropped()
+    pub fn assert_released(&self) {
+        self.model.assert_released()
     }
 }
 
@@ -185,6 +200,7 @@ impl<V> PartialEq for WeakView<V> {
 
 impl<V> Eq for WeakView<V> {}
 
+/// A dynamically-typed handle to a view, which can be downcast to a [View] for a specific type.
 #[derive(Clone, Debug)]
 pub struct AnyView {
     model: AnyModel,
@@ -193,11 +209,15 @@ pub struct AnyView {
 }
 
 impl AnyView {
+    /// Indicate that this view should be cached when using it as an element.
+    /// When using this method, the view's previous layout and paint will be recycled from the previous frame if [ViewContext::notify] has not been called since it was rendered.
+    /// The one exception is when [WindowContext::refresh] is called, in which case caching is ignored.
     pub fn cached(mut self) -> Self {
         self.cache = true;
         self
     }
 
+    /// Convert this to a weak handle.
     pub fn downgrade(&self) -> AnyWeakView {
         AnyWeakView {
             model: self.model.downgrade(),
@@ -205,6 +225,8 @@ impl AnyView {
         }
     }
 
+    /// Convert this to a [View] of a specific type.
+    /// If this handle does not contain a view of the specified type, returns itself in an `Err` variant.
     pub fn downcast<T: 'static>(self) -> Result<View<T>, Self> {
         match self.model.downcast() {
             Ok(model) => Ok(View { model }),
@@ -216,10 +238,12 @@ impl AnyView {
         }
     }
 
+    /// Gets the [TypeId] of the underlying view.
     pub fn entity_type(&self) -> TypeId {
         self.model.entity_type
     }
 
+    /// Gets the entity id of this handle.
     pub fn entity_id(&self) -> EntityId {
         self.model.entity_id()
     }
@@ -337,12 +361,14 @@ impl IntoElement for AnyView {
     }
 }
 
+/// A weak, dynamically-typed view handle that does not prevent the view from being released.
 pub struct AnyWeakView {
     model: AnyWeakModel,
     layout: fn(&AnyView, &mut WindowContext) -> (LayoutId, AnyElement),
 }
 
 impl AnyWeakView {
+    /// Convert to a strongly-typed handle if the referenced view has not yet been released.
     pub fn upgrade(&self) -> Option<AnyView> {
         let model = self.model.upgrade()?;
         Some(AnyView {

crates/gpui/src/window.rs πŸ”—

@@ -5,13 +5,14 @@ use crate::{
     AsyncWindowContext, AvailableSpace, Bounds, BoxShadow, Context, Corners, CursorStyle,
     DevicePixels, DispatchActionListener, DispatchNodeId, DispatchTree, DisplayId, Edges, Effect,
     Entity, EntityId, EventEmitter, FileDropEvent, Flatten, FontId, GlobalElementId, GlyphId, Hsla,
-    ImageData, InputEvent, IsZero, KeyBinding, KeyContext, KeyDownEvent, KeystrokeEvent, LayoutId,
-    Model, ModelContext, Modifiers, MonochromeSprite, MouseButton, MouseMoveEvent, MouseUpEvent,
-    Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point,
-    PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams, RenderImageParams,
-    RenderSvgParams, ScaledPixels, Scene, Shadow, SharedString, Size, Style, SubscriberSet,
-    Subscription, Surface, TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext,
-    WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS,
+    ImageData, IsZero, KeyBinding, KeyContext, KeyDownEvent, KeyEvent, KeystrokeEvent, LayoutId,
+    Model, ModelContext, Modifiers, MonochromeSprite, MouseButton, MouseEvent, MouseMoveEvent,
+    MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput,
+    PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptLevel, Quad, Render,
+    RenderGlyphParams, RenderImageParams, RenderSvgParams, ScaledPixels, Scene, Shadow,
+    SharedString, Size, Style, SubscriberSet, Subscription, Surface, TaffyLayoutEngine, Task,
+    Underline, UnderlineStyle, View, VisualContext, WeakView, WindowBounds, WindowOptions,
+    SUBPIXEL_VARIANTS,
 };
 use anyhow::{anyhow, Context as _, Result};
 use collections::{FxHashMap, FxHashSet};
@@ -29,7 +30,7 @@ use std::{
     borrow::{Borrow, BorrowMut, Cow},
     cell::RefCell,
     collections::hash_map::Entry,
-    fmt::Debug,
+    fmt::{Debug, Display},
     future::Future,
     hash::{Hash, Hasher},
     marker::PhantomData,
@@ -315,6 +316,7 @@ pub(crate) struct Frame {
     pub(crate) depth_map: Vec<(StackingOrder, EntityId, Bounds<Pixels>)>,
     pub(crate) z_index_stack: StackingOrder,
     pub(crate) next_stacking_order_id: u32,
+    next_root_z_index: u8,
     content_mask_stack: Vec<ContentMask<Pixels>>,
     element_offset_stack: Vec<Point<Pixels>>,
     requested_input_handler: Option<RequestedInputHandler>,
@@ -323,6 +325,9 @@ pub(crate) struct Frame {
     requested_cursor_style: Option<CursorStyle>,
     pub(crate) view_stack: Vec<EntityId>,
     pub(crate) reused_views: FxHashSet<EntityId>,
+
+    #[cfg(any(test, feature = "test-support"))]
+    pub(crate) debug_bounds: collections::FxHashMap<String, Bounds<Pixels>>,
 }
 
 impl Frame {
@@ -337,6 +342,7 @@ impl Frame {
             depth_map: Vec::new(),
             z_index_stack: StackingOrder::default(),
             next_stacking_order_id: 0,
+            next_root_z_index: 0,
             content_mask_stack: Vec::new(),
             element_offset_stack: Vec::new(),
             requested_input_handler: None,
@@ -345,6 +351,9 @@ impl Frame {
             requested_cursor_style: None,
             view_stack: Vec::new(),
             reused_views: FxHashSet::default(),
+
+            #[cfg(any(test, feature = "test-support"))]
+            debug_bounds: FxHashMap::default(),
         }
     }
 
@@ -354,6 +363,7 @@ impl Frame {
         self.dispatch_tree.clear();
         self.depth_map.clear();
         self.next_stacking_order_id = 0;
+        self.next_root_z_index = 0;
         self.reused_views.clear();
         self.scene.clear();
         self.requested_input_handler.take();
@@ -968,7 +978,7 @@ impl<'a> WindowContext<'a> {
     /// Register a mouse event listener on the window for the next frame. The type of event
     /// is determined by the first parameter of the given listener. When the next frame is rendered
     /// the listener will be cleared.
-    pub fn on_mouse_event<Event: 'static>(
+    pub fn on_mouse_event<Event: MouseEvent>(
         &mut self,
         mut handler: impl FnMut(&Event, DispatchPhase, &mut WindowContext) + 'static,
     ) {
@@ -996,7 +1006,7 @@ impl<'a> WindowContext<'a> {
     ///
     /// This is a fairly low-level method, so prefer using event handlers on elements unless you have
     /// a specific need to register a global listener.
-    pub fn on_key_event<Event: 'static>(
+    pub fn on_key_event<Event: KeyEvent>(
         &mut self,
         listener: impl Fn(&Event, DispatchPhase, &mut WindowContext) + 'static,
     ) {
@@ -1617,7 +1627,7 @@ impl<'a> WindowContext<'a> {
     }
 
     /// Dispatch a mouse or keyboard event on the window.
-    pub fn dispatch_event(&mut self, event: InputEvent) -> bool {
+    pub fn dispatch_event(&mut self, event: PlatformInput) -> bool {
         // Handlers may set this to false by calling `stop_propagation`.
         self.app.propagate_event = true;
         // Handlers may set this to true by calling `prevent_default`.
@@ -1626,37 +1636,37 @@ impl<'a> WindowContext<'a> {
         let event = match event {
             // Track the mouse position with our own state, since accessing the platform
             // API for the mouse position can only occur on the main thread.
-            InputEvent::MouseMove(mouse_move) => {
+            PlatformInput::MouseMove(mouse_move) => {
                 self.window.mouse_position = mouse_move.position;
                 self.window.modifiers = mouse_move.modifiers;
-                InputEvent::MouseMove(mouse_move)
+                PlatformInput::MouseMove(mouse_move)
             }
-            InputEvent::MouseDown(mouse_down) => {
+            PlatformInput::MouseDown(mouse_down) => {
                 self.window.mouse_position = mouse_down.position;
                 self.window.modifiers = mouse_down.modifiers;
-                InputEvent::MouseDown(mouse_down)
+                PlatformInput::MouseDown(mouse_down)
             }
-            InputEvent::MouseUp(mouse_up) => {
+            PlatformInput::MouseUp(mouse_up) => {
                 self.window.mouse_position = mouse_up.position;
                 self.window.modifiers = mouse_up.modifiers;
-                InputEvent::MouseUp(mouse_up)
+                PlatformInput::MouseUp(mouse_up)
             }
-            InputEvent::MouseExited(mouse_exited) => {
+            PlatformInput::MouseExited(mouse_exited) => {
                 self.window.modifiers = mouse_exited.modifiers;
-                InputEvent::MouseExited(mouse_exited)
+                PlatformInput::MouseExited(mouse_exited)
             }
-            InputEvent::ModifiersChanged(modifiers_changed) => {
+            PlatformInput::ModifiersChanged(modifiers_changed) => {
                 self.window.modifiers = modifiers_changed.modifiers;
-                InputEvent::ModifiersChanged(modifiers_changed)
+                PlatformInput::ModifiersChanged(modifiers_changed)
             }
-            InputEvent::ScrollWheel(scroll_wheel) => {
+            PlatformInput::ScrollWheel(scroll_wheel) => {
                 self.window.mouse_position = scroll_wheel.position;
                 self.window.modifiers = scroll_wheel.modifiers;
-                InputEvent::ScrollWheel(scroll_wheel)
+                PlatformInput::ScrollWheel(scroll_wheel)
             }
             // Translate dragging and dropping of external files from the operating system
             // to internal drag and drop events.
-            InputEvent::FileDrop(file_drop) => match file_drop {
+            PlatformInput::FileDrop(file_drop) => match file_drop {
                 FileDropEvent::Entered { position, paths } => {
                     self.window.mouse_position = position;
                     if self.active_drag.is_none() {
@@ -1666,7 +1676,7 @@ impl<'a> WindowContext<'a> {
                             cursor_offset: position,
                         });
                     }
-                    InputEvent::MouseMove(MouseMoveEvent {
+                    PlatformInput::MouseMove(MouseMoveEvent {
                         position,
                         pressed_button: Some(MouseButton::Left),
                         modifiers: Modifiers::default(),
@@ -1674,7 +1684,7 @@ impl<'a> WindowContext<'a> {
                 }
                 FileDropEvent::Pending { position } => {
                     self.window.mouse_position = position;
-                    InputEvent::MouseMove(MouseMoveEvent {
+                    PlatformInput::MouseMove(MouseMoveEvent {
                         position,
                         pressed_button: Some(MouseButton::Left),
                         modifiers: Modifiers::default(),
@@ -1683,21 +1693,21 @@ impl<'a> WindowContext<'a> {
                 FileDropEvent::Submit { position } => {
                     self.activate(true);
                     self.window.mouse_position = position;
-                    InputEvent::MouseUp(MouseUpEvent {
+                    PlatformInput::MouseUp(MouseUpEvent {
                         button: MouseButton::Left,
                         position,
                         modifiers: Modifiers::default(),
                         click_count: 1,
                     })
                 }
-                FileDropEvent::Exited => InputEvent::MouseUp(MouseUpEvent {
+                FileDropEvent::Exited => PlatformInput::MouseUp(MouseUpEvent {
                     button: MouseButton::Left,
                     position: Point::default(),
                     modifiers: Modifiers::default(),
                     click_count: 1,
                 }),
             },
-            InputEvent::KeyDown(_) | InputEvent::KeyUp(_) => event,
+            PlatformInput::KeyDown(_) | PlatformInput::KeyUp(_) => event,
         };
 
         if let Some(any_mouse_event) = event.mouse_event() {
@@ -2127,7 +2137,7 @@ impl<'a> WindowContext<'a> {
                     .unwrap();
 
                 // Actual: Option<AnyElement> <- View
-                // Requested: () <- AnyElemet
+                // Requested: () <- AnyElement
                 let state = state_box
                     .take()
                     .expect("element state is already on the stack");
@@ -2450,8 +2460,13 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {
         };
         let new_stacking_order_id =
             post_inc(&mut self.window_mut().next_frame.next_stacking_order_id);
+        let new_root_z_index = post_inc(&mut self.window_mut().next_frame.next_root_z_index);
         let old_stacking_order = mem::take(&mut self.window_mut().next_frame.z_index_stack);
         self.window_mut().next_frame.z_index_stack.id = new_stacking_order_id;
+        self.window_mut()
+            .next_frame
+            .z_index_stack
+            .push(new_root_z_index);
         self.window_mut().next_frame.content_mask_stack.push(mask);
         let result = f(self);
         self.window_mut().next_frame.content_mask_stack.pop();
@@ -2975,7 +2990,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
     /// Add a listener for any mouse event that occurs in the window.
     /// This is a fairly low level method.
     /// Typically, you'll want to use methods on UI elements, which perform bounds checking etc.
-    pub fn on_mouse_event<Event: 'static>(
+    pub fn on_mouse_event<Event: MouseEvent>(
         &mut self,
         handler: impl Fn(&mut V, &Event, DispatchPhase, &mut ViewContext<V>) + 'static,
     ) {
@@ -2988,7 +3003,7 @@ impl<'a, V: 'static> ViewContext<'a, V> {
     }
 
     /// Register a callback to be invoked when the given Key Event is dispatched to the window.
-    pub fn on_key_event<Event: 'static>(
+    pub fn on_key_event<Event: KeyEvent>(
         &mut self,
         handler: impl Fn(&mut V, &Event, DispatchPhase, &mut ViewContext<V>) + 'static,
     ) {
@@ -3370,6 +3385,20 @@ pub enum ElementId {
     NamedInteger(SharedString, usize),
 }
 
+impl Display for ElementId {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            ElementId::View(entity_id) => write!(f, "view-{}", entity_id)?,
+            ElementId::Integer(ix) => write!(f, "{}", ix)?,
+            ElementId::Name(name) => write!(f, "{}", name)?,
+            ElementId::FocusHandle(__) => write!(f, "FocusHandle")?,
+            ElementId::NamedInteger(s, i) => write!(f, "{}-{}", s, i)?,
+        }
+
+        Ok(())
+    }
+}
+
 impl ElementId {
     pub(crate) fn from_entity_id(entity_id: EntityId) -> Self {
         ElementId::View(entity_id)

crates/gpui_macros/src/gpui_macros.rs πŸ”—

@@ -53,7 +53,7 @@ pub fn style_helpers(input: TokenStream) -> TokenStream {
 /// variety of scenarios and interleavings just by changing the seed.
 ///
 /// #[gpui::test] also takes three different arguments:
-/// - `#[gpui::test(interations=10)]` will run the test ten times with a different initial SEED.
+/// - `#[gpui::test(iterations=10)]` will run the test ten times with a different initial SEED.
 /// - `#[gpui::test(retries=3)]` will run the test up to four times if it fails to try and make it pass.
 /// - `#[gpui::test(on_failure="crate::test::report_failure")]` will call the specified function after the
 ///    tests fail so that you can write out more detail about the failure.

crates/journal/src/journal.rs πŸ”—

@@ -1,6 +1,6 @@
 use anyhow::Result;
 use chrono::{Datelike, Local, NaiveTime, Timelike};
-use editor::scroll::autoscroll::Autoscroll;
+use editor::scroll::Autoscroll;
 use editor::Editor;
 use gpui::{actions, AppContext, ViewContext, WindowContext};
 use schemars::JsonSchema;

crates/language/src/buffer_tests.rs πŸ”—

@@ -275,7 +275,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
         let version_before_format = format_diff.base_version.clone();
         buffer.apply_diff(format_diff, cx);
 
-        // The outcome depends on the order of concurrent taks.
+        // The outcome depends on the order of concurrent tasks.
         //
         // If the edit occurred while searching for trailing whitespace ranges,
         // then the trailing whitespace region touched by the edit is left intact.

crates/language/src/language.rs πŸ”—

@@ -951,7 +951,7 @@ impl LanguageRegistry {
         if language.fake_adapter.is_some() {
             let task = cx.spawn(|cx| async move {
                 let (servers_tx, fake_adapter) = language.fake_adapter.as_ref().unwrap();
-                let (server, mut fake_server) = lsp::LanguageServer::fake(
+                let (server, mut fake_server) = lsp::FakeLanguageServer::new(
                     fake_adapter.name.to_string(),
                     fake_adapter.capabilities.clone(),
                     cx.clone(),

crates/language_tools/src/lsp_log.rs πŸ”—

@@ -1,5 +1,5 @@
 use collections::{HashMap, VecDeque};
-use editor::{Editor, EditorEvent, MoveToEnd};
+use editor::{actions::MoveToEnd, Editor, EditorEvent};
 use futures::{channel::mpsc, StreamExt};
 use gpui::{
     actions, div, AnchorCorner, AnyElement, AppContext, Context, EventEmitter, FocusHandle,

crates/language_tools/src/syntax_tree_view.rs πŸ”—

@@ -1,4 +1,4 @@
-use editor::{scroll::autoscroll::Autoscroll, Anchor, Editor, ExcerptId};
+use editor::{scroll::Autoscroll, Anchor, Editor, ExcerptId};
 use gpui::{
     actions, canvas, div, rems, uniform_list, AnyElement, AppContext, AvailableSpace, Div,
     EventEmitter, FocusHandle, FocusableView, Hsla, InteractiveElement, IntoElement, Model,

crates/live_kit_client/LiveKitBridge/Package.resolved πŸ”—

@@ -6,8 +6,8 @@
         "repositoryURL": "https://github.com/livekit/client-sdk-swift.git",
         "state": {
           "branch": null,
-          "revision": "8b9cefed8d1669ec8fce41376b56dce3036a5f50",
-          "version": "1.1.4"
+          "revision": "7331b813a5ab8a95cfb81fb2b4ed10519428b9ff",
+          "version": "1.0.12"
         }
       },
       {
@@ -24,8 +24,8 @@
         "repositoryURL": "https://github.com/webrtc-sdk/Specs.git",
         "state": {
           "branch": null,
-          "revision": "4fa8d6d647fc759cdd0265fd413d2f28ea2e0e08",
-          "version": "114.5735.8"
+          "revision": "2f6bab30c8df0fe59ab3e58bc99097f757f85f65",
+          "version": "104.5112.17"
         }
       },
       {

crates/live_kit_client/LiveKitBridge/Package.swift πŸ”—

@@ -15,7 +15,7 @@ let package = Package(
             targets: ["LiveKitBridge"]),
     ],
     dependencies: [
-        .package(url: "https://github.com/livekit/client-sdk-swift.git", .exact("1.1.4")),
+        .package(url: "https://github.com/livekit/client-sdk-swift.git", .exact("1.0.12")),
     ],
     targets: [
         // Targets are the basic building blocks of a package. A target can define a module or a test suite.

crates/live_kit_client/examples/test_app.rs πŸ”—

@@ -1,4 +1,4 @@
-use std::{sync::Arc, time::Duration};
+use std::time::Duration;
 
 use futures::StreamExt;
 use gpui::{actions, KeyBinding, Menu, MenuItem};
@@ -12,7 +12,7 @@ actions!(live_kit_client, [Quit]);
 fn main() {
     SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
 
-    gpui::App::production(Arc::new(())).run(|cx| {
+    gpui::App::new().run(|cx| {
         #[cfg(any(test, feature = "test-support"))]
         println!("USING TEST LIVEKIT");
 

crates/lsp/src/lsp.rs πŸ”—

@@ -39,6 +39,7 @@ type NotificationHandler = Box<dyn Send + FnMut(Option<usize>, &str, AsyncAppCon
 type ResponseHandler = Box<dyn Send + FnOnce(Result<String, Error>)>;
 type IoHandler = Box<dyn Send + FnMut(IoKind, &str)>;
 
+/// Kind of language server stdio given to an IO handler.
 #[derive(Debug, Clone, Copy)]
 pub enum IoKind {
     StdOut,
@@ -46,12 +47,15 @@ pub enum IoKind {
     StdErr,
 }
 
+/// Represents a launchable language server. This can either be a standalone binary or the path
+/// to a runtime with arguments to instruct it to launch the actual language server file.
 #[derive(Debug, Clone, Deserialize)]
 pub struct LanguageServerBinary {
     pub path: PathBuf,
     pub arguments: Vec<OsString>,
 }
 
+/// A running language server process.
 pub struct LanguageServer {
     server_id: LanguageServerId,
     next_id: AtomicUsize,
@@ -70,10 +74,12 @@ pub struct LanguageServer {
     _server: Option<Mutex<Child>>,
 }
 
+/// Identifies a running language server.
 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
 #[repr(transparent)]
 pub struct LanguageServerId(pub usize);
 
+/// Handle to a language server RPC activity subscription.
 pub enum Subscription {
     Notification {
         method: &'static str,
@@ -85,6 +91,9 @@ pub enum Subscription {
     },
 }
 
+/// Language server protocol RPC request message.
+///
+/// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage)
 #[derive(Serialize, Deserialize)]
 pub struct Request<'a, T> {
     jsonrpc: &'static str,
@@ -93,6 +102,7 @@ pub struct Request<'a, T> {
     params: T,
 }
 
+/// Language server protocol RPC request response message before it is deserialized into a concrete type.
 #[derive(Serialize, Deserialize)]
 struct AnyResponse<'a> {
     jsonrpc: &'a str,
@@ -103,6 +113,9 @@ struct AnyResponse<'a> {
     result: Option<&'a RawValue>,
 }
 
+/// Language server protocol RPC request response message.
+///
+/// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#responseMessage)
 #[derive(Serialize)]
 struct Response<T> {
     jsonrpc: &'static str,
@@ -111,6 +124,9 @@ struct Response<T> {
     error: Option<Error>,
 }
 
+/// Language server protocol RPC notification message.
+///
+/// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage)
 #[derive(Serialize, Deserialize)]
 struct Notification<'a, T> {
     jsonrpc: &'static str,
@@ -119,6 +135,7 @@ struct Notification<'a, T> {
     params: T,
 }
 
+/// Language server RPC notification message before it is deserialized into a concrete type.
 #[derive(Debug, Clone, Deserialize)]
 struct AnyNotification<'a> {
     #[serde(default)]
@@ -135,6 +152,7 @@ struct Error {
 }
 
 impl LanguageServer {
+    /// Starts a language server process.
     pub fn new(
         stderr_capture: Arc<Mutex<Option<String>>>,
         server_id: LanguageServerId,
@@ -277,6 +295,7 @@ impl LanguageServer {
         }
     }
 
+    /// List of code action kinds this language server reports being able to emit.
     pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
         self.code_action_kinds.clone()
     }
@@ -427,9 +446,10 @@ impl LanguageServer {
         Ok(())
     }
 
-    /// Initializes a language server.
-    /// Note that `options` is used directly to construct [`InitializeParams`],
-    /// which is why it is owned.
+    /// Initializes a language server by sending the `Initialize` request.
+    /// Note that `options` is used directly to construct [`InitializeParams`], which is why it is owned.
+    ///
+    /// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize)
     pub async fn initialize(mut self, options: Option<Value>) -> Result<Arc<Self>> {
         let root_uri = Url::from_file_path(&self.root_path).unwrap();
         #[allow(deprecated)]
@@ -564,6 +584,7 @@ impl LanguageServer {
         Ok(Arc::new(self))
     }
 
+    /// Sends a shutdown request to the language server process and prepares the [`LanguageServer`] to be dropped.
     pub fn shutdown(&self) -> Option<impl 'static + Send + Future<Output = Option<()>>> {
         if let Some(tasks) = self.io_tasks.lock().take() {
             let response_handlers = self.response_handlers.clone();
@@ -598,6 +619,9 @@ impl LanguageServer {
         }
     }
 
+    /// Register a handler to handle incoming LSP notifications.
+    ///
+    /// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage)
     #[must_use]
     pub fn on_notification<T, F>(&self, f: F) -> Subscription
     where
@@ -607,6 +631,9 @@ impl LanguageServer {
         self.on_custom_notification(T::METHOD, f)
     }
 
+    /// Register a handler to handle incoming LSP requests.
+    ///
+    /// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage)
     #[must_use]
     pub fn on_request<T, F, Fut>(&self, f: F) -> Subscription
     where
@@ -618,6 +645,7 @@ impl LanguageServer {
         self.on_custom_request(T::METHOD, f)
     }
 
+    /// Registers a handler to inspect all language server process stdio.
     #[must_use]
     pub fn on_io<F>(&self, f: F) -> Subscription
     where
@@ -631,20 +659,23 @@ impl LanguageServer {
         }
     }
 
+    /// Removes a request handler registers via [`Self::on_request`].
     pub fn remove_request_handler<T: request::Request>(&self) {
         self.notification_handlers.lock().remove(T::METHOD);
     }
 
+    /// Removes a notification handler registers via [`Self::on_notification`].
     pub fn remove_notification_handler<T: notification::Notification>(&self) {
         self.notification_handlers.lock().remove(T::METHOD);
     }
 
+    /// Checks if a notification handler has been registered via [`Self::on_notification`].
     pub fn has_notification_handler<T: notification::Notification>(&self) -> bool {
         self.notification_handlers.lock().contains_key(T::METHOD)
     }
 
     #[must_use]
-    pub fn on_custom_notification<Params, F>(&self, method: &'static str, mut f: F) -> Subscription
+    fn on_custom_notification<Params, F>(&self, method: &'static str, mut f: F) -> Subscription
     where
         F: 'static + FnMut(Params, AsyncAppContext) + Send,
         Params: DeserializeOwned,
@@ -668,11 +699,7 @@ impl LanguageServer {
     }
 
     #[must_use]
-    pub fn on_custom_request<Params, Res, Fut, F>(
-        &self,
-        method: &'static str,
-        mut f: F,
-    ) -> Subscription
+    fn on_custom_request<Params, Res, Fut, F>(&self, method: &'static str, mut f: F) -> Subscription
     where
         F: 'static + FnMut(Params, AsyncAppContext) -> Fut + Send,
         Fut: 'static + Future<Output = Result<Res>>,
@@ -750,22 +777,29 @@ impl LanguageServer {
         }
     }
 
+    /// Get the name of the running language server.
     pub fn name(&self) -> &str {
         &self.name
     }
 
+    /// Get the reported capabilities of the running language server.
     pub fn capabilities(&self) -> &ServerCapabilities {
         &self.capabilities
     }
 
+    /// Get the id of the running language server.
     pub fn server_id(&self) -> LanguageServerId {
         self.server_id
     }
 
+    /// Get the root path of the project the language server is running against.
     pub fn root_path(&self) -> &PathBuf {
         &self.root_path
     }
 
+    /// Sends a RPC request to the language server.
+    ///
+    /// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage)
     pub fn request<T: request::Request>(
         &self,
         params: T::Params,
@@ -839,7 +873,7 @@ impl LanguageServer {
             futures::select! {
                 response = rx.fuse() => {
                     let elapsed = started.elapsed();
-                    log::trace!("Took {elapsed:?} to recieve response to {method:?} id {id}");
+                    log::trace!("Took {elapsed:?} to receive response to {method:?} id {id}");
                     response?
                 }
 
@@ -851,6 +885,9 @@ impl LanguageServer {
         }
     }
 
+    /// Sends a RPC notification to the language server.
+    ///
+    /// [LSP Specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage)
     pub fn notify<T: notification::Notification>(&self, params: T::Params) -> Result<()> {
         Self::notify_internal::<T>(&self.outbound_tx, params)
     }
@@ -879,6 +916,7 @@ impl Drop for LanguageServer {
 }
 
 impl Subscription {
+    /// Detaching a subscription handle prevents it from unsubscribing on drop.
     pub fn detach(&mut self) {
         match self {
             Subscription::Notification {
@@ -925,6 +963,7 @@ impl Drop for Subscription {
     }
 }
 
+/// Mock language server for use in tests.
 #[cfg(any(test, feature = "test-support"))]
 #[derive(Clone)]
 pub struct FakeLanguageServer {
@@ -933,29 +972,18 @@ pub struct FakeLanguageServer {
 }
 
 #[cfg(any(test, feature = "test-support"))]
-impl LanguageServer {
-    pub fn full_capabilities() -> ServerCapabilities {
-        ServerCapabilities {
-            document_highlight_provider: Some(OneOf::Left(true)),
-            code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
-            document_formatting_provider: Some(OneOf::Left(true)),
-            document_range_formatting_provider: Some(OneOf::Left(true)),
-            definition_provider: Some(OneOf::Left(true)),
-            type_definition_provider: Some(TypeDefinitionProviderCapability::Simple(true)),
-            ..Default::default()
-        }
-    }
-
-    pub fn fake(
+impl FakeLanguageServer {
+    /// Construct a fake language server.
+    pub fn new(
         name: String,
         capabilities: ServerCapabilities,
         cx: AsyncAppContext,
-    ) -> (Self, FakeLanguageServer) {
+    ) -> (LanguageServer, FakeLanguageServer) {
         let (stdin_writer, stdin_reader) = async_pipe::pipe();
         let (stdout_writer, stdout_reader) = async_pipe::pipe();
         let (notifications_tx, notifications_rx) = channel::unbounded();
 
-        let server = Self::new_internal(
+        let server = LanguageServer::new_internal(
             LanguageServerId(0),
             stdin_writer,
             stdout_reader,
@@ -968,7 +996,7 @@ impl LanguageServer {
             |_| {},
         );
         let fake = FakeLanguageServer {
-            server: Arc::new(Self::new_internal(
+            server: Arc::new(LanguageServer::new_internal(
                 LanguageServerId(0),
                 stdout_writer,
                 stdin_reader,
@@ -1013,12 +1041,29 @@ impl LanguageServer {
     }
 }
 
+#[cfg(any(test, feature = "test-support"))]
+impl LanguageServer {
+    pub fn full_capabilities() -> ServerCapabilities {
+        ServerCapabilities {
+            document_highlight_provider: Some(OneOf::Left(true)),
+            code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
+            document_formatting_provider: Some(OneOf::Left(true)),
+            document_range_formatting_provider: Some(OneOf::Left(true)),
+            definition_provider: Some(OneOf::Left(true)),
+            type_definition_provider: Some(TypeDefinitionProviderCapability::Simple(true)),
+            ..Default::default()
+        }
+    }
+}
+
 #[cfg(any(test, feature = "test-support"))]
 impl FakeLanguageServer {
+    /// See [`LanguageServer::notify`].
     pub fn notify<T: notification::Notification>(&self, params: T::Params) {
         self.server.notify::<T>(params).ok();
     }
 
+    /// See [`LanguageServer::request`].
     pub async fn request<T>(&self, params: T::Params) -> Result<T::Result>
     where
         T: request::Request,
@@ -1028,11 +1073,13 @@ impl FakeLanguageServer {
         self.server.request::<T>(params).await
     }
 
+    /// Attempts [`Self::try_receive_notification`], unwrapping if it has not received the specified type yet.
     pub async fn receive_notification<T: notification::Notification>(&mut self) -> T::Params {
         self.server.executor.start_waiting();
         self.try_receive_notification::<T>().await.unwrap()
     }
 
+    /// Consumes the notification channel until it finds a notification for the specified type.
     pub async fn try_receive_notification<T: notification::Notification>(
         &mut self,
     ) -> Option<T::Params> {
@@ -1048,6 +1095,7 @@ impl FakeLanguageServer {
         }
     }
 
+    /// Registers a handler for a specific kind of request. Removes any existing handler for specified request type.
     pub fn handle_request<T, F, Fut>(
         &self,
         mut handler: F,
@@ -1076,6 +1124,7 @@ impl FakeLanguageServer {
         responded_rx
     }
 
+    /// Registers a handler for a specific kind of notification. Removes any existing handler for specified notification type.
     pub fn handle_notification<T, F>(
         &self,
         mut handler: F,
@@ -1096,6 +1145,7 @@ impl FakeLanguageServer {
         handled_rx
     }
 
+    /// Removes any existing handler for specified notification type.
     pub fn remove_request_handler<T>(&mut self)
     where
         T: 'static + request::Request,
@@ -1103,6 +1153,7 @@ impl FakeLanguageServer {
         self.server.remove_request_handler::<T>();
     }
 
+    /// Simulate that the server has started work and notifies about its progress with the specified token.
     pub async fn start_progress(&self, token: impl Into<String>) {
         let token = token.into();
         self.request::<request::WorkDoneProgressCreate>(WorkDoneProgressCreateParams {
@@ -1116,6 +1167,7 @@ impl FakeLanguageServer {
         });
     }
 
+    /// Simulate that the server has completed work and notifies about that with the specified token.
     pub fn end_progress(&self, token: impl Into<String>) {
         self.notify::<notification::Progress>(ProgressParams {
             token: NumberOrString::String(token.into()),
@@ -1139,7 +1191,7 @@ mod tests {
     #[gpui::test]
     async fn test_fake(cx: &mut TestAppContext) {
         let (server, mut fake) =
-            LanguageServer::fake("the-lsp".to_string(), Default::default(), cx.to_async());
+            FakeLanguageServer::new("the-lsp".to_string(), Default::default(), cx.to_async());
 
         let (message_tx, message_rx) = channel::unbounded();
         let (diagnostics_tx, diagnostics_rx) = channel::unbounded();

crates/multi_buffer/src/multi_buffer.rs πŸ”—

@@ -72,7 +72,7 @@ pub enum Event {
         ids: Vec<ExcerptId>,
     },
     Edited {
-        sigleton_buffer_edited: bool,
+        singleton_buffer_edited: bool,
     },
     TransactionUndone {
         transaction_id: TransactionId,
@@ -1112,7 +1112,7 @@ impl MultiBuffer {
             new: edit_start..edit_end,
         }]);
         cx.emit(Event::Edited {
-            sigleton_buffer_edited: false,
+            singleton_buffer_edited: false,
         });
         cx.emit(Event::ExcerptsAdded {
             buffer,
@@ -1138,7 +1138,7 @@ impl MultiBuffer {
             new: 0..0,
         }]);
         cx.emit(Event::Edited {
-            sigleton_buffer_edited: false,
+            singleton_buffer_edited: false,
         });
         cx.emit(Event::ExcerptsRemoved { ids });
         cx.notify();
@@ -1348,7 +1348,7 @@ impl MultiBuffer {
 
         self.subscriptions.publish_mut(edits);
         cx.emit(Event::Edited {
-            sigleton_buffer_edited: false,
+            singleton_buffer_edited: false,
         });
         cx.emit(Event::ExcerptsRemoved { ids });
         cx.notify();
@@ -1411,7 +1411,7 @@ impl MultiBuffer {
     ) {
         cx.emit(match event {
             language::Event::Edited => Event::Edited {
-                sigleton_buffer_edited: true,
+                singleton_buffer_edited: true,
             },
             language::Event::DirtyChanged => Event::DirtyChanged,
             language::Event::Saved => Event::Saved,
@@ -4280,13 +4280,13 @@ mod tests {
             events.read().as_slice(),
             &[
                 Event::Edited {
-                    sigleton_buffer_edited: false
+                    singleton_buffer_edited: false
                 },
                 Event::Edited {
-                    sigleton_buffer_edited: false
+                    singleton_buffer_edited: false
                 },
                 Event::Edited {
-                    sigleton_buffer_edited: false
+                    singleton_buffer_edited: false
                 }
             ]
         );

crates/outline/src/outline.rs πŸ”—

@@ -1,6 +1,6 @@
 use editor::{
-    display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Anchor, AnchorRangeExt,
-    DisplayPoint, Editor, EditorMode, ToPoint,
+    display_map::ToDisplayPoint, scroll::Autoscroll, Anchor, AnchorRangeExt, DisplayPoint, Editor,
+    EditorMode, ToPoint,
 };
 use fuzzy::StringMatch;
 use gpui::{

crates/picker/src/picker.rs πŸ”—

@@ -4,7 +4,7 @@ use gpui::{
     FocusableView, Length, MouseButton, MouseDownEvent, Render, Task, UniformListScrollHandle,
     View, ViewContext, WindowContext,
 };
-use std::{cmp, sync::Arc};
+use std::sync::Arc;
 use ui::{prelude::*, v_flex, Color, Divider, Label, ListItem, ListItemSpacing, ListSeparator};
 use workspace::ModalView;
 
@@ -103,7 +103,7 @@ impl<D: PickerDelegate> Picker<D> {
         let count = self.delegate.match_count();
         if count > 0 {
             let index = self.delegate.selected_index();
-            let ix = cmp::min(index + 1, count - 1);
+            let ix = if index == count - 1 { 0 } else { index + 1 };
             self.delegate.set_selected_index(ix, cx);
             self.scroll_handle.scroll_to_item(ix);
             cx.notify();
@@ -114,7 +114,7 @@ impl<D: PickerDelegate> Picker<D> {
         let count = self.delegate.match_count();
         if count > 0 {
             let index = self.delegate.selected_index();
-            let ix = index.saturating_sub(1);
+            let ix = if index == 0 { count - 1 } else { index - 1 };
             self.delegate.set_selected_index(ix, cx);
             self.scroll_handle.scroll_to_item(ix);
             cx.notify();

crates/project/src/lsp_command.rs πŸ”—

@@ -2253,7 +2253,7 @@ impl LspCommand for InlayHints {
             language_server_for_buffer(&project, &buffer, server_id, &mut cx)?;
         // `typescript-language-server` adds padding to the left for type hints, turning
         // `const foo: boolean` into `const foo : boolean` which looks odd.
-        // `rust-analyzer` does not have the padding for this case, and we have to accomodate both.
+        // `rust-analyzer` does not have the padding for this case, and we have to accommodate both.
         //
         // We could trim the whole string, but being pessimistic on par with the situation above,
         // there might be a hint with multiple whitespaces at the end(s) which we need to display properly.

crates/project/src/project.rs πŸ”—

@@ -5578,7 +5578,7 @@ impl Project {
         // 3. We run a scan over all the candidate buffers on multiple background threads.
         //    We cannot assume that there will even be a match - while at least one match
         //    is guaranteed for files obtained from FS, the buffers we got from memory (unsaved files/unnamed buffers) might not have a match at all.
-        //    There is also an auxilliary background thread responsible for result gathering.
+        //    There is also an auxiliary background thread responsible for result gathering.
         //    This is where the sorted list of buffers comes into play to maintain sorted order; Whenever this background thread receives a notification (buffer has/doesn't have matches),
         //    it keeps it around. It reports matches in sorted order, though it accepts them in unsorted order as well.
         //    As soon as the match info on next position in sorted order becomes available, it reports it (if it's a match) or skips to the next
@@ -8550,7 +8550,7 @@ fn glob_literal_prefix<'a>(glob: &'a str) -> &'a str {
             break;
         } else {
             if i > 0 {
-                // Acount for separator prior to this part
+                // Account for separator prior to this part
                 literal_end += path::MAIN_SEPARATOR.len_utf8();
             }
             literal_end += part.len();

crates/project/src/project_settings.rs πŸ”—

@@ -9,7 +9,7 @@ use std::sync::Arc;
 pub struct ProjectSettings {
     /// Configuration for language servers.
     ///
-    /// The following settings can be overriden for specific language servers:
+    /// The following settings can be overridden for specific language servers:
     /// - initialization_options
     /// To override settings for a language, add an entry for that language server's
     /// name to the lsp value.

crates/project_panel/src/file_associations.rs πŸ”—

@@ -42,9 +42,9 @@ impl FileAssociations {
     }
 
     pub fn get_icon(path: &Path, cx: &AppContext) -> Option<Arc<str>> {
-        let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
+        let this = cx.try_global::<Self>()?;
 
-        // FIXME: Associate a type with the languages and have the file's langauge
+        // FIXME: Associate a type with the languages and have the file's language
         //        override these associations
         maybe!({
             let suffix = path.icon_suffix()?;
@@ -58,7 +58,7 @@ impl FileAssociations {
     }
 
     pub fn get_folder_icon(expanded: bool, cx: &AppContext) -> Option<Arc<str>> {
-        let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
+        let this = cx.try_global::<Self>()?;
 
         let key = if expanded {
             EXPANDED_DIRECTORY_TYPE
@@ -72,7 +72,7 @@ impl FileAssociations {
     }
 
     pub fn get_chevron_icon(expanded: bool, cx: &AppContext) -> Option<Arc<str>> {
-        let this = cx.has_global::<Self>().then(|| cx.global::<Self>())?;
+        let this = cx.try_global::<Self>()?;
 
         let key = if expanded {
             EXPANDED_CHEVRON_TYPE

crates/project_panel/src/project_panel.rs πŸ”—

@@ -3,7 +3,7 @@ mod project_panel_settings;
 use settings::Settings;
 
 use db::kvp::KEY_VALUE_STORE;
-use editor::{scroll::autoscroll::Autoscroll, Cancel, Editor};
+use editor::{actions::Cancel, scroll::Autoscroll, Editor};
 use file_associations::FileAssociations;
 
 use anyhow::{anyhow, Result};

crates/project_symbols/src/project_symbols.rs πŸ”—

@@ -1,4 +1,4 @@
-use editor::{scroll::autoscroll::Autoscroll, styled_runs_for_code_label, Bias, Editor};
+use editor::{scroll::Autoscroll, styled_runs_for_code_label, Bias, Editor};
 use fuzzy::{StringMatch, StringMatchCandidate};
 use gpui::{
     actions, rems, AppContext, DismissEvent, FontWeight, Model, ParentElement, StyledText, Task,

crates/quick_action_bar/src/quick_action_bar.rs πŸ”—

@@ -45,13 +45,13 @@ impl Render for QuickActionBar {
             "toggle inlay hints",
             IconName::InlayHint,
             editor.read(cx).inlay_hints_enabled(),
-            Box::new(editor::ToggleInlayHints),
+            Box::new(editor::actions::ToggleInlayHints),
             "Toggle Inlay Hints",
             {
                 let editor = editor.clone();
                 move |_, cx| {
                     editor.update(cx, |editor, cx| {
-                        editor.toggle_inlay_hints(&editor::ToggleInlayHints, cx);
+                        editor.toggle_inlay_hints(&editor::actions::ToggleInlayHints, cx);
                     });
                 }
             },

crates/recent_projects/src/recent_projects.rs πŸ”—

@@ -32,7 +32,7 @@ impl RecentProjects {
     fn new(delegate: RecentProjectsDelegate, rem_width: f32, cx: &mut ViewContext<Self>) -> Self {
         let picker = cx.new_view(|cx| Picker::new(delegate, cx));
         let _subscription = cx.subscribe(&picker, |_, _, _, cx| cx.emit(DismissEvent));
-        // We do not want to block the UI on a potentially lenghty call to DB, so we're gonna swap
+        // We do not want to block the UI on a potentially lengthy call to DB, so we're gonna swap
         // out workspace locations once the future runs to completion.
         cx.spawn(|this, mut cx| async move {
             let workspaces = WORKSPACE_DB

crates/refineable/derive_refineable/src/derive_refineable.rs πŸ”—

@@ -141,7 +141,7 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
         })
         .collect();
 
-    let refinement_refine_assigments: Vec<TokenStream2> = fields
+    let refinement_refine_assignments: Vec<TokenStream2> = fields
         .iter()
         .map(|field| {
             let name = &field.ident;
@@ -161,7 +161,7 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
         })
         .collect();
 
-    let refinement_refined_assigments: Vec<TokenStream2> = fields
+    let refinement_refined_assignments: Vec<TokenStream2> = fields
         .iter()
         .map(|field| {
             let name = &field.ident;
@@ -181,7 +181,7 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
         })
         .collect();
 
-    let from_refinement_assigments: Vec<TokenStream2> = fields
+    let from_refinement_assignments: Vec<TokenStream2> = fields
         .iter()
         .map(|field| {
             let name = &field.ident;
@@ -272,11 +272,11 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
             type Refinement = #refinement_ident #ty_generics;
 
             fn refine(&mut self, refinement: &Self::Refinement) {
-                #( #refinement_refine_assigments )*
+                #( #refinement_refine_assignments )*
             }
 
             fn refined(mut self, refinement: Self::Refinement) -> Self {
-                #( #refinement_refined_assigments )*
+                #( #refinement_refined_assignments )*
                 self
             }
         }
@@ -286,7 +286,7 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
         {
             fn from(value: #refinement_ident #ty_generics) -> Self {
                 Self {
-                    #( #from_refinement_assigments )*
+                    #( #from_refinement_assignments )*
                 }
             }
         }

crates/search/src/buffer_search.rs πŸ”—

@@ -7,7 +7,7 @@ use crate::{
     ToggleCaseSensitive, ToggleReplace, ToggleWholeWord,
 };
 use collections::HashMap;
-use editor::{Editor, EditorElement, EditorStyle, Tab};
+use editor::{actions::Tab, Editor, EditorElement, EditorStyle};
 use futures::channel::oneshot;
 use gpui::{
     actions, div, impl_actions, Action, AppContext, ClickEvent, EventEmitter, FocusableView,
@@ -429,6 +429,11 @@ pub trait SearchActionsRegistrar {
         &mut self,
         callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
     );
+
+    fn register_handler_for_dismissed_search<A: Action>(
+        &mut self,
+        callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
+    );
 }
 
 type GetSearchBar<T> =
@@ -457,16 +462,62 @@ impl<'a, 'b, T: 'static> DivRegistrar<'a, 'b, T> {
 }
 
 impl<T: 'static> SearchActionsRegistrar for DivRegistrar<'_, '_, T> {
-    fn register_handler<A: gpui::Action>(
+    fn register_handler<A: Action>(
         &mut self,
         callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
     ) {
         let getter = self.search_getter;
         self.div = self.div.take().map(|div| {
             div.on_action(self.cx.listener(move |this, action, cx| {
-                (getter)(this, cx)
+                let should_notify = (getter)(this, cx)
                     .clone()
-                    .map(|search_bar| search_bar.update(cx, |this, cx| callback(this, action, cx)));
+                    .map(|search_bar| {
+                        search_bar.update(cx, |search_bar, cx| {
+                            if search_bar.is_dismissed()
+                                || search_bar.active_searchable_item.is_none()
+                            {
+                                false
+                            } else {
+                                callback(search_bar, action, cx);
+                                true
+                            }
+                        })
+                    })
+                    .unwrap_or(false);
+                if should_notify {
+                    cx.notify();
+                } else {
+                    cx.propagate();
+                }
+            }))
+        });
+    }
+
+    fn register_handler_for_dismissed_search<A: Action>(
+        &mut self,
+        callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
+    ) {
+        let getter = self.search_getter;
+        self.div = self.div.take().map(|div| {
+            div.on_action(self.cx.listener(move |this, action, cx| {
+                let should_notify = (getter)(this, cx)
+                    .clone()
+                    .map(|search_bar| {
+                        search_bar.update(cx, |search_bar, cx| {
+                            if search_bar.is_dismissed() {
+                                callback(search_bar, action, cx);
+                                true
+                            } else {
+                                false
+                            }
+                        })
+                    })
+                    .unwrap_or(false);
+                if should_notify {
+                    cx.notify();
+                } else {
+                    cx.propagate();
+                }
             }))
         });
     }
@@ -488,44 +539,86 @@ impl SearchActionsRegistrar for Workspace {
             pane.update(cx, move |this, cx| {
                 this.toolbar().update(cx, move |this, cx| {
                     if let Some(search_bar) = this.item_of_type::<BufferSearchBar>() {
-                        search_bar.update(cx, move |this, cx| callback(this, action, cx));
-                        cx.notify();
+                        let should_notify = search_bar.update(cx, move |search_bar, cx| {
+                            if search_bar.is_dismissed()
+                                || search_bar.active_searchable_item.is_none()
+                            {
+                                false
+                            } else {
+                                callback(search_bar, action, cx);
+                                true
+                            }
+                        });
+                        if should_notify {
+                            cx.notify();
+                        } else {
+                            cx.propagate();
+                        }
+                    }
+                })
+            });
+        });
+    }
+
+    fn register_handler_for_dismissed_search<A: Action>(
+        &mut self,
+        callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
+    ) {
+        self.register_action(move |workspace, action: &A, cx| {
+            if workspace.has_active_modal(cx) {
+                cx.propagate();
+                return;
+            }
+
+            let pane = workspace.active_pane();
+            pane.update(cx, move |this, cx| {
+                this.toolbar().update(cx, move |this, cx| {
+                    if let Some(search_bar) = this.item_of_type::<BufferSearchBar>() {
+                        let should_notify = search_bar.update(cx, move |search_bar, cx| {
+                            if search_bar.is_dismissed() {
+                                callback(search_bar, action, cx);
+                                true
+                            } else {
+                                false
+                            }
+                        });
+                        if should_notify {
+                            cx.notify();
+                        } else {
+                            cx.propagate();
+                        }
                     }
                 })
             });
         });
     }
 }
+
 impl BufferSearchBar {
-    pub fn register_inner(registrar: &mut impl SearchActionsRegistrar) {
+    pub fn register(registrar: &mut impl SearchActionsRegistrar) {
         registrar.register_handler(|this, action: &ToggleCaseSensitive, cx| {
             if this.supported_options().case {
                 this.toggle_case_sensitive(action, cx);
             }
         });
-
         registrar.register_handler(|this, action: &ToggleWholeWord, cx| {
             if this.supported_options().word {
                 this.toggle_whole_word(action, cx);
             }
         });
-
         registrar.register_handler(|this, action: &ToggleReplace, cx| {
             if this.supported_options().replacement {
                 this.toggle_replace(action, cx);
             }
         });
-
         registrar.register_handler(|this, _: &ActivateRegexMode, cx| {
             if this.supported_options().regex {
                 this.activate_search_mode(SearchMode::Regex, cx);
             }
         });
-
         registrar.register_handler(|this, _: &ActivateTextMode, cx| {
             this.activate_search_mode(SearchMode::Text, cx);
         });
-
         registrar.register_handler(|this, action: &CycleMode, cx| {
             if this.supported_options().regex {
                 // If regex is not supported then search has just one mode (text) - in that case there's no point in supporting
@@ -533,7 +626,6 @@ impl BufferSearchBar {
                 this.cycle_mode(action, cx)
             }
         });
-
         registrar.register_handler(|this, action: &SelectNextMatch, cx| {
             this.select_next_match(action, cx);
         });
@@ -543,20 +635,20 @@ impl BufferSearchBar {
         registrar.register_handler(|this, action: &SelectAllMatches, cx| {
             this.select_all_matches(action, cx);
         });
-        registrar.register_handler(|this, _: &editor::Cancel, cx| {
-            if this.dismissed {
-                cx.propagate();
-            } else {
-                this.dismiss(&Dismiss, cx);
-            }
+        registrar.register_handler(|this, _: &editor::actions::Cancel, cx| {
+            this.dismiss(&Dismiss, cx);
         });
+
+        // register deploy buffer search for both search bar states, since we want to focus into the search bar
+        // when the deploy action is triggered in the buffer.
         registrar.register_handler(|this, deploy, cx| {
             this.deploy(deploy, cx);
+        });
+        registrar.register_handler_for_dismissed_search(|this, deploy, cx| {
+            this.deploy(deploy, cx);
         })
     }
-    fn register(workspace: &mut Workspace) {
-        Self::register_inner(workspace);
-    }
+
     pub fn new(cx: &mut ViewContext<Self>) -> Self {
         let query_editor = cx.new_view(|cx| Editor::single_line(cx));
         cx.subscribe(&query_editor, Self::on_query_editor_event)
@@ -1081,7 +1173,7 @@ mod tests {
 
     use super::*;
     use editor::{DisplayPoint, Editor};
-    use gpui::{Context, EmptyView, Hsla, TestAppContext, VisualTestContext};
+    use gpui::{Context, Hsla, TestAppContext, VisualTestContext};
     use language::Buffer;
     use smol::stream::StreamExt as _;
     use unindent::Unindent as _;
@@ -1114,7 +1206,7 @@ mod tests {
                 .unindent(),
             )
         });
-        let (_, cx) = cx.add_window_view(|_| EmptyView {});
+        let cx = cx.add_empty_window();
         let editor = cx.new_view(|cx| Editor::for_buffer(buffer.clone(), None, cx));
 
         let search_bar = cx.new_view(|cx| {
@@ -1461,7 +1553,7 @@ mod tests {
             "Should pick a query with multiple results"
         );
         let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text));
-        let window = cx.add_window(|_| EmptyView {});
+        let window = cx.add_window(|_| ());
 
         let editor = window.build_view(cx, |cx| Editor::for_buffer(buffer.clone(), None, cx));
 
@@ -1657,7 +1749,7 @@ mod tests {
         "#
         .unindent();
         let buffer = cx.new_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), buffer_text));
-        let (_, cx) = cx.add_window_view(|_| EmptyView {});
+        let cx = cx.add_empty_window();
 
         let editor = cx.new_view(|cx| Editor::for_buffer(buffer.clone(), None, cx));
 

crates/search/src/history.rs πŸ”—

@@ -85,7 +85,7 @@ mod tests {
         assert_eq!(
             search_history.current(),
             None,
-            "No current selection should be set fo the default search history"
+            "No current selection should be set for the default search history"
         );
 
         search_history.add("rust".to_string());

crates/search/src/project_search.rs πŸ”—

@@ -7,15 +7,15 @@ use crate::{
 use anyhow::{Context as _, Result};
 use collections::HashMap;
 use editor::{
-    items::active_match_index, scroll::autoscroll::Autoscroll, Anchor, Editor, EditorEvent,
-    MultiBuffer, SelectAll, MAX_TAB_TITLE_LEN,
+    actions::SelectAll, items::active_match_index, scroll::Autoscroll, Anchor, Editor, EditorEvent,
+    MultiBuffer, MAX_TAB_TITLE_LEN,
 };
 use editor::{EditorElement, EditorStyle};
 use gpui::{
-    actions, div, AnyElement, AnyView, AppContext, Context as _, Element, EntityId, EventEmitter,
-    FocusHandle, FocusableView, FontStyle, FontWeight, Hsla, InteractiveElement, IntoElement,
-    KeyContext, Model, ModelContext, ParentElement, PromptLevel, Render, SharedString, Styled,
-    Subscription, Task, TextStyle, View, ViewContext, VisualContext, WeakModel, WeakView,
+    actions, div, Action, AnyElement, AnyView, AppContext, Context as _, Element, EntityId,
+    EventEmitter, FocusHandle, FocusableView, FontStyle, FontWeight, Hsla, InteractiveElement,
+    IntoElement, KeyContext, Model, ModelContext, ParentElement, PromptLevel, Render, SharedString,
+    Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext, WeakModel, WeakView,
     WhiteSpace, WindowContext,
 };
 use menu::Confirm;
@@ -36,6 +36,7 @@ use std::{
     time::{Duration, Instant},
 };
 use theme::ThemeSettings;
+use workspace::{DeploySearch, NewSearch};
 
 use ui::{
     h_flex, prelude::*, v_flex, Icon, IconButton, IconName, Label, LabelCommon, LabelSize,
@@ -60,10 +61,62 @@ struct ActiveSettings(HashMap<WeakModel<Project>, ProjectSearchSettings>);
 pub fn init(cx: &mut AppContext) {
     cx.set_global(ActiveSettings::default());
     cx.observe_new_views(|workspace: &mut Workspace, _cx| {
-        workspace
-            .register_action(ProjectSearchView::new_search)
-            .register_action(ProjectSearchView::deploy_search)
-            .register_action(ProjectSearchBar::search_in_new);
+        register_workspace_action(workspace, move |search_bar, _: &ToggleFilters, cx| {
+            search_bar.toggle_filters(cx);
+        });
+        register_workspace_action(workspace, move |search_bar, _: &ToggleCaseSensitive, cx| {
+            search_bar.toggle_search_option(SearchOptions::CASE_SENSITIVE, cx);
+        });
+        register_workspace_action(workspace, move |search_bar, _: &ToggleWholeWord, cx| {
+            search_bar.toggle_search_option(SearchOptions::WHOLE_WORD, cx);
+        });
+        register_workspace_action(workspace, move |search_bar, action: &ToggleReplace, cx| {
+            search_bar.toggle_replace(action, cx)
+        });
+        register_workspace_action(workspace, move |search_bar, _: &ActivateRegexMode, cx| {
+            search_bar.activate_search_mode(SearchMode::Regex, cx)
+        });
+        register_workspace_action(workspace, move |search_bar, _: &ActivateTextMode, cx| {
+            search_bar.activate_search_mode(SearchMode::Text, cx)
+        });
+        register_workspace_action(
+            workspace,
+            move |search_bar, _: &ActivateSemanticMode, cx| {
+                search_bar.activate_search_mode(SearchMode::Semantic, cx)
+            },
+        );
+        register_workspace_action(workspace, move |search_bar, action: &CycleMode, cx| {
+            search_bar.cycle_mode(action, cx)
+        });
+        register_workspace_action(
+            workspace,
+            move |search_bar, action: &SelectNextMatch, cx| {
+                search_bar.select_next_match(action, cx)
+            },
+        );
+
+        // Only handle search_in_new if there is a search present
+        register_workspace_action_for_present_search(workspace, |workspace, action, cx| {
+            ProjectSearchView::search_in_new(workspace, action, cx)
+        });
+
+        // Both on present and dismissed search, we need to unconditionally handle those actions to focus from the editor.
+        workspace.register_action(move |workspace, action: &DeploySearch, cx| {
+            if workspace.has_active_modal(cx) {
+                cx.propagate();
+                return;
+            }
+            ProjectSearchView::deploy_search(workspace, action, cx);
+            cx.notify();
+        });
+        workspace.register_action(move |workspace, action: &NewSearch, cx| {
+            if workspace.has_active_modal(cx) {
+                cx.propagate();
+                return;
+            }
+            ProjectSearchView::new_search(workspace, action, cx);
+            cx.notify();
+        });
     })
     .detach();
 }
@@ -960,6 +1013,37 @@ impl ProjectSearchView {
         Self::existing_or_new_search(workspace, existing, cx)
     }
 
+    fn search_in_new(workspace: &mut Workspace, _: &SearchInNew, cx: &mut ViewContext<Workspace>) {
+        if let Some(search_view) = workspace
+            .active_item(cx)
+            .and_then(|item| item.downcast::<ProjectSearchView>())
+        {
+            let new_query = search_view.update(cx, |search_view, cx| {
+                let new_query = search_view.build_search_query(cx);
+                if new_query.is_some() {
+                    if let Some(old_query) = search_view.model.read(cx).active_query.clone() {
+                        search_view.query_editor.update(cx, |editor, cx| {
+                            editor.set_text(old_query.as_str(), cx);
+                        });
+                        search_view.search_options = SearchOptions::from_query(&old_query);
+                    }
+                }
+                new_query
+            });
+            if let Some(new_query) = new_query {
+                let model = cx.new_model(|cx| {
+                    let mut model = ProjectSearch::new(workspace.project().clone(), cx);
+                    model.search(new_query, cx);
+                    model
+                });
+                workspace.add_item(
+                    Box::new(cx.new_view(|cx| ProjectSearchView::new(model, cx, None))),
+                    cx,
+                );
+            }
+        }
+    }
+
     // Add another search tab to the workspace.
     fn new_search(
         workspace: &mut Workspace,
@@ -1262,17 +1346,11 @@ impl ProjectSearchView {
     }
 }
 
-impl Default for ProjectSearchBar {
-    fn default() -> Self {
-        Self::new()
-    }
-}
-
 impl ProjectSearchBar {
     pub fn new() -> Self {
         Self {
-            active_project_search: Default::default(),
-            subscription: Default::default(),
+            active_project_search: None,
+            subscription: None,
         }
     }
 
@@ -1303,42 +1381,11 @@ impl ProjectSearchBar {
         }
     }
 
-    fn search_in_new(workspace: &mut Workspace, _: &SearchInNew, cx: &mut ViewContext<Workspace>) {
-        if let Some(search_view) = workspace
-            .active_item(cx)
-            .and_then(|item| item.downcast::<ProjectSearchView>())
-        {
-            let new_query = search_view.update(cx, |search_view, cx| {
-                let new_query = search_view.build_search_query(cx);
-                if new_query.is_some() {
-                    if let Some(old_query) = search_view.model.read(cx).active_query.clone() {
-                        search_view.query_editor.update(cx, |editor, cx| {
-                            editor.set_text(old_query.as_str(), cx);
-                        });
-                        search_view.search_options = SearchOptions::from_query(&old_query);
-                    }
-                }
-                new_query
-            });
-            if let Some(new_query) = new_query {
-                let model = cx.new_model(|cx| {
-                    let mut model = ProjectSearch::new(workspace.project().clone(), cx);
-                    model.search(new_query, cx);
-                    model
-                });
-                workspace.add_item(
-                    Box::new(cx.new_view(|cx| ProjectSearchView::new(model, cx, None))),
-                    cx,
-                );
-            }
-        }
-    }
-
-    fn tab(&mut self, _: &editor::Tab, cx: &mut ViewContext<Self>) {
+    fn tab(&mut self, _: &editor::actions::Tab, cx: &mut ViewContext<Self>) {
         self.cycle_field(Direction::Next, cx);
     }
 
-    fn tab_previous(&mut self, _: &editor::TabPrev, cx: &mut ViewContext<Self>) {
+    fn tab_previous(&mut self, _: &editor::actions::TabPrev, cx: &mut ViewContext<Self>) {
         self.cycle_field(Direction::Prev, cx);
     }
 
@@ -1502,6 +1549,22 @@ impl ProjectSearchBar {
         }
     }
 
+    pub fn select_next_match(&mut self, _: &SelectNextMatch, cx: &mut ViewContext<Self>) {
+        if let Some(search) = self.active_project_search.as_ref() {
+            search.update(cx, |this, cx| {
+                this.select_match(Direction::Next, cx);
+            })
+        }
+    }
+
+    fn select_prev_match(&mut self, _: &SelectPrevMatch, cx: &mut ViewContext<Self>) {
+        if let Some(search) = self.active_project_search.as_ref() {
+            search.update(cx, |this, cx| {
+                this.select_match(Direction::Prev, cx);
+            })
+        }
+    }
+
     fn new_placeholder_text(&self, cx: &mut ViewContext<Self>) -> Option<String> {
         let previous_query_keystrokes = cx
             .bindings_for_action(&PreviousHistoryQuery {})
@@ -1870,6 +1933,8 @@ impl Render for ProjectSearchBar {
                     }))
                 })
             })
+            .on_action(cx.listener(Self::select_next_match))
+            .on_action(cx.listener(Self::select_prev_match))
             .child(
                 h_flex()
                     .justify_between()
@@ -1963,6 +2028,60 @@ impl ToolbarItemView for ProjectSearchBar {
     }
 }
 
+fn register_workspace_action<A: Action>(
+    workspace: &mut Workspace,
+    callback: fn(&mut ProjectSearchBar, &A, &mut ViewContext<ProjectSearchBar>),
+) {
+    workspace.register_action(move |workspace, action: &A, cx| {
+        if workspace.has_active_modal(cx) {
+            cx.propagate();
+            return;
+        }
+
+        workspace.active_pane().update(cx, |pane, cx| {
+            pane.toolbar().update(cx, move |workspace, cx| {
+                if let Some(search_bar) = workspace.item_of_type::<ProjectSearchBar>() {
+                    search_bar.update(cx, move |search_bar, cx| {
+                        if search_bar.active_project_search.is_some() {
+                            callback(search_bar, action, cx);
+                            cx.notify();
+                        } else {
+                            cx.propagate();
+                        }
+                    });
+                }
+            });
+        })
+    });
+}
+
+fn register_workspace_action_for_present_search<A: Action>(
+    workspace: &mut Workspace,
+    callback: fn(&mut Workspace, &A, &mut ViewContext<Workspace>),
+) {
+    workspace.register_action(move |workspace, action: &A, cx| {
+        if workspace.has_active_modal(cx) {
+            cx.propagate();
+            return;
+        }
+
+        let should_notify = workspace
+            .active_pane()
+            .read(cx)
+            .toolbar()
+            .read(cx)
+            .item_of_type::<ProjectSearchBar>()
+            .map(|search_bar| search_bar.read(cx).active_project_search.is_some())
+            .unwrap_or(false);
+        if should_notify {
+            callback(workspace, action, cx);
+            cx.notify();
+        } else {
+            cx.propagate();
+        }
+    });
+}
+
 #[cfg(test)]
 pub mod tests {
     use super::*;
@@ -2579,7 +2698,7 @@ pub mod tests {
                     );
                     assert!(
                         search_view_2.query_editor.focus_handle(cx).is_focused(cx),
-                        "Focus should be moved into query editor fo the new window"
+                        "Focus should be moved into query editor of the new window"
                     );
                 });
         }).unwrap();

crates/semantic_index/README.md πŸ”—

@@ -10,7 +10,7 @@ nDCG@k:
 - "The relevance of result is represented by a score (also known as a 'grade') that is assigned to the search query. The scores of these results are then discounted based on their position in the search results -- did they get recommended first or last?"
 
 MRR@k:
-- "Mean reciprocal rank quantifies the rank of the first relevant item found in teh recommendation list."
+- "Mean reciprocal rank quantifies the rank of the first relevant item found in the recommendation list."
 
 MAP@k:
 - "Mean average precision averages the precision@k metric at each relevant item position in the recommendation list.

crates/semantic_index/src/parsing.rs πŸ”—

@@ -76,7 +76,7 @@ pub struct CodeContextRetriever {
 
 // Every match has an item, this represents the fundamental treesitter symbol and anchors the search
 // Every match has one or more 'name' captures. These indicate the display range of the item for deduplication.
-// If there are preceeding comments, we track this with a context capture
+// If there are preceding comments, we track this with a context capture
 // If there is a piece that should be collapsed in hierarchical queries, we capture it with a collapse capture
 // If there is a piece that should be kept inside a collapsed node, we capture it with a keep capture
 #[derive(Debug, Clone)]

crates/semantic_index/src/semantic_index.rs πŸ”—

@@ -275,11 +275,8 @@ pub struct SearchResult {
 
 impl SemanticIndex {
     pub fn global(cx: &mut AppContext) -> Option<Model<SemanticIndex>> {
-        if cx.has_global::<Model<Self>>() {
-            Some(cx.global::<Model<SemanticIndex>>().clone())
-        } else {
-            None
-        }
+        cx.try_global::<Model<Self>>()
+            .map(|semantic_index| semantic_index.clone())
     }
 
     pub fn authenticate(&mut self, cx: &mut AppContext) -> bool {

crates/semantic_index/src/semantic_index_tests.rs πŸ”—

@@ -110,7 +110,7 @@ async fn test_semantic_index(cx: &mut TestAppContext) {
         cx,
     );
 
-    // Test Include Files Functonality
+    // Test Include Files Functionality
     let include_files = vec![PathMatcher::new("*.rs").unwrap()];
     let exclude_files = vec![PathMatcher::new("*.rs").unwrap()];
     let rust_only_search_results = semantic_index
@@ -576,7 +576,7 @@ async fn test_code_context_retrieval_lua() {
             setmetatable(classdef, { __index = baseclass })
             -- All class instances have a reference to the class object.
             classdef.class = classdef
-            --- Recursivly allocates the inheritance tree of the instance.
+            --- Recursively allocates the inheritance tree of the instance.
             -- @param mastertable The 'root' of the inheritance tree.
             -- @return Returns the instance with the allocated inheritance tree.
             function classdef.alloc(mastertable)
@@ -607,7 +607,7 @@ async fn test_code_context_retrieval_lua() {
                     setmetatable(classdef, { __index = baseclass })
                     -- All class instances have a reference to the class object.
                     classdef.class = classdef
-                    --- Recursivly allocates the inheritance tree of the instance.
+                    --- Recursively allocates the inheritance tree of the instance.
                     -- @param mastertable The 'root' of the inheritance tree.
                     -- @return Returns the instance with the allocated inheritance tree.
                     function classdef.alloc(mastertable)
@@ -617,7 +617,7 @@ async fn test_code_context_retrieval_lua() {
                 end"#.unindent(),
             114),
             (r#"
-            --- Recursivly allocates the inheritance tree of the instance.
+            --- Recursively allocates the inheritance tree of the instance.
             -- @param mastertable The 'root' of the inheritance tree.
             -- @return Returns the instance with the allocated inheritance tree.
             function classdef.alloc(mastertable)
@@ -626,7 +626,7 @@ async fn test_code_context_retrieval_lua() {
                 -- Any functions this instance does not know of will 'look up' to the superclass definition.
                 setmetatable(instance, { __index = classdef, __newindex = mastertable })
                 return instance
-            end"#.unindent(), 809),
+            end"#.unindent(), 810),
         ]
     );
 }

crates/sqlez/src/migrations.rs πŸ”—

@@ -191,7 +191,7 @@ mod test {
     fn migrations_dont_rerun() {
         let connection = Connection::open_memory(Some("migrations_dont_rerun"));
 
-        // Create migration which clears a tabl
+        // Create migration which clears a table
 
         // Manually create the table for that migration with a row
         connection

crates/storybook/src/stories/auto_height_editor.rs πŸ”—

@@ -10,7 +10,11 @@ pub struct AutoHeightEditorStory {
 
 impl AutoHeightEditorStory {
     pub fn new(cx: &mut WindowContext) -> View<Self> {
-        cx.bind_keys([KeyBinding::new("enter", editor::Newline, Some("Editor"))]);
+        cx.bind_keys([KeyBinding::new(
+            "enter",
+            editor::actions::Newline,
+            Some("Editor"),
+        )]);
         cx.new_view(|cx| Self {
             editor: cx.new_view(|cx| {
                 let mut editor = Editor::auto_height(3, cx);

crates/storybook/src/stories/text.rs πŸ”—

@@ -65,7 +65,7 @@ impl Render for TextStory {
                                     ))
                     )
                     .usage(indoc! {r##"
-                        // NOTE: When rendering text in a horizonal flex container,
+                        // NOTE: When rendering text in a horizontal flex container,
                         // Taffy will not pass width constraints down from the parent.
                         // To fix this, render text in a parent with overflow: hidden
 
@@ -149,7 +149,7 @@ impl Render for TextStory {
 //         "Meanwhile, the lazy dog decided it was time for a change. ",
 //         "He started daily workout routines, ate healthier and became the fastest dog in town.",
 //     ))))
-//             // NOTE: When rendering text in a horizonal flex container,
+//             // NOTE: When rendering text in a horizontal flex container,
 //             // Taffy will not pass width constraints down from the parent.
 //             // To fix this, render text in a parent with overflow: hidden
 //                     .child(div().h_5())

crates/storybook/src/storybook.rs πŸ”—

@@ -60,8 +60,7 @@ fn main() {
     });
     let theme_name = args.theme.unwrap_or("One Dark".to_string());
 
-    let asset_source = Arc::new(Assets);
-    gpui::App::production(asset_source).run(move |cx| {
+    gpui::App::new().with_assets(Assets).run(move |cx| {
         load_embedded_fonts(cx).unwrap();
 
         let mut store = SettingsStore::default();

crates/terminal/src/terminal.rs πŸ”—

@@ -47,7 +47,7 @@ use std::{
     os::unix::prelude::AsRawFd,
     path::PathBuf,
     sync::Arc,
-    time::{Duration, Instant},
+    time::Duration,
 };
 use thiserror::Error;
 
@@ -385,8 +385,6 @@ impl TerminalBuilder {
             last_content: Default::default(),
             last_mouse: None,
             matches: Vec::new(),
-            last_synced: Instant::now(),
-            sync_task: None,
             selection_head: None,
             shell_fd: fd as u32,
             shell_pid,
@@ -542,8 +540,6 @@ pub struct Terminal {
     last_mouse_position: Option<Point<Pixels>>,
     pub matches: Vec<RangeInclusive<AlacPoint>>,
     pub last_content: TerminalContent,
-    last_synced: Instant,
-    sync_task: Option<Task<()>>,
     pub selection_head: Option<AlacPoint>,
     pub breadcrumb_text: String,
     shell_pid: u32,
@@ -977,40 +973,15 @@ impl Terminal {
         self.input(paste_text);
     }
 
-    pub fn try_sync(&mut self, cx: &mut ModelContext<Self>) {
+    pub fn sync(&mut self, cx: &mut ModelContext<Self>) {
         let term = self.term.clone();
-
-        let mut terminal = if let Some(term) = term.try_lock_unfair() {
-            term
-        } else if self.last_synced.elapsed().as_secs_f32() > 0.25 {
-            term.lock_unfair() // It's been too long, force block
-        } else if let None = self.sync_task {
-            //Skip this frame
-            let delay = cx.background_executor().timer(Duration::from_millis(16));
-            self.sync_task = Some(cx.spawn(|weak_handle, mut cx| async move {
-                delay.await;
-                if let Some(handle) = weak_handle.upgrade() {
-                    handle
-                        .update(&mut cx, |terminal, cx| {
-                            terminal.sync_task.take();
-                            cx.notify();
-                        })
-                        .ok();
-                }
-            }));
-            return;
-        } else {
-            //No lock and delayed rendering already scheduled, nothing to do
-            return;
-        };
-
+        let mut terminal = term.lock_unfair();
         //Note that the ordering of events matters for event processing
         while let Some(e) = self.events.pop_front() {
             self.process_terminal_event(&e, &mut terminal, cx)
         }
 
         self.last_content = Self::make_content(&terminal, &self.last_content);
-        self.last_synced = Instant::now();
     }
 
     fn make_content(term: &Term<ZedListener>, last_content: &TerminalContent) -> TerminalContent {

crates/terminal_view/src/terminal_element.rs πŸ”—

@@ -250,8 +250,8 @@ impl TerminalElement {
 
                 //Layout current cell text
                 {
-                    let cell_text = cell.c.to_string();
                     if !is_blank(&cell) {
+                        let cell_text = cell.c.to_string();
                         let cell_style =
                             TerminalElement::cell_style(&cell, fg, theme, text_style, hyperlink);
 
@@ -446,7 +446,7 @@ impl TerminalElement {
 
         let last_hovered_word = self.terminal.update(cx, |terminal, cx| {
             terminal.set_size(dimensions);
-            terminal.try_sync(cx);
+            terminal.sync(cx);
             if self.can_navigate_to_selected_word && terminal.can_navigate_to_selected_word() {
                 terminal.last_content.last_hovered_word.clone()
             } else {
@@ -587,24 +587,6 @@ impl TerminalElement {
         }
     }
 
-    fn register_key_listeners(&self, cx: &mut WindowContext) {
-        cx.on_key_event({
-            let this = self.terminal.clone();
-            move |event: &ModifiersChangedEvent, phase, cx| {
-                if phase != DispatchPhase::Bubble {
-                    return;
-                }
-
-                let handled =
-                    this.update(cx, |term, _| term.try_modifiers_change(&event.modifiers));
-
-                if handled {
-                    cx.refresh();
-                }
-            }
-        });
-    }
-
     fn register_mouse_listeners(
         &mut self,
         origin: Point<Pixels>,
@@ -772,53 +754,68 @@ impl Element for TerminalElement {
 
         self.register_mouse_listeners(origin, layout.mode, bounds, cx);
 
-        let mut interactivity = mem::take(&mut self.interactivity);
-        interactivity.paint(bounds, bounds.size, state, cx, |_, _, cx| {
-            cx.handle_input(&self.focus, terminal_input_handler);
+        self.interactivity
+            .paint(bounds, bounds.size, state, cx, |_, _, cx| {
+                cx.handle_input(&self.focus, terminal_input_handler);
 
-            self.register_key_listeners(cx);
+                cx.on_key_event({
+                    let this = self.terminal.clone();
+                    move |event: &ModifiersChangedEvent, phase, cx| {
+                        if phase != DispatchPhase::Bubble {
+                            return;
+                        }
 
-            for rect in &layout.rects {
-                rect.paint(origin, &layout, cx);
-            }
+                        let handled =
+                            this.update(cx, |term, _| term.try_modifiers_change(&event.modifiers));
 
-            cx.with_z_index(1, |cx| {
-                for (relative_highlighted_range, color) in layout.relative_highlighted_ranges.iter()
-                {
-                    if let Some((start_y, highlighted_range_lines)) =
-                        to_highlighted_range_lines(relative_highlighted_range, &layout, origin)
-                    {
-                        let hr = HighlightedRange {
-                            start_y, //Need to change this
-                            line_height: layout.dimensions.line_height,
-                            lines: highlighted_range_lines,
-                            color: color.clone(),
-                            //Copied from editor. TODO: move to theme or something
-                            corner_radius: 0.15 * layout.dimensions.line_height,
-                        };
-                        hr.paint(bounds, cx);
+                        if handled {
+                            cx.refresh();
+                        }
                     }
-                }
-            });
+                });
 
-            cx.with_z_index(2, |cx| {
-                for cell in &layout.cells {
-                    cell.paint(origin, &layout, bounds, cx);
+                for rect in &layout.rects {
+                    rect.paint(origin, &layout, cx);
                 }
-            });
 
-            if self.cursor_visible {
-                cx.with_z_index(3, |cx| {
-                    if let Some(cursor) = &layout.cursor {
-                        cursor.paint(origin, cx);
+                cx.with_z_index(1, |cx| {
+                    for (relative_highlighted_range, color) in
+                        layout.relative_highlighted_ranges.iter()
+                    {
+                        if let Some((start_y, highlighted_range_lines)) =
+                            to_highlighted_range_lines(relative_highlighted_range, &layout, origin)
+                        {
+                            let hr = HighlightedRange {
+                                start_y, //Need to change this
+                                line_height: layout.dimensions.line_height,
+                                lines: highlighted_range_lines,
+                                color: color.clone(),
+                                //Copied from editor. TODO: move to theme or something
+                                corner_radius: 0.15 * layout.dimensions.line_height,
+                            };
+                            hr.paint(bounds, cx);
+                        }
                     }
                 });
-            }
 
-            if let Some(mut element) = layout.hyperlink_tooltip.take() {
-                element.draw(origin, bounds.size.map(AvailableSpace::Definite), cx)
-            }
-        });
+                cx.with_z_index(2, |cx| {
+                    for cell in &layout.cells {
+                        cell.paint(origin, &layout, bounds, cx);
+                    }
+                });
+
+                if self.cursor_visible {
+                    cx.with_z_index(3, |cx| {
+                        if let Some(cursor) = &layout.cursor {
+                            cursor.paint(origin, cx);
+                        }
+                    });
+                }
+
+                if let Some(mut element) = layout.hyperlink_tooltip.take() {
+                    element.draw(origin, bounds.size.map(AvailableSpace::Definite), cx)
+                }
+            });
     }
 }
 

crates/terminal_view/src/terminal_panel.rs πŸ”—

@@ -387,7 +387,7 @@ impl Render for TerminalPanel {
             },
             cx,
         );
-        BufferSearchBar::register_inner(&mut registrar);
+        BufferSearchBar::register(&mut registrar);
         registrar.into_div().size_full().child(self.pane.clone())
     }
 }

crates/terminal_view/src/terminal_view.rs πŸ”—

@@ -2,7 +2,7 @@ mod persistence;
 pub mod terminal_element;
 pub mod terminal_panel;
 
-use editor::{scroll::autoscroll::Autoscroll, Editor};
+use editor::{scroll::Autoscroll, Editor};
 use gpui::{
     div, impl_actions, overlay, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
     FocusableView, KeyContext, KeyDownEvent, Keystroke, Model, MouseButton, MouseDownEvent, Pixels,
@@ -357,7 +357,7 @@ impl TerminalView {
         }
     }
 
-    fn select_all(&mut self, _: &editor::SelectAll, cx: &mut ViewContext<Self>) {
+    fn select_all(&mut self, _: &editor::actions::SelectAll, cx: &mut ViewContext<Self>) {
         self.terminal.update(cx, |term, _| term.select_all());
         cx.notify();
     }
@@ -674,9 +674,9 @@ impl Render for TerminalView {
                     self.can_navigate_to_selected_word,
                 )),
             )
-            .children(self.context_menu.as_ref().map(|(menu, positon, _)| {
+            .children(self.context_menu.as_ref().map(|(menu, position, _)| {
                 overlay()
-                    .position(*positon)
+                    .position(*position)
                     .anchor(gpui::AnchorCorner::TopLeft)
                     .child(menu.clone())
             }))

crates/theme/Cargo.toml πŸ”—

@@ -34,6 +34,7 @@ story = { path = "../story", optional = true }
 toml.workspace = true
 uuid.workspace = true
 util = { path = "../util" }
+color = {path = "../color"}
 itertools = { version = "0.11.0", optional = true }
 
 [dev-dependencies]

crates/theme/src/styles/syntax.rs πŸ”—

@@ -127,7 +127,7 @@ impl SyntaxTheme {
         }
     }
 
-    // TOOD: Get this working with `#[cfg(test)]`. Why isn't it?
+    // TODO: Get this working with `#[cfg(test)]`. Why isn't it?
     pub fn new_test(colors: impl IntoIterator<Item = (&'static str, Hsla)>) -> Self {
         SyntaxTheme {
             highlights: colors

crates/theme_importer/src/main.rs πŸ”—

@@ -188,7 +188,7 @@ fn main() -> Result<()> {
 
     let zed1_themes_path = PathBuf::from_str("assets/themes")?;
 
-    let zed1_theme_familes = [
+    let zed1_theme_families = [
         "Andromeda",
         "Atelier",
         "Ayu",
@@ -207,7 +207,7 @@ fn main() -> Result<()> {
     );
 
     let mut zed1_themes_by_family: IndexMap<String, Vec<UserTheme>> = IndexMap::from_iter(
-        zed1_theme_familes
+        zed1_theme_families
             .into_iter()
             .map(|family| (family.to_string(), Vec::new())),
     );

crates/ui/src/components/button/button_like.rs πŸ”—

@@ -111,7 +111,7 @@ pub enum ButtonStyle {
     #[default]
     Subtle,
 
-    /// Used for buttons that only change forground color on hover and active states.
+    /// Used for buttons that only change foreground color on hover and active states.
     ///
     /// TODO: Better docs for this.
     Transparent,
@@ -293,7 +293,7 @@ impl ButtonSize {
 /// This is also used to build the prebuilt buttons.
 #[derive(IntoElement)]
 pub struct ButtonLike {
-    base: Div,
+    pub base: Div,
     id: ElementId,
     pub(super) style: ButtonStyle,
     pub(super) disabled: bool,

crates/ui/src/components/button/icon_button.rs πŸ”—

@@ -24,14 +24,16 @@ pub struct IconButton {
 
 impl IconButton {
     pub fn new(id: impl Into<ElementId>, icon: IconName) -> Self {
-        Self {
+        let mut this = Self {
             base: ButtonLike::new(id),
             shape: IconButtonShape::Wide,
             icon,
             icon_size: IconSize::default(),
             icon_color: Color::Default,
             selected_icon: None,
-        }
+        };
+        this.base.base = this.base.base.debug_selector(|| format!("ICON-{:?}", icon));
+        this
     }
 
     pub fn shape(mut self, shape: IconButtonShape) -> Self {
@@ -127,16 +129,25 @@ impl VisibleOnHover for IconButton {
 }
 
 impl RenderOnce for IconButton {
-    fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
+    fn render(self, cx: &mut WindowContext) -> impl IntoElement {
         let is_disabled = self.base.disabled;
         let is_selected = self.base.selected;
         let selected_style = self.base.selected_style;
 
         self.base
             .map(|this| match self.shape {
-                IconButtonShape::Square => this
-                    .width(self.icon_size.rems().into())
-                    .height(self.icon_size.rems().into()),
+                IconButtonShape::Square => {
+                    let icon_size = self.icon_size.rems() * cx.rem_size();
+                    let padding = match self.icon_size {
+                        IconSize::Indicator => px(0.),
+                        IconSize::XSmall => px(0.),
+                        IconSize::Small => px(2.),
+                        IconSize::Medium => px(2.),
+                    };
+
+                    this.width((icon_size + padding * 2.).into())
+                        .height((icon_size + padding * 2.).into())
+                }
                 IconButtonShape::Wide => this,
             })
             .child(

crates/ui/src/components/context_menu.rs πŸ”—

@@ -51,6 +51,7 @@ impl ContextMenu {
             let _on_blur_subscription = cx.on_blur(&focus_handle, |this: &mut ContextMenu, cx| {
                 this.cancel(&menu::Cancel, cx)
             });
+            cx.refresh();
             f(
                 Self {
                     items: Default::default(),
@@ -302,6 +303,7 @@ impl Render for ContextMenu {
                                         .w_full()
                                         .justify_between()
                                         .child(label_element)
+                                        .debug_selector(|| format!("MENU_ITEM-{}", label))
                                         .children(action.as_ref().and_then(|action| {
                                             KeyBinding::for_action(&**action, cx)
                                                 .map(|binding| div().ml_1().child(binding))

crates/ui/src/components/popover.rs πŸ”—

@@ -12,7 +12,7 @@ use smallvec::SmallVec;
 /// user's mouse.)
 ///
 /// Example: A "new" menu with options like "new file", "new folder", etc,
-/// Linear's "Display" menu, a profile menu that appers when you click your avatar.
+/// Linear's "Display" menu, a profile menu that appears when you click your avatar.
 ///
 /// Related elements:
 ///

crates/ui/src/components/right_click_menu.rs πŸ”—

@@ -1,9 +1,9 @@
 use std::{cell::RefCell, rc::Rc};
 
 use gpui::{
-    overlay, AnchorCorner, AnyElement, Bounds, DismissEvent, DispatchPhase, Element, ElementId,
-    IntoElement, LayoutId, ManagedView, MouseButton, MouseDownEvent, ParentElement, Pixels, Point,
-    View, VisualContext, WindowContext,
+    overlay, AnchorCorner, AnyElement, BorrowWindow, Bounds, DismissEvent, DispatchPhase, Element,
+    ElementId, InteractiveBounds, IntoElement, LayoutId, ManagedView, MouseButton, MouseDownEvent,
+    ParentElement, Pixels, Point, View, VisualContext, WindowContext,
 };
 
 pub struct RightClickMenu<M: ManagedView> {
@@ -136,10 +136,14 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
         let child_layout_id = element_state.child_layout_id.clone();
         let child_bounds = cx.layout_bounds(child_layout_id.unwrap());
 
+        let interactive_bounds = InteractiveBounds {
+            bounds: bounds.intersect(&cx.content_mask().bounds),
+            stacking_order: cx.stacking_order().clone(),
+        };
         cx.on_mouse_event(move |event: &MouseDownEvent, phase, cx| {
             if phase == DispatchPhase::Bubble
                 && event.button == MouseButton::Right
-                && bounds.contains(&event.position)
+                && interactive_bounds.visibly_contains(&event.position, cx)
             {
                 cx.stop_propagation();
                 cx.prevent_default();

crates/ui/src/components/stories/icon_button.rs πŸ”—

@@ -1,7 +1,7 @@
 use gpui::Render;
 use story::{StoryContainer, StoryItem, StorySection};
 
-use crate::{prelude::*, Tooltip};
+use crate::{prelude::*, IconButtonShape, Tooltip};
 use crate::{IconButton, IconName};
 
 pub struct IconButtonStory;
@@ -113,9 +113,36 @@ impl Render for IconButtonStory {
 
         StoryContainer::new(
             "Icon Button",
-            "crates/ui2/src/components/stories/icon_button.rs",
+            "crates/ui/src/components/stories/icon_button.rs",
+        )
+        .child(StorySection::new().children(buttons))
+        .child(
+            StorySection::new().child(StoryItem::new(
+                "Square",
+                h_flex()
+                    .gap_2()
+                    .child(
+                        IconButton::new("square-medium", IconName::Close)
+                            .shape(IconButtonShape::Square)
+                            .icon_size(IconSize::Medium),
+                    )
+                    .child(
+                        IconButton::new("square-small", IconName::Close)
+                            .shape(IconButtonShape::Square)
+                            .icon_size(IconSize::Small),
+                    )
+                    .child(
+                        IconButton::new("square-xsmall", IconName::Close)
+                            .shape(IconButtonShape::Square)
+                            .icon_size(IconSize::XSmall),
+                    )
+                    .child(
+                        IconButton::new("square-indicator", IconName::Close)
+                            .shape(IconButtonShape::Square)
+                            .icon_size(IconSize::Indicator),
+                    ),
+            )),
         )
-        .children(vec![StorySection::new().children(buttons)])
         .into_element()
     }
 }

crates/ui/src/components/stories/toggle_button.rs πŸ”—

@@ -9,7 +9,7 @@ impl Render for ToggleButtonStory {
     fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
         StoryContainer::new(
             "Toggle Button",
-            "crates/ui2/src/components/stories/toggle_button.rs",
+            "crates/ui/src/components/stories/toggle_button.rs",
         )
         .child(
             StorySection::new().child(

crates/ui/src/components/tab.rs πŸ”—

@@ -37,8 +37,11 @@ pub struct Tab {
 
 impl Tab {
     pub fn new(id: impl Into<ElementId>) -> Self {
+        let id = id.into();
         Self {
-            div: div().id(id),
+            div: div()
+                .id(id.clone())
+                .debug_selector(|| format!("TAB-{}", id)),
             selected: false,
             position: TabPosition::First,
             close_side: TabCloseSide::End,

crates/ui/src/styles/elevation.rs πŸ”—

@@ -85,7 +85,7 @@ impl LayerIndex {
     }
 }
 
-/// An appropriate z-index for the given layer based on its intended useage.
+/// An appropriate z-index for the given layer based on its intended usage.
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 pub enum ElementIndex {
     Effect,

crates/vcs_menu/src/lib.rs πŸ”—

@@ -342,7 +342,7 @@ impl PickerDelegate for BranchListDelegate {
                                             }
                                             let status = repo.change_branch(&current_pick);
                                             if status.is_err() {
-                                                this.delegate.display_error_toast(format!("Failed to chec branch '{current_pick}', check for conflicts or unstashed files"), cx);
+                                                this.delegate.display_error_toast(format!("Failed to check branch '{current_pick}', check for conflicts or unstashed files"), cx);
                                                 status?;
                                             }
                                             this.cancel(&Default::default(), cx);

crates/vim/src/command.rs πŸ”—

@@ -1,5 +1,5 @@
 use command_palette::CommandInterceptResult;
-use editor::{SortLinesCaseInsensitive, SortLinesCaseSensitive};
+use editor::actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive};
 use gpui::{impl_actions, Action, AppContext, ViewContext};
 use serde_derive::Deserialize;
 use workspace::{SaveIntent, Workspace};
@@ -204,25 +204,31 @@ pub fn command_interceptor(mut query: &str, _: &AppContext) -> Option<CommandInt
 
         // quickfix / loclist (merged together for now)
         "cl" | "cli" | "clis" | "clist" => ("clist", diagnostics::Deploy.boxed_clone()),
-        "cc" => ("cc", editor::Hover.boxed_clone()),
-        "ll" => ("ll", editor::Hover.boxed_clone()),
-        "cn" | "cne" | "cnex" | "cnext" => ("cnext", editor::GoToDiagnostic.boxed_clone()),
-        "lne" | "lnex" | "lnext" => ("cnext", editor::GoToDiagnostic.boxed_clone()),
-
-        "cpr" | "cpre" | "cprev" | "cprevi" | "cprevio" | "cpreviou" | "cprevious" => {
-            ("cprevious", editor::GoToPrevDiagnostic.boxed_clone())
+        "cc" => ("cc", editor::actions::Hover.boxed_clone()),
+        "ll" => ("ll", editor::actions::Hover.boxed_clone()),
+        "cn" | "cne" | "cnex" | "cnext" => ("cnext", editor::actions::GoToDiagnostic.boxed_clone()),
+        "lne" | "lnex" | "lnext" => ("cnext", editor::actions::GoToDiagnostic.boxed_clone()),
+
+        "cpr" | "cpre" | "cprev" | "cprevi" | "cprevio" | "cpreviou" | "cprevious" => (
+            "cprevious",
+            editor::actions::GoToPrevDiagnostic.boxed_clone(),
+        ),
+        "cN" | "cNe" | "cNex" | "cNext" => {
+            ("cNext", editor::actions::GoToPrevDiagnostic.boxed_clone())
         }
-        "cN" | "cNe" | "cNex" | "cNext" => ("cNext", editor::GoToPrevDiagnostic.boxed_clone()),
-        "lp" | "lpr" | "lpre" | "lprev" | "lprevi" | "lprevio" | "lpreviou" | "lprevious" => {
-            ("lprevious", editor::GoToPrevDiagnostic.boxed_clone())
+        "lp" | "lpr" | "lpre" | "lprev" | "lprevi" | "lprevio" | "lpreviou" | "lprevious" => (
+            "lprevious",
+            editor::actions::GoToPrevDiagnostic.boxed_clone(),
+        ),
+        "lN" | "lNe" | "lNex" | "lNext" => {
+            ("lNext", editor::actions::GoToPrevDiagnostic.boxed_clone())
         }
-        "lN" | "lNe" | "lNex" | "lNext" => ("lNext", editor::GoToPrevDiagnostic.boxed_clone()),
 
         // modify the buffer (should accept [range])
         "j" | "jo" | "joi" | "join" => ("join", JoinLines.boxed_clone()),
         "d" | "de" | "del" | "dele" | "delet" | "delete" | "dl" | "dell" | "delel" | "deletl"
         | "deletel" | "dp" | "dep" | "delp" | "delep" | "deletp" | "deletep" => {
-            ("delete", editor::DeleteLine.boxed_clone())
+            ("delete", editor::actions::DeleteLine.boxed_clone())
         }
         "sor" | "sor " | "sort" | "sort " => ("sort", SortLinesCaseSensitive.boxed_clone()),
         "sor i" | "sort i" => ("sort i", SortLinesCaseInsensitive.boxed_clone()),

crates/vim/src/insert.rs πŸ”—

@@ -1,5 +1,5 @@
 use crate::{normal::repeat, state::Mode, Vim};
-use editor::{scroll::autoscroll::Autoscroll, Bias};
+use editor::{scroll::Autoscroll, Bias};
 use gpui::{actions, Action, ViewContext};
 use language::SelectionGoal;
 use workspace::Workspace;

crates/vim/src/mode_indicator.rs πŸ”—

@@ -4,12 +4,14 @@ use workspace::{item::ItemHandle, ui::prelude::*, StatusItemView};
 
 use crate::{state::Mode, Vim};
 
+/// The ModeIndicator displays the current mode in the status bar.
 pub struct ModeIndicator {
-    pub mode: Option<Mode>,
+    pub(crate) mode: Option<Mode>,
     _subscriptions: Vec<Subscription>,
 }
 
 impl ModeIndicator {
+    /// Construct a new mode indicator in this window.
     pub fn new(cx: &mut ViewContext<Self>) -> Self {
         let _subscriptions = vec![
             cx.observe_global::<Vim>(|this, cx| this.update_mode(cx)),
@@ -26,24 +28,16 @@ impl ModeIndicator {
 
     fn update_mode(&mut self, cx: &mut ViewContext<Self>) {
         // Vim doesn't exist in some tests
-        if !cx.has_global::<Vim>() {
+        let Some(vim) = cx.try_global::<Vim>() else {
             return;
-        }
+        };
 
-        let vim = Vim::read(cx);
         if vim.enabled {
             self.mode = Some(vim.state().mode);
         } else {
             self.mode = None;
         }
     }
-
-    pub fn set_mode(&mut self, mode: Mode, cx: &mut ViewContext<Self>) {
-        if self.mode != Some(mode) {
-            self.mode = Some(mode);
-            cx.notify();
-        }
-    }
 }
 
 impl Render for ModeIndicator {

crates/vim/src/motion.rs πŸ”—

@@ -1,11 +1,10 @@
 use editor::{
-    char_kind,
     display_map::{DisplaySnapshot, FoldPoint, ToDisplayPoint},
     movement::{self, find_boundary, find_preceding_boundary, FindRange, TextLayoutDetails},
-    Bias, CharKind, DisplayPoint, ToOffset,
+    Bias, DisplayPoint, ToOffset,
 };
 use gpui::{actions, impl_actions, px, ViewContext, WindowContext};
-use language::{Point, Selection, SelectionGoal};
+use language::{char_kind, CharKind, Point, Selection, SelectionGoal};
 use serde::Deserialize;
 use workspace::Workspace;
 

crates/vim/src/normal.rs πŸ”—

@@ -18,7 +18,7 @@ use crate::{
     Vim,
 };
 use collections::HashSet;
-use editor::scroll::autoscroll::Autoscroll;
+use editor::scroll::Autoscroll;
 use editor::{Bias, DisplayPoint};
 use gpui::{actions, ViewContext, WindowContext};
 use language::SelectionGoal;

crates/vim/src/normal/case.rs πŸ”—

@@ -1,4 +1,4 @@
-use editor::scroll::autoscroll::Autoscroll;
+use editor::scroll::Autoscroll;
 use gpui::ViewContext;
 use language::{Bias, Point};
 use workspace::Workspace;

crates/vim/src/normal/change.rs πŸ”—

@@ -1,13 +1,12 @@
 use crate::{motion::Motion, object::Object, state::Mode, utils::copy_selections_content, Vim};
 use editor::{
-    char_kind,
     display_map::DisplaySnapshot,
     movement::{self, FindRange, TextLayoutDetails},
-    scroll::autoscroll::Autoscroll,
-    CharKind, DisplayPoint,
+    scroll::Autoscroll,
+    DisplayPoint,
 };
 use gpui::WindowContext;
-use language::Selection;
+use language::{char_kind, CharKind, Selection};
 
 pub fn change_motion(vim: &mut Vim, motion: Motion, times: Option<usize>, cx: &mut WindowContext) {
     // Some motions ignore failure when switching to normal mode

crates/vim/src/normal/delete.rs πŸ”—

@@ -1,6 +1,6 @@
 use crate::{motion::Motion, object::Object, utils::copy_selections_content, Vim};
 use collections::{HashMap, HashSet};
-use editor::{display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Bias};
+use editor::{display_map::ToDisplayPoint, scroll::Autoscroll, Bias};
 use gpui::WindowContext;
 use language::Point;
 

crates/vim/src/normal/increment.rs πŸ”—

@@ -1,6 +1,6 @@
 use std::ops::Range;
 
-use editor::{scroll::autoscroll::Autoscroll, MultiBufferSnapshot, ToOffset, ToPoint};
+use editor::{scroll::Autoscroll, MultiBufferSnapshot, ToOffset, ToPoint};
 use gpui::{impl_actions, ViewContext, WindowContext};
 use language::{Bias, Point};
 use serde::Deserialize;

crates/vim/src/normal/paste.rs πŸ”—

@@ -1,8 +1,7 @@
 use std::{borrow::Cow, cmp};
 
 use editor::{
-    display_map::ToDisplayPoint, movement, scroll::autoscroll::Autoscroll, ClipboardSelection,
-    DisplayPoint,
+    display_map::ToDisplayPoint, movement, scroll::Autoscroll, ClipboardSelection, DisplayPoint,
 };
 use gpui::{impl_actions, ViewContext};
 use language::{Bias, SelectionGoal};

crates/vim/src/normal/repeat.rs πŸ”—

@@ -12,7 +12,7 @@ actions!(vim, [Repeat, EndRepeat]);
 
 fn should_replay(action: &Box<dyn Action>) -> bool {
     // skip so that we don't leave the character palette open
-    if editor::ShowCharacterPalette.partial_eq(&**action) {
+    if editor::actions::ShowCharacterPalette.partial_eq(&**action) {
         return false;
     }
     true
@@ -152,7 +152,7 @@ pub(crate) fn repeat(cx: &mut WindowContext, from_insert_mode: bool) {
 
         let mut count = Vim::read(cx).workspace_state.recorded_count.unwrap_or(1);
 
-        // if we came from insert mode we're just doing repititions 2 onwards.
+        // if we came from insert mode we're just doing repetitions 2 onwards.
         if from_insert_mode {
             count -= 1;
             new_actions[0] = actions[0].clone();

crates/vim/src/normal/scroll.rs πŸ”—

@@ -1,7 +1,7 @@
 use crate::Vim;
 use editor::{
     display_map::ToDisplayPoint,
-    scroll::{scroll_amount::ScrollAmount, VERTICAL_SCROLL_MARGIN},
+    scroll::{ScrollAmount, VERTICAL_SCROLL_MARGIN},
     DisplayPoint, Editor,
 };
 use gpui::{actions, ViewContext};

crates/vim/src/normal/search.rs πŸ”—

@@ -278,7 +278,7 @@ fn parse_replace_all(query: &str) -> Replacement {
         return Replacement::default();
     }
 
-    let Some(delimeter) = chars.next() else {
+    let Some(delimiter) = chars.next() else {
         return Replacement::default();
     };
 
@@ -301,13 +301,13 @@ fn parse_replace_all(query: &str) -> Replacement {
                 buffer.push('$')
             // unescape escaped parens
             } else if phase == 0 && c == '(' || c == ')' {
-            } else if c != delimeter {
+            } else if c != delimiter {
                 buffer.push('\\')
             }
             buffer.push(c)
         } else if c == '\\' {
             escaped = true;
-        } else if c == delimeter {
+        } else if c == delimiter {
             if phase == 0 {
                 buffer = &mut replacement;
                 phase = 1;

crates/vim/src/object.rs πŸ”—

@@ -1,13 +1,12 @@
 use std::ops::Range;
 
 use editor::{
-    char_kind,
     display_map::{DisplaySnapshot, ToDisplayPoint},
     movement::{self, FindRange},
-    Bias, CharKind, DisplayPoint,
+    Bias, DisplayPoint,
 };
 use gpui::{actions, impl_actions, ViewContext, WindowContext};
-use language::Selection;
+use language::{char_kind, CharKind, Selection};
 use serde::Deserialize;
 use workspace::Workspace;
 

crates/vim/src/test.rs πŸ”—

@@ -71,6 +71,30 @@ async fn test_toggle_through_settings(cx: &mut gpui::TestAppContext) {
     assert_eq!(cx.mode(), Mode::Normal);
 }
 
+#[gpui::test]
+async fn test_cancel_selection(cx: &mut gpui::TestAppContext) {
+    let mut cx = VimTestContext::new(cx, true).await;
+
+    cx.set_state(
+        indoc! {"The quick brown fox juˇmps over the lazy dog"},
+        Mode::Normal,
+    );
+    // jumps
+    cx.simulate_keystrokes(["v", "l", "l"]);
+    cx.assert_editor_state("The quick brown fox ju«mpsˇ» over the lazy dog");
+
+    cx.simulate_keystrokes(["escape"]);
+    cx.assert_editor_state("The quick brown fox jumpˇs over the lazy dog");
+
+    // go back to the same selection state
+    cx.simulate_keystrokes(["v", "h", "h"]);
+    cx.assert_editor_state("The quick brown fox juΒ«Λ‡mpsΒ» over the lazy dog");
+
+    // Ctrl-[ should behave like Esc
+    cx.simulate_keystrokes(["ctrl-["]);
+    cx.assert_editor_state("The quick brown fox juˇmps over the lazy dog");
+}
+
 #[gpui::test]
 async fn test_buffer_search(cx: &mut gpui::TestAppContext) {
     let mut cx = VimTestContext::new(cx, true).await;

crates/vim/src/test/neovim_connection.rs πŸ”—

@@ -359,7 +359,7 @@ impl NeovimConnection {
         // to add one to the end in visual mode.
         match mode {
             Some(Mode::VisualBlock) if selection_row != cursor_row => {
-                // in zed we fake a block selecrtion by using multiple cursors (one per line)
+                // in zed we fake a block selection by using multiple cursors (one per line)
                 // this code emulates that.
                 // to deal with casees where the selection is not perfectly rectangular we extract
                 // the content of the selection via the "a register to get the shape correctly.

crates/vim/src/vim.rs πŸ”—

@@ -1,3 +1,5 @@
+//! Vim support for Zed.
+
 #[cfg(test)]
 mod test;
 
@@ -38,12 +40,18 @@ use crate::state::ReplayableAction;
 /// Default: false
 pub struct VimModeSetting(pub bool);
 
+/// An Action to Switch between modes
 #[derive(Clone, Deserialize, PartialEq)]
 pub struct SwitchMode(pub Mode);
 
+/// PushOperator is used to put vim into a "minor" mode,
+/// where it's waiting for a specific next set of keystrokes.
+/// For example 'd' needs a motion to complete.
 #[derive(Clone, Deserialize, PartialEq)]
 pub struct PushOperator(pub Operator);
 
+/// Number is used to manage vim's count. Pushing a digit
+/// multiplis the current value by 10 and adds the digit.
 #[derive(Clone, Deserialize, PartialEq)]
 struct Number(usize);
 
@@ -51,11 +59,13 @@ actions!(
     vim,
     [Tab, Enter, Object, InnerObject, FindForward, FindBackward]
 );
+
 // in the workspace namespace so it's not filtered out when vim is disabled.
 actions!(workspace, [ToggleVimMode]);
 
 impl_actions!(vim, [SwitchMode, PushOperator, Number]);
 
+/// Initializes the `vim` crate.
 pub fn init(cx: &mut AppContext) {
     cx.set_global(Vim::default());
     VimModeSetting::register(cx);
@@ -119,6 +129,7 @@ fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
     visual::register(workspace, cx);
 }
 
+/// Registers a keystroke observer to observe keystrokes for the Vim integration.
 pub fn observe_keystrokes(cx: &mut WindowContext) {
     cx.observe_keystrokes(|keystroke_event, cx| {
         if let Some(action) = keystroke_event
@@ -160,6 +171,7 @@ pub fn observe_keystrokes(cx: &mut WindowContext) {
     .detach()
 }
 
+/// The state pertaining to Vim mode. Stored as a global.
 #[derive(Default)]
 pub struct Vim {
     active_editor: Option<WeakView<Editor>>,
@@ -251,6 +263,8 @@ impl Vim {
         Some(editor.update(cx, update))
     }
 
+    /// When doing an action that modifies the buffer, we start recording so that `.`
+    /// will replay the action.
     pub fn start_recording(&mut self, cx: &mut WindowContext) {
         if !self.workspace_state.replaying {
             self.workspace_state.recording = true;
@@ -295,12 +309,19 @@ impl Vim {
         }
     }
 
+    /// When finishing an action that modifies the buffer, stop recording.
+    /// as you usually call this within a keystroke handler we also ensure that
+    /// the current action is recorded.
     pub fn stop_recording(&mut self) {
         if self.workspace_state.recording {
             self.workspace_state.stop_recording_after_next_action = true;
         }
     }
 
+    /// Stops recording actions immediately rather than waiting until after the
+    /// next action to stop recording.
+    ///
+    /// This doesn't include the current action.
     pub fn stop_recording_immediately(&mut self, action: Box<dyn Action>) {
         if self.workspace_state.recording {
             self.workspace_state
@@ -311,6 +332,7 @@ impl Vim {
         }
     }
 
+    /// Explicitly record one action (equivalents to start_recording and stop_recording)
     pub fn record_current_action(&mut self, cx: &mut WindowContext) {
         self.start_recording(cx);
         self.stop_recording();
@@ -516,6 +538,7 @@ impl Vim {
         }
     }
 
+    /// Returns the state of the active editor.
     pub fn state(&self) -> &EditorState {
         if let Some(active_editor) = self.active_editor.as_ref() {
             if let Some(state) = self.editor_states.get(&active_editor.entity_id()) {
@@ -526,6 +549,7 @@ impl Vim {
         &self.default_state
     }
 
+    /// Updates the state of the active editor.
     pub fn update_state<T>(&mut self, func: impl FnOnce(&mut EditorState) -> T) -> T {
         let mut state = self.state().clone();
         let ret = func(&mut state);

crates/vim/src/visual.rs πŸ”—

@@ -5,7 +5,7 @@ use collections::HashMap;
 use editor::{
     display_map::{DisplaySnapshot, ToDisplayPoint},
     movement,
-    scroll::autoscroll::Autoscroll,
+    scroll::Autoscroll,
     Bias, DisplayPoint, Editor,
 };
 use gpui::{actions, ViewContext, WindowContext};
@@ -201,15 +201,13 @@ pub fn visual_block_motion(
         let mut row = tail.row();
 
         loop {
-            let layed_out_line = map.layout_row(row, &text_layout_details);
+            let laid_out_line = map.layout_row(row, &text_layout_details);
             let start = DisplayPoint::new(
                 row,
-                layed_out_line.closest_index_for_x(positions.start) as u32,
-            );
-            let mut end = DisplayPoint::new(
-                row,
-                layed_out_line.closest_index_for_x(positions.end) as u32,
+                laid_out_line.closest_index_for_x(positions.start) as u32,
             );
+            let mut end =
+                DisplayPoint::new(row, laid_out_line.closest_index_for_x(positions.end) as u32);
             if end <= start {
                 if start.column() == map.line_len(start.row()) {
                     end = start;
@@ -218,7 +216,7 @@ pub fn visual_block_motion(
                 }
             }
 
-            if positions.start <= layed_out_line.width {
+            if positions.start <= laid_out_line.width {
                 let selection = Selection {
                     id: s.new_selection_id(),
                     start: start.to_point(map),

crates/welcome/src/base_keymap_setting.rs πŸ”—

@@ -4,7 +4,7 @@ use schemars::JsonSchema;
 use serde::{Deserialize, Serialize};
 use settings::Settings;
 
-/// Base key bindings scheme. Base keymaps can be overriden with user keymaps.
+/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
 ///
 /// Default: VSCode
 #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]

crates/welcome/src/welcome.rs πŸ”—

@@ -60,190 +60,197 @@ pub struct WelcomePage {
 
 impl Render for WelcomePage {
     fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
-        h_flex().full().track_focus(&self.focus_handle).child(
-            v_flex()
-                .w_96()
-                .gap_4()
-                .mx_auto()
-                .child(
-                    svg()
-                        .path("icons/logo_96.svg")
-                        .text_color(gpui::white())
-                        .w(px(96.))
-                        .h(px(96.))
-                        .mx_auto(),
-                )
-                .child(
-                    h_flex()
-                        .justify_center()
-                        .child(Label::new("Code at the speed of thought")),
-                )
-                .child(
-                    v_flex()
-                        .gap_2()
-                        .child(
-                            Button::new("choose-theme", "Choose a theme")
-                                .full_width()
-                                .on_click(cx.listener(|this, _, cx| {
-                                    this.telemetry
-                                        .report_app_event("welcome page: change theme".to_string());
-                                    this.workspace
-                                        .update(cx, |workspace, cx| {
-                                            theme_selector::toggle(
-                                                workspace,
-                                                &Default::default(),
-                                                cx,
-                                            )
-                                        })
-                                        .ok();
-                                })),
-                        )
-                        .child(
-                            Button::new("choose-keymap", "Choose a keymap")
-                                .full_width()
-                                .on_click(cx.listener(|this, _, cx| {
-                                    this.telemetry.report_app_event(
-                                        "welcome page: change keymap".to_string(),
-                                    );
-                                    this.workspace
-                                        .update(cx, |workspace, cx| {
-                                            base_keymap_picker::toggle(
-                                                workspace,
-                                                &Default::default(),
-                                                cx,
-                                            )
-                                        })
-                                        .ok();
-                                })),
-                        )
-                        .child(
-                            Button::new("install-cli", "Install the CLI")
-                                .full_width()
-                                .on_click(cx.listener(|this, _, cx| {
-                                    this.telemetry
-                                        .report_app_event("welcome page: install cli".to_string());
-                                    cx.app_mut()
-                                        .spawn(
-                                            |cx| async move { install_cli::install_cli(&cx).await },
+        h_flex()
+            .full()
+            .bg(cx.theme().colors().editor_background)
+            .track_focus(&self.focus_handle)
+            .child(
+                v_flex()
+                    .w_96()
+                    .gap_4()
+                    .mx_auto()
+                    .child(
+                        svg()
+                            .path("icons/logo_96.svg")
+                            .text_color(gpui::white())
+                            .w(px(96.))
+                            .h(px(96.))
+                            .mx_auto(),
+                    )
+                    .child(
+                        h_flex()
+                            .justify_center()
+                            .child(Label::new("Code at the speed of thought")),
+                    )
+                    .child(
+                        v_flex()
+                            .gap_2()
+                            .child(
+                                Button::new("choose-theme", "Choose a theme")
+                                    .full_width()
+                                    .on_click(cx.listener(|this, _, cx| {
+                                        this.telemetry.report_app_event(
+                                            "welcome page: change theme".to_string(),
+                                        );
+                                        this.workspace
+                                            .update(cx, |workspace, cx| {
+                                                theme_selector::toggle(
+                                                    workspace,
+                                                    &Default::default(),
+                                                    cx,
+                                                )
+                                            })
+                                            .ok();
+                                    })),
+                            )
+                            .child(
+                                Button::new("choose-keymap", "Choose a keymap")
+                                    .full_width()
+                                    .on_click(cx.listener(|this, _, cx| {
+                                        this.telemetry.report_app_event(
+                                            "welcome page: change keymap".to_string(),
+                                        );
+                                        this.workspace
+                                            .update(cx, |workspace, cx| {
+                                                base_keymap_picker::toggle(
+                                                    workspace,
+                                                    &Default::default(),
+                                                    cx,
+                                                )
+                                            })
+                                            .ok();
+                                    })),
+                            )
+                            .child(
+                                Button::new("install-cli", "Install the CLI")
+                                    .full_width()
+                                    .on_click(cx.listener(|this, _, cx| {
+                                        this.telemetry.report_app_event(
+                                            "welcome page: install cli".to_string(),
+                                        );
+                                        cx.app_mut()
+                                            .spawn(|cx| async move {
+                                                install_cli::install_cli(&cx).await
+                                            })
+                                            .detach_and_log_err(cx);
+                                    })),
+                            ),
+                    )
+                    .child(
+                        v_flex()
+                            .p_3()
+                            .gap_2()
+                            .bg(cx.theme().colors().elevated_surface_background)
+                            .border_1()
+                            .border_color(cx.theme().colors().border)
+                            .rounded_md()
+                            .child(
+                                h_flex()
+                                    .gap_2()
+                                    .child(
+                                        Checkbox::new(
+                                            "enable-vim",
+                                            if VimModeSetting::get_global(cx).0 {
+                                                ui::Selection::Selected
+                                            } else {
+                                                ui::Selection::Unselected
+                                            },
                                         )
-                                        .detach_and_log_err(cx);
-                                })),
-                        ),
-                )
-                .child(
-                    v_flex()
-                        .p_3()
-                        .gap_2()
-                        .bg(cx.theme().colors().elevated_surface_background)
-                        .border_1()
-                        .border_color(cx.theme().colors().border)
-                        .rounded_md()
-                        .child(
-                            h_flex()
-                                .gap_2()
-                                .child(
-                                    Checkbox::new(
-                                        "enable-vim",
-                                        if VimModeSetting::get_global(cx).0 {
-                                            ui::Selection::Selected
-                                        } else {
-                                            ui::Selection::Unselected
-                                        },
+                                        .on_click(
+                                            cx.listener(move |this, selection, cx| {
+                                                this.telemetry.report_app_event(
+                                                    "welcome page: toggle vim".to_string(),
+                                                );
+                                                this.update_settings::<VimModeSetting>(
+                                                    selection,
+                                                    cx,
+                                                    |setting, value| *setting = Some(value),
+                                                );
+                                            }),
+                                        ),
                                     )
-                                    .on_click(cx.listener(
-                                        move |this, selection, cx| {
-                                            this.telemetry.report_app_event(
-                                                "welcome page: toggle vim".to_string(),
-                                            );
-                                            this.update_settings::<VimModeSetting>(
-                                                selection,
-                                                cx,
-                                                |setting, value| *setting = Some(value),
-                                            );
-                                        },
-                                    )),
-                                )
-                                .child(Label::new("Enable vim mode")),
-                        )
-                        .child(
-                            h_flex()
-                                .gap_2()
-                                .child(
-                                    Checkbox::new(
-                                        "enable-telemetry",
-                                        if TelemetrySettings::get_global(cx).metrics {
-                                            ui::Selection::Selected
-                                        } else {
-                                            ui::Selection::Unselected
-                                        },
-                                    )
-                                    .on_click(cx.listener(
-                                        move |this, selection, cx| {
-                                            this.telemetry.report_app_event(
-                                                "welcome page: toggle metric telemetry".to_string(),
-                                            );
-                                            this.update_settings::<TelemetrySettings>(
-                                                selection,
-                                                cx,
-                                                {
-                                                    let telemetry = this.telemetry.clone();
+                                    .child(Label::new("Enable vim mode")),
+                            )
+                            .child(
+                                h_flex()
+                                    .gap_2()
+                                    .child(
+                                        Checkbox::new(
+                                            "enable-telemetry",
+                                            if TelemetrySettings::get_global(cx).metrics {
+                                                ui::Selection::Selected
+                                            } else {
+                                                ui::Selection::Unselected
+                                            },
+                                        )
+                                        .on_click(
+                                            cx.listener(move |this, selection, cx| {
+                                                this.telemetry.report_app_event(
+                                                    "welcome page: toggle metric telemetry"
+                                                        .to_string(),
+                                                );
+                                                this.update_settings::<TelemetrySettings>(
+                                                    selection,
+                                                    cx,
+                                                    {
+                                                        let telemetry = this.telemetry.clone();
 
-                                                    move |settings, value| {
-                                                        settings.metrics = Some(value);
+                                                        move |settings, value| {
+                                                            settings.metrics = Some(value);
 
-                                                        telemetry.report_setting_event(
-                                                            "metric telemetry",
-                                                            value.to_string(),
-                                                        );
-                                                    }
-                                                },
-                                            );
-                                        },
-                                    )),
-                                )
-                                .child(Label::new("Send anonymous usage data")),
-                        )
-                        .child(
-                            h_flex()
-                                .gap_2()
-                                .child(
-                                    Checkbox::new(
-                                        "enable-crash",
-                                        if TelemetrySettings::get_global(cx).diagnostics {
-                                            ui::Selection::Selected
-                                        } else {
-                                            ui::Selection::Unselected
-                                        },
+                                                            telemetry.report_setting_event(
+                                                                "metric telemetry",
+                                                                value.to_string(),
+                                                            );
+                                                        }
+                                                    },
+                                                );
+                                            }),
+                                        ),
                                     )
-                                    .on_click(cx.listener(
-                                        move |this, selection, cx| {
-                                            this.telemetry.report_app_event(
-                                                "welcome page: toggle diagnostic telemetry"
-                                                    .to_string(),
-                                            );
-                                            this.update_settings::<TelemetrySettings>(
-                                                selection,
-                                                cx,
-                                                {
-                                                    let telemetry = this.telemetry.clone();
+                                    .child(Label::new("Send anonymous usage data")),
+                            )
+                            .child(
+                                h_flex()
+                                    .gap_2()
+                                    .child(
+                                        Checkbox::new(
+                                            "enable-crash",
+                                            if TelemetrySettings::get_global(cx).diagnostics {
+                                                ui::Selection::Selected
+                                            } else {
+                                                ui::Selection::Unselected
+                                            },
+                                        )
+                                        .on_click(
+                                            cx.listener(move |this, selection, cx| {
+                                                this.telemetry.report_app_event(
+                                                    "welcome page: toggle diagnostic telemetry"
+                                                        .to_string(),
+                                                );
+                                                this.update_settings::<TelemetrySettings>(
+                                                    selection,
+                                                    cx,
+                                                    {
+                                                        let telemetry = this.telemetry.clone();
 
-                                                    move |settings, value| {
-                                                        settings.diagnostics = Some(value);
+                                                        move |settings, value| {
+                                                            settings.diagnostics = Some(value);
 
-                                                        telemetry.report_setting_event(
-                                                            "diagnostic telemetry",
-                                                            value.to_string(),
-                                                        );
-                                                    }
-                                                },
-                                            );
-                                        },
-                                    )),
-                                )
-                                .child(Label::new("Send crash reports")),
-                        ),
-                ),
-        )
+                                                            telemetry.report_setting_event(
+                                                                "diagnostic telemetry",
+                                                                value.to_string(),
+                                                            );
+                                                        }
+                                                    },
+                                                );
+                                            }),
+                                        ),
+                                    )
+                                    .child(Label::new("Send crash reports")),
+                            ),
+                    ),
+            )
     }
 }
 

crates/workspace/src/item.rs πŸ”—

@@ -448,11 +448,13 @@ impl<T: Item> ItemHandle for View<T> {
                             workspace.unfollow(&pane, cx);
                         }
 
-                        if item.add_event_to_update_proto(
-                            event,
-                            &mut *pending_update.borrow_mut(),
-                            cx,
-                        ) && !pending_update_scheduled.load(Ordering::SeqCst)
+                        if item.focus_handle(cx).contains_focused(cx)
+                            && item.add_event_to_update_proto(
+                                event,
+                                &mut *pending_update.borrow_mut(),
+                                cx,
+                            )
+                            && !pending_update_scheduled.load(Ordering::SeqCst)
                         {
                             pending_update_scheduled.store(true, Ordering::SeqCst);
                             cx.defer({
@@ -586,13 +588,9 @@ impl<T: Item> ItemHandle for View<T> {
     }
 
     fn to_followable_item_handle(&self, cx: &AppContext) -> Option<Box<dyn FollowableItemHandle>> {
-        if cx.has_global::<FollowableItemBuilders>() {
-            let builders = cx.global::<FollowableItemBuilders>();
-            let item = self.to_any();
-            Some(builders.get(&item.entity_type())?.1(&item))
-        } else {
-            None
-        }
+        let builders = cx.try_global::<FollowableItemBuilders>()?;
+        let item = self.to_any();
+        Some(builders.get(&item.entity_type())?.1(&item))
     }
 
     fn on_release(

crates/workspace/src/pane.rs πŸ”—

@@ -195,7 +195,7 @@ struct NavHistoryState {
     next_timestamp: Arc<AtomicUsize>,
 }
 
-#[derive(Copy, Clone)]
+#[derive(Debug, Copy, Clone)]
 pub enum NavigationMode {
     Normal,
     GoingBack,
@@ -239,6 +239,7 @@ impl Pane {
         let focus_handle = cx.focus_handle();
 
         let subscriptions = vec![
+            cx.on_focus(&focus_handle, Pane::focus_in),
             cx.on_focus_in(&focus_handle, Pane::focus_in),
             cx.on_focus_out(&focus_handle, Pane::focus_out),
         ];
@@ -1462,7 +1463,7 @@ impl Pane {
                                 .icon_size(IconSize::Small)
                                 .on_click({
                                     let view = cx.view().clone();
-                                    move |_, cx| view.update(cx, Self::navigate_backward)
+                                    move |_, cx| view.update(cx, Self::navigate_forward)
                                 })
                                 .disabled(!self.can_navigate_forward())
                                 .tooltip(|cx| Tooltip::for_action("Go Forward", &GoForward, cx)),
@@ -1485,7 +1486,7 @@ impl Pane {
             .child(
                 div()
                     .min_w_6()
-                    // HACK: This empty child is currently necessary to force the drop traget to appear
+                    // HACK: This empty child is currently necessary to force the drop target to appear
                     // despite us setting a min width above.
                     .child("")
                     .h_full()

crates/workspace/src/pane_group.rs πŸ”—

@@ -3,14 +3,14 @@ use anyhow::{anyhow, Result};
 use call::{ActiveCall, ParticipantLocation};
 use collections::HashMap;
 use gpui::{
-    point, size, AnyView, AnyWeakView, Axis, Bounds, Entity as _, IntoElement, Model, Pixels,
+    point, size, AnyView, AnyWeakView, Axis, Bounds, IntoElement, Model, MouseButton, Pixels,
     Point, View, ViewContext,
 };
 use parking_lot::Mutex;
 use project::Project;
 use serde::Deserialize;
 use std::sync::Arc;
-use ui::{prelude::*, Button};
+use ui::prelude::*;
 
 pub const HANDLE_HITBOX_SIZE: f32 = 4.0;
 const HORIZONTAL_MIN_SIZE: f32 = 80.;
@@ -183,6 +183,7 @@ impl Member {
 
                 let mut leader_border = None;
                 let mut leader_status_box = None;
+                let mut leader_join_data = None;
                 if let Some(leader) = &leader {
                     let mut leader_color = cx
                         .theme()
@@ -199,44 +200,21 @@ impl Member {
                             if Some(leader_project_id) == project.read(cx).remote_id() {
                                 None
                             } else {
-                                let leader_user = leader.user.clone();
-                                let leader_user_id = leader.user.id;
-                                Some(
-                                    Button::new(
-                                        ("leader-status", pane.entity_id()),
-                                        format!(
-                                            "Follow {} to their active project",
-                                            leader_user.github_login,
-                                        ),
-                                    )
-                                    .on_click(cx.listener(
-                                        move |this, _, cx| {
-                                            crate::join_remote_project(
-                                                leader_project_id,
-                                                leader_user_id,
-                                                this.app_state().clone(),
-                                                cx,
-                                            )
-                                            .detach_and_log_err(cx);
-                                        },
-                                    )),
-                                )
+                                leader_join_data = Some((leader_project_id, leader.user.id));
+                                Some(Label::new(format!(
+                                    "Follow {} to their active project",
+                                    leader.user.github_login,
+                                )))
                             }
                         }
-                        ParticipantLocation::UnsharedProject => Some(Button::new(
-                            ("leader-status", pane.entity_id()),
-                            format!(
-                                "{} is viewing an unshared Zed project",
-                                leader.user.github_login
-                            ),
-                        )),
-                        ParticipantLocation::External => Some(Button::new(
-                            ("leader-status", pane.entity_id()),
-                            format!(
-                                "{} is viewing a window outside of Zed",
-                                leader.user.github_login
-                            ),
-                        )),
+                        ParticipantLocation::UnsharedProject => Some(Label::new(format!(
+                            "{} is viewing an unshared Zed project",
+                            leader.user.github_login
+                        ))),
+                        ParticipantLocation::External => Some(Label::new(format!(
+                            "{} is viewing a window outside of Zed",
+                            leader.user.github_login
+                        ))),
                     };
                 }
 
@@ -263,8 +241,27 @@ impl Member {
                                 .w_96()
                                 .bottom_3()
                                 .right_3()
+                                .elevation_2(cx)
+                                .p_1()
                                 .z_index(1)
-                                .child(status_box),
+                                .child(status_box)
+                                .when_some(
+                                    leader_join_data,
+                                    |this, (leader_project_id, leader_user_id)| {
+                                        this.cursor_pointer().on_mouse_down(
+                                            MouseButton::Left,
+                                            cx.listener(move |this, _, cx| {
+                                                crate::join_remote_project(
+                                                    leader_project_id,
+                                                    leader_user_id,
+                                                    this.app_state().clone(),
+                                                    cx,
+                                                )
+                                                .detach_and_log_err(cx);
+                                            }),
+                                        )
+                                    },
+                                ),
                         )
                     })
                     .into_any()
@@ -701,6 +698,7 @@ mod element {
             workspace
                 .update(cx, |this, cx| this.schedule_serialize(cx))
                 .log_err();
+            cx.stop_propagation();
             cx.refresh();
         }
 
@@ -757,8 +755,10 @@ mod element {
                                 workspace
                                     .update(cx, |this, cx| this.schedule_serialize(cx))
                                     .log_err();
+
                                 cx.refresh();
                             }
+                            cx.stop_propagation();
                         }
                     }
                 });

crates/workspace/src/workspace.rs πŸ”—

@@ -25,7 +25,7 @@ use futures::{
     Future, FutureExt, StreamExt,
 };
 use gpui::{
-    actions, canvas, div, impl_actions, point, size, Action, AnyElement, AnyModel, AnyView,
+    actions, canvas, div, impl_actions, point, px, size, Action, AnyElement, AnyModel, AnyView,
     AnyWeakView, AppContext, AsyncAppContext, AsyncWindowContext, BorrowWindow, Bounds, Context,
     Div, DragMoveEvent, Element, Entity, EntityId, EventEmitter, FocusHandle, FocusableView,
     GlobalPixels, InteractiveElement, IntoElement, KeyContext, LayoutId, ManagedView, Model,
@@ -616,8 +616,8 @@ impl Workspace {
         let modal_layer = cx.new_view(|_| ModalLayer::new());
 
         let mut active_call = None;
-        if cx.has_global::<Model<ActiveCall>>() {
-            let call = cx.global::<Model<ActiveCall>>().clone();
+        if let Some(call) = cx.try_global::<Model<ActiveCall>>() {
+            let call = call.clone();
             let mut subscriptions = Vec::new();
             subscriptions.push(cx.subscribe(&call, Self::on_active_call_event));
             active_call = Some((call, subscriptions));
@@ -2617,7 +2617,7 @@ impl Workspace {
 
                             // If the item belongs to a particular project, then it should
                             // only be included if this project is shared, and the follower
-                            // is in thie project.
+                            // is in the project.
                             //
                             // Some items, like channel notes, do not belong to a particular
                             // project, so they should be included regardless of whether the
@@ -3686,11 +3686,8 @@ impl WorkspaceStore {
         update: proto::update_followers::Variant,
         cx: &AppContext,
     ) -> Option<()> {
-        if !cx.has_global::<Model<ActiveCall>>() {
-            return None;
-        }
-
-        let room_id = ActiveCall::global(cx).read(cx).room()?.read(cx).id();
+        let active_call = cx.try_global::<Model<ActiveCall>>()?;
+        let room_id = active_call.read(cx).room()?.read(cx).id();
         let follower_ids: Vec<_> = self
             .followers
             .iter()
@@ -4302,6 +4299,10 @@ fn parse_pixel_size_env_var(value: &str) -> Option<Size<GlobalPixels>> {
     Some(size((width as f64).into(), (height as f64).into()))
 }
 
+pub fn titlebar_height(cx: &mut WindowContext) -> Pixels {
+    (1.75 * cx.rem_size()).max(px(32.))
+}
+
 struct DisconnectedOverlay;
 
 impl Element for DisconnectedOverlay {
@@ -4318,7 +4319,7 @@ impl Element for DisconnectedOverlay {
             .bg(background)
             .absolute()
             .left_0()
-            .top_0()
+            .top(titlebar_height(cx))
             .size_full()
             .flex()
             .items_center()

crates/zed/Cargo.toml πŸ”—

@@ -29,6 +29,7 @@ command_palette = { path = "../command_palette" }
 # component_test = { path = "../component_test" }
 client = { path = "../client" }
 # clock = { path = "../clock" }
+color = { path = "../color" }
 copilot = { path = "../copilot" }
 copilot_ui = { path = "../copilot_ui" }
 diagnostics = { path = "../diagnostics" }

crates/zed/src/app_menus.rs πŸ”—

@@ -53,39 +53,46 @@ pub fn app_menus() -> Vec<Menu<'static>> {
         Menu {
             name: "Edit",
             items: vec![
-                MenuItem::os_action("Undo", editor::Undo, OsAction::Undo),
-                MenuItem::os_action("Redo", editor::Redo, OsAction::Redo),
+                MenuItem::os_action("Undo", editor::actions::Undo, OsAction::Undo),
+                MenuItem::os_action("Redo", editor::actions::Redo, OsAction::Redo),
                 MenuItem::separator(),
-                MenuItem::os_action("Cut", editor::Cut, OsAction::Cut),
-                MenuItem::os_action("Copy", editor::Copy, OsAction::Copy),
-                MenuItem::os_action("Paste", editor::Paste, OsAction::Paste),
+                MenuItem::os_action("Cut", editor::actions::Cut, OsAction::Cut),
+                MenuItem::os_action("Copy", editor::actions::Copy, OsAction::Copy),
+                MenuItem::os_action("Paste", editor::actions::Paste, OsAction::Paste),
                 MenuItem::separator(),
                 MenuItem::action("Find", search::buffer_search::Deploy { focus: true }),
                 MenuItem::action("Find In Project", workspace::NewSearch),
                 MenuItem::separator(),
-                MenuItem::action("Toggle Line Comment", editor::ToggleComments::default()),
-                MenuItem::action("Emoji & Symbols", editor::ShowCharacterPalette),
+                MenuItem::action(
+                    "Toggle Line Comment",
+                    editor::actions::ToggleComments::default(),
+                ),
+                MenuItem::action("Emoji & Symbols", editor::actions::ShowCharacterPalette),
             ],
         },
         Menu {
             name: "Selection",
             items: vec![
-                MenuItem::os_action("Select All", editor::SelectAll, OsAction::SelectAll),
-                MenuItem::action("Expand Selection", editor::SelectLargerSyntaxNode),
-                MenuItem::action("Shrink Selection", editor::SelectSmallerSyntaxNode),
+                MenuItem::os_action(
+                    "Select All",
+                    editor::actions::SelectAll,
+                    OsAction::SelectAll,
+                ),
+                MenuItem::action("Expand Selection", editor::actions::SelectLargerSyntaxNode),
+                MenuItem::action("Shrink Selection", editor::actions::SelectSmallerSyntaxNode),
                 MenuItem::separator(),
-                MenuItem::action("Add Cursor Above", editor::AddSelectionAbove),
-                MenuItem::action("Add Cursor Below", editor::AddSelectionBelow),
+                MenuItem::action("Add Cursor Above", editor::actions::AddSelectionAbove),
+                MenuItem::action("Add Cursor Below", editor::actions::AddSelectionBelow),
                 MenuItem::action(
                     "Select Next Occurrence",
-                    editor::SelectNext {
+                    editor::actions::SelectNext {
                         replace_newest: false,
                     },
                 ),
                 MenuItem::separator(),
-                MenuItem::action("Move Line Up", editor::MoveLineUp),
-                MenuItem::action("Move Line Down", editor::MoveLineDown),
-                MenuItem::action("Duplicate Selection", editor::DuplicateLine),
+                MenuItem::action("Move Line Up", editor::actions::MoveLineUp),
+                MenuItem::action("Move Line Down", editor::actions::MoveLineDown),
+                MenuItem::action("Duplicate Selection", editor::actions::DuplicateLine),
             ],
         },
         Menu {
@@ -124,13 +131,13 @@ pub fn app_menus() -> Vec<Menu<'static>> {
                 MenuItem::action("Go to File", file_finder::Toggle),
                 // MenuItem::action("Go to Symbol in Project", project_symbols::Toggle),
                 MenuItem::action("Go to Symbol in Editor", outline::Toggle),
-                MenuItem::action("Go to Definition", editor::GoToDefinition),
-                MenuItem::action("Go to Type Definition", editor::GoToTypeDefinition),
-                MenuItem::action("Find All References", editor::FindAllReferences),
+                MenuItem::action("Go to Definition", editor::actions::GoToDefinition),
+                MenuItem::action("Go to Type Definition", editor::actions::GoToTypeDefinition),
+                MenuItem::action("Find All References", editor::actions::FindAllReferences),
                 MenuItem::action("Go to Line/Column", go_to_line::Toggle),
                 MenuItem::separator(),
-                MenuItem::action("Next Problem", editor::GoToDiagnostic),
-                MenuItem::action("Previous Problem", editor::GoToPrevDiagnostic),
+                MenuItem::action("Next Problem", editor::actions::GoToDiagnostic),
+                MenuItem::action("Previous Problem", editor::actions::GoToPrevDiagnostic),
             ],
         },
         Menu {

crates/zed/src/main.rs πŸ”—

@@ -67,7 +67,7 @@ fn main() {
     }
 
     log::info!("========== starting zed ==========");
-    let app = App::production(Arc::new(Assets));
+    let app = App::new().with_assets(Assets);
 
     let (installation_id, existing_installation_id_found) = app
         .background_executor()
@@ -102,13 +102,15 @@ fn main() {
     let open_listener = listener.clone();
     app.on_open_urls(move |urls, _| open_listener.open_urls(&urls));
     app.on_reopen(move |cx| {
-        if cx.has_global::<Weak<AppState>>() {
-            if let Some(app_state) = cx.global::<Weak<AppState>>().upgrade() {
-                workspace::open_new(&app_state, cx, |workspace, cx| {
-                    Editor::new_file(workspace, &Default::default(), cx)
-                })
-                .detach();
-            }
+        if let Some(app_state) = cx
+            .try_global::<Weak<AppState>>()
+            .map(|app_state| app_state.upgrade())
+            .flatten()
+        {
+            workspace::open_new(&app_state, cx, |workspace, cx| {
+                Editor::new_file(workspace, &Default::default(), cx)
+            })
+            .detach();
         }
     });
 

crates/zed/src/open_listener.rs πŸ”—

@@ -1,7 +1,7 @@
 use anyhow::{anyhow, Context, Result};
 use cli::{ipc, IpcHandshake};
 use cli::{ipc::IpcSender, CliRequest, CliResponse};
-use editor::scroll::autoscroll::Autoscroll;
+use editor::scroll::Autoscroll;
 use editor::Editor;
 use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};
 use futures::channel::{mpsc, oneshot};

crates/zed/src/zed.rs πŸ”—

@@ -730,7 +730,7 @@ fn open_bundled_file(
 mod tests {
     use super::*;
     use assets::Assets;
-    use editor::{scroll::autoscroll::Autoscroll, DisplayPoint, Editor, EditorEvent};
+    use editor::{scroll::Autoscroll, DisplayPoint, Editor, EditorEvent};
     use gpui::{
         actions, Action, AnyWindowHandle, AppContext, AssetSource, Entity, TestAppContext,
         VisualTestContext, WindowHandle,
@@ -1809,9 +1809,9 @@ mod tests {
                 assert!(workspace.active_item(cx).is_none());
             })
             .unwrap();
-        editor_1.assert_dropped();
-        editor_2.assert_dropped();
-        buffer.assert_dropped();
+        editor_1.assert_released();
+        editor_2.assert_released();
+        buffer.assert_released();
     }
 
     #[gpui::test]

docs/old/building-zed.md πŸ”—

@@ -36,7 +36,7 @@ Expect this to take 30min to an hour! Some of these steps will take quite a whil
        Unfortunately, unselecting `repo` scope and selecting every its inner scope instead does not allow the token users to read from private repositories
      - (not applicable) Fine-grained Tokens, at the moment of writing, did not allow any kind of access of non-owned private repos
    - Keep the token in the browser tab/editor for the next two steps
-1. (Optional but reccomended) Add your GITHUB_TOKEN to your `.zshrc` or `.bashrc` like this: `export GITHUB_TOKEN=yourGithubAPIToken`
+1. (Optional but recommended) Add your GITHUB_TOKEN to your `.zshrc` or `.bashrc` like this: `export GITHUB_TOKEN=yourGithubAPIToken`
 1. Ensure the Zed.dev website is checked out in a sibling directory and install it's dependencies:
     ```
     cd ..

docs/old/release-process.md πŸ”—

@@ -87,10 +87,14 @@ This means that when releasing a new version of Zed that has changes to the RPC
 
 1. This script will make local changes only, and print out a shell command that you can use to push the branch and tag.
 1. Pushing the new tag will trigger a CI build that, when finished will upload a new versioned docker image to the DigitalOcean docker registry.
-1. Once that CI job completes, you will be able to run the following command to deploy that docker image. The script takes two arguments: an environment (`production`, `preview`, or `staging`), and a version number (e.g. `0.10.1`).
+1. If needing a migration:
+   - First check that the migration is valid. The database serves both preview and stable simultaneously, so new columns need to have defaults and old tables or columns can't be dropped.
+   - Then use `script/deploy-migration` <release channel> <version number> (production, staging, preview, nightly). ex: `script/deploy-migration preview 0.19.0`
+    - If there is an 'Error: container is waiting to start', you can review logs manually with: `kubectl --namespace <environment> logs <pod name>` to make sure the mgiration ran successfully.
+1. Once that CI job completes, you will be able to run the following command to deploy that docker image. The script takes two arguments: an environment (`production`, `preview`, or `staging`), and a version number (e.g. `0.10.1`):
 
-   ```
-   script/deploy preview 0.10.1
-   ```
+```
+script/deploy preview 0.10.1
+```
 
-1. This command should complete quickly, updating the given environment to use the given version number of the `collab` server.
+1. This command should complete quickly, updating the given environment to use the given version number of the `collab` server.

docs/old/zed/syntax-highlighting.md πŸ”—

@@ -4,7 +4,7 @@ This doc is a work in progress!
 
 ## Defining syntax highlighting rules
 
-We use tree-sitter queries to match certian properties to highlight.
+We use tree-sitter queries to match certain properties to highlight.
 
 ### Simple Example:
 

docs/src/SUMMARY.md πŸ”—

@@ -4,15 +4,18 @@
 [Feedback](./feedback.md)
 
 # Configuring Zed
+
 - [Settings](./configuring_zed.md)
 - [Vim Mode](./configuring_zed__configuring_vim.md)
 
 # Using Zed
+
 - [Workflows]()
 - [Collaboration]()
 - [Using AI]()
 
 # Contributing to Zed
+
 - [How to Contribute]()
 - [Building from Source](./developing_zed__building_zed.md)
 - [Local Collaboration](./developing_zed__local_collaboration.md)

docs/src/configuring_zed.md πŸ”—

@@ -4,7 +4,7 @@
 
 Folder-specific settings are used to override Zed's global settings for files within a specific directory in the project panel.  To get started, create a `.zed` subdirectory and add a `settings.json` within it.  It should be noted that folder-specific settings don't need to live only a project's root, but can be defined at multiple levels in the project hierarchy.  In setups like this, Zed will find the configuration nearest to the file you are working in and apply those settings to it.  In most cases, this level of flexibility won't be needed and a single configuration for all files in a project is all that is required; the `Zed > Settings > Open Local Settings` menu action is built for this case.  Running this action will look for a `.zed/settings.json` file at the root of the first top-level directory in your project panel.  If it does not exist, it will create it.
 
-The following global settings can be overriden with a folder-specific configuration:
+The following global settings can be overridden with a folder-specific configuration:
 
 - `copilot`
 - `enable_language_server`

docs/src/developing_zed__adding_languages.md πŸ”—

@@ -8,7 +8,7 @@ Zed uses the [Language Server Protocol](https://microsoft.github.io/language-ser
 
 ### Defining syntax highlighting rules
 
-We use tree-sitter queries to match certian properties to highlight.
+We use tree-sitter queries to match certain properties to highlight.
 
 #### Simple Example:
 

docs/src/developing_zed__building_zed.md πŸ”—

@@ -1,107 +1,73 @@
 # Building Zed
 
-🚧 TODO:
-- [ ] Tidy up & update instructions
-- [ ] Remove ZI-specific things
-- [ ] Rework any steps that currently require a ZI-specific account
-
-How to build Zed from source for the first time.
-
-## Prerequisites
-
-- Be added to the GitHub organization
-- Be added to the Vercel team
-
-## Process
-
-Expect this to take 30min to an hour! Some of these steps will take quite a while based on your connection speed, and how long your first build will be.
-
-1. Install the [GitHub CLI](https://cli.github.com/):
-   - `brew install gh`
-1. Clone the `zed` repo
-   - `gh repo clone zed-industries/zed`
-1. Install Xcode from the macOS App Store
-1. Install Xcode command line tools
-   - `xcode-select --install`
-   - If xcode-select --print-path prints /Library/Developer/CommandLineTools… run `sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer.`
-1. Install [Postgres](https://postgresapp.com)
-1. Install rust/rustup
-   - `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
-1. Install the wasm toolchain
-   - `rustup target add wasm32-wasi`
-1. Install Livekit & Foreman
-   - `brew install livekit`
-   - `brew install foreman`
-1. Generate an GitHub API Key
-   - Go to https://github.com/settings/tokens and Generate new token
-   - GitHub currently provides two kinds of tokens:
-     - Classic Tokens, where only `repo` (Full control of private repositories) OAuth scope has to be selected
-       Unfortunately, unselecting `repo` scope and selecting every its inner scope instead does not allow the token users to read from private repositories
-     - (not applicable) Fine-grained Tokens, at the moment of writing, did not allow any kind of access of non-owned private repos
-   - Keep the token in the browser tab/editor for the next two steps
-1. (Optional but reccomended) Add your GITHUB_TOKEN to your `.zshrc` or `.bashrc` like this: `export GITHUB_TOKEN=yourGithubAPIToken`
-1. Ensure the Zed.dev website is checked out in a sibling directory and install its dependencies:
+## Dependencies
+
+- Install [Rust](https://www.rust-lang.org/tools/install)
+- Install [Xcode](https://apps.apple.com/us/app/xcode/id497799835?mt=12) from the macOS App Store
+
+- Install [Xcode command line tools](https://developer.apple.com/xcode/resources/)
+
+    ```bash
+    xcode-select --install
     ```
-    cd ..
-    git clone https://github.com/zed-industries/zed.dev
-    cd zed.dev && npm install
-    npm install -g vercel
+
+- Ensure that the Xcode command line tools are using your newly installed copy of Xcode:
+
+    ```
+    sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
     ```
-1. Link your zed.dev project to Vercel
-    - `vercel link`
-    - Select the `zed-industries` team. If you don't have this get someone on the team to add you to it.
-    - Select the `zed.dev` project
-1. Run `vercel pull` to pull down the environment variables and project info from Vercel
-1. Open Postgres.app
-1. From `./path/to/zed/`:
-    - Run:
-        - `GITHUB_TOKEN={yourGithubAPIToken} script/bootstrap`
-        - Replace `{yourGithubAPIToken}` with the API token you generated above.
-        - You don't need to include the GITHUB_TOKEN if you exported it above.
-    - Consider removing the token (if it's fine for you to recreate such tokens during occasional migrations) or store this token somewhere safe (like your Zed 1Password vault).
-   - If you get:
-     - ```bash
-       Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
-       Please create a new installation in /opt/homebrew using one of the
-       "Alternative Installs" from:
-       https://docs.brew.sh/Installation
-       ```
-     - In that case try:
-       - `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
-   - If Homebrew is not in your PATH:
-     - Replace `{username}` with your home folder name (usually your login name)
-     - `echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/{username}/.zprofile`
-     - `eval "$(/opt/homebrew/bin/brew shellenv)"`
-1. To run the Zed app:
-    - If you are working on zed:
-      - `cargo run`
-    - If you are just using the latest version, but not working on zed:
-      - `cargo run --release`
-    - If you need to run the collaboration server locally:
-      - `script/zed-local`
 
-## Troubleshooting
+* Install the Rust wasm toolchain:
+
+    ```bash
+    rustup target add wasm32-wasi
+    ```
+
+## Backend Dependencies
+
+If you are developing collaborative features of Zed, you'll need to install the dependencies of zed's `collab` server:
+
+- Install [Postgres](https://postgresapp.com)
+- Install [Livekit](https://formulae.brew.sh/formula/livekit) and [Foreman](https://formulae.brew.sh/formula/foreman)
+
+    ```bash
+    brew install livekit foreman
+    ```
+
+## Building Zed from Source
 
-### `error: failed to run custom build command for gpui v0.1.0 (/Users/path/to/zed)`
+Once you have the dependencies installed, you can build Zed using [Cargo](https://doc.rust-lang.org/cargo/).
 
-- Try `xcode-select --switch /Applications/Xcode.app/Contents/Developer`
+For a debug build:
 
-### `xcrun: error: unable to find utility "metal", not a developer tool or in PATH`
+```
+cargo run
+```
 
-### Seeding errors during `script/bootstrap` runs
+For a release build:
 
 ```
-seeding database...
-thread 'main' panicked at 'failed to deserialize github user from 'https://api.github.com/orgs/zed-industries/teams/staff/members': reqwest::Error { kind: Decode, source: Error("invalid type: map, expected a sequence", line: 1, column: 0) }', crates/collab/src/bin/seed.rs:111:10
+cargo run --release
 ```
 
-Wrong permissions for `GITHUB_TOKEN` token used, the token needs to be able to read from private repos.
-For Classic GitHub Tokens, that required OAuth scope `repo` (seacrh the scope name above for more details)
+And to run the tests:
+
+```
+cargo test --workspace
+```
 
-Same command
+## Troubleshooting
+
+### Error compiling metal shaders
+
+```
+error: failed to run custom build command for gpui v0.1.0 (/Users/path/to/zed)`**
+
+xcrun: error: unable to find utility "metal", not a developer tool or in PATH
+```
 
-`sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer`
+Try `xcode-select --switch /Applications/Xcode.app/Contents/Developer`
 
-### If you experience errors that mention some dependency is using unstable features
+### Cargo errors claiming that a dependency is using unstable features
 
-Try `cargo clean` and `cargo build`
+Try `cargo clean` and `cargo build`,

docs/src/developing_zed__local_collaboration.md πŸ”—

@@ -1,22 +1,46 @@
 # Local Collaboration
 
-## Setting up the local collaboration server
+First, make sure you've installed Zed's [backend dependencies](/developing_zed__building_zed.html#backend-dependencies).
 
-### Setting up for the first time?
+## Database setup
 
-1. Make sure you have livekit installed (`brew install livekit`)
-1. Install [Postgres](https://postgresapp.com) and run it.
-1. Then, from the root of the repo, run `script/bootstrap`.
+Before you can run the `collab` server locally, you'll need to set up a `zed` Postgres database.
 
-### Have a db that is out of date? / Need to migrate?
+```
+script/bootstrap
+```
 
-1. Make sure you have livekit installed (`brew install livekit`)
-1. Try `cd crates/collab && cargo run -- migrate` from the root of the repo.
-1. Run `script/seed-db`
+This script will set up the `zed` Postgres database, and populate it with some users. It requires internet access, because it fetches some users from the GitHub API.
 
-## Testing collab locally
+The script will create several *admin* users, who you'll sign in as by default when developing locally. The GitHub logins for these default admin users are specified in this file:
 
-1. Run `foreman start` from the root of the repo.
-1. In another terminal run `script/zed-local`.
-1. Two copies of Zed will open. Add yourself as a contact in the one that is not you.
-1. Start a collaboration session as normal with any open project.
+```
+cat crates/collab/.admins.default.json
+```
+
+To use a different set of admin users, you can create a file called `.admins.json` in the same directory:
+
+```
+cat > crates/collab/.admins.json <<JSON
+[
+  "your-github-login",
+  "another-github-login"
+]
+JSON
+```
+
+## Testing collaborative features locally
+
+In one terminal, run Zed's collaboration server and the `livekit` dev server:
+
+```
+foreman start
+```
+
+In a second terminal, run two or more instances of Zed.
+
+```
+script/zed-local -2
+```
+
+This script starts one to four instances of Zed, depending on the `-2`, `-3` or `-4` flags. Each instance will be connected to the local `collab` server, signed in as a different user from `.admins.json` or `.admins.default.json`.

script/deploy-collab πŸ”—

@@ -4,7 +4,7 @@ set -eu
 source script/lib/deploy-helpers.sh
 
 if [[ $# < 2 ]]; then
-  echo "Usage: $0 <production|staging|preview> <tag-name> (nightly is not yet supported)"
+  echo "Usage: $0 <production|preview|nightly|staging> <tag-name>"
   exit 1
 fi
 environment=$1

script/seed-db πŸ”—

@@ -2,8 +2,4 @@
 set -e
 
 cd crates/collab
-
-# Export contents of .env.toml
-eval "$(cargo run --quiet --bin dotenv)"
-
 cargo run --quiet --package=collab --features seed-support --bin seed -- $@

script/squawk πŸ”—

@@ -8,13 +8,12 @@ set -e
 
 if [ -z "$GITHUB_BASE_REF" ]; then
   echo 'Not a pull request, skipping squawk modified migrations linting'
-  return 0
+  exit
 fi
 
 SQUAWK_VERSION=0.26.0
 SQUAWK_BIN="./target/squawk-$SQUAWK_VERSION"
-SQUAWK_ARGS="--assume-in-transaction"
-
+SQUAWK_ARGS="--assume-in-transaction --config script/lib/squawk.toml"
 
 if  [ ! -f "$SQUAWK_BIN" ]; then
   curl -L -o "$SQUAWK_BIN" "https://github.com/sbdchd/squawk/releases/download/v$SQUAWK_VERSION/squawk-darwin-x86_64"

script/what-is-deployed πŸ”—

@@ -4,16 +4,11 @@ set -eu
 source script/lib/deploy-helpers.sh
 
 if [[ $# < 1 ]]; then
-  echo "Usage: $0 <production|staging|preview> (nightly is not yet supported)"
+  echo "Usage: $0 <production|preview|nightly|staging>"
   exit 1
 fi
 environment=$1
 
-if [[ ${environment} == "nightly" ]]; then
-  echo "nightly is not yet supported"
-  exit 1
-fi
-
 export_vars_for_environment ${environment}
 target_zed_kube_cluster
 

script/zed-local πŸ”—

@@ -4,6 +4,11 @@ const HELP = `
 USAGE
   zed-local  [options]  [zed args]
 
+SUMMARY
+  Runs 1-4 instances of Zed using a locally-running collaboration server.
+  Each instance of Zed will be signed in as a different user specified in
+  either \`.admins.json\` or \`.admins.default.json\`.
+
 OPTIONS
   --help        Print this help message
   --release     Build Zed in release mode
@@ -12,6 +17,16 @@ OPTIONS
 `.trim();
 
 const { spawn, execFileSync } = require("child_process");
+const assert = require("assert");
+
+const defaultUsers = require("../crates/collab/.admins.default.json");
+let users = defaultUsers;
+try {
+  const customUsers = require("../crates/collab/.admins.json");
+  assert(customUsers.length > 0);
+  assert(customUsers.every((user) => typeof user === "string"));
+  users.splice(0, 0, ...customUsers);
+} catch (_) {}
 
 const RESOLUTION_REGEX = /(\d+) x (\d+)/;
 const DIGIT_FLAG_REGEX = /^--?(\d+)$/;
@@ -71,10 +86,6 @@ if (instanceCount > 1) {
   }
 }
 
-let users = ["nathansobo", "as-cii", "maxbrunsfeld", "iamnbutler"];
-
-const RUST_LOG = process.env.RUST_LOG || "info";
-
 // If a user is specified, make sure it's first in the list
 const user = process.env.ZED_IMPERSONATE;
 if (user) {
@@ -88,18 +99,12 @@ const positions = [
   `${instanceWidth},${instanceHeight}`,
 ];
 
-const buildArgs = (() => {
-  const buildArgs = ["build"];
-  if (isReleaseMode) {
-    buildArgs.push("--release");
-  }
-
-  return buildArgs;
-})();
-const zedBinary = (() => {
-  const target = isReleaseMode ? "release" : "debug";
-  return `target/${target}/Zed`;
-})();
+let buildArgs = ["build"];
+let zedBinary = "target/debug/Zed";
+if (isReleaseMode) {
+  buildArgs.push("--release");
+  zedBinary = "target/release/Zed";
+}
 
 execFileSync("cargo", buildArgs, { stdio: "inherit" });
 setTimeout(() => {
@@ -115,7 +120,7 @@ setTimeout(() => {
         ZED_ADMIN_API_TOKEN: "secret",
         ZED_WINDOW_SIZE: `${instanceWidth},${instanceHeight}`,
         PATH: process.env.PATH,
-        RUST_LOG,
+        RUST_LOG: process.env.RUST_LOG || "info",
       },
     });
   }

typos.toml πŸ”—

@@ -0,0 +1,22 @@
+[files]
+ignore-files = true
+extend-exclude = [
+    # glsl isn't recognized by this tool
+    "crates/zed/src/languages/glsl/*",
+    # File suffixes aren't typos
+    "assets/icons/file_icons/file_types.json",
+    # Not our typos
+    "assets/themes/src/vscode/*",
+    "crates/live_kit_server/*",
+    # Vim makes heavy use of partial typing tables
+    "crates/vim/*",
+    # Editor and file finder rely on partial typing and custom in-string syntax
+    "crates/file_finder/src/file_finder.rs",
+    "crates/editor/src/editor_tests.rs",
+    # :/
+    "crates/collab/migrations/20231009181554_add_release_channel_to_rooms.sql",
+]
+
+[default]
+extend-ignore-re = ["ba"]
+check-filename = true