From 03e2f240ee84c41f0305598125b4c27639d434e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Mon, 24 Jun 2024 18:52:07 +0800 Subject: [PATCH] windows: Fix JSON schema validation (#13459) This PR needs suggestions, especially from the Zed team. As I mentioned in a previous issue #13394 , the `vscode-json-languageserver` that Zed originally relied on has some issues with JSON schema validation on Windows, and it hasn't been updated for a long time. This PR uses the more frequently updated `vscode-langservers-extracted`, which resolves this issue. Currently, `vscode-langservers-extracted` includes not only the JSON LSP server but also LSP servers for other languages. I think we might need a package specifically for the JSON LSP server, such as something like `vscode-json-langserver-extracted`, or we could consider using the LSP servers for other languages from this package as well. And, there are some issues with installing `vscode-langservers-extracted` on Windows, causing the `postinstall` script to fail. However, this does not seem to affect any functionality. Therefore, I think the best solution is for the Zed team to maintain a package like `vscode-json-langserver-extracted` or something else. This way, we can update it promptly and address the installation issues on Windows. Any suggestions or advices are welcome. #### JSON vaildation on Winodws https://github.com/zed-industries/zed/assets/14981363/8cd7ff54-28ec-4601-b2e5-183e2fae2051 Closes #13394 Release Notes: - Fixed JSON schema validation issue on Windows.(#13394 ) --- crates/languages/src/json.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/languages/src/json.rs b/crates/languages/src/json.rs index 5c7d3c6fc3..5bdeda8bb9 100644 --- a/crates/languages/src/json.rs +++ b/crates/languages/src/json.rs @@ -21,7 +21,8 @@ use std::{ use task::{TaskTemplate, TaskTemplates, VariableName}; use util::{maybe, ResultExt}; -const SERVER_PATH: &str = "node_modules/vscode-json-languageserver/bin/vscode-json-languageserver"; +const SERVER_PATH: &str = + "node_modules/vscode-langservers-extracted/bin/vscode-json-language-server"; // Origin: https://github.com/SchemaStore/schemastore const TSCONFIG_SCHEMA: &str = include_str!("json/schemas/tsconfig.json"); @@ -133,7 +134,7 @@ impl LspAdapter for JsonLspAdapter { ) -> Result> { Ok(Box::new( self.node - .npm_package_latest_version("vscode-json-languageserver") + .npm_package_latest_version("vscode-langservers-extracted") .await?, ) as Box<_>) } @@ -146,7 +147,7 @@ impl LspAdapter for JsonLspAdapter { ) -> Result { let latest_version = latest_version.downcast::().unwrap(); let server_path = container_dir.join(SERVER_PATH); - let package_name = "vscode-json-languageserver"; + let package_name = "vscode-langservers-extracted"; let should_install_language_server = self .node @@ -154,9 +155,11 @@ impl LspAdapter for JsonLspAdapter { .await; if should_install_language_server { + // TODO: the postinstall fails on Windows self.node .npm_install_packages(&container_dir, &[(package_name, latest_version.as_str())]) - .await?; + .await + .log_err(); } Ok(LanguageServerBinary { @@ -240,7 +243,11 @@ async fn get_cached_server_binary( .log_err() } -fn schema_file_match(path: &Path) -> &Path { +#[inline] +fn schema_file_match(path: &Path) -> String { path.strip_prefix(path.parent().unwrap().parent().unwrap()) .unwrap() + .display() + .to_string() + .replace('\\', "/") }