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.89k stars 2.69k forks source link

Getting the Python autocompletions (LSP) to work with fish shell #7317

Open janek opened 7 months ago

janek commented 7 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

This has been discussed before, but I thought it might stil be productive to make an issue, since there seems to be none open right now, and the Python LSP clearly works for some people (looking at issues), while it doesn't work for others. I'm hoping to find a sequence of steps that can be used to debug/get it to work


I did the following:


By the way, do these instructions mean that you have to use virtualenv for the LSP to work for a given project?

I understand from other issues that the Zed team knows about these problems and is working towards switching the Python LSP; so this is not a complaint, I just would really like to try working in Zed :) and perhaps this also helps others

I didn't try analyzing the log myself yet, but I'm attaching it below. I think it also has traces of other LSP issues, so I'm also thankful for tips about those :)

Environment

Zed: v0.120.6 (Zed) OS: macOS 14.0.0 Memory: 32 GiB Architecture: aarch64

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

No response

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

If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.

2024-02-03T00:59:14 [ERROR] crates/lsp/src/lsp.rs:615: server shut down 2024-02-03T00:59:14 [ERROR] missing executable in directory "/Users/janek/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js" 2024-02-03T00:59:14 [INFO] About to spawn test binary 2024-02-03T00:59:14 [WARN] test binary failed to launch 2024-02-03T00:59:14 [WARN] test binary check failed 2024-02-03T00:59:14 [INFO] beginning to reinstall server 2024-02-03T00:59:14 [INFO] deleting server container 2024-02-03T00:59:14 [INFO] starting language server "pyright", path: "/Users/janek/Developer/personal/ooo", id: 2 2024-02-03T00:59:14 [INFO] Node runtime install_if_needed 2024-02-03T00:59:14 [INFO] Node runtime install_if_needed 2024-02-03T00:59:15 [INFO] Node runtime install_if_needed 2024-02-03T00:59:15 [ERROR] crates/lsp/src/lsp.rs:255: invalid LSP message header "" 2024-02-03T00:59:15 [ERROR] failed to start language server "pyright": oneshot canceled 2024-02-03T00:59:15 [ERROR] server stderr: Some("node:internal/modules/cjs/loader:1078\n throw err;\n ^\n\nError: Cannot find module '/Users/janek/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js'\n at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)\n at Module._load (node:internal/modules/cjs/loader:920:27)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n at node:internal/main/run_main_module:23:47 {\n code: 'MODULE_NOT_FOUND',\n requireStack: []\n}\n\nNode.js v18.15.0\n") 2024-02-03T00:59:15 [ERROR] missing executable in directory "/Users/janek/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js" 2024-02-03T00:59:15 [ERROR] crates/lsp/src/lsp.rs:277: Broken pipe (os error 32) 2024-02-03T00:59:15 [ERROR] crates/lsp/src/lsp.rs:615: server shut down 2024-02-03T00:59:15 [INFO] About to spawn test binary 2024-02-03T00:59:15 [WARN] test binary failed to launch 2024-02-03T00:59:15 [WARN] test binary check failed 2024-02-03T00:59:15 [INFO] beginning to reinstall server 2024-02-03T00:59:15 [INFO] deleting server container 2024-02-03T00:59:15 [INFO] starting language server "pyright", path: "/Users/janek/Developer/personal/ooo", id: 3 2024-02-03T00:59:15 [INFO] Node runtime install_if_needed 2024-02-03T00:59:16 [INFO] Node runtime install_if_needed 2024-02-03T00:59:17 [INFO] Node runtime install_if_needed 2024-02-03T00:59:17 [ERROR] crates/lsp/src/lsp.rs:255: invalid LSP message header "" 2024-02-03T00:59:17 [ERROR] failed to start language server "pyright": oneshot canceled 2024-02-03T00:59:17 [ERROR] server stderr: Some("node:internal/modules/cjs/loader:1078\n throw err;\n ^\n\nError: Cannot find module '/Users/janek/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js'\n at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)\n at Module._load (node:internal/modules/cjs/loader:920:27)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n at node:internal/main/run_main_module:23:47 {\n code: 'MODULE_NOT_FOUND',\n requireStack: []\n}\n\nNode.js v18.15.0\n") 2024-02-03T00:59:17 [ERROR] crates/lsp/src/lsp.rs:615: server shut down 2024-02-03T00:59:17 [ERROR] crates/lsp/src/lsp.rs:277: Broken pipe (os error 32) 2024-02-03T00:59:17 [ERROR] missing executable in directory "/Users/janek/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js" 2024-02-03T00:59:17 [INFO] About to spawn test binary 2024-02-03T00:59:17 [WARN] test binary failed to launch 2024-02-03T00:59:17 [WARN] test binary check failed 2024-02-03T00:59:17 [INFO] beginning to reinstall server 2024-02-03T00:59:17 [INFO] deleting server container 2024-02-03T00:59:17 [INFO] starting language server "pyright", path: "/Users/janek/Developer/personal/ooo", id: 4 2024-02-03T00:59:17 [INFO] Node runtime install_if_needed 2024-02-03T00:59:18 [INFO] Node runtime install_if_needed 2024-02-03T00:59:18 [INFO] Node runtime install_if_needed 2024-02-03T00:59:19 [ERROR] crates/lsp/src/lsp.rs:255: invalid LSP message header "" 2024-02-03T00:59:19 [ERROR] failed to start language server "pyright": oneshot canceled 2024-02-03T00:59:19 [ERROR] server stderr: Some("node:internal/modules/cjs/loader:1078\n throw err;\n ^\n\nError: Cannot find module '/Users/janek/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js'\n at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)\n at Module._load (node:internal/modules/cjs/loader:920:27)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n at node:internal/main/run_main_module:23:47 {\n code: 'MODULE_NOT_FOUND',\n requireStack: []\n}\n\nNode.js v18.15.0\n") 2024-02-03T00:59:19 [ERROR] crates/lsp/src/lsp.rs:277: Broken pipe (os error 32) 2024-02-03T00:59:19 [ERROR] crates/lsp/src/lsp.rs:615: server shut down 2024-02-03T00:59:19 [ERROR] missing executable in directory "/Users/janek/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js" 2024-02-03T00:59:19 [INFO] About to spawn test binary 2024-02-03T00:59:19 [WARN] test binary failed to launch 2024-02-03T00:59:19 [WARN] test binary check failed 2024-02-03T00:59:19 [INFO] beginning to reinstall server 2024-02-03T00:59:19 [INFO] deleting server container 2024-02-03T00:59:19 [INFO] starting language server "pyright", path: "/Users/janek/Developer/personal/ooo", id: 5 2024-02-03T00:59:19 [INFO] Node runtime install_if_needed 2024-02-03T00:59:19 [INFO] Node runtime install_if_needed 2024-02-03T00:59:20 [INFO] Node runtime install_if_needed 2024-02-03T00:59:20 [ERROR] crates/lsp/src/lsp.rs:255: invalid LSP message header "" 2024-02-03T00:59:20 [ERROR] failed to start language server "pyright": oneshot canceled 2024-02-03T00:59:20 [ERROR] server stderr: Some("node:internal/modules/cjs/loader:1078\n throw err;\n ^\n\nError: Cannot find module '/Users/janek/Library/Application Support/Zed/languages/pyright/node_modules/pyright/langserver.index.js'\n at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)\n at Module._load (node:internal/modules/cjs/loader:920:27)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n at node:internal/main/run_main_module:23:47 {\n code: 'MODULE_NOT_FOUND',\n requireStack: []\n}\n\nNode.js v18.15.0\n") 2024-02-03T00:59:20 [ERROR] Hit 4 reinstallation attempts for "pyright" 2024-02-03T00:59:20 [ERROR] crates/lsp/src/lsp.rs:277: Broken pipe (os error 32) 2024-02-03T00:59:20 [ERROR] crates/lsp/src/lsp.rs:615: server shut down 2024-02-03T00:59:21 [INFO] build git repository ".git" 2024-02-03T00:59:21 [INFO] reload git repository ".git" 2024-02-03T00:59:21 [INFO] reload git repository ".git" 2024-02-03T01:01:38 [INFO] build git repository ".git" 2024-02-03T01:01:39 [INFO] reload git repository ".git" 2024-02-03T01:01:41 [INFO] starting language server "clangd", path: "/Users/janek/Developer/personal/polywaker/wemos-ha-base", id: 6 2024-02-03T01:02:08 [INFO] stopping language server clangd 2024-02-03T01:02:08 [ERROR] crates/lsp/src/lsp.rs:615: oneshot canceled 2024-02-03T01:02:08 [INFO] starting language server "clangd", path: "/Users/janek/Developer/personal/polywaker/wemos-ha-base", id: 7 2024-02-03T01:02:16 [INFO] build git repository ".git" 2024-02-03T01:02:16 [INFO] starting language server "clangd", path: "/Users/janek/Developer/personal/polywaker/wemos-ha-base", id: 8 2024-02-03T01:02:16 [INFO] reload git repository ".git" 2024-02-03T01:02:16 [INFO] reload git repository ".git" 2024-02-03T01:02:22 [INFO] build git repository ".git" 2024-02-03T01:02:22 [INFO] reload git repository ".git" 2024-02-03T01:02:34 [INFO] Initializing default prettier with plugins {"prettier-plugin-tailwindcss", "prettier-plugin-svelte"

JosephTLyons commented 7 months ago

Hey @janek, have you tried restarting Zed after adding in the pyrightconfig.json file? I know for some users, simply adding it is enough to get the completions running, but for others, a restart is sometimes needed.

For your terminal issue, what happens if you switch your activation script setting to fish?

"detect_venv": {
  "on": {
    "directories": [".env", "env", ".venv", "venv"],
    "activate_script": "fish"
  }
}

Does your venv get detected automatically and opened correctly without the error you were running into?

mkubasz commented 7 months ago

@JosephTLyons Same problem. Didn't load using terminal. LSP works.

janek commented 7 months ago

hi @JosephTLyons, thank you for your help! Yes, I had tried restarting and it didn't help.

I now added the settings you posted (in Zed's cmd+,/settings.json), then restarted and that solved the issue! Thank you very much.

avegancafe commented 7 months ago

Hm, I added those settings and it fixed my issue that my shell wasn't properly loading the venv, but didn't fix my issue that the LSP isn't using the venv. Any ideas?

janek commented 7 months ago

From me not really. I think this means you already have a .pyrightconfig and restarted Zed. but just in case, please make sure you do. My config was:

{
  "venvPath": ".",
  "venv": ".venv"
}

And you could look at and post the log, using the command zed: open log (after cmd+shift+p to search for commands).

bahrom04 commented 1 month ago

not working