Extract Astro support into an extension (#9835)
This PR extracts Astro support into an extension and removes the built-in Astro support from Zed. Release Notes: - Removed built-in support for Astro, in favor of making it available as an extension. The Astro extension will be suggested for download when you open a `.astro` file.
This commit is contained in:
parent
7807f23e2a
commit
3676ca879b
14 changed files with 145 additions and 157 deletions
16
extensions/astro/Cargo.toml
Normal file
16
extensions/astro/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "zed_astro"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
license = "Apache-2.0"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/astro.rs"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
zed_extension_api = "0.0.4"
|
1
extensions/astro/LICENSE-APACHE
Symbolic link
1
extensions/astro/LICENSE-APACHE
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../LICENSE-APACHE
|
15
extensions/astro/extension.toml
Normal file
15
extensions/astro/extension.toml
Normal file
|
@ -0,0 +1,15 @@
|
|||
id = "astro"
|
||||
name = "Astro"
|
||||
description = "Astro support."
|
||||
version = "0.0.1"
|
||||
schema_version = 1
|
||||
authors = ["Alvaro Gaona <alvgaona@gmail.com>"]
|
||||
repository = "https://github.com/zed-industries/zed"
|
||||
|
||||
[language_servers.astro-language-server]
|
||||
name = "Astro Language Server"
|
||||
language = "Astro"
|
||||
|
||||
[grammars.astro]
|
||||
repository = "https://github.com/virchau13/tree-sitter-astro"
|
||||
commit = "dfa0893bdc4bdfada102043404758c66e3580568"
|
3
extensions/astro/languages/astro/brackets.scm
Normal file
3
extensions/astro/languages/astro/brackets.scm
Normal file
|
@ -0,0 +1,3 @@
|
|||
("{" @open "}" @close)
|
||||
("<" @open ">" @close)
|
||||
("\"" @open "\"" @close)
|
23
extensions/astro/languages/astro/config.toml
Normal file
23
extensions/astro/languages/astro/config.toml
Normal file
|
@ -0,0 +1,23 @@
|
|||
name = "Astro"
|
||||
grammar = "astro"
|
||||
path_suffixes = ["astro"]
|
||||
block_comment = ["<!-- ", " -->"]
|
||||
autoclose_before = ";:.,=}])>"
|
||||
brackets = [
|
||||
{ start = "{", end = "}", close = true, newline = true },
|
||||
{ start = "[", end = "]", close = true, newline = true },
|
||||
{ start = "(", end = ")", close = true, newline = true },
|
||||
{ start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },
|
||||
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
||||
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
||||
{ start = "`", end = "`", close = true, newline = false, not_in = ["string"] },
|
||||
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
|
||||
]
|
||||
word_characters = ["#", "$", "-"]
|
||||
scope_opt_in_language_servers = ["tailwindcss-language-server"]
|
||||
prettier_parser_name = "astro"
|
||||
prettier_plugins = ["prettier-plugin-astro"]
|
||||
|
||||
[overrides.string]
|
||||
word_characters = ["-"]
|
||||
opt_into_language_servers = ["tailwindcss-language-server"]
|
25
extensions/astro/languages/astro/highlights.scm
Normal file
25
extensions/astro/languages/astro/highlights.scm
Normal file
|
@ -0,0 +1,25 @@
|
|||
(tag_name) @tag
|
||||
(erroneous_end_tag_name) @keyword
|
||||
(doctype) @constant
|
||||
(attribute_name) @property
|
||||
(attribute_value) @string
|
||||
(comment) @comment
|
||||
|
||||
[
|
||||
(attribute_value)
|
||||
(quoted_attribute_value)
|
||||
] @string
|
||||
|
||||
"=" @operator
|
||||
|
||||
[
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
"</"
|
||||
"/>"
|
||||
] @tag.delimiter
|
16
extensions/astro/languages/astro/injections.scm
Normal file
16
extensions/astro/languages/astro/injections.scm
Normal file
|
@ -0,0 +1,16 @@
|
|||
; inherits: html_tags
|
||||
(frontmatter
|
||||
(raw_text) @content
|
||||
(#set! "language" "typescript"))
|
||||
|
||||
(interpolation
|
||||
(raw_text) @content
|
||||
(#set! "language" "tsx"))
|
||||
|
||||
(script_element
|
||||
(raw_text) @content
|
||||
(#set! "language" "typescript"))
|
||||
|
||||
(style_element
|
||||
(raw_text) @content
|
||||
(#set! "language" "css"))
|
100
extensions/astro/src/astro.rs
Normal file
100
extensions/astro/src/astro.rs
Normal file
|
@ -0,0 +1,100 @@
|
|||
use std::{env, fs};
|
||||
use zed_extension_api::{self as zed, Result};
|
||||
|
||||
const SERVER_PATH: &str = "node_modules/@astrojs/language-server/bin/nodeServer.js";
|
||||
const PACKAGE_NAME: &str = "@astrojs/language-server";
|
||||
|
||||
struct AstroExtension {
|
||||
did_find_server: bool,
|
||||
}
|
||||
|
||||
impl AstroExtension {
|
||||
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 AstroExtension {
|
||||
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#"{
|
||||
"provideFormatter": true,
|
||||
"typescript": {
|
||||
"tsdk": "node_modules/typescript/lib"
|
||||
}
|
||||
}"#;
|
||||
|
||||
Ok(Some(initialization_options.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
zed::register_extension!(AstroExtension);
|
Loading…
Add table
Add a link
Reference in a new issue