ZIm/crates
Max Brunsfeld e67c44a562
Fix file-reloading race condition (#3348)
### Summary

This PR fixes a bug that @as-cii and @osiewicz saw when the on-disk
contents of files changed due to running `git checkout` at the command
line. It caused a buffer's contents to diverge from the file's on disk
contents, but the buffer to show an *unmodified* status.

I've also introduced new APIs on gpui's deterministic executor, which
make it possible to write a test that reliably triggered the bug.

### Details

The bug is triggered by the following sequence of events:
1. A buffer's file changes on disk while the buffer is *unmodified*
2. Zed reloads the new content of the file
3. Before updating the buffer itself, Zed computes a *diff* between the
buffer's current contents, and the newly-loaded contents
4. While this diff is being computed, one of two things happens:
     1. the buffer changes on-disk *again*.
2. the user edits the buffer, but undoes the edit, so that the buffer
returns to an unmodified state

The bug itself was caused by a few things:
* The buffer diffing algorithm is pretty slow, because we perform a
character-wise diff
* We previously allowed multiple reload tasks to run concurrently
* When discarding an out-of-date diff, we failed to update parts of the
buffer's state (`saved_fingerprint`) which allow us to recognize that
the buffer's content differs from the file.

It was also difficult to reproduce the problem in tests, because under
deterministic execution, because it was extremely unlikely for other
tasks to make progress *after* a file had been reloaded, but *before*
the disk task has resolved. To help with testing, I introduced a pair of
executor APIs:

`spawn_labeled`, - for spawning a background task with a given *label*
`deprioritize_task` - for forcing tasks with a given label to run
*after* all other concurrent tasks.

I also made the `Model::next_event` test helper method more useful, in
that it no longer runs *until* parked in order to wait for the next
event to occur. It just steps the executor one poll at a time until the
model emits an event.

Release Notes:

- Fixed a bug that caused buffers to report incorrect modified/conflict
status when their buffers changed on disk multiple times in rapid
succession.
2023-11-16 20:19:16 -08:00
..
activity_indicator Unify icons using multiple variants, remove all unused icons 2023-09-15 12:50:49 -04:00
ai Add gpt-4-1106-preview model 2023-11-14 08:28:57 -05:00
ai2 Add gpt-4-1106-preview model 2023-11-14 08:28:57 -05:00
assistant Add gpt-4-1106-preview model 2023-11-14 08:28:57 -05:00
audio chore: remove unused features from rodio crate. (#2869) 2023-08-21 11:07:31 +02:00
audio2 Remove the 2s from source code 2023-11-02 10:55:02 -07:00
auto_update auto-update: Link to the current release's changelog, not the latest one (#3076) 2023-10-02 15:24:09 +02:00
breadcrumbs Move breadcrumb style to toolbar 2023-08-29 16:37:48 -04:00
call Merge branch 'main' into zed2 2023-10-27 10:55:15 +02:00
call2 Get workspace compiling with new event emitters 2023-11-08 19:29:00 -08:00
channel Set up UI to allow dragging a channel to the root 2023-10-25 15:39:02 +02:00
channel2 Get workspace compiling with new event emitters 2023-11-08 19:29:00 -08:00
cli Code to allow opening zed:/channel/1234 2023-10-05 14:57:45 -07:00
client Mark contact acceptance notifications as read automatically 2023-10-22 12:22:47 +02:00
client2 checkpoint 2023-11-08 23:16:04 -08:00
clock Remove local timestamps from CRDT operations 2023-08-31 16:23:06 -07:00
collab WIP 2023-11-06 11:18:56 -08:00
collab2 Parameterize theme2::init to allow loading just the base theme (#3345) 2023-11-16 13:03:30 -05:00
collab_ui Get collab2 green 2023-11-03 18:01:06 -07:00
collab_ui2 Actions‽ (#3349) 2023-11-16 18:18:04 -08:00
collections Move command palette filter into collections crate 2023-03-28 20:13:17 -07:00
command_palette Fix get_most_public_ancestor 2023-10-17 09:41:34 -06:00
command_palette2 #RemoveThe2 2023-11-16 18:04:35 -08:00
component_test Merge branch 'main' into disclosable-component 2023-08-23 16:30:27 -07:00
context_menu Add components example 2023-08-15 03:06:43 -07:00
copilot Port buffer reload bug fixes back to gpui1 crates 2023-11-16 16:03:14 -08:00
copilot2 WIP 2023-11-13 15:53:04 -08:00
copilot_button Unify icons using multiple variants, remove all unused icons 2023-09-15 12:50:49 -04:00
db Change from try (reserved keyword) to maybe 2023-10-25 07:10:21 -07:00
db2 Remove the 2s from source code 2023-11-02 10:55:02 -07:00
diagnostics Do not add diagnostics for any selection in the diagnostics panel 2023-11-10 13:35:58 +02:00
drag_and_drop Fix bug in channel rendering 2023-09-20 16:40:29 -07:00
editor Merge branch 'main' into search-query-suggestion-fixes 2023-11-09 14:18:17 -08:00
editor2 Actions‽ (#3349) 2023-11-16 18:18:04 -08:00
feature_flags Add feature flags handling to the client, rewrite staff mode to a trait extension style 2023-08-25 17:00:53 -07:00
feature_flags2 Remove the 2s from source code 2023-11-02 10:55:02 -07:00
feedback Add memory and cpu events 2023-10-02 19:35:31 -04:00
file_finder Omit history files with path that does not exist on disk anymore 2023-10-10 12:26:48 +03:00
file_finder2 Parameterize theme2::init to allow loading just the base theme (#3345) 2023-11-16 13:03:30 -05:00
fs Revert unnecessary style changes 2023-10-12 16:17:41 +03:00
fs2 port rope2 to zed2 2023-11-03 12:15:23 -04:00
fsevent 🎨 Specify more dependencies at the workspace level 2023-04-24 17:41:55 -07:00
fuzzy Ignore history items' paths when matching search queries 2023-10-09 23:14:32 +03:00
fuzzy2 Remove the 2s from source code 2023-11-02 10:55:02 -07:00
git move git2 to workspace dependency globally 2023-09-19 16:13:47 -04:00
git3 git -> git3 2023-11-02 19:18:01 -06:00
go_to_line Store an AnyWindowHandle in WindowContext 2023-08-08 11:08:37 -06:00
go_to_line2 Merge branch 'main' into element-types 2023-11-14 12:10:26 -07:00
gpui Implement most core actions 2023-11-14 00:06:33 -08:00
gpui2 Fix file-reloading race condition (#3348) 2023-11-16 20:19:16 -08:00
gpui2_macros Re-implement actions as derive macros instead of blanket impls 2023-11-16 17:32:02 -08:00
gpui_macros Suppress unused vars warning generated by gpui macro 2023-11-04 13:54:37 +02:00
install_cli Remove potential osascript hijacking 2023-08-18 17:40:08 -07:00
install_cli2 Implement most core actions 2023-11-14 00:06:33 -08:00
journal Enable test-support on editor in tests 2023-05-20 09:54:38 -06:00
journal2 Move journal2 to workspace2 2023-11-03 12:55:06 +02:00
language Don't update file's saved mtime when reload is aborted 2023-11-16 18:02:49 -08:00
language2 Don't update file's saved mtime when reload is aborted 2023-11-16 18:02:49 -08:00
language_selector Add tooltip to language selector 2023-09-08 12:41:32 -04:00
language_tools Reduce max log lines, clean log buffers better 2023-10-17 21:47:21 +03:00
live_kit_client WIP - make livekit work in GPUI2 2023-10-31 14:04:03 -07:00
live_kit_client2 Re-implement actions as derive macros instead of blanket impls 2023-11-16 17:32:02 -08:00
live_kit_server Fix notifications for membership changes too 2023-10-19 23:05:06 -06:00
lsp Capture language server stderr during startup/init and log if failure 2023-10-26 12:29:22 +02:00
lsp2 Remove the 2s from source code 2023-11-02 10:55:02 -07:00
media Update rust-bindgen dev-dependencies 2023-06-04 23:34:22 -04:00
menu Position and style the channel editor correctly 2023-08-08 14:06:29 -07:00
menu2 Call init 2023-11-09 13:14:11 -07:00
multi_buffer Extract multi_buffer module out of editor (#3170) 2023-10-25 19:31:47 +02:00
multi_buffer2 Get workspace compiling with new event emitters 2023-11-08 19:29:00 -08:00
node_runtime Avoid user NPM config/cache & put NodeRuntime installation behind a lock 2023-11-14 14:49:31 -05:00
notifications Load more notifications when scrolling down 2023-10-22 17:10:21 +02:00
notifications2 Add notifications2 2023-11-08 21:23:31 -08:00
outline feat(workspace): allow alternative actions to open files and symbols in split 2023-07-14 21:49:15 +02:00
picker Ensure the picker waits for pending updates 2023-09-20 20:44:26 -06:00
picker2 Merge branch 'main' into element-types 2023-11-14 15:49:10 -08:00
plugin 🎨 Specify more dependencies at the workspace level 2023-04-24 17:41:55 -07:00
plugin_macros Fix typos 2023-06-02 22:02:19 -04:00
plugin_runtime Fix typos 2023-06-02 22:02:19 -04:00
prettier Do not propose prettier formatters for documents in node_modules/ 2023-11-09 14:49:37 +02:00
prettier2 Merge branch 'main' into editor-tests 2023-11-13 09:54:02 -08:00
project Port buffer reload bug fixes back to gpui1 crates 2023-11-16 16:03:14 -08:00
project2 Rename deprioritize_task -> deprioritize 2023-11-16 20:03:18 -08:00
project_panel Change from try (reserved keyword) to maybe 2023-10-25 07:10:21 -07:00
project_panel2 Parameterize theme2::init to allow loading just the base theme (#3345) 2023-11-16 13:03:30 -05:00
project_symbols Add local next LSP adapter 2023-09-21 18:09:02 -07:00
quick_action_bar Hide inlay hints toggle if they are not supported by the current editor 2023-09-26 23:52:11 +02:00
recent_projects WIP 2023-08-10 10:26:48 -06:00
refineable Generalize Refineable derive macro to derive arbitrary traits on the refinement type 2023-11-09 13:23:31 -08:00
rich_text Account for markdown styling in mentions offset calculation. 2023-10-23 12:50:57 +02:00
rich_text2 Convert rich_text2 2023-11-02 19:30:33 -06:00
rope Port buffer reload bug fixes back to gpui1 crates 2023-11-16 16:03:14 -08:00
rope2 Fix race conditions and bugs in Buffer::reload 2023-11-16 16:03:14 -08:00
rpc Bump RPC version for channels + notifications changes 2023-10-25 17:37:14 +02:00
rpc2 checkpoint 2023-11-08 23:16:04 -08:00
search Add prettier workspace resolution test 2023-11-03 11:02:50 +02:00
semantic_index Add gpt-4-1106-preview model 2023-11-14 08:28:57 -05:00
settings Add feature flags handling to the client, rewrite staff mode to a trait extension style 2023-08-25 17:00:53 -07:00
settings2 Actions‽ (#3349) 2023-11-16 18:18:04 -08:00
snippet 🎨 Specify more dependencies at the workspace level 2023-04-24 17:41:55 -07:00
sqlez WIP 2023-11-16 10:40:02 +02:00
sqlez_macros 🎨 Specify more dependencies at the workspace level 2023-04-24 17:41:55 -07:00
storybook2 Parameterize theme2::init to allow loading just the base theme (#3345) 2023-11-16 13:03:30 -05:00
sum_tree Ensure collaborators cursor colors are the same in channel buffers as in projects 2023-08-24 11:31:41 -07:00
terminal Add Nushell support to venv activation 2023-10-01 23:38:30 -04:00
terminal2 More compilation fixes 2023-11-16 10:04:18 +02:00
terminal_view Allow file links in markdown & filter links a bit aggressively 2023-10-12 12:11:27 -04:00
terminal_view2 Re-implement actions as derive macros instead of blanket impls 2023-11-16 17:32:02 -08:00
text Don't depend on gpui2 in text 2023-11-03 14:53:08 +01:00
text2 port rope2 to zed2 2023-11-03 12:15:23 -04:00
theme Set up UI to allow dragging a channel to the root 2023-10-25 15:39:02 +02:00
theme2 Add ui_font settings and set default rem size accordingly (#3346) 2023-11-16 15:40:33 -05:00
theme_importer theme_importer: Support importing themes containing comments (#3298) 2023-11-09 19:22:15 -05:00
theme_selector Add feature flags handling to the client, rewrite staff mode to a trait extension style 2023-08-25 17:00:53 -07:00
ui2 Actions‽ (#3349) 2023-11-16 18:18:04 -08:00
util Add prettier workspace resolution test 2023-11-03 11:02:50 +02:00
vcs_menu vcs_menu: Fix a circular view handle in modal picker. 2023-10-25 18:34:14 +02:00
vim wip 2023-11-01 13:53:45 -06:00
welcome Add enable vim mode checkbox to welcome screen 2023-10-08 20:07:59 -04:00
workspace link to channel notes (#3167) 2023-10-25 15:53:34 +02:00
workspace2 Actions‽ (#3349) 2023-11-16 18:18:04 -08:00
xtask Fixup xtask compilation 2023-06-22 18:06:52 +02:00
zed v0.114.x dev 2023-11-15 12:47:40 -05:00
zed-actions Port journal to GPUI2 2023-10-28 11:37:25 -04:00
zed2 Re-implement actions as derive macros instead of blanket impls 2023-11-16 17:32:02 -08:00
zed_actions2 Re-implement actions as derive macros instead of blanket impls 2023-11-16 17:32:02 -08:00