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
12 changed files with 127 additions and 144 deletions
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"
|
9
extensions/prisma/languages/prisma/config.toml
Normal file
9
extensions/prisma/languages/prisma/config.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
name = "Prisma"
|
||||
grammar = "prisma"
|
||||
path_suffixes = ["prisma"]
|
||||
line_comments = ["// "]
|
||||
brackets = [
|
||||
{ start = "{", end = "}", close = true, newline = true },
|
||||
{ start = "[", end = "]", close = true, newline = true },
|
||||
{ start = "(", end = ")", close = true, newline = true }
|
||||
]
|
26
extensions/prisma/languages/prisma/highlights.scm
Normal file
26
extensions/prisma/languages/prisma/highlights.scm
Normal file
|
@ -0,0 +1,26 @@
|
|||
[
|
||||
"datasource"
|
||||
"enum"
|
||||
"generator"
|
||||
"model"
|
||||
] @keyword
|
||||
|
||||
(comment) @comment
|
||||
(developer_comment) @comment
|
||||
|
||||
(arguments) @property
|
||||
(attribute) @function
|
||||
(call_expression) @function
|
||||
(column_type) @type
|
||||
(enumeral) @constant
|
||||
(identifier) @variable
|
||||
(string) @string
|
||||
|
||||
"(" @punctuation.bracket
|
||||
")" @punctuation.bracket
|
||||
"[" @punctuation.bracket
|
||||
"]" @punctuation.bracket
|
||||
"{" @punctuation.bracket
|
||||
"}" @punctuation.bracket
|
||||
"=" @operator
|
||||
"@" @operator
|
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…
Add table
Add a link
Reference in a new issue