Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swift support #6831

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typ
tree-sitter-ruby = "0.20.0"
tree-sitter-html = "0.19.0"
tree-sitter-scheme = { git = "https://github.com/6cdh/tree-sitter-scheme", rev = "af0fd1fa452cb2562dc7b5c8a8c55551c39273b9"}
tree-sitter-swift = "0.4.0"
tree-sitter-svelte = { git = "https://github.com/Himujjal/tree-sitter-svelte", rev = "697bb515471871e85ff799ea57a76298a71a9cca"}
tree-sitter-racket = { git = "https://github.com/zed-industries/tree-sitter-racket", rev = "eb010cf2c674c6fd9a6316a84e28ef90190fe51a"}
tree-sitter-yaml = { git = "https://github.com/zed-industries/tree-sitter-yaml", rev = "f545a41f57502e1b5ddf2a6668896c1b0620f930"}
Expand Down
1 change: 1 addition & 0 deletions crates/zed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ tree-sitter-html.workspace = true
tree-sitter-php.workspace = true
tree-sitter-scheme.workspace = true
tree-sitter-svelte.workspace = true
tree-sitter-swift.workspace = true
tree-sitter-racket.workspace = true
tree-sitter-yaml.workspace = true
tree-sitter-lua.workspace = true
Expand Down
7 changes: 6 additions & 1 deletion crates/zed/src/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod python;
mod ruby;
mod rust;
mod svelte;
mod swift;
mod tailwind;
mod typescript;
mod uiua;
Expand Down Expand Up @@ -242,6 +243,11 @@ pub fn init(
Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
],
);
language(
"swift",
tree_sitter_swift::language(),
vec![Arc::new(swift::SourcekitLspAdapter)],
);
language(
"php",
tree_sitter_php::language(),
Expand All @@ -250,7 +256,6 @@ pub fn init(
Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
],
);

language("elm", tree_sitter_elm::language(), vec![]);
language("glsl", tree_sitter_glsl::language(), vec![]);
language("nix", tree_sitter_nix::language(), vec![]);
Expand Down
59 changes: 59 additions & 0 deletions crates/zed/src/languages/swift.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::LanguageServerBinary;
use std::{any::Any, ffi::OsString, path::PathBuf};

pub struct SourcekitLspAdapter;

#[async_trait]
impl LspAdapter for SourcekitLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName("swift-sourcekit-lsp".into())
}

fn short_name(&self) -> &'static str {
"sourcekit-lsp"
}

async fn fetch_latest_server_version(
&self,
_: &dyn LspAdapterDelegate,
) -> Result<Box<dyn 'static + Any + Send>> {
Ok(Box::new(()))
}

async fn fetch_server_binary(
&self,
_version: Box<dyn 'static + Send + Any>,
_container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Result<LanguageServerBinary> {
Err(anyhow!(
"swift toolchain must be installed and available in your $PATH"
))
}

async fn cached_server_binary(
&self,
_: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_sourcekit_lsp_binary(vec![])
}

async fn installation_test_binary(&self, _: PathBuf) -> Option<LanguageServerBinary> {
get_cached_sourcekit_lsp_binary(vec!["--help".into()])
}

fn can_be_reinstalled(&self) -> bool {
false
}
}

fn get_cached_sourcekit_lsp_binary(arguments: Vec<OsString>) -> Option<LanguageServerBinary> {
Some(LanguageServerBinary {
path: "/usr/bin/sourcekit-lsp".into(),
arguments,
})
}
5 changes: 5 additions & 0 deletions crates/zed/src/languages/swift/brackets.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
("(" @open ")" @close)
("[" @open "]" @close)
("{" @open "}" @close)
("<" @open ">" @close)
("\"" @open "\"" @close)
11 changes: 11 additions & 0 deletions crates/zed/src/languages/swift/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = "Swift"
path_suffixes = ["swift"]
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 = false, newline = true, not_in = ["string", "comment"] },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
]
Loading
Loading