svelte: Extract to zed-extensions/svelte repository (#19425)
This PR extracts the Svelte extension to the [zed-extensions/svelte](https://github.com/zed-extensions/svelte) repository. Release Notes: - N/A
This commit is contained in:
parent
2db9090a2f
commit
15449cdf30
14 changed files with 0 additions and 473 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -14866,13 +14866,6 @@ dependencies = [
|
||||||
"zed_extension_api 0.1.0",
|
"zed_extension_api 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zed_svelte"
|
|
||||||
version = "0.2.1"
|
|
||||||
dependencies = [
|
|
||||||
"zed_extension_api 0.1.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed_terraform"
|
name = "zed_terraform"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
|
|
@ -158,7 +158,6 @@ members = [
|
||||||
"extensions/ruff",
|
"extensions/ruff",
|
||||||
"extensions/slash-commands-example",
|
"extensions/slash-commands-example",
|
||||||
"extensions/snippets",
|
"extensions/snippets",
|
||||||
"extensions/svelte",
|
|
||||||
"extensions/terraform",
|
"extensions/terraform",
|
||||||
"extensions/test-extension",
|
"extensions/test-extension",
|
||||||
"extensions/toml",
|
"extensions/toml",
|
||||||
|
|
3
extensions/svelte/.gitignore
vendored
3
extensions/svelte/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
||||||
target
|
|
||||||
*.wasm
|
|
||||||
grammars
|
|
|
@ -1,16 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "zed_svelte"
|
|
||||||
version = "0.2.1"
|
|
||||||
edition = "2021"
|
|
||||||
publish = false
|
|
||||||
license = "Apache-2.0"
|
|
||||||
|
|
||||||
[lints]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
path = "src/svelte.rs"
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
zed_extension_api = "0.1.0"
|
|
|
@ -1 +0,0 @@
|
||||||
../../LICENSE-APACHE
|
|
|
@ -1,15 +0,0 @@
|
||||||
id = "svelte"
|
|
||||||
name = "Svelte"
|
|
||||||
description = "Svelte support"
|
|
||||||
version = "0.2.1"
|
|
||||||
schema_version = 1
|
|
||||||
authors = []
|
|
||||||
repository = "https://github.com/zed-extensions/svelte"
|
|
||||||
|
|
||||||
[language_servers.svelte-language-server]
|
|
||||||
name = "Svelte Language Server"
|
|
||||||
language = "Svelte"
|
|
||||||
|
|
||||||
[grammars.svelte]
|
|
||||||
repository = "https://github.com/tree-sitter-grammars/tree-sitter-svelte"
|
|
||||||
commit = "3f06f705410683adb17d146b5eca28c62fe81ba6"
|
|
|
@ -1,7 +0,0 @@
|
||||||
("<" @open ">" @close)
|
|
||||||
("{" @open "}" @close)
|
|
||||||
("'" @open "'" @close)
|
|
||||||
("\"" @open "\"" @close)
|
|
||||||
("(" @open ")" @close)
|
|
||||||
; ("[" @open "]" @close)
|
|
||||||
; ("`" @open "`" @close)
|
|
|
@ -1,22 +0,0 @@
|
||||||
name = "Svelte"
|
|
||||||
grammar = "svelte"
|
|
||||||
path_suffixes = ["svelte"]
|
|
||||||
block_comment = ["<!-- ", " -->"]
|
|
||||||
autoclose_before = ":\"'}]>"
|
|
||||||
brackets = [
|
|
||||||
{ start = "{", end = "}", close = true, newline = true },
|
|
||||||
{ start = "<", end = ">", close = true, newline = true, not_in = ["string"] },
|
|
||||||
{ start = "[", end = "]", close = true, newline = true },
|
|
||||||
{ start = "(", end = ")", close = true, newline = true },
|
|
||||||
{ start = "!--", end = " --", close = true, newline = true },
|
|
||||||
{ start = "\"", end = "\"", close = true, newline = true, not_in = ["string"] },
|
|
||||||
{ start = "'", end = "'", close = true, newline = true, not_in = ["string"] },
|
|
||||||
{ start = "`", end = "`", close = true, newline = true, not_in = ["string"] },
|
|
||||||
]
|
|
||||||
scope_opt_in_language_servers = ["tailwindcss-language-server"]
|
|
||||||
prettier_parser_name = "svelte"
|
|
||||||
prettier_plugins = ["prettier-plugin-svelte"]
|
|
||||||
|
|
||||||
[overrides.string]
|
|
||||||
word_characters = ["-"]
|
|
||||||
opt_into_language_servers = ["tailwindcss-language-server"]
|
|
|
@ -1,108 +0,0 @@
|
||||||
|
|
||||||
; comments
|
|
||||||
(comment) @comment
|
|
||||||
|
|
||||||
; property attribute
|
|
||||||
(attribute_directive) @attribute.function
|
|
||||||
(attribute_identifier) @attribute
|
|
||||||
(attribute_modifier) @attribute.special
|
|
||||||
|
|
||||||
; Style component attributes as @property
|
|
||||||
(start_tag
|
|
||||||
(
|
|
||||||
(tag_name) @_tag_name
|
|
||||||
(#match? @_tag_name "^[A-Z]")
|
|
||||||
)
|
|
||||||
(attribute
|
|
||||||
(attribute_name
|
|
||||||
(attribute_identifier) @tag.property
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
; Style self-closing component attributes as @tag.property
|
|
||||||
(self_closing_tag
|
|
||||||
(
|
|
||||||
(tag_name) @_tag_name
|
|
||||||
(#match? @_tag_name "^[A-Z]")
|
|
||||||
)
|
|
||||||
(attribute
|
|
||||||
(attribute_name
|
|
||||||
(attribute_identifier) @tag.property
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
; style elements starting with lowercase letters as tags
|
|
||||||
(
|
|
||||||
(tag_name) @tag
|
|
||||||
(#match? @tag "^[a-z]")
|
|
||||||
)
|
|
||||||
|
|
||||||
; style elements starting with uppercase letters as components (types)
|
|
||||||
; Also valid might be to treat them as constructors
|
|
||||||
(
|
|
||||||
(tag_name) @tag @tag.component.type.constructor
|
|
||||||
(#match? @tag "^[A-Z]")
|
|
||||||
)
|
|
||||||
|
|
||||||
[
|
|
||||||
"<"
|
|
||||||
">"
|
|
||||||
"</"
|
|
||||||
"/>"
|
|
||||||
] @tag.punctuation.bracket
|
|
||||||
|
|
||||||
|
|
||||||
[
|
|
||||||
"{"
|
|
||||||
"}"
|
|
||||||
] @punctuation.bracket
|
|
||||||
|
|
||||||
[
|
|
||||||
"|"
|
|
||||||
] @punctuation.delimiter
|
|
||||||
|
|
||||||
|
|
||||||
[
|
|
||||||
"@"
|
|
||||||
"#"
|
|
||||||
":"
|
|
||||||
"/"
|
|
||||||
] @tag.punctuation.special
|
|
||||||
|
|
||||||
"=" @operator
|
|
||||||
|
|
||||||
|
|
||||||
; Treating (if, each, ...) as a keyword inside of blocks
|
|
||||||
; like {#if ...} or {#each ...}
|
|
||||||
(block_start_tag
|
|
||||||
tag: _ @keyword
|
|
||||||
)
|
|
||||||
|
|
||||||
(block_tag
|
|
||||||
tag: _ @keyword
|
|
||||||
)
|
|
||||||
|
|
||||||
(block_end_tag
|
|
||||||
tag: _ @keyword
|
|
||||||
)
|
|
||||||
|
|
||||||
(expression_tag
|
|
||||||
tag: _ @keyword
|
|
||||||
)
|
|
||||||
|
|
||||||
; Style quoted string attribute values
|
|
||||||
(quoted_attribute_value) @string
|
|
||||||
|
|
||||||
|
|
||||||
; Highlight the `as` keyword in each blocks
|
|
||||||
(each_start
|
|
||||||
("as") @tag.keyword
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
; Highlight the snippet name as a function
|
|
||||||
; (e.g. {#snippet foo(bar)}
|
|
||||||
(snippet_name) @function
|
|
|
@ -1,9 +0,0 @@
|
||||||
[
|
|
||||||
(element)
|
|
||||||
(if_statement)
|
|
||||||
(each_statement)
|
|
||||||
(await_statement)
|
|
||||||
(snippet_statement)
|
|
||||||
(script_element)
|
|
||||||
(style_element)
|
|
||||||
] @indent
|
|
|
@ -1,84 +0,0 @@
|
||||||
; ; injections.scm
|
|
||||||
; ; --------------
|
|
||||||
|
|
||||||
; Match script tags with a lang attribute
|
|
||||||
(script_element
|
|
||||||
(start_tag
|
|
||||||
(attribute
|
|
||||||
(attribute_name) @_attr_name
|
|
||||||
(#eq? @_attr_name "lang")
|
|
||||||
(quoted_attribute_value
|
|
||||||
(attribute_value) @language
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(raw_text) @content
|
|
||||||
)
|
|
||||||
|
|
||||||
; Match script tags without a lang attribute
|
|
||||||
(script_element
|
|
||||||
(start_tag
|
|
||||||
(attribute
|
|
||||||
(attribute_name) @_attr_name
|
|
||||||
)*
|
|
||||||
)
|
|
||||||
(raw_text) @content
|
|
||||||
(#not-any-of? @_attr_name "lang")
|
|
||||||
(#set! language "javascript")
|
|
||||||
)
|
|
||||||
|
|
||||||
; Match the contents of the script's generics="T extends string" as typescript code
|
|
||||||
;
|
|
||||||
; Disabled for the time-being because tree-sitter is treating the generics
|
|
||||||
; attribute as a top-level typescript statement, where `T extends string` is
|
|
||||||
; not a valid top-level typescript statement.
|
|
||||||
;
|
|
||||||
; (script_element
|
|
||||||
; (start_tag
|
|
||||||
; (attribute
|
|
||||||
; (attribute_name) @_attr_name
|
|
||||||
; (#eq? @_attr_name "generics")
|
|
||||||
; (quoted_attribute_value
|
|
||||||
; (attribute_value) @content
|
|
||||||
; )
|
|
||||||
; )
|
|
||||||
; )
|
|
||||||
; (#set! language "typescript")
|
|
||||||
; )
|
|
||||||
|
|
||||||
|
|
||||||
; Mark everything as typescript because it's
|
|
||||||
; a more generic superset of javascript
|
|
||||||
; Not sure if it's possible to somehow refer to the
|
|
||||||
; script's language attribute here.
|
|
||||||
((svelte_raw_text) @content
|
|
||||||
(#set! "language" "ts")
|
|
||||||
)
|
|
||||||
|
|
||||||
; Match <style lang="language"> as the specified language
|
|
||||||
(style_element
|
|
||||||
(start_tag
|
|
||||||
(attribute
|
|
||||||
(attribute_name) @_attr_name
|
|
||||||
(#eq? @_attr_name "lang")
|
|
||||||
(quoted_attribute_value
|
|
||||||
(attribute_value) @language
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(raw_text) @content
|
|
||||||
)
|
|
||||||
|
|
||||||
; Match <style> tags without a lang attribute as CSS
|
|
||||||
(style_element
|
|
||||||
(start_tag
|
|
||||||
(attribute
|
|
||||||
(attribute_name) @_attr_name
|
|
||||||
)*
|
|
||||||
)
|
|
||||||
(raw_text) @content
|
|
||||||
(#not-any-of? @_attr_name "lang")
|
|
||||||
(#set! language "css")
|
|
||||||
)
|
|
||||||
|
|
||||||
; Downstream TODO: Style @component comments as markdown
|
|
|
@ -1,69 +0,0 @@
|
||||||
|
|
||||||
(script_element
|
|
||||||
(start_tag) @name
|
|
||||||
(raw_text) @context @item
|
|
||||||
)
|
|
||||||
|
|
||||||
(script_element
|
|
||||||
(end_tag) @name @item
|
|
||||||
)
|
|
||||||
|
|
||||||
(style_element
|
|
||||||
(start_tag) @name
|
|
||||||
(raw_text) @context
|
|
||||||
) @item
|
|
||||||
|
|
||||||
|
|
||||||
(document) @item
|
|
||||||
|
|
||||||
(comment) @annotation
|
|
||||||
|
|
||||||
(if_statement
|
|
||||||
(if_start) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
(else_block
|
|
||||||
(else_start) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
(else_if_block
|
|
||||||
(else_if_start) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
(element
|
|
||||||
(start_tag) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
(element
|
|
||||||
(self_closing_tag) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
|
|
||||||
; (if_end) @name @item
|
|
||||||
|
|
||||||
(each_statement
|
|
||||||
(each_start) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
|
|
||||||
(snippet_statement
|
|
||||||
(snippet_start) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
(snippet_end) @name @item
|
|
||||||
|
|
||||||
(html_tag) @name @item
|
|
||||||
|
|
||||||
(const_tag) @name @item
|
|
||||||
|
|
||||||
(await_statement
|
|
||||||
(await_start) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
(then_block
|
|
||||||
(then_start) @name
|
|
||||||
) @item
|
|
||||||
|
|
||||||
(catch_block
|
|
||||||
(catch_start) @name
|
|
||||||
) @item
|
|
|
@ -1,7 +0,0 @@
|
||||||
(comment) @comment
|
|
||||||
|
|
||||||
[
|
|
||||||
(raw_text)
|
|
||||||
(attribute_value)
|
|
||||||
(quoted_attribute_value)
|
|
||||||
] @string
|
|
|
@ -1,124 +0,0 @@
|
||||||
use std::{env, fs};
|
|
||||||
use zed_extension_api::{self as zed, serde_json, Result};
|
|
||||||
|
|
||||||
struct SvelteExtension {
|
|
||||||
did_find_server: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
const SERVER_PATH: &str = "node_modules/svelte-language-server/bin/server.js";
|
|
||||||
const PACKAGE_NAME: &str = "svelte-language-server";
|
|
||||||
|
|
||||||
impl SvelteExtension {
|
|
||||||
fn server_exists(&self) -> bool {
|
|
||||||
fs::metadata(SERVER_PATH).map_or(false, |stat| stat.is_file())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn server_script_path(&mut self, id: &zed::LanguageServerId) -> 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(
|
|
||||||
id,
|
|
||||||
&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(
|
|
||||||
id,
|
|
||||||
&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 SvelteExtension {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
did_find_server: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn language_server_command(
|
|
||||||
&mut self,
|
|
||||||
id: &zed::LanguageServerId,
|
|
||||||
_: &zed::Worktree,
|
|
||||||
) -> Result<zed::Command> {
|
|
||||||
let server_path = self.server_script_path(id)?;
|
|
||||||
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,
|
|
||||||
_: &zed::LanguageServerId,
|
|
||||||
_: &zed::Worktree,
|
|
||||||
) -> Result<Option<serde_json::Value>> {
|
|
||||||
let config = serde_json::json!({
|
|
||||||
"inlayHints": {
|
|
||||||
"parameterNames": {
|
|
||||||
"enabled": "all",
|
|
||||||
"suppressWhenArgumentMatchesName": false
|
|
||||||
},
|
|
||||||
"parameterTypes": {
|
|
||||||
"enabled": true
|
|
||||||
},
|
|
||||||
"variableTypes": {
|
|
||||||
"enabled": true,
|
|
||||||
"suppressWhenTypeMatchesName": false
|
|
||||||
},
|
|
||||||
"propertyDeclarationTypes": {
|
|
||||||
"enabled": true
|
|
||||||
},
|
|
||||||
"functionLikeReturnTypes": {
|
|
||||||
"enabled": true
|
|
||||||
},
|
|
||||||
"enumMemberValues": {
|
|
||||||
"enabled": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(Some(serde_json::json!({
|
|
||||||
"provideFormatter": true,
|
|
||||||
"configuration": {
|
|
||||||
"typescript": config,
|
|
||||||
"javascript": config
|
|
||||||
}
|
|
||||||
})))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
zed::register_extension!(SvelteExtension);
|
|
Loading…
Add table
Add a link
Reference in a new issue