diff --git a/Cargo.lock b/Cargo.lock index 603e648706..426e708113 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17247,13 +17247,6 @@ dependencies = [ "zed_extension_api 0.1.0", ] -[[package]] -name = "zed_zig" -version = "0.3.3" -dependencies = [ - "zed_extension_api 0.1.0", -] - [[package]] name = "zeno" version = "0.2.3" diff --git a/Cargo.toml b/Cargo.toml index fde4d68d59..d9a0ec9cba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -181,7 +181,6 @@ members = [ "extensions/test-extension", "extensions/toml", "extensions/uiua", - "extensions/zig", # # Tooling diff --git a/docs/src/languages/zig.md b/docs/src/languages/zig.md index e929f0061e..4a48405d0c 100644 --- a/docs/src/languages/zig.md +++ b/docs/src/languages/zig.md @@ -1,6 +1,6 @@ # Zig -Zig support is available through the [Zig extension](https://github.com/zed-industries/zed/tree/main/extensions/zig). +Zig support is available through the [Zig extension](https://github.com/zed-extensions/zig). - Tree-sitter: [tree-sitter-zig](https://github.com/tree-sitter-grammars/tree-sitter-zig) - Language Server: [zls](https://github.com/zigtools/zls) diff --git a/extensions/zig/Cargo.toml b/extensions/zig/Cargo.toml deleted file mode 100644 index 2e3d0ffa66..0000000000 --- a/extensions/zig/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "zed_zig" -version = "0.3.3" -edition.workspace = true -publish.workspace = true -license = "Apache-2.0" - -[lints] -workspace = true - -[lib] -path = "src/zig.rs" -crate-type = ["cdylib"] - -[dependencies] -zed_extension_api = "0.1.0" diff --git a/extensions/zig/LICENSE-APACHE b/extensions/zig/LICENSE-APACHE deleted file mode 120000 index 1cd601d0a3..0000000000 --- a/extensions/zig/LICENSE-APACHE +++ /dev/null @@ -1 +0,0 @@ -../../LICENSE-APACHE \ No newline at end of file diff --git a/extensions/zig/extension.toml b/extensions/zig/extension.toml deleted file mode 100644 index 265b0b1eef..0000000000 --- a/extensions/zig/extension.toml +++ /dev/null @@ -1,15 +0,0 @@ -id = "zig" -name = "Zig" -description = "Zig support." -version = "0.3.3" -schema_version = 1 -authors = ["Allan Calix "] -repository = "https://github.com/zed-industries/zed" - -[language_servers.zls] -name = "zls" -language = "Zig" - -[grammars.zig] -repository = "https://github.com/tree-sitter-grammars/tree-sitter-zig" -commit = "eb7d58c2dc4fbeea4745019dee8df013034ae66b" diff --git a/extensions/zig/languages/zig/brackets.scm b/extensions/zig/languages/zig/brackets.scm deleted file mode 100644 index 191fd9c084..0000000000 --- a/extensions/zig/languages/zig/brackets.scm +++ /dev/null @@ -1,3 +0,0 @@ -("(" @open ")" @close) -("[" @open "]" @close) -("{" @open "}" @close) diff --git a/extensions/zig/languages/zig/config.toml b/extensions/zig/languages/zig/config.toml deleted file mode 100644 index 838b4f2116..0000000000 --- a/extensions/zig/languages/zig/config.toml +++ /dev/null @@ -1,12 +0,0 @@ -name = "Zig" -grammar = "zig" -path_suffixes = ["zig", "zon"] -line_comments = ["// ", "/// ", "//! "] -autoclose_before = ";:.,=}])" -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 = ["string"] }, - { start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] }, -] diff --git a/extensions/zig/languages/zig/highlights.scm b/extensions/zig/languages/zig/highlights.scm deleted file mode 100644 index c4be851e88..0000000000 --- a/extensions/zig/languages/zig/highlights.scm +++ /dev/null @@ -1,295 +0,0 @@ -; Variables - -(identifier) @variable - -; Parameters - -(parameter - name: (identifier) @variable.parameter) - -; Types - -(parameter - type: (identifier) @type) - -((identifier) @type - (#match? @type "^[A-Z_][a-zA-Z0-9_]*")) - -(variable_declaration - (identifier) @type - "=" - [ - (struct_declaration) - (enum_declaration) - (union_declaration) - (opaque_declaration) - ]) - -[ - (builtin_type) - "anyframe" -] @type.builtin - -; Constants - -((identifier) @constant - (#match? @constant "^[A-Z][A-Z_0-9]+$")) - -[ - "null" - "unreachable" - "undefined" -] @constant.builtin - -(field_expression - . - member: (identifier) @constant) - -(enum_declaration - (container_field - type: (identifier) @constant)) - -; Labels - -(block_label (identifier) @label) - -(break_label (identifier) @label) - -; Fields - -(field_initializer - . - (identifier) @variable.member) - -(field_expression - (_) - member: (identifier) @property) - -(field_expression - (_) - member: (identifier) @type (#match? @type "^[A-Z_][a-zA-Z0-9_]*")) - -(container_field - name: (identifier) @property) - -(initializer_list - (assignment_expression - left: (field_expression - . - member: (identifier) @property))) - -; Functions - -(builtin_identifier) @function.builtin - -(call_expression - function: (identifier) @function.call) - -(call_expression - function: (field_expression - member: (identifier) @function.call)) - -(function_declaration - name: (identifier) @function) - -; Modules - -(variable_declaration - (identifier) @module - (builtin_function - (builtin_identifier) @keyword.import - (#any-of? @keyword.import "@import" "@cImport"))) - -; Builtins - -[ - "c" - "..." -] @variable.builtin - -((identifier) @variable.builtin - (#eq? @variable.builtin "_")) - -(calling_convention - (identifier) @variable.builtin) - -; Keywords - -[ - "asm" - "defer" - "errdefer" - "test" - "error" - "const" - "var" -] @keyword - -[ - "struct" - "union" - "enum" - "opaque" -] @keyword.type - -[ - "async" - "await" - "suspend" - "nosuspend" - "resume" -] @keyword.coroutine - -"fn" @keyword.function - -[ - "and" - "or" - "orelse" -] @keyword.operator - -"return" @keyword.return - -[ - "if" - "else" - "switch" -] @keyword.conditional - -[ - "for" - "while" - "break" - "continue" -] @keyword.repeat - -[ - "usingnamespace" - "export" -] @keyword.import - -[ - "try" - "catch" -] @keyword.exception - -[ - "volatile" - "allowzero" - "noalias" - "addrspace" - "align" - "callconv" - "linksection" - "pub" - "inline" - "noinline" - "extern" - "comptime" - "packed" - "threadlocal" -] @keyword.modifier - -; Operator - -[ - "=" - "*=" - "*%=" - "*|=" - "/=" - "%=" - "+=" - "+%=" - "+|=" - "-=" - "-%=" - "-|=" - "<<=" - "<<|=" - ">>=" - "&=" - "^=" - "|=" - "!" - "~" - "-" - "-%" - "&" - "==" - "!=" - ">" - ">=" - "<=" - "<" - "&" - "^" - "|" - "<<" - ">>" - "<<|" - "+" - "++" - "+%" - "-%" - "+|" - "-|" - "*" - "/" - "%" - "**" - "*%" - "*|" - "||" - ".*" - ".?" - "?" - ".." -] @operator - -; Literals - -(character) @string - -([ - (string) - (multiline_string) -] @string - (#set! "priority" 95)) - -(integer) @number - -(float) @number.float - -(boolean) @boolean - -(escape_sequence) @string.escape - -; Punctuation - -[ - "[" - "]" - "(" - ")" - "{" - "}" -] @punctuation.bracket - -[ - ";" - "." - "," - ":" - "=>" - "->" -] @punctuation.delimiter - -(payload "|" @punctuation.bracket) - -; Comments - -(comment) @comment - -((comment) @comment.documentation - (#match? @comment.documentation "^//(/|!)")) diff --git a/extensions/zig/languages/zig/indents.scm b/extensions/zig/languages/zig/indents.scm deleted file mode 100644 index aba33b9ae7..0000000000 --- a/extensions/zig/languages/zig/indents.scm +++ /dev/null @@ -1,17 +0,0 @@ -[ - (block) - (switch_expression) - (initializer_list) -] @indent.begin - -(block - "}" @indent.end) - -(_ "[" "]" @end) @indent -(_ "{" "}" @end) @indent -(_ "(" ")" @end) @indent - -[ - (comment) - (multiline_string) -] @indent.ignore diff --git a/extensions/zig/languages/zig/injections.scm b/extensions/zig/languages/zig/injections.scm deleted file mode 100644 index 48a1b44c9b..0000000000 --- a/extensions/zig/languages/zig/injections.scm +++ /dev/null @@ -1,10 +0,0 @@ -((comment) @injection.content - (#set! injection.language "comment")) - -; TODO: add when asm is added -; (asm_output_item (string) @injection.content -; (#set! injection.language "asm")) -; (asm_input_item (string) @injection.content -; (#set! injection.language "asm")) -; (asm_clobbers (string) @injection.content -; (#set! injection.language "asm")) diff --git a/extensions/zig/languages/zig/outline.scm b/extensions/zig/languages/zig/outline.scm deleted file mode 100644 index acb2cc6986..0000000000 --- a/extensions/zig/languages/zig/outline.scm +++ /dev/null @@ -1,50 +0,0 @@ -(test_declaration - "test" @context - [ - (string) - (identifier) - ] @name) @item - -(function_declaration - "pub"? @context - [ - "extern" - "export" - "inline" - "noinline" - ]? @context - "fn" @context - name: (_) @name) @item - -(source_file - (variable_declaration - "pub"? @context - (identifier) @name - "=" (_) @context) @item) - -(struct_declaration - (variable_declaration - "pub"? @context - (identifier) @name - "=" (_) @context) @item) - -(union_declaration - (variable_declaration - "pub"? @context - (identifier) @name - "=" (_) @context) @item) - -(enum_declaration - (variable_declaration - "pub"? @context - (identifier) @name - "=" (_) @context) @item) - -(opaque_declaration - (variable_declaration - "pub"? @context - (identifier) @name - "=" (_) @context) @item) - -(container_field - . (_) @name) @item diff --git a/extensions/zig/languages/zig/textobjects.scm b/extensions/zig/languages/zig/textobjects.scm deleted file mode 100644 index b08df97ea9..0000000000 --- a/extensions/zig/languages/zig/textobjects.scm +++ /dev/null @@ -1,27 +0,0 @@ -(function_declaration - body: (_ - "{" - (_)* @function.inside - "}")) @function.around - -(test_declaration - (block - "{" - (_)* @function.inside - "}")) @function.around - -(variable_declaration - (struct_declaration - "struct" - "{" - [(_) ","]* @class.inside - "}")) @class.around - -(variable_declaration - (enum_declaration - "enum" - "{" - (_)* @class.inside - "}")) @class.around - -(comment)+ @comment.around diff --git a/extensions/zig/src/zig.rs b/extensions/zig/src/zig.rs deleted file mode 100644 index 4b05736b84..0000000000 --- a/extensions/zig/src/zig.rs +++ /dev/null @@ -1,171 +0,0 @@ -use std::fs; -use zed_extension_api::{self as zed, serde_json, settings::LspSettings, LanguageServerId, Result}; - -struct ZigExtension { - cached_binary_path: Option, -} - -#[derive(Clone)] -struct ZlsBinary { - path: String, - args: Option>, - environment: Option>, -} - -impl ZigExtension { - fn language_server_binary( - &mut self, - language_server_id: &LanguageServerId, - worktree: &zed::Worktree, - ) -> Result { - let mut args: Option> = None; - - let (platform, arch) = zed::current_platform(); - let environment = match platform { - zed::Os::Mac | zed::Os::Linux => Some(worktree.shell_env()), - zed::Os::Windows => None, - }; - - if let Ok(lsp_settings) = LspSettings::for_worktree("zls", worktree) { - if let Some(binary) = lsp_settings.binary { - args = binary.arguments; - if let Some(path) = binary.path { - return Ok(ZlsBinary { - path: path.clone(), - args, - environment, - }); - } - } - } - - if let Some(path) = worktree.which("zls") { - return Ok(ZlsBinary { - path, - args, - environment, - }); - } - - if let Some(path) = &self.cached_binary_path { - if fs::metadata(path).map_or(false, |stat| stat.is_file()) { - return Ok(ZlsBinary { - path: path.clone(), - args, - environment, - }); - } - } - - zed::set_language_server_installation_status( - language_server_id, - &zed::LanguageServerInstallationStatus::CheckingForUpdate, - ); - - // Note that in github releases and on zlstools.org the tar.gz asset is not shown - // but is available at https://builds.zigtools.org/zls-{os}-{arch}-{version}.tar.gz - let release = zed::latest_github_release( - "zigtools/zls", - zed::GithubReleaseOptions { - require_assets: true, - pre_release: false, - }, - )?; - - let arch: &str = match arch { - zed::Architecture::Aarch64 => "aarch64", - zed::Architecture::X86 => "x86", - zed::Architecture::X8664 => "x86_64", - }; - - let os: &str = match platform { - zed::Os::Mac => "macos", - zed::Os::Linux => "linux", - zed::Os::Windows => "windows", - }; - - let extension: &str = match platform { - zed::Os::Mac | zed::Os::Linux => "tar.gz", - zed::Os::Windows => "zip", - }; - - let asset_name: String = format!("zls-{}-{}-{}.{}", os, arch, release.version, extension); - let download_url = format!("https://builds.zigtools.org/{}", asset_name); - - let version_dir = format!("zls-{}", release.version); - let binary_path = match platform { - zed::Os::Mac | zed::Os::Linux => format!("{version_dir}/zls"), - zed::Os::Windows => format!("{version_dir}/zls.exe"), - }; - - if !fs::metadata(&binary_path).map_or(false, |stat| stat.is_file()) { - zed::set_language_server_installation_status( - language_server_id, - &zed::LanguageServerInstallationStatus::Downloading, - ); - - zed::download_file( - &download_url, - &version_dir, - match platform { - zed::Os::Mac | zed::Os::Linux => zed::DownloadedFileType::GzipTar, - zed::Os::Windows => zed::DownloadedFileType::Zip, - }, - ) - .map_err(|e| format!("failed to download file: {e}"))?; - - zed::make_file_executable(&binary_path)?; - - let entries = - fs::read_dir(".").map_err(|e| format!("failed to list working directory {e}"))?; - for entry in entries { - let entry = entry.map_err(|e| format!("failed to load directory entry {e}"))?; - if entry.file_name().to_str() != Some(&version_dir) { - fs::remove_dir_all(entry.path()).ok(); - } - } - } - - self.cached_binary_path = Some(binary_path.clone()); - Ok(ZlsBinary { - path: binary_path, - args, - environment, - }) - } -} - -impl zed::Extension for ZigExtension { - fn new() -> Self { - Self { - cached_binary_path: None, - } - } - - fn language_server_command( - &mut self, - language_server_id: &LanguageServerId, - worktree: &zed::Worktree, - ) -> Result { - let zls_binary = self.language_server_binary(language_server_id, worktree)?; - Ok(zed::Command { - command: zls_binary.path, - args: zls_binary.args.unwrap_or_default(), - env: zls_binary.environment.unwrap_or_default(), - }) - } - - fn language_server_workspace_configuration( - &mut self, - _language_server_id: &zed::LanguageServerId, - worktree: &zed::Worktree, - ) -> Result> { - let settings = LspSettings::for_worktree("zls", worktree) - .ok() - .and_then(|lsp_settings| lsp_settings.settings.clone()) - .unwrap_or_default(); - Ok(Some(settings)) - } -} - -zed::register_extension!(ZigExtension);