Extract HTML support into an extension (#10130)
This PR extracts HTML support into an extension and removes the built-in HTML support from Zed. Release Notes: - Removed built-in support for HTML, in favor of making it available as an extension. The HTML extension will be suggested for download when you open a `.html`, `.htm`, or `.shtml` file.
This commit is contained in:
parent
256b446bdf
commit
49c53bc0ec
17 changed files with 133 additions and 145 deletions
16
extensions/html/Cargo.toml
Normal file
16
extensions/html/Cargo.toml
Normal file
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "zed_html"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
license = "Apache-2.0"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/html.rs"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
zed_extension_api = "0.0.4"
|
1
extensions/html/LICENSE-APACHE
Symbolic link
1
extensions/html/LICENSE-APACHE
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../LICENSE-APACHE
|
15
extensions/html/extension.toml
Normal file
15
extensions/html/extension.toml
Normal file
|
@ -0,0 +1,15 @@
|
|||
id = "html"
|
||||
name = "HTML"
|
||||
description = "HTML support."
|
||||
version = "0.0.1"
|
||||
schema_version = 1
|
||||
authors = ["Isaac Clayton <slightknack@gmail.com>"]
|
||||
repository = "https://github.com/zed-industries/zed"
|
||||
|
||||
[language_servers.vscode-html-language-server]
|
||||
name = "vscode-html-language-server"
|
||||
language = "HTML"
|
||||
|
||||
[grammars.html]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-html"
|
||||
commit = "bfa075d83c6b97cd48440b3829ab8d24a2319809"
|
2
extensions/html/languages/html/brackets.scm
Normal file
2
extensions/html/languages/html/brackets.scm
Normal file
|
@ -0,0 +1,2 @@
|
|||
("<" @open ">" @close)
|
||||
("\"" @open "\"" @close)
|
15
extensions/html/languages/html/config.toml
Normal file
15
extensions/html/languages/html/config.toml
Normal file
|
@ -0,0 +1,15 @@
|
|||
name = "HTML"
|
||||
grammar = "html"
|
||||
path_suffixes = ["html", "htm", "shtml"]
|
||||
autoclose_before = ">})"
|
||||
block_comment = ["<!-- ", " -->"]
|
||||
brackets = [
|
||||
{ start = "{", end = "}", close = true, newline = true },
|
||||
{ start = "[", end = "]", close = true, newline = true },
|
||||
{ start = "(", end = ")", close = true, newline = true },
|
||||
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
|
||||
{ start = "<", end = ">", close = true, newline = true, not_in = ["comment", "string"] },
|
||||
{ start = "!--", end = " --", close = true, newline = false, not_in = ["comment", "string"] },
|
||||
]
|
||||
word_characters = ["-"]
|
||||
prettier_parser_name = "html"
|
16
extensions/html/languages/html/highlights.scm
Normal file
16
extensions/html/languages/html/highlights.scm
Normal file
|
@ -0,0 +1,16 @@
|
|||
(tag_name) @keyword
|
||||
(erroneous_end_tag_name) @keyword
|
||||
(doctype) @constant
|
||||
(attribute_name) @property
|
||||
(attribute_value) @string
|
||||
(comment) @comment
|
||||
|
||||
"=" @operator
|
||||
|
||||
[
|
||||
"<"
|
||||
">"
|
||||
"<!"
|
||||
"</"
|
||||
"/>"
|
||||
] @punctuation.bracket
|
6
extensions/html/languages/html/indents.scm
Normal file
6
extensions/html/languages/html/indents.scm
Normal file
|
@ -0,0 +1,6 @@
|
|||
(start_tag ">" @end) @indent
|
||||
(self_closing_tag "/>" @end) @indent
|
||||
|
||||
(element
|
||||
(start_tag) @start
|
||||
(end_tag)? @end) @indent
|
7
extensions/html/languages/html/injections.scm
Normal file
7
extensions/html/languages/html/injections.scm
Normal file
|
@ -0,0 +1,7 @@
|
|||
(script_element
|
||||
(raw_text) @content
|
||||
(#set! "language" "javascript"))
|
||||
|
||||
(style_element
|
||||
(raw_text) @content
|
||||
(#set! "language" "css"))
|
0
extensions/html/languages/html/outline.scm
Normal file
0
extensions/html/languages/html/outline.scm
Normal file
2
extensions/html/languages/html/overrides.scm
Normal file
2
extensions/html/languages/html/overrides.scm
Normal file
|
@ -0,0 +1,2 @@
|
|||
(comment) @comment
|
||||
(quoted_attribute_value) @string
|
86
extensions/html/src/html.rs
Normal file
86
extensions/html/src/html.rs
Normal file
|
@ -0,0 +1,86 @@
|
|||
use std::{env, fs};
|
||||
use zed_extension_api::{self as zed, Result};
|
||||
|
||||
const SERVER_PATH: &str =
|
||||
"node_modules/vscode-langservers-extracted/bin/vscode-html-language-server";
|
||||
const PACKAGE_NAME: &str = "vscode-langservers-extracted";
|
||||
|
||||
struct HtmlExtension {
|
||||
did_find_server: bool,
|
||||
}
|
||||
|
||||
impl HtmlExtension {
|
||||
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 HtmlExtension {
|
||||
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!(HtmlExtension);
|
Loading…
Add table
Add a link
Reference in a new issue