Extract TOML support into an extension (#9940)

This PR extracts TOML support into an extension and removes the built-in
TOML support from Zed.

There's a small workaround necessary in order for us to set the file
permissions on the `taplo` binary so that it can be run. Eventually
we'll want to build this into the extension API, but for now we're just
hard-coding it on the host side.

Release Notes:

- Removed built-in support for TOML, in favor of making it available as
an extension. The TOML extension will be suggested for download when you
open a `.toml` or `Cargo.lock` file.
This commit is contained in:
Marshall Bowers 2024-03-28 18:40:12 -04:00 committed by GitHub
parent 90cf73b746
commit d074586fbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 156 additions and 142 deletions

View file

@ -32,7 +32,6 @@ mod ruby;
mod rust;
mod tailwind;
mod terraform;
mod toml;
mod typescript;
mod vue;
mod yaml;
@ -99,7 +98,6 @@ pub fn init(
("ruby", tree_sitter_ruby::language()),
("rust", tree_sitter_rust::language()),
("scheme", tree_sitter_scheme::language()),
("toml", tree_sitter_toml::language()),
("tsx", tree_sitter_typescript::language_tsx()),
("typescript", tree_sitter_typescript::language_typescript()),
("vue", tree_sitter_vue::language()),
@ -236,7 +234,6 @@ pub fn init(
vec![Arc::new(rust::RustLspAdapter)],
RustContextProvider
);
language!("toml", vec![Arc::new(toml::TaploLspAdapter)]);
match &DenoSettings::get(None, cx).enable {
true => {
language!(

View file

@ -1,126 +0,0 @@
use anyhow::{bail, Context, Result};
use async_compression::futures::bufread::GzipDecoder;
use async_trait::async_trait;
use futures::{io::BufReader, StreamExt};
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::LanguageServerBinary;
use smol::fs::{self, File};
use std::{any::Any, path::PathBuf};
use util::github::latest_github_release;
use util::maybe;
use util::{github::GitHubLspBinaryVersion, ResultExt};
pub struct TaploLspAdapter;
#[async_trait(?Send)]
impl LspAdapter for TaploLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName("taplo-ls".into())
}
async fn fetch_latest_server_version(
&self,
delegate: &dyn LspAdapterDelegate,
) -> Result<Box<dyn 'static + Send + Any>> {
let release =
latest_github_release("tamasfe/taplo", true, false, delegate.http_client()).await?;
let asset_name = format!(
"taplo-full-{os}-{arch}.gz",
os = match std::env::consts::OS {
"macos" => "darwin",
"linux" => "linux",
"windows" => "windows",
other => bail!("Running on unsupported os: {other}"),
},
arch = std::env::consts::ARCH
);
let asset = release
.assets
.iter()
.find(|asset| asset.name == asset_name)
.context(format!("no asset found matching {asset_name:?}"))?;
Ok(Box::new(GitHubLspBinaryVersion {
name: release.tag_name,
url: asset.browser_download_url.clone(),
}))
}
async fn fetch_server_binary(
&self,
version: Box<dyn 'static + Send + Any>,
container_dir: PathBuf,
delegate: &dyn LspAdapterDelegate,
) -> Result<LanguageServerBinary> {
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
let binary_path = container_dir.join("taplo");
if fs::metadata(&binary_path).await.is_err() {
let mut response = delegate
.http_client()
.get(&version.url, Default::default(), true)
.await
.context("error downloading release")?;
let decompressed_bytes = GzipDecoder::new(BufReader::new(response.body_mut()));
let mut file = File::create(&binary_path).await?;
futures::io::copy(decompressed_bytes, &mut file).await?;
// todo("windows")
#[cfg(not(windows))]
{
fs::set_permissions(
&binary_path,
<fs::Permissions as fs::unix::PermissionsExt>::from_mode(0o755),
)
.await?;
}
}
Ok(LanguageServerBinary {
path: binary_path,
env: None,
arguments: vec!["lsp".into(), "stdio".into()],
})
}
async fn cached_server_binary(
&self,
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir)
.await
.map(|mut binary| {
binary.arguments = vec!["--help".into()];
binary
})
}
}
async fn get_cached_server_binary(container_dir: PathBuf) -> Option<LanguageServerBinary> {
maybe!(async {
let mut last = None;
let mut entries = fs::read_dir(&container_dir).await?;
while let Some(entry) = entries.next().await {
last = Some(entry?.path());
}
anyhow::Ok(LanguageServerBinary {
path: last.context("no cached binary")?,
env: None,
arguments: Default::default(),
})
})
.await
.log_err()
}

View file

@ -1,3 +0,0 @@
("[" @open "]" @close)
("{" @open "}" @close)
("\"" @open "\"" @close)

View file

@ -1,11 +0,0 @@
name = "TOML"
grammar = "toml"
path_suffixes = ["Cargo.lock", "toml"]
line_comments = ["# "]
autoclose_before = ",]}"
brackets = [
{ 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 = false, not_in = ["comment", "string"] },
]

View file

@ -1,37 +0,0 @@
; Properties
;-----------
(bare_key) @property
(quoted_key) @property
; Literals
;---------
(boolean) @constant
(comment) @comment
(string) @string
(integer) @number
(float) @number
(offset_date_time) @string.special
(local_date_time) @string.special
(local_date) @string.special
(local_time) @string.special
; Punctuation
;------------
[
"."
","
] @punctuation.delimiter
"=" @operator
[
"["
"]"
"[["
"]]"
"{"
"}"
] @punctuation.bracket

View file

@ -1,15 +0,0 @@
(table
.
"["
.
(_) @name) @item
(table_array_element
.
"[["
.
(_) @name) @item
(pair
.
(_) @name) @item

View file

@ -1,2 +0,0 @@
(comment) @comment
(string) @string

View file

@ -1 +0,0 @@
(pair (bare_key) "=" (_) @redact)