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
49.71k stars 3.05k forks source link

gopls: packages.load error: JSON decoding failed : invalid character 'x' in string escape code #11647

Open xushuhui opened 6 months ago

xushuhui commented 6 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

I input command brew upgrade zed and zed version from 0.132.2 to 0.134.4. this is error "gopls: packages.load error: JSON decoding failed : invalid character 'x' in string escape code " when I open exist go project in zed.

Environment

Zed: v0.134.4 (Zed) OS: macOS 13.0.1 Memory: 16 GiB Architecture: x86_64

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

image

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

2024-05-10T14:34:48+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None }) 2024-05-10T14:34:48+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None }) 2024-05-10T14:35:06+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None }) 2024-05-10T14:35:07+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/suggest.go 2024-05-10T14:35:07+08:00 [ERROR] crates/project/src/project.rs:7009: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/suggest.go 2024-05-10T14:35:07+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None }) 2024-05-10T14:35:07+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None })

xushuhui commented 5 months ago

log file

2024-05-30T14:18:39+08:00 [ERROR] unexpected item event after pane was dropped
2024-05-30T14:19:08+08:00 [INFO] Initializing default prettier with plugins {}
2024-05-30T14:19:08+08:00 [INFO] starting language servers for Lua: lua-language-server
2024-05-30T16:40:01+08:00 [INFO] building git repository, `.git` path in the worktree: ".git"
2024-05-30T16:40:01+08:00 [INFO] Initializing default prettier with plugins {}
2024-05-30T16:40:01+08:00 [INFO] starting language servers for Go: gopls
2024-05-30T16:40:01+08:00 [INFO] starting language server "gopls", path: "/Users/xsh/fm/fm-suggest", id: 10
2024-05-30T16:40:01+08:00 [ERROR] crates/workspace/src/persistence/model.rs:313: No worktree for path: "/Users/xsh/.config/zed/settings.json"
2024-05-30T16:40:02+08:00 [INFO] found user-installed language server for Go. path: "/Users/xsh/go/bin/gopls", arguments: ["-mode=stdio"]
2024-05-30T16:40:02+08:00 [INFO] starting language server. binary path: "/Users/xsh/go/bin/gopls", working directory: "/Users/xsh/fm/fm-suggest", args: ["-mode=stdio"]
2024-05-30T16:40:02+08:00 [INFO] Language server with id 10 sent unhandled notification window/logMessage:
{
  "type": 1,
  "message": "2024/05/30 16:40:02 creating temp dir: mkdir /var/folders/d9/h1ryx87j3pq8gcx7knm2xssh0000gn/T/\n\u001b[?2004l/gopls-6762.1: no such file or directory\n"
}
2024-05-30T16:40:02+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:40:02+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:40:03+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:40:03+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:40:07+08:00 [INFO] Initializing default prettier with plugins {}
2024-05-30T16:40:07+08:00 [INFO] starting language servers for Go Mod: gopls
2024-05-30T16:42:15+08:00 [ERROR] crates/lsp/src/lsp.rs:779: oneshot canceled
2024-05-30T16:42:15+08:00 [INFO] building git repository, `.git` path in the worktree: ".git"
2024-05-30T16:42:15+08:00 [INFO] Initializing default prettier with plugins {}
2024-05-30T16:42:15+08:00 [INFO] starting language servers for Go: gopls
2024-05-30T16:42:15+08:00 [INFO] starting language server "gopls", path: "/Users/xsh/fm/fm-suggest", id: 11
2024-05-30T16:42:15+08:00 [ERROR] crates/workspace/src/persistence/model.rs:313: Deserializer does not exist for item kind: diagnostics
2024-05-30T16:42:16+08:00 [INFO] found user-installed language server for Go. path: "/Users/xsh/go/bin/gopls", arguments: ["-mode=stdio"]
2024-05-30T16:42:16+08:00 [INFO] starting language server. binary path: "/Users/xsh/go/bin/gopls", working directory: "/Users/xsh/fm/fm-suggest", args: ["-mode=stdio"]
2024-05-30T16:42:16+08:00 [INFO] Language server with id 11 sent unhandled notification window/logMessage:
{
  "type": 1,
  "message": "2024/05/30 16:42:16 creating temp dir: mkdir /var/folders/d9/h1ryx87j3pq8gcx7knm2xssh0000gn/T/\n\u001b[?2004l/gopls-6871.1: no such file or directory\n"
}
2024-05-30T16:42:16+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:42:16+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:42:21+08:00 [ERROR] crates/lsp/src/lsp.rs:779: oneshot canceled
Etesam913 commented 5 months ago

