zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
46.83k stars 2.68k forks source link

Empty project after reopening (instead of last workspace) #15642

Closed apricotbucket28 closed 1 month ago

apricotbucket28 commented 1 month ago

Check for existing issues

Describe the bug / provide steps to reproduce it

When closing Zed and then reopening, sometimes the workspace won't be restored and an empty project will be opened instead.

Reproduction steps:

  1. Open any project in Zed
  2. Close the window via the title bar close button, Ctrl + Shift + W or similar.
  3. Reopen Zed.
  4. Find that the project is not restored, but an empty project is instead.

Interestingly, I found that the following setting fixes the issue:

{
  "restore_on_startup": "last_workspace"
}

Environment

Zed: v0.148.0 (Zed Nightly 3bd9a3f478337deb4d46a711d5a3d5c0e4627216) OS: Linux Wayland fedora 40 Memory: 30.5 GiB Architecture: x86_64 GPU: AMD Radeon RX 6700 XT (RADV NAVI22) || radv || Mesa 24.1.4

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log
2024-08-01T15:28:51.226722309-03:00 [INFO] ========== starting zed ==========
2024-08-01T15:28:51.251541149-03:00 [INFO] perform;
2024-08-01T15:28:51.251637249-03:00 [INFO] read_command;
2024-08-01T15:28:51.251707039-03:00 [INFO] Opening main db
2024-08-01T15:28:51.251771339-03:00 [INFO] read_command;
2024-08-01T15:28:51.251916879-03:00 [INFO] socket reader;
2024-08-01T15:28:51.252103879-03:00 [INFO] new;
2024-08-01T15:28:51.252543198-03:00 [INFO] keep_updated;
2024-08-01T15:28:51.254421907-03:00 [INFO] Using git binary path: None
2024-08-01T15:28:51.273404042-03:00 [ERROR] No such file or directory (os error 2) about ["/home/apricotbucket28/.config/github-copilot"]
2024-08-01T15:28:51.273924541-03:00 [INFO] extensions updated. loading 8, reloading 0, unloading 0
2024-08-01T15:28:51.27521294-03:00 [INFO] activate is not implemented on Linux, ignoring the call
2024-08-01T15:28:51.27610899-03:00 [INFO] Opening main db
2024-08-01T15:28:51.276300199-03:00 [INFO] perform;
2024-08-01T15:28:51.276385079-03:00 [INFO] read_command;
2024-08-01T15:28:51.276479229-03:00 [INFO] read_command;
2024-08-01T15:28:51.276644109-03:00 [INFO] socket reader;
2024-08-01T15:28:51.279476977-03:00 [INFO] new;
2024-08-01T15:28:51.279992887-03:00 [INFO] keep_updated;
2024-08-01T15:28:51.299564101-03:00 [INFO] Enabling Vulkan Portability
2024-08-01T15:28:51.299632041-03:00 [INFO] Enabling color space support
2024-08-01T15:28:51.319606785-03:00 [INFO] Adapter "AMD Radeon RX 6700 XT (RADV NAVI22)"
2024-08-01T15:28:51.319679605-03:00 [INFO] Ray tracing is supported
2024-08-01T15:28:51.323857292-03:00 [INFO] Using surface present mode MAILBOX
2024-08-01T15:28:51.324135162-03:00 [WARN] Unable to forbid exclusive full screen
2024-08-01T15:28:51.324779171-03:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-08-01T15:28:51.324854271-03:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-08-01T15:28:51.324920041-03:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: PreMultiplied }
2024-08-01T15:28:51.328881128-03:00 [INFO] Using GPU: GPUSpecs { is_software_emulated: false, device_name: "AMD Radeon RX 6700 XT (RADV NAVI22)", driver_name: "radv", driver_info: "Mesa 24.1.4" }
2024-08-01T15:28:51.329189538-03:00 [INFO] set status on client 0: Authenticating
2024-08-01T15:28:51.329816997-03:00 [INFO] perform;
2024-08-01T15:28:51.329920507-03:00 [INFO] read_command;
2024-08-01T15:28:51.329999587-03:00 [INFO] Opening main db
2024-08-01T15:28:51.330101167-03:00 [INFO] read_command;
2024-08-01T15:28:51.330213767-03:00 [INFO] socket reader;
2024-08-01T15:28:51.335527723-03:00 [INFO] new;
2024-08-01T15:28:51.335905192-03:00 [INFO] keep_updated;
2024-08-01T15:28:51.362796791-03:00 [INFO] set environment variables from shell:/usr/bin/zsh, path:/home/apricotbucket28/.local/bin:/usr/lib64/ccache:/home/apricotbucket28/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/apricotbucket28/Development/flutter/bin:/home/apricotbucket28/.cargo/bin:/home/apricotbucket28/.local/zed-nightly.app/bin
2024-08-01T15:28:51.370537205-03:00 [INFO] Using surface present mode MAILBOX
2024-08-01T15:28:51.370850615-03:00 [WARN] Unable to forbid exclusive full screen
2024-08-01T15:28:51.371419134-03:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: Ignored }
2024-08-01T15:28:51.374642832-03:00 [INFO] Initializing default prettier with plugins {}
2024-08-01T15:28:51.375555961-03:00 [INFO] Using surface present mode MAILBOX
2024-08-01T15:28:51.375833171-03:00 [WARN] Unable to forbid exclusive full screen
2024-08-01T15:28:51.376066971-03:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: PreMultiplied }
2024-08-01T15:28:51.378797759-03:00 [INFO] Initializing default prettier with plugins {}
2024-08-01T15:28:51.378949888-03:00 [INFO] Initializing default prettier with plugins {}
2024-08-01T15:28:51.379511608-03:00 [INFO] Using surface present mode MAILBOX
2024-08-01T15:28:51.379789978-03:00 [WARN] Unable to forbid exclusive full screen
2024-08-01T15:28:51.383804784-03:00 [INFO] set status on client 119342: Connecting
2024-08-01T15:28:51.384705734-03:00 [INFO] Opening main db
2024-08-01T15:28:51.390416909-03:00 [INFO] Initializing default prettier with plugins {}
2024-08-01T15:28:51.392366048-03:00 [ERROR] no worktrees when constructing ProjectLspAdapterDelegate
2024-08-01T15:28:51.394555086-03:00 [INFO] perform;
2024-08-01T15:28:51.394661996-03:00 [INFO] read_command;
2024-08-01T15:28:51.394771806-03:00 [INFO] read_command;
2024-08-01T15:28:51.395027816-03:00 [INFO] socket reader;
2024-08-01T15:28:51.398391553-03:00 [INFO] perform;
2024-08-01T15:28:51.398489613-03:00 [INFO] read_command;
2024-08-01T15:28:51.398568293-03:00 [INFO] read_command;
2024-08-01T15:28:51.398651683-03:00 [INFO] socket reader;
2024-08-01T15:28:51.411690482-03:00 [INFO] Initializing default prettier with plugins {}
2024-08-01T15:28:51.41419622-03:00 [INFO] perform;
2024-08-01T15:28:51.41430663-03:00 [INFO] read_command;
2024-08-01T15:28:51.41440514-03:00 [INFO] read_command;
2024-08-01T15:28:51.41454106-03:00 [INFO] socket reader;
2024-08-01T15:28:51.417332398-03:00 [INFO] perform;
2024-08-01T15:28:51.417398548-03:00 [INFO] read_command;
2024-08-01T15:28:51.417464618-03:00 [INFO] read_command;
2024-08-01T15:28:51.417540958-03:00 [INFO] socket reader;
2024-08-01T15:28:51.430816137-03:00 [INFO] Initializing default prettier with plugins {}
2024-08-01T15:28:51.431426977-03:00 [INFO] perform;
2024-08-01T15:28:51.431534357-03:00 [INFO] read_command;
2024-08-01T15:28:51.431613477-03:00 [INFO] read_command;
2024-08-01T15:28:51.431727137-03:00 [INFO] socket reader;
2024-08-01T15:28:51.434549275-03:00 [INFO] perform;
2024-08-01T15:28:51.434633115-03:00 [INFO] read_command;
2024-08-01T15:28:51.434710714-03:00 [INFO] read_command;
2024-08-01T15:28:51.434809984-03:00 [INFO] socket reader;
2024-08-01T15:28:51.657733588-03:00 [INFO] Initializing default prettier with plugins {}
2024-08-01T15:28:51.658567368-03:00 [INFO] perform;
2024-08-01T15:28:51.658645268-03:00 [INFO] read_command;
2024-08-01T15:28:51.658709898-03:00 [INFO] read_command;
2024-08-01T15:28:51.658810938-03:00 [INFO] socket reader;
2024-08-01T15:28:51.663640704-03:00 [INFO] perform;
2024-08-01T15:28:51.663735514-03:00 [INFO] read_command;
2024-08-01T15:28:51.663816593-03:00 [INFO] read_command;
2024-08-01T15:28:51.663920333-03:00 [INFO] socket reader;
2024-08-01T15:28:51.66789427-03:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-08-01T15:28:52.18728989-03:00 [INFO] add connection to peer
2024-08-01T15:28:52.18736361-03:00 [INFO] add_connection;
2024-08-01T15:28:52.18746374-03:00 [INFO] waiting for server hello
2024-08-01T15:28:52.215157128-03:00 [INFO] got server hello
2024-08-01T15:28:52.215224278-03:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 462, id: 862635 })
2024-08-01T15:28:52.215332758-03:00 [INFO] set status on client 119342: Connected { peer_id: PeerId { owner_id: 462, id: 862635 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-08-01T15:28:54.103937297-03:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-08-01T15:28:54.115375358-03:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-08-01T15:28:54.128757017-03:00 [INFO] Creating a descriptor pool for at most 256 sets
2024-08-01T15:28:54.142058817-03:00 [INFO] Creating a descriptor pool for at most 256 sets
notpeter commented 1 month ago

I think this is partially a side effect of the difference between Mac (apps can be "open" but with no open windows) and Liunux/Windows (apps quit when the last window is closed).

The default for restore_on_startup is last_session which reopens all workspaces open when you quit, but none if you quit by closing the last workspace. While last_workspace re-opens the most recent workspace, even if you explicitly closed the workspace instead of quitting.

There is some more discussion here, but this is definitely still in development:

mrnugget commented 1 month ago

Thanks for reporting @apricotbucket28 and thanks @notpeter for digging in.

Agree, I think we need to do something like I outlined here: https://github.com/zed-industries/zed/pull/14965#issuecomment-2263610500

I just hope we can come up with something that's less hacky than this.

apricotbucket28 commented 1 month ago

Hi @mrnugget! IMHO the solution you came up with is fine, maybe the comment could be a bit more descriptive. Something like this:

// On Linux and Windows, closing the last window will also close the entire program
// See https://github.com/zed-industries/zed/issues/15642
#[cfg(not(target_os = "macos"))]
let quitting = quitting || cx.windows().len() == 1;

If you think it's fine I can open up a PR with the fix!

VSCode, for reference, seems to do the following:

Zed with the aforementioned fix matches VSCode's behaviour, except in the last case (an empty project opens instead, probably a different issue here)

Edit: There's actually a bug with this approach, replacing the current workspace in the current window will cause multiple workspaces to be opened again. Second edit: So that implementation isn't correct, but that bug seems to exist in master nevertheless.

mrnugget commented 1 month ago

Thanks @apricotbucket28!