zed icon indicating copy to clipboard operation
zed copied to clipboard

Wrong behaviour opening file that contains colon : in filename

Open liuyujielol opened this issue 1 year ago • 6 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

When opening a file has : in its filename, zed opens a new buffer instead of the file. For example, when opening a file named a:b.txt it opens a new buffer named a. This hapens on lastest stable v0.143.6 and master, self compiled or relaese binary.

Environment

OS: Gentoo Linux 2.15 x86_64 CPU: AMD Ryzen 7 3700X GPU: AMD Radeon RX 6500 XT DE: KDE Plasma 6.1.2 WM: KWin (Wayland)

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

relaese binary https://github.com/zed-industries/zed/releases/tag/v0.143.6 image

compile from master image

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

Zed.log

2024-07-11T04:29:56+08:00 [INFO] ========== starting zed ==========
2024-07-11T04:29:56+08:00 [INFO] Opening main db
2024-07-11T04:29:56+08:00 [INFO] perform;
2024-07-11T04:29:56+08:00 [INFO] read_command;
2024-07-11T04:29:56+08:00 [INFO] read_command;
2024-07-11T04:29:56+08:00 [INFO] socket reader;
2024-07-11T04:29:56+08:00 [INFO] new;
2024-07-11T04:29:56+08:00 [INFO] keep_updated;
2024-07-11T04:29:56+08:00 [INFO] Using git binary path: None
2024-07-11T04:29:57+08:00 [INFO] extensions updated. loading 2, reloading 0, unloading 0
2024-07-11T04:29:57+08:00 [INFO] activate is not implemented on Linux, ignoring the call
2024-07-11T04:29:57+08:00 [INFO] perform;
2024-07-11T04:29:57+08:00 [INFO] read_command;
2024-07-11T04:29:57+08:00 [INFO] Opening main db
2024-07-11T04:29:57+08:00 [INFO] read_command;
2024-07-11T04:29:57+08:00 [INFO] socket reader;
2024-07-11T04:29:57+08:00 [INFO] new;
2024-07-11T04:29:57+08:00 [INFO] keep_updated;
2024-07-11T04:29:57+08:00 [INFO] Enabling Vulkan Portability
2024-07-11T04:29:57+08:00 [INFO] Enabling color space support
2024-07-11T04:29:57+08:00 [INFO] set environment variables from shell:/bin/zsh, path:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin:/usr/lib/llvm/18/bin:/etc/eselect/wine/bin
2024-07-11T04:29:57+08:00 [INFO] Adapter "AMD Radeon RX 6500 XT (RADV NAVI24)"
2024-07-11T04:29:57+08:00 [INFO] Ray tracing is supported
2024-07-11T04:29:57+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:29:57+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:29:57+08:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-07-11T04:29:57+08:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-07-11T04:29:57+08:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: PreMultiplied }
2024-07-11T04:29:57+08:00 [INFO] set status on client 0: Authenticating
2024-07-11T04:29:57+08:00 [INFO] Opening main db
2024-07-11T04:29:57+08:00 [INFO] perform;
2024-07-11T04:29:57+08:00 [INFO] read_command;
2024-07-11T04:29:57+08:00 [INFO] read_command;
2024-07-11T04:29:57+08:00 [INFO] socket reader;
2024-07-11T04:29:57+08:00 [ERROR] failed to canonicalize root path: No such file or directory (os error 2)
2024-07-11T04:29:57+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:29:57+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:29:57+08:00 [INFO] new;
2024-07-11T04:29:57+08:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: Ignored }
2024-07-11T04:29:57+08:00 [INFO] keep_updated;
2024-07-11T04:29:57+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:29:57+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:29:57+08:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: PreMultiplied }
2024-07-11T04:29:57+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:29:57+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:29:57+08:00 [INFO] set status on client 177024: Connecting
2024-07-11T04:29:57+08:00 [INFO] Opening main db
2024-07-11T04:29:57+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:29:57+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:29:58+08:00 [INFO] Node runtime install_if_needed
2024-07-11T04:29:58+08:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-07-11T04:29:59+08:00 [INFO] starting language server. binary path: "/home/skye/.local/share/zed/node/node-v18.15.0-linux-x64/bin/node", working directory: "/", args: ["/home/skye/.local/share/zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-07-11T04:29:59+08:00 [INFO] add connection to peer
2024-07-11T04:29:59+08:00 [INFO] add_connection;
2024-07-11T04:29:59+08:00 [INFO] waiting for server hello
2024-07-11T04:29:59+08:00 [INFO] got server hello
2024-07-11T04:29:59+08:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 451, id: 5449048 })
2024-07-11T04:29:59+08:00 [INFO] set status on client 177024: Connected { peer_id: PeerId { owner_id: 451, id: 5449048 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-07-11T04:29:59+08:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-10T20:29:59.754Z] Agent service starting",
  "metadataStr": "[DEBUG] [agent] [2024-07-10T20:29:59.754Z]",
  "extra": [
    "Agent service starting"
  ]
}
2024-07-11T04:29:59+08:00 [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
  "registrations": [
    {
      "id": "6d232666-e706-4ad6-a15b-0f6856d51ad6",
      "method": "workspace/didChangeWorkspaceFolders",
      "registerOptions": {}
    }
  ]
}
2024-07-11T04:29:59+08:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-10T20:29:59.773Z] Telemetry initialized",
  "metadataStr": "[DEBUG] [agent] [2024-07-10T20:29:59.773Z]",
  "extra": [
    "Telemetry initialized"
  ]
}
2024-07-11T04:31:56+08:00 [ERROR] window not found
2024-07-11T04:31:56+08:00 [ERROR] window not found
2024-07-11T04:32:08+08:00 [INFO] ========== starting zed ==========
2024-07-11T04:32:08+08:00 [INFO] Opening main db
2024-07-11T04:32:08+08:00 [INFO] perform;
2024-07-11T04:32:08+08:00 [INFO] read_command;
2024-07-11T04:32:08+08:00 [INFO] read_command;
2024-07-11T04:32:08+08:00 [INFO] socket reader;
2024-07-11T04:32:08+08:00 [INFO] new;
2024-07-11T04:32:08+08:00 [INFO] Using git binary path: None
2024-07-11T04:32:08+08:00 [INFO] keep_updated;
2024-07-11T04:32:08+08:00 [INFO] extensions updated. loading 2, reloading 0, unloading 0
2024-07-11T04:32:08+08:00 [INFO] activate is not implemented on Linux, ignoring the call
2024-07-11T04:32:08+08:00 [INFO] perform;
2024-07-11T04:32:08+08:00 [INFO] read_command;
2024-07-11T04:32:08+08:00 [INFO] read_command;
2024-07-11T04:32:08+08:00 [INFO] socket reader;
2024-07-11T04:32:08+08:00 [INFO] new;
2024-07-11T04:32:08+08:00 [INFO] keep_updated;
2024-07-11T04:32:08+08:00 [INFO] set status on client 0: Authenticating
2024-07-11T04:32:08+08:00 [INFO] Opening main db
2024-07-11T04:32:08+08:00 [INFO] perform;
2024-07-11T04:32:08+08:00 [INFO] read_command;
2024-07-11T04:32:08+08:00 [INFO] read_command;
2024-07-11T04:32:08+08:00 [INFO] socket reader;
2024-07-11T04:32:08+08:00 [INFO] set environment variables from shell:/bin/zsh, path:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/bin:/usr/lib/llvm/18/bin:/etc/eselect/wine/bin
2024-07-11T04:32:08+08:00 [INFO] Enabling Vulkan Portability
2024-07-11T04:32:08+08:00 [INFO] Enabling color space support
2024-07-11T04:32:08+08:00 [INFO] new;
2024-07-11T04:32:08+08:00 [INFO] keep_updated;
2024-07-11T04:32:08+08:00 [INFO] Adapter "AMD Radeon RX 6500 XT (RADV NAVI24)"
2024-07-11T04:32:08+08:00 [INFO] Ray tracing is supported
2024-07-11T04:32:08+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:32:08+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:32:08+08:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-07-11T04:32:08+08:00 [INFO] Creating a descriptor pool for at most 16 sets
2024-07-11T04:32:08+08:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: PreMultiplied }
2024-07-11T04:32:08+08:00 [INFO] set status on client 177024: Connecting
2024-07-11T04:32:08+08:00 [INFO] Opening main db
2024-07-11T04:32:08+08:00 [ERROR] failed to canonicalize root path: No such file or directory (os error 2)
2024-07-11T04:32:08+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:32:08+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:32:08+08:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: Ignored }
2024-07-11T04:32:08+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:32:08+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:32:08+08:00 [INFO] Initializing Blade pipelines for surface SurfaceInfo { format: Bgra8UnormSrgb, alpha: PreMultiplied }
2024-07-11T04:32:08+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:32:08+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:32:08+08:00 [INFO] Opening main db
2024-07-11T04:32:08+08:00 [INFO] Using surface present mode MAILBOX
2024-07-11T04:32:08+08:00 [WARN] Unable to forbid exclusive full screen
2024-07-11T04:32:09+08:00 [INFO] Node runtime install_if_needed
2024-07-11T04:32:10+08:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-07-11T04:32:10+08:00 [INFO] starting language server. binary path: "/home/skye/.local/share/zed/node/node-v18.15.0-linux-x64/bin/node", working directory: "/", args: ["/home/skye/.local/share/zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-07-11T04:32:11+08:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-10T20:32:11.636Z] Agent service starting",
  "metadataStr": "[DEBUG] [agent] [2024-07-10T20:32:11.636Z]",
  "extra": [
    "Agent service starting"
  ]
}
2024-07-11T04:32:11+08:00 [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
  "registrations": [
    {
      "id": "6d4f1ca8-614d-432f-b11e-fcec43908aba",
      "method": "workspace/didChangeWorkspaceFolders",
      "registerOptions": {}
    }
  ]
}
2024-07-11T04:32:11+08:00 [INFO] add connection to peer
2024-07-11T04:32:11+08:00 [INFO] add_connection;
2024-07-11T04:32:11+08:00 [INFO] waiting for server hello
2024-07-11T04:32:11+08:00 [INFO] got server hello
2024-07-11T04:32:11+08:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 451, id: 5450237 })
2024-07-11T04:32:11+08:00 [INFO] set status on client 177024: Connected { peer_id: PeerId { owner_id: 451, id: 5450237 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-07-11T04:32:11+08:00 [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-10T20:32:11.674Z] Telemetry initialized",
  "metadataStr": "[DEBUG] [agent] [2024-07-10T20:32:11.674Z]",
  "extra": [
    "Telemetry initialized"
  ]
}

liuyujielol avatar Jul 10 '24 20:07 liuyujielol

Specifically, I was trying to read Gentoo portage's compile log, they are plain txt files named like:

/var/log/portage/app-editors:zed-0.143.6:20240710-201212.log

liuyujielol avatar Jul 10 '24 20:07 liuyujielol

https://github.com/zed-industries/zed/blob/aedd56b6dcd494fd30f48a6e1c59897dd8fb3f3c/crates/zed/src/zed/open_listener.rs#L296-L303

This seems to be the culprit: Zed tries to parse a file:LINE:COLUMN notation out of the path string it's asked to open. Instead of falling back to the old file after unsuccessful parsing, it seems to throw away :.. suffix entirely which is wrong.

SomeoneToIgnore avatar Jul 10 '24 20:07 SomeoneToIgnore

@SomeoneToIgnore what's the expected behaviour for line and column here? For instance for ./target/release/zed ./foo.rs:1:2 what should we expect?

adrianEffe avatar Jul 11 '24 15:07 adrianEffe

To note, there's Zed (./target/release/zed) and Zed CLI.

IIRC the recommended approach is be to call the CLI with anything "clever" as arguments and let it to open Zed with whatever's needed.

To add the confusion, both seem to follow the same agreement and try to parse whatever's passed as ./foo.rs:1:2 as a path with some line and column number.

Zeditor: https://github.com/zed-industries/zed/blob/d32e9f759c289a111f4a104b40f258c00fd4727b/crates/zed/src/main.rs#L871-L877

Cli: https://github.com/zed-industries/zed/blob/d32e9f759c289a111f4a104b40f258c00fd4727b/crates/cli/src/main.rs#L41

Both seem to converge here: https://github.com/zed-industries/zed/blob/d32e9f759c289a111f4a104b40f258c00fd4727b/crates/zed/src/zed/open_listener.rs#L163

where the ./foo.rs:1:2 is parsed into PathLikeWithPosition , with the ./foo.rs path canonicalized into /some/absolute/path/foo.rs and row and column values parsed as digits. The path data is used by Zed to open a buffer for the path given: https://github.com/zed-industries/zed/blob/d32e9f759c289a111f4a104b40f258c00fd4727b/crates/zed/src/zed/open_listener.rs#L190 and place the caret, scrolling to the row and column given: https://github.com/zed-industries/zed/blob/d32e9f759c289a111f4a104b40f258c00fd4727b/crates/zed/src/zed/open_listener.rs#L206-L208

The culprit seems to be the parsing into PathLikeWithPosition per se. There are some tests: https://github.com/zed-industries/zed/blob/d32e9f759c289a111f4a104b40f258c00fd4727b/crates/util/src/paths.rs#L380-L387 and we need another one + the parser fix, to make it preserve everything in the path, if parsing the row or the column fails — currently that seems to work differrently.

SomeoneToIgnore avatar Jul 11 '24 16:07 SomeoneToIgnore

Editing the title to reflect this also happens on MacOS.

notpeter avatar Aug 09 '24 19:08 notpeter

@SomeoneToIgnore this is such a great discovery and write up. You are for sure not someone to ignore. I am a bit interested in writing some Rust. I will start to work on this issue.

erickguan avatar Aug 21 '24 20:08 erickguan