mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
Extract PureScript support into an extension (#9824)
This PR extracts PureScript support into an extension and removes the built-in PureScript support from Zed. Release Notes: - Removed built-in support for PureScript, in favor of making it available as an extension. The PureScript extension will be suggested for download when you open a `.purs` file.
This commit is contained in:
parent
d77cda1ea9
commit
b8ef97015c
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -5322,7 +5322,6 @@ dependencies = [
|
|||||||
"tree-sitter-ocaml",
|
"tree-sitter-ocaml",
|
||||||
"tree-sitter-php",
|
"tree-sitter-php",
|
||||||
"tree-sitter-proto",
|
"tree-sitter-proto",
|
||||||
"tree-sitter-purescript",
|
|
||||||
"tree-sitter-python",
|
"tree-sitter-python",
|
||||||
"tree-sitter-racket",
|
"tree-sitter-racket",
|
||||||
"tree-sitter-regex",
|
"tree-sitter-regex",
|
||||||
@ -10412,15 +10411,6 @@ dependencies = [
|
|||||||
"tree-sitter",
|
"tree-sitter",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tree-sitter-purescript"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "git+https://github.com/postsolar/tree-sitter-purescript?rev=v0.1.0#0554811a512b9cec08b5a83ce9096eb22da18213"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"tree-sitter",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter-python"
|
name = "tree-sitter-python"
|
||||||
version = "0.20.4"
|
version = "0.20.4"
|
||||||
@ -12613,6 +12603,13 @@ dependencies = [
|
|||||||
"zed_extension_api 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"zed_extension_api 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zed_purescript"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"zed_extension_api 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed_svelte"
|
name = "zed_svelte"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
@ -98,6 +98,7 @@ members = [
|
|||||||
"extensions/gleam",
|
"extensions/gleam",
|
||||||
"extensions/haskell",
|
"extensions/haskell",
|
||||||
"extensions/prisma",
|
"extensions/prisma",
|
||||||
|
"extensions/purescript",
|
||||||
"extensions/svelte",
|
"extensions/svelte",
|
||||||
"extensions/uiua",
|
"extensions/uiua",
|
||||||
|
|
||||||
@ -313,7 +314,6 @@ tree-sitter-nu = { git = "https://github.com/nushell/tree-sitter-nu", rev = "7dd
|
|||||||
tree-sitter-ocaml = { git = "https://github.com/tree-sitter/tree-sitter-ocaml", rev = "4abfdc1c7af2c6c77a370aee974627be1c285b3b" }
|
tree-sitter-ocaml = { git = "https://github.com/tree-sitter/tree-sitter-ocaml", rev = "4abfdc1c7af2c6c77a370aee974627be1c285b3b" }
|
||||||
tree-sitter-php = "0.21.1"
|
tree-sitter-php = "0.21.1"
|
||||||
tree-sitter-proto = { git = "https://github.com/rewinfrey/tree-sitter-proto", rev = "36d54f288aee112f13a67b550ad32634d0c2cb52" }
|
tree-sitter-proto = { git = "https://github.com/rewinfrey/tree-sitter-proto", rev = "36d54f288aee112f13a67b550ad32634d0c2cb52" }
|
||||||
tree-sitter-purescript = { git = "https://github.com/postsolar/tree-sitter-purescript", rev = "v0.1.0" }
|
|
||||||
tree-sitter-python = "0.20.2"
|
tree-sitter-python = "0.20.2"
|
||||||
tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a" }
|
tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a" }
|
||||||
tree-sitter-regex = "0.20.0"
|
tree-sitter-regex = "0.20.0"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::wasm_host::{wit::LanguageServerConfig, WasmExtension, WasmHost};
|
use crate::wasm_host::{wit::LanguageServerConfig, WasmExtension, WasmHost};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures::{Future, FutureExt};
|
use futures::{Future, FutureExt};
|
||||||
use gpui::AsyncAppContext;
|
use gpui::AsyncAppContext;
|
||||||
@ -120,7 +120,9 @@ impl LspAdapter for ExtensionLspAdapter {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
Ok(if let Some(json_options) = json_options {
|
Ok(if let Some(json_options) = json_options {
|
||||||
serde_json::from_str(&json_options)?
|
serde_json::from_str(&json_options).with_context(|| {
|
||||||
|
format!("failed to parse initialization_options from extension: {json_options}")
|
||||||
|
})?
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
|
@ -39,6 +39,7 @@ pub fn suggested_extension(file_extension_or_name: &str) -> Option<Arc<str>> {
|
|||||||
("make", "Makefile"),
|
("make", "Makefile"),
|
||||||
("nix", "nix"),
|
("nix", "nix"),
|
||||||
("prisma", "prisma"),
|
("prisma", "prisma"),
|
||||||
|
("purescript", "purs"),
|
||||||
("r", "r"),
|
("r", "r"),
|
||||||
("r", "R"),
|
("r", "R"),
|
||||||
("sql", "sql"),
|
("sql", "sql"),
|
||||||
|
@ -65,7 +65,6 @@ tree-sitter-nu.workspace = true
|
|||||||
tree-sitter-ocaml.workspace = true
|
tree-sitter-ocaml.workspace = true
|
||||||
tree-sitter-php.workspace = true
|
tree-sitter-php.workspace = true
|
||||||
tree-sitter-proto.workspace = true
|
tree-sitter-proto.workspace = true
|
||||||
tree-sitter-purescript.workspace = true
|
|
||||||
tree-sitter-python.workspace = true
|
tree-sitter-python.workspace = true
|
||||||
tree-sitter-racket.workspace = true
|
tree-sitter-racket.workspace = true
|
||||||
tree-sitter-regex.workspace = true
|
tree-sitter-regex.workspace = true
|
||||||
|
@ -29,7 +29,6 @@ mod lua;
|
|||||||
mod nu;
|
mod nu;
|
||||||
mod ocaml;
|
mod ocaml;
|
||||||
mod php;
|
mod php;
|
||||||
mod purescript;
|
|
||||||
mod python;
|
mod python;
|
||||||
mod ruby;
|
mod ruby;
|
||||||
mod rust;
|
mod rust;
|
||||||
@ -99,7 +98,6 @@ pub fn init(
|
|||||||
),
|
),
|
||||||
("php", tree_sitter_php::language_php()),
|
("php", tree_sitter_php::language_php()),
|
||||||
("proto", tree_sitter_proto::language()),
|
("proto", tree_sitter_proto::language()),
|
||||||
("purescript", tree_sitter_purescript::language()),
|
|
||||||
("python", tree_sitter_python::language()),
|
("python", tree_sitter_python::language()),
|
||||||
("racket", tree_sitter_racket::language()),
|
("racket", tree_sitter_racket::language()),
|
||||||
("regex", tree_sitter_regex::language()),
|
("regex", tree_sitter_regex::language()),
|
||||||
@ -342,12 +340,6 @@ pub fn init(
|
|||||||
Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
|
Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
language!(
|
|
||||||
"purescript",
|
|
||||||
vec![Arc::new(purescript::PurescriptLspAdapter::new(
|
|
||||||
node_runtime.clone(),
|
|
||||||
))]
|
|
||||||
);
|
|
||||||
language!(
|
language!(
|
||||||
"elm",
|
"elm",
|
||||||
vec![Arc::new(elm::ElmLspAdapter::new(node_runtime.clone()))]
|
vec![Arc::new(elm::ElmLspAdapter::new(node_runtime.clone()))]
|
||||||
|
@ -1,145 +0,0 @@
|
|||||||
use anyhow::{anyhow, Result};
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use collections::HashMap;
|
|
||||||
use futures::StreamExt;
|
|
||||||
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
|
|
||||||
use lsp::LanguageServerBinary;
|
|
||||||
use node_runtime::NodeRuntime;
|
|
||||||
use serde_json::json;
|
|
||||||
use smol::fs;
|
|
||||||
use std::{
|
|
||||||
any::Any,
|
|
||||||
ffi::OsString,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
use util::{maybe, ResultExt};
|
|
||||||
|
|
||||||
const SERVER_PATH: &str = "node_modules/.bin/purescript-language-server";
|
|
||||||
|
|
||||||
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
|
||||||
vec![server_path.into(), "--stdio".into()]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PurescriptLspAdapter {
|
|
||||||
node: Arc<dyn NodeRuntime>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PurescriptLspAdapter {
|
|
||||||
// todo(linux): remove
|
|
||||||
#[cfg_attr(target_os = "linux", allow(dead_code))]
|
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
|
||||||
Self { node }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
|
||||||
impl LspAdapter for PurescriptLspAdapter {
|
|
||||||
fn name(&self) -> LanguageServerName {
|
|
||||||
LanguageServerName("purescript-language-server".into())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_latest_server_version(
|
|
||||||
&self,
|
|
||||||
_: &dyn LspAdapterDelegate,
|
|
||||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
|
||||||
Ok(Box::new(
|
|
||||||
self.node
|
|
||||||
.npm_package_latest_version("purescript-language-server")
|
|
||||||
.await?,
|
|
||||||
) as Box<_>)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_server_binary(
|
|
||||||
&self,
|
|
||||||
latest_version: Box<dyn 'static + Send + Any>,
|
|
||||||
container_dir: PathBuf,
|
|
||||||
_: &dyn LspAdapterDelegate,
|
|
||||||
) -> Result<LanguageServerBinary> {
|
|
||||||
let latest_version = latest_version.downcast::<String>().unwrap();
|
|
||||||
let server_path = container_dir.join(SERVER_PATH);
|
|
||||||
let package_name = "purescript-language-server";
|
|
||||||
|
|
||||||
let should_install_npm_package = self
|
|
||||||
.node
|
|
||||||
.should_install_npm_package(package_name, &server_path, &container_dir, &latest_version)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if should_install_npm_package {
|
|
||||||
self.node
|
|
||||||
.npm_install_packages(&container_dir, &[(package_name, latest_version.as_str())])
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(LanguageServerBinary {
|
|
||||||
path: self.node.binary_path().await?,
|
|
||||||
env: None,
|
|
||||||
arguments: server_binary_arguments(&server_path),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn cached_server_binary(
|
|
||||||
&self,
|
|
||||||
container_dir: PathBuf,
|
|
||||||
_: &dyn LspAdapterDelegate,
|
|
||||||
) -> Option<LanguageServerBinary> {
|
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn installation_test_binary(
|
|
||||||
&self,
|
|
||||||
container_dir: PathBuf,
|
|
||||||
) -> Option<LanguageServerBinary> {
|
|
||||||
get_cached_server_binary(container_dir, &*self.node).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn initialization_options(
|
|
||||||
self: Arc<Self>,
|
|
||||||
_: &Arc<dyn LspAdapterDelegate>,
|
|
||||||
) -> Result<Option<serde_json::Value>> {
|
|
||||||
Ok(Some(json!({
|
|
||||||
"purescript": {
|
|
||||||
"addSpagoSources": true
|
|
||||||
}
|
|
||||||
})))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn language_ids(&self) -> HashMap<String, String> {
|
|
||||||
[("PureScript".into(), "purescript".into())]
|
|
||||||
.into_iter()
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_cached_server_binary(
|
|
||||||
container_dir: PathBuf,
|
|
||||||
node: &dyn NodeRuntime,
|
|
||||||
) -> Option<LanguageServerBinary> {
|
|
||||||
maybe!(async {
|
|
||||||
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 server_path = last_version_dir.join(SERVER_PATH);
|
|
||||||
if server_path.exists() {
|
|
||||||
Ok(LanguageServerBinary {
|
|
||||||
path: node.binary_path().await?,
|
|
||||||
env: None,
|
|
||||||
arguments: server_binary_arguments(&server_path),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Err(anyhow!(
|
|
||||||
"missing executable in directory {:?}",
|
|
||||||
last_version_dir
|
|
||||||
))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
.log_err()
|
|
||||||
}
|
|
16
extensions/purescript/Cargo.toml
Normal file
16
extensions/purescript/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "zed_purescript"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
license = "Apache-2.0"
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/purescript.rs"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
zed_extension_api = "0.0.4"
|
1
extensions/purescript/LICENSE-APACHE
Symbolic link
1
extensions/purescript/LICENSE-APACHE
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../LICENSE-APACHE
|
15
extensions/purescript/extension.toml
Normal file
15
extensions/purescript/extension.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
id = "purescript"
|
||||||
|
name = "PureScript"
|
||||||
|
description = "PureScript support."
|
||||||
|
version = "0.0.1"
|
||||||
|
schema_version = 1
|
||||||
|
authors = ["Iván Molina Rebolledo <ivanmolinarebolledo@gmail.com>"]
|
||||||
|
repository = "https://github.com/zed-industries/zed"
|
||||||
|
|
||||||
|
[language_servers.purescript-language-server]
|
||||||
|
name = "PureScript Language Server"
|
||||||
|
language = "PureScript"
|
||||||
|
|
||||||
|
[grammars.purescript]
|
||||||
|
repository = "https://github.com/postsolar/tree-sitter-purescript"
|
||||||
|
commit = "0554811a512b9cec08b5a83ce9096eb22da18213"
|
99
extensions/purescript/src/purescript.rs
Normal file
99
extensions/purescript/src/purescript.rs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
use std::{env, fs};
|
||||||
|
use zed_extension_api::{self as zed, Result};
|
||||||
|
|
||||||
|
const SERVER_PATH: &str = "node_modules/.bin/purescript-language-server";
|
||||||
|
const PACKAGE_NAME: &str = "purescript-language-server";
|
||||||
|
|
||||||
|
struct PrismaExtension {
|
||||||
|
did_find_server: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PrismaExtension {
|
||||||
|
fn server_exists(&self) -> bool {
|
||||||
|
fs::metadata(SERVER_PATH).map_or(false, |stat| stat.is_file())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn server_script_path(&mut self, config: zed::LanguageServerConfig) -> Result<String> {
|
||||||
|
let server_exists = self.server_exists();
|
||||||
|
if self.did_find_server && server_exists {
|
||||||
|
return Ok(SERVER_PATH.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
zed::set_language_server_installation_status(
|
||||||
|
&config.name,
|
||||||
|
&zed::LanguageServerInstallationStatus::CheckingForUpdate,
|
||||||
|
);
|
||||||
|
let version = zed::npm_package_latest_version(PACKAGE_NAME)?;
|
||||||
|
|
||||||
|
if !server_exists
|
||||||
|
|| zed::npm_package_installed_version(PACKAGE_NAME)?.as_ref() != Some(&version)
|
||||||
|
{
|
||||||
|
zed::set_language_server_installation_status(
|
||||||
|
&config.name,
|
||||||
|
&zed::LanguageServerInstallationStatus::Downloading,
|
||||||
|
);
|
||||||
|
let result = zed::npm_install_package(PACKAGE_NAME, &version);
|
||||||
|
match result {
|
||||||
|
Ok(()) => {
|
||||||
|
if !self.server_exists() {
|
||||||
|
Err(format!(
|
||||||
|
"installed package '{PACKAGE_NAME}' did not contain expected path '{SERVER_PATH}'",
|
||||||
|
))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
if !self.server_exists() {
|
||||||
|
Err(error)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.did_find_server = true;
|
||||||
|
Ok(SERVER_PATH.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl zed::Extension for PrismaExtension {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
did_find_server: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn language_server_command(
|
||||||
|
&mut self,
|
||||||
|
config: zed::LanguageServerConfig,
|
||||||
|
_worktree: &zed::Worktree,
|
||||||
|
) -> Result<zed::Command> {
|
||||||
|
let server_path = self.server_script_path(config)?;
|
||||||
|
Ok(zed::Command {
|
||||||
|
command: zed::node_binary_path()?,
|
||||||
|
args: vec![
|
||||||
|
env::current_dir()
|
||||||
|
.unwrap()
|
||||||
|
.join(&server_path)
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string(),
|
||||||
|
"--stdio".to_string(),
|
||||||
|
],
|
||||||
|
env: Default::default(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn language_server_initialization_options(
|
||||||
|
&mut self,
|
||||||
|
_config: zed::LanguageServerConfig,
|
||||||
|
_worktree: &zed::Worktree,
|
||||||
|
) -> Result<Option<String>> {
|
||||||
|
let initialization_options = r#"{
|
||||||
|
"purescript": {
|
||||||
|
"addSpagoSources": true
|
||||||
|
}
|
||||||
|
}"#;
|
||||||
|
|
||||||
|
Ok(Some(initialization_options.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zed::register_extension!(PrismaExtension);
|
Loading…
Reference in New Issue
Block a user