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 )
This commit is contained in:
张小白 2024-06-24 18:52:07 +08:00 committed by GitHub
parent 145cd798c0
commit 03e2f240ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<Box<dyn 'static + Send + Any>> {
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<LanguageServerBinary> {
let latest_version = latest_version.downcast::<String>().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('\\', "/")
}