Revert "Merge pull request #1359 from zed-industries/plugin-json-enable"
This reverts commit94b443a704
, reversing changes made to285832e810
.
This commit is contained in:
parent
142a019ada
commit
815ce22fb7
3 changed files with 110 additions and 6 deletions
|
@ -3,11 +3,11 @@ pub use language::*;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use rust_embed::RustEmbed;
|
use rust_embed::RustEmbed;
|
||||||
use std::{borrow::Cow, str, sync::Arc};
|
use std::{borrow::Cow, str, sync::Arc};
|
||||||
use util::ResultExt;
|
|
||||||
|
|
||||||
mod c;
|
mod c;
|
||||||
mod go;
|
mod go;
|
||||||
mod installation;
|
mod installation;
|
||||||
|
mod json;
|
||||||
mod language_plugin;
|
mod language_plugin;
|
||||||
mod python;
|
mod python;
|
||||||
mod rust;
|
mod rust;
|
||||||
|
@ -33,7 +33,7 @@ lazy_static! {
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn init(languages: Arc<LanguageRegistry>, executor: Arc<Background>) {
|
pub async fn init(languages: Arc<LanguageRegistry>, _executor: Arc<Background>) {
|
||||||
for (name, grammar, lsp_adapter) in [
|
for (name, grammar, lsp_adapter) in [
|
||||||
(
|
(
|
||||||
"c",
|
"c",
|
||||||
|
@ -53,10 +53,7 @@ pub async fn init(languages: Arc<LanguageRegistry>, executor: Arc<Background>) {
|
||||||
(
|
(
|
||||||
"json",
|
"json",
|
||||||
tree_sitter_json::language(),
|
tree_sitter_json::language(),
|
||||||
match language_plugin::new_json(executor).await.log_err() {
|
Some(CachedLspAdapter::new(json::JsonLspAdapter).await),
|
||||||
Some(lang) => Some(CachedLspAdapter::new(lang).await),
|
|
||||||
None => None,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"markdown",
|
"markdown",
|
||||||
|
|
106
crates/zed/src/languages/json.rs
Normal file
106
crates/zed/src/languages/json.rs
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
use super::installation::{npm_install_packages, npm_package_latest_version};
|
||||||
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use client::http::HttpClient;
|
||||||
|
use collections::HashMap;
|
||||||
|
use futures::StreamExt;
|
||||||
|
use language::{LanguageServerName, LspAdapter};
|
||||||
|
use serde_json::json;
|
||||||
|
use smol::fs;
|
||||||
|
use std::{any::Any, path::PathBuf, sync::Arc};
|
||||||
|
use util::ResultExt;
|
||||||
|
|
||||||
|
pub struct JsonLspAdapter;
|
||||||
|
|
||||||
|
impl JsonLspAdapter {
|
||||||
|
const BIN_PATH: &'static str =
|
||||||
|
"node_modules/vscode-json-languageserver/bin/vscode-json-languageserver";
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl LspAdapter for JsonLspAdapter {
|
||||||
|
async fn name(&self) -> LanguageServerName {
|
||||||
|
LanguageServerName("vscode-json-languageserver".into())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn server_args(&self) -> Vec<String> {
|
||||||
|
vec!["--stdio".into()]
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_latest_server_version(
|
||||||
|
&self,
|
||||||
|
_: Arc<dyn HttpClient>,
|
||||||
|
) -> Result<Box<dyn 'static + Any + Send>> {
|
||||||
|
Ok(Box::new(npm_package_latest_version("vscode-json-languageserver").await?) as Box<_>)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_server_binary(
|
||||||
|
&self,
|
||||||
|
version: Box<dyn 'static + Send + Any>,
|
||||||
|
_: Arc<dyn HttpClient>,
|
||||||
|
container_dir: PathBuf,
|
||||||
|
) -> Result<PathBuf> {
|
||||||
|
let version = version.downcast::<String>().unwrap();
|
||||||
|
let version_dir = container_dir.join(version.as_str());
|
||||||
|
fs::create_dir_all(&version_dir)
|
||||||
|
.await
|
||||||
|
.context("failed to create version directory")?;
|
||||||
|
let binary_path = version_dir.join(Self::BIN_PATH);
|
||||||
|
|
||||||
|
if fs::metadata(&binary_path).await.is_err() {
|
||||||
|
npm_install_packages(
|
||||||
|
[("vscode-json-languageserver", version.as_str())],
|
||||||
|
&version_dir,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Some(mut entries) = fs::read_dir(&container_dir).await.log_err() {
|
||||||
|
while let Some(entry) = entries.next().await {
|
||||||
|
if let Some(entry) = entry.log_err() {
|
||||||
|
let entry_path = entry.path();
|
||||||
|
if entry_path.as_path() != version_dir {
|
||||||
|
fs::remove_dir_all(&entry_path).await.log_err();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(binary_path)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<PathBuf> {
|
||||||
|
(|| async move {
|
||||||
|
let mut last_version_dir = None;
|
||||||
|
let mut entries = fs::read_dir(&container_dir).await?;
|
||||||
|
while let Some(entry) = entries.next().await {
|
||||||
|
let entry = entry?;
|
||||||
|
if entry.file_type().await?.is_dir() {
|
||||||
|
last_version_dir = Some(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let last_version_dir = last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?;
|
||||||
|
let bin_path = last_version_dir.join(Self::BIN_PATH);
|
||||||
|
if bin_path.exists() {
|
||||||
|
Ok(bin_path)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!(
|
||||||
|
"missing executable in directory {:?}",
|
||||||
|
last_version_dir
|
||||||
|
))
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
.await
|
||||||
|
.log_err()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn initialization_options(&self) -> Option<serde_json::Value> {
|
||||||
|
Some(json!({
|
||||||
|
"provideFormatter": true
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn language_ids(&self) -> HashMap<String, String> {
|
||||||
|
[("JSON".into(), "jsonc".into())].into_iter().collect()
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ use plugin_runtime::{Plugin, PluginBinary, PluginBuilder, WasiFn};
|
||||||
use std::{any::Any, path::PathBuf, sync::Arc};
|
use std::{any::Any, path::PathBuf, sync::Arc};
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
|
pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
|
||||||
let plugin = PluginBuilder::new_default()?
|
let plugin = PluginBuilder::new_default()?
|
||||||
.host_function_async("command", |command: String| async move {
|
.host_function_async("command", |command: String| async move {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue