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.54k stars 3.03k forks source link

[Windows] Failed to start language server, generated path seems invalid #17571

Open conorvenus opened 2 months ago

conorvenus commented 2 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Whenever Zed attempts to start a language server, it seems to produce the wrong path to the server.js module:

2024-09-08T19:27:04.1166287+01:00 [INFO] starting language server. binary path: "C:\\Users\\conor\\AppData\\Local\\Zed\\node\\node-v22.5.1-win-x64\\node.exe", working directory: "C:\\Users\\conor\\Desktop\\portfolio", args: ["/C:\\Users\\conor\\AppData\\Local\\Zed\\extensions\\work\\svelte/node_modules/svelte-language-server/bin/server.js", "--stdio"]
2024-09-08T19:27:04.1794046+01:00 [ERROR] cannot read LSP message headers
2024-09-08T19:27:04.1796993+01:00 [ERROR] failed to start language server "svelte-language-server": oneshot canceled
2024-09-08T19:27:04.1797999+01:00 [ERROR] server stderr: Some("node:internal/modules/cjs/loader:1222\r\n  throw err;\r\n  ^\r\n\r\nError: Cannot find module 'C:\\C:\\...

It can first be noticed in the args: ["/C:\\..."] with a prepended / which then node seems to interpret as the module being located at C:\\C:\\...

In terms of reproducibility, I am unsure, I just built Zed on my machine, ran it and installed a few extensions and that was it.

Environment

Zed: v0.152.0 (Zed Dev 072513f59f54290d03424d8873a6e6dd46764b7e) OS: Windows 10.0.22631 Memory: 15.8 GiB Architecture: x86_64 GPU: Intel(R) Iris(R) Xe Graphics || Intel Corporation || 101.5989

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-09-08T19:27:04.1166287+01:00 [INFO] starting language server. binary path: "C:\\Users\\conor\\AppData\\Local\\Zed\\node\\node-v22.5.1-win-x64\\node.exe", working directory: "C:\\Users\\conor\\Desktop\\portfolio", args: ["/C:\\Users\\conor\\AppData\\Local\\Zed\\extensions\\work\\svelte/node_modules/svelte-language-server/bin/server.js", "--stdio"]
2024-09-08T19:27:04.1794046+01:00 [ERROR] cannot read LSP message headers
2024-09-08T19:27:04.1796993+01:00 [ERROR] failed to start language server "svelte-language-server": oneshot canceled
2024-09-08T19:27:04.1797999+01:00 [ERROR] server stderr: Some("node:internal/modules/cjs/loader:1222\r\n  throw err;\r\n  ^\r\n\r\nError: Cannot find module 'C:\\C:\\Users\\conor\\AppData\\Local\\Zed\\extensions\\work\\svelte\\node_modules\\svelte-language-server\\bin\\server.js'\r\n    at Module._resolveFilename (node:internal/modules/cjs/loader:1219:15)\r\n    at Module._load (node:internal/modules/cjs/loader:1045:27)\r\n    at TracingChannel.traceSync (node:diagnostics_channel:315:14)\r\n    at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)\r\n    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:158:5)\r\n    at node:internal/main/run_main_module:30:49 {\r\n  code: 'MODULE_NOT_FOUND',\r\n  requireStack: []\r\n}\r\n\r\nNode.js v22.5.1\r\n")
AlbertMarashi commented 2 months ago

Seems like a windows bug

dovakin0007 commented 2 months ago

its svelte language server specific issue I believe and the same happens with tailwindcss for me but for the other languages it does work fine

conorvenus commented 2 months ago

its svelte language server specific issue I believe and the same happens with tailwindcss for me but for the other languages it does work fine

I am unsure, because it does the same for HTML too for me - so I am thinking it must just be an issue with how the paths are formed on Windows within Zed for whatever reason.

dovakin0007 commented 2 months ago

its svelte language server specific issue I believe and the same happens with tailwindcss for me but for the other languages it does work fine

I am unsure, because it does the same for HTML too for me - so I am thinking it must just be an issue with how the paths are formed on Windows within Zed for whatever reason.

maybe but it has something to do with node modules how they handle directory I didn't have any issues with Zig extension

conorvenus commented 2 months ago

its svelte language server specific issue I believe and the same happens with tailwindcss for me but for the other languages it does work fine

I am unsure, because it does the same for HTML too for me - so I am thinking it must just be an issue with how the paths are formed on Windows within Zed for whatever reason.

maybe but it has something to do with node modules how they handle directory I didn't have any issues with Zig extension

Perhaps - by the looks of it to me, it seems to be a problem within Zed itself passing args as ['/C:\\...'], that prepended / shouldn't be there on Windows (and this is potentially the source of the issue)

conorvenus commented 1 month ago

Ok yeah, as I suspected, the prepended / seems to be the source of the issue:

            Ok(LanguageServerBinary {
                path,
                arguments: command.args.into_iter().map(|arg| arg.replace("/C:", "C:").into()).collect(),
                env: Some(command.env.into_iter().collect()),
            })

Here is a very rudimentary fix for my machine in extension_lsp_adapter.rs, if somebody else who is more familiar with the Zed codebase could figure out where this / on path names is coming from, please let me know.

bartaldavid commented 1 month ago

Any updates on this? Other than this, the nightly build from https://github.com/deevus/zed-windows-builds seems to work fine.

ItaloCunhaBueno commented 1 month ago

I'm having the exact same issue with svelte's language server, seems to be a node issue, python's language server are working fine. I'm also using deevus nightly build from https://github.com/deevus/zed-windows-builds

Here's the log:

Language server error: svelte-language-server

oneshot canceled
-- stderr--
node:internal/modules/cjs/loader:1251
  throw err;
  ^

Error: Cannot find module 'C:\C:\Users\Italo\AppData\Local\Zed\extensions\work\svelte\node_modules\svelte-language-server\bin\server.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:166:5)
    at node:internal/main/run_main_module:30:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v22.8.0
JunkuiZhang commented 1 month ago

Extension which is downloaded from extension store could not work for now, see #15004

A temp solution:

diff --git a/crates/extension/src/extension_lsp_adapter.rs b/crates/extension/src/extension_lsp_adapter.rs
index 25179acec..ccc1cbf5e 100644
--- a/crates/extension/src/extension_lsp_adapter.rs
+++ b/crates/extension/src/extension_lsp_adapter.rs
@@ -88,7 +88,17 @@ impl LspAdapter for ExtensionLspAdapter {

             Ok(LanguageServerBinary {
                 path,
-                arguments: command.args.into_iter().map(|arg| arg.into()).collect(),
+                arguments: command
+                    .args
+                    .into_iter()
+                    .map(|arg| {
+                        if let Some(arg) = arg.strip_prefix('/') {
+                            arg.into()
+                        } else {
+                            arg.into()
+                        }
+                    })
+                    .collect(),
                 env: Some(command.env.into_iter().collect()),
             })
         }
edugzlez commented 1 month ago

Extension which is downloaded from extension store could not work for now, see #15004

A temp solution:

diff --git a/crates/extension/src/extension_lsp_adapter.rs b/crates/extension/src/extension_lsp_adapter.rs
index 25179acec..ccc1cbf5e 100644
--- a/crates/extension/src/extension_lsp_adapter.rs
+++ b/crates/extension/src/extension_lsp_adapter.rs
@@ -88,7 +88,17 @@ impl LspAdapter for ExtensionLspAdapter {

             Ok(LanguageServerBinary {
                 path,
-                arguments: command.args.into_iter().map(|arg| arg.into()).collect(),
+                arguments: command
+                    .args
+                    .into_iter()
+                    .map(|arg| {
+                        if let Some(arg) = arg.strip_prefix('/') {
+                            arg.into()
+                        } else {
+                            arg.into()
+                        }
+                    })
+                    .collect(),
                 env: Some(command.env.into_iter().collect()),
             })
         }

The problem exists elsewhere as well. The temporary solution does not work globally.

For astro it loads typescript_tsdk_path with env::current_dir(), but this does not pass by argument in the LanguageServerBinary, so it still gives problems.

https://github.com/zed-industries/zed/blob/051627c4493b5f5446cb3957576be89899b1d386/extensions/astro/src/astro.rs#L116

There should be a way to fix it without having to patch it. It is strange that the env::current_dir() and subsequent instructions are causing this problem.

JunkuiZhang commented 1 month ago

There should be a way to fix it without having to patch it. It is strange that the env::current_dir() and subsequent instructions are causing this problem.

From my understanding, the WASM environment is some kind of sand-box, which has a unix-style file system. As a result, when calling current_dir() within WASM, the returned path will always begin with /. Unfortunately, it seems there's no way to change this behavior.

alvgaona commented 3 weeks ago

The same happens for @astrojs/language-server in Windows.

Language server error: astro-language-server

oneshot canceled
-- stderr--
node:internal/modules/cjs/loader:1051
  throw err;
  ^

Error: Cannot find module 'C:\C:\Users\alvga\AppData\Local\Zed\extensions\work\astro\node_modules\@astrojs\language-server\bin\nodeServer.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.5.0

For some reason it has C:\C:\.

simonerlic commented 2 weeks ago

The same happens for @astrojs/language-server in Windows.

Language server error: astro-language-server

oneshot canceled
-- stderr--
node:internal/modules/cjs/loader:1051
  throw err;
  ^

Error: Cannot find module 'C:\C:\Users\alvga\AppData\Local\Zed\extensions\work\astro\node_modules\@astrojs\language-server\bin\nodeServer.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.5.0

For some reason it has C:\C:\.

Curious -- do you have multiple drives? I wonder if this is a multi-drive issue on Windows. Mine shows as D:\C:\, as my projects are on D:\

alvgaona commented 2 weeks ago

The same happens for @astrojs/language-server in Windows.

Language server error: astro-language-server

oneshot canceled
-- stderr--
node:internal/modules/cjs/loader:1051
  throw err;
  ^

Error: Cannot find module 'C:\C:\Users\alvga\AppData\Local\Zed\extensions\work\astro\node_modules\@astrojs\language-server\bin\nodeServer.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.5.0

For some reason it has C:\C:\.

Curious -- do you have multiple drives? I wonder if this is a multi-drive issue on Windows. Mine shows as D:\C:\, as my projects are on D:\

My projects are in C:\ . I have an extra drive with letter E:\.

simonerlic commented 2 weeks ago

The same happens for @astrojs/language-server in Windows.

Language server error: astro-language-server

oneshot canceled
-- stderr--
node:internal/modules/cjs/loader:1051
  throw err;
  ^

Error: Cannot find module 'C:\C:\Users\alvga\AppData\Local\Zed\extensions\work\astro\node_modules\@astrojs\language-server\bin\nodeServer.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.5.0

For some reason it has C:\C:\.

Curious -- do you have multiple drives? I wonder if this is a multi-drive issue on Windows. Mine shows as D:\C:\, as my projects are on D:\

My projects are in C:\ . I have an extra drive with letter E:\.

I'm starting to think that this might be caused by the assumption that the user has a single-drive system - maybe whatever call they make to get the file path returns just the path normally on a single drive system, and the path with the drive on multi drive systems?

I'll take a look this evening, as I'm not familiar with how it determines the path currently.