mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-26 10:14:39 +03:00
Extract Prisma support into an extension (#9820)
This PR extracts Prisma support into an extension and removes the built-in Prisma support from Zed. Release Notes: - Removed built-in support for Prisma, in favor of making it available as an extension. The Prisma extension will be suggested for download when you open a `.prisma` file.
This commit is contained in:
parent
71441317bd
commit
dbcff2a420
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -5315,7 +5315,6 @@ dependencies = [
|
|||||||
"tree-sitter-nu",
|
"tree-sitter-nu",
|
||||||
"tree-sitter-ocaml",
|
"tree-sitter-ocaml",
|
||||||
"tree-sitter-php",
|
"tree-sitter-php",
|
||||||
"tree-sitter-prisma-io",
|
|
||||||
"tree-sitter-proto",
|
"tree-sitter-proto",
|
||||||
"tree-sitter-purescript",
|
"tree-sitter-purescript",
|
||||||
"tree-sitter-python",
|
"tree-sitter-python",
|
||||||
@ -10398,15 +10397,6 @@ dependencies = [
|
|||||||
"tree-sitter",
|
"tree-sitter",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tree-sitter-prisma-io"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "git+https://github.com/victorhqc/tree-sitter-prisma#eca2596a355b1a9952b4f80f8f9caed300a272b5"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"tree-sitter",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter-proto"
|
name = "tree-sitter-proto"
|
||||||
version = "0.0.2"
|
version = "0.0.2"
|
||||||
@ -12609,6 +12599,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_prisma"
|
||||||
|
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"
|
||||||
|
@ -97,8 +97,9 @@ members = [
|
|||||||
|
|
||||||
"extensions/gleam",
|
"extensions/gleam",
|
||||||
"extensions/haskell",
|
"extensions/haskell",
|
||||||
"extensions/uiua",
|
"extensions/prisma",
|
||||||
"extensions/svelte",
|
"extensions/svelte",
|
||||||
|
"extensions/uiua",
|
||||||
|
|
||||||
"tooling/xtask",
|
"tooling/xtask",
|
||||||
]
|
]
|
||||||
@ -311,7 +312,6 @@ tree-sitter-nix = { git = "https://github.com/nix-community/tree-sitter-nix", re
|
|||||||
tree-sitter-nu = { git = "https://github.com/nushell/tree-sitter-nu", rev = "7dd29f9616822e5fc259f5b4ae6c4ded9a71a132" }
|
tree-sitter-nu = { git = "https://github.com/nushell/tree-sitter-nu", rev = "7dd29f9616822e5fc259f5b4ae6c4ded9a71a132" }
|
||||||
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-prisma-io = { git = "https://github.com/victorhqc/tree-sitter-prisma" }
|
|
||||||
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-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"
|
||||||
|
@ -38,6 +38,7 @@ pub fn suggested_extension(file_extension_or_name: &str) -> Option<Arc<str>> {
|
|||||||
("latex", "tex"),
|
("latex", "tex"),
|
||||||
("make", "Makefile"),
|
("make", "Makefile"),
|
||||||
("nix", "nix"),
|
("nix", "nix"),
|
||||||
|
("prisma", "prisma"),
|
||||||
("r", "r"),
|
("r", "r"),
|
||||||
("r", "R"),
|
("r", "R"),
|
||||||
("sql", "sql"),
|
("sql", "sql"),
|
||||||
|
@ -64,7 +64,6 @@ tree-sitter-nix.workspace = true
|
|||||||
tree-sitter-nu.workspace = true
|
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-prisma-io.workspace = true
|
|
||||||
tree-sitter-proto.workspace = true
|
tree-sitter-proto.workspace = true
|
||||||
tree-sitter-purescript.workspace = true
|
tree-sitter-purescript.workspace = true
|
||||||
tree-sitter-python.workspace = true
|
tree-sitter-python.workspace = true
|
||||||
|
@ -29,7 +29,6 @@ mod lua;
|
|||||||
mod nu;
|
mod nu;
|
||||||
mod ocaml;
|
mod ocaml;
|
||||||
mod php;
|
mod php;
|
||||||
mod prisma;
|
|
||||||
mod purescript;
|
mod purescript;
|
||||||
mod python;
|
mod python;
|
||||||
mod ruby;
|
mod ruby;
|
||||||
@ -99,7 +98,6 @@ pub fn init(
|
|||||||
tree_sitter_ocaml::language_ocaml_interface(),
|
tree_sitter_ocaml::language_ocaml_interface(),
|
||||||
),
|
),
|
||||||
("php", tree_sitter_php::language_php()),
|
("php", tree_sitter_php::language_php()),
|
||||||
("prisma", tree_sitter_prisma_io::language()),
|
|
||||||
("proto", tree_sitter_proto::language()),
|
("proto", tree_sitter_proto::language()),
|
||||||
("purescript", tree_sitter_purescript::language()),
|
("purescript", tree_sitter_purescript::language()),
|
||||||
("python", tree_sitter_python::language()),
|
("python", tree_sitter_python::language()),
|
||||||
@ -370,12 +368,6 @@ pub fn init(
|
|||||||
vec![Arc::new(terraform::TerraformLspAdapter)]
|
vec![Arc::new(terraform::TerraformLspAdapter)]
|
||||||
);
|
);
|
||||||
language!("hcl", vec![]);
|
language!("hcl", vec![]);
|
||||||
language!(
|
|
||||||
"prisma",
|
|
||||||
vec![Arc::new(prisma::PrismaLspAdapter::new(
|
|
||||||
node_runtime.clone(),
|
|
||||||
))]
|
|
||||||
);
|
|
||||||
language!("dart", vec![Arc::new(dart::DartLanguageServer {})]);
|
language!("dart", vec![Arc::new(dart::DartLanguageServer {})]);
|
||||||
|
|
||||||
languages.register_secondary_lsp_adapter(
|
languages.register_secondary_lsp_adapter(
|
||||||
|
@ -1,123 +0,0 @@
|
|||||||
use anyhow::{anyhow, Result};
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use futures::StreamExt;
|
|
||||||
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
|
|
||||||
use lsp::LanguageServerBinary;
|
|
||||||
use node_runtime::NodeRuntime;
|
|
||||||
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/prisma-language-server";
|
|
||||||
|
|
||||||
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
|
||||||
vec![server_path.into(), "--stdio".into()]
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PrismaLspAdapter {
|
|
||||||
node: Arc<dyn NodeRuntime>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PrismaLspAdapter {
|
|
||||||
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
|
|
||||||
PrismaLspAdapter { node }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
|
||||||
impl LspAdapter for PrismaLspAdapter {
|
|
||||||
fn name(&self) -> LanguageServerName {
|
|
||||||
LanguageServerName("prisma-language-server".into())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fetch_latest_server_version(
|
|
||||||
&self,
|
|
||||||
_: &dyn LspAdapterDelegate,
|
|
||||||
) -> Result<Box<dyn 'static + Any + Send>> {
|
|
||||||
Ok(Box::new(
|
|
||||||
self.node
|
|
||||||
.npm_package_latest_version("@prisma/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 = "@prisma/language-server";
|
|
||||||
|
|
||||||
let should_install_language_server = self
|
|
||||||
.node
|
|
||||||
.should_install_npm_package(package_name, &server_path, &container_dir, &latest_version)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if should_install_language_server {
|
|
||||||
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 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/prisma/Cargo.toml
Normal file
16
extensions/prisma/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "zed_prisma"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
license = "Apache-2.0"
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/prisma.rs"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
zed_extension_api = "0.0.4"
|
1
extensions/prisma/LICENSE-APACHE
Symbolic link
1
extensions/prisma/LICENSE-APACHE
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../LICENSE-APACHE
|
15
extensions/prisma/extension.toml
Normal file
15
extensions/prisma/extension.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
id = "prisma"
|
||||||
|
name = "Prisma"
|
||||||
|
description = "Prisma support."
|
||||||
|
version = "0.0.1"
|
||||||
|
schema_version = 1
|
||||||
|
authors = ["Matthew Gramigna <matthewgramigna@gmail.com>"]
|
||||||
|
repository = "https://github.com/zed-industries/zed"
|
||||||
|
|
||||||
|
[language_servers.prisma-language-server]
|
||||||
|
name = "Prisma Language Server"
|
||||||
|
language = "Prisma"
|
||||||
|
|
||||||
|
[grammars.prisma]
|
||||||
|
repository = "https://github.com/victorhqc/tree-sitter-prisma"
|
||||||
|
commit = "eca2596a355b1a9952b4f80f8f9caed300a272b5"
|
85
extensions/prisma/src/prisma.rs
Normal file
85
extensions/prisma/src/prisma.rs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
use std::{env, fs};
|
||||||
|
use zed_extension_api::{self as zed, Result};
|
||||||
|
|
||||||
|
const SERVER_PATH: &str = "node_modules/.bin/prisma-language-server";
|
||||||
|
const PACKAGE_NAME: &str = "@prisma/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(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zed::register_extension!(PrismaExtension);
|
Loading…
Reference in New Issue
Block a user