I am having the same issue

benjsto commented 5 months ago

I also have run into this issue in recent weeks!

d1y commented 5 months ago

Can someone provide a minimum example repo?

xushuhui commented 5 months ago

I update zed 0.137.6 today, the problem no fixed, log file is

2024-06-03T10:09:18+08:00 [INFO] ========== starting zed ==========
2024-06-03T10:09:18+08:00 [INFO] Opening main db
2024-06-03T10:09:18+08:00 [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git")
2024-06-03T10:09:18+08:00 [INFO] set environment variables from shell:/usr/local/bin/fish, path:/opt/go/bin:/Users/xsh/go/bin:/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
2024-06-03T10:09:18+08:00 [ERROR] crates/theme/src/settings.rs:432: theme not found: Catppuccin Macchiato
2024-06-03T10:09:18+08:00 [INFO] extensions updated. loading 5, reloading 0, unloading 0
2024-06-03T10:09:18+08:00 [INFO] Opening main db
2024-06-03T10:09:18+08:00 [INFO] building git repository, `.git` path in the worktree: ".git"
2024-06-03T10:09:19+08:00 [INFO] Opening main db
2024-06-03T10:09:19+08:00 [INFO] set status on client 0: Authenticating
2024-06-03T10:09:19+08:00 [INFO] Opening main db
2024-06-03T10:09:19+08:00 [INFO] set status on client 79320: Connecting
2024-06-03T10:09:19+08:00 [INFO] Initializing default prettier with plugins {}
2024-06-03T10:09:19+08:00 [INFO] starting language servers for Go: gopls
2024-06-03T10:09:19+08:00 [INFO] starting language server "gopls", path: "/Users/xsh/fm/fm-suggest", id: 1
2024-06-03T10:09:19+08:00 [INFO] Initializing default prettier with plugins {}
2024-06-03T10:09:19+08:00 [INFO] starting language servers for Go: gopls
2024-06-03T10:09:19+08:00 [ERROR] crates/workspace/src/persistence/model.rs:313: Deserializer does not exist for item kind: diagnostics
2024-06-03T10:09:19+08:00 [INFO] found user-installed language server for Go. path: "/Users/xsh/go/bin/gopls", arguments: ["-mode=stdio"]
2024-06-03T10:09:19+08:00 [INFO] starting language server. binary path: "/Users/xsh/go/bin/gopls", working directory: "/Users/xsh/fm/fm-suggest", args: ["-mode=stdio"]
2024-06-03T10:09:19+08:00 [INFO] Language server with id 1 sent unhandled notification window/logMessage:
{
  "type": 1,
  "message": "2024/06/03 10:09:19 creating temp dir: mkdir /var/folders/d9/h1ryx87j3pq8gcx7knm2xssh0000gn/T/\n\u001b[?2004l/gopls-56436.1: no such file or directory\n"
}
2024-06-03T10:09:19+08:00 [INFO] Node runtime install_if_needed
2024-06-03T10:09:19+08:00 [INFO] Initializing default prettier with plugins {}
2024-06-03T10:09:19+08:00 [INFO] starting language servers for Go: gopls
2024-06-03T10:09:20+08:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-06-03T10:09:21+08:00 [INFO] starting language server. binary path: "/Users/xsh/Library/Application Support/Zed/node/node-v18.15.0-darwin-x64/bin/node", working directory: "/", args: ["/Users/xsh/Library/Application Support/Zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-06-03T10:09:21+08:00 [INFO] add connection to peer
2024-06-03T10:09:21+08:00 [INFO] add_connection;
2024-06-03T10:09:21+08:00 [INFO] waiting for server hello
2024-06-03T10:09:21+08:00 [INFO] got server hello
2024-06-03T10:09:21+08:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 440, id: 1820744 })
2024-06-03T10:09:21+08:00 [INFO] set status on client 79320: Connected { peer_id: PeerId { owner_id: 440, id: 1820744 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-06-03T10:09:21+08:00 [ERROR] crates/lsp/src/lsp.rs:360: cannot read LSP message headers
2024-06-03T10:09:21+08:00 [ERROR] crates/lsp/src/lsp.rs:382: Broken pipe (os error 32)
2024-06-03T10:09:21+08:00 [ERROR] crates/lsp/src/lsp.rs:779: server shut down
2024-06-03T10:09:24+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-06-03T10:09:24+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-06-03T10:09:25+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-06-03T10:09:25+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
E-ricus commented 4 months ago

Can someone provide a minimum example repo?

@d1y for me It happens with any repo/project, as simple as a folder with: go.mod

module example/simple

go 1.22

main.go

package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello World")
}

But just realised it only happens while using gopls from the path, rather than the one downloaded by zed. As soon as I removed from my path gopls, and zed downloads it the Error disappears, and everything works. If I install gopls again, and zed priorities that one, the error appears again.

Using gopls: 0.15.3 (both manually installed and by zed) Zed 0.139.3 Macos 14.5

setalid commented 1 month ago

I experienced this issue when installing a new version of Go. Installing the same version of go as I have in my go.mod file resolved the issue for me (at least the same minor version). I have no confidence in this solution, but it might be worth testing out.

cjek420 commented 1 month ago

Installed Go 1.23 and hit this bug with all my projects which have Go code. Updated go.mod to match the installed version of Go. Made sure the gopls is the one installed by Zed. Nothing helped. This is with Zed 0.155.2, Go 1.23.2, gopls_0.16.2, MacOS 15.0.1

Please give us away to hide or auto hide the error dialog.

diwakergupta commented 1 month ago

I'm also hitting this with latest Zed (0.156.0) on Mac, go 1.23.2

Is there a workaround?

cjek420 commented 1 month ago

To add more information, when this error message happens Zed consumes 40% of the CPU. When I close all the Go files the error message vanishes and Zed returns an idle state.

gm0stache commented 3 weeks ago

same issue!

diwakergupta commented 3 weeks ago

I'm also hitting this with latest Zed (0.156.0) on Mac, go 1.23.2

Is there a workaround?

For anyone else that needs a workaround, I found one! Starting Zed from the command line works for me šŸ¤·šŸ½ Starting it directly via Spotlight or Applications results in this error.

notpeter commented 6 days ago

For folks running into this, can you confirm that you don't have multiple copies of gopls installed (perhaps one via homebrew/apt and one via go's package manager). It may be an older version of gopls acting up.

Please see the docs for example instructions for uninstalling and installing the most up to date version of gopls. https://zed.dev/docs/languages/go

For anyone else that needs a workaround, I found one! Starting Zed from the command line works for me šŸ¤·šŸ½ Starting it directly via Spotlight or Applications results in this error.

This is likely due to slightly different PATH environment variables between when Zed is launched from Finder and launched from your shell. It may be the the Gui launched zed is getting an old homebrew version, while the shell is getting another.

(If this doesn't solved your issue, my apologies for giving false hope ;)

cjek420 commented 5 days ago

I only have one copy of gopls which is the one installed by Zed, .../Library/Application Support/Zed/languages/gopls/gopls_0.16.2 telemetry .../Library/Application Support/Zed/languages/gopls/gopls_0.16.2 -mode=stdio

With the latest version of Zed 0.159.10 this is no longer an issue.

notpeter commented 5 days ago

@xushuhui Are you still seeing this with the latest Zed? Or is this OK to close?

rustatian commented 6 hours ago

Having this issue on a clean macOS + latest Zed install. Tried to remove the gopls from the GOBIN (to leave only 1 gopls downloaded by Zed), does not help. The only solution for me is to run Zed from the terminal.

I can guess that the problem is in some envs which are not populated via the regular start. Because after starting from the terminal I see in logs that Zed found user-installed language server for gopls in PATH which does not appear on a regular start. I'm using Fish shell if that helps.