Extract Dockerfile extension (#9832)

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

There's already an existing [Dockerfile
extension](https://github.com/d1y/dockerfile.zed) that was just missing
language server support. Language server support is being added to that
extension in https://github.com/d1y/dockerfile.zed/pull/2.

Release Notes:

- Removed built-in support for Dockerfile, in favor of making it
available as an extension. The Dockerfile extension will be suggested
for download when you open a `Dockerfile`.
This commit is contained in:
Marshall Bowers 2024-03-26 16:38:21 -04:00 committed by GitHub
parent 181dc86b48
commit 7807f23e2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 0 additions and 223 deletions

10
Cargo.lock generated
View File

@ -5301,7 +5301,6 @@ dependencies = [
"tree-sitter-cpp",
"tree-sitter-css",
"tree-sitter-dart",
"tree-sitter-dockerfile",
"tree-sitter-elixir",
"tree-sitter-elm",
"tree-sitter-embedded-template",
@ -10207,15 +10206,6 @@ dependencies = [
"tree-sitter",
]
[[package]]
name = "tree-sitter-dockerfile"
version = "0.1.0"
source = "git+https://github.com/camdencheek/tree-sitter-dockerfile?rev=33e22c33bcdbfc33d42806ee84cfd0b1248cc392#33e22c33bcdbfc33d42806ee84cfd0b1248cc392"
dependencies = [
"cc",
"tree-sitter",
]
[[package]]
name = "tree-sitter-elixir"
version = "0.1.0"

View File

@ -291,7 +291,6 @@ tree-sitter-clojure = { git = "https://github.com/prcastro/tree-sitter-clojure",
tree-sitter-c-sharp = { git = "https://github.com/tree-sitter/tree-sitter-c-sharp", rev = "dd5e59721a5f8dae34604060833902b882023aaf" }
tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "f44509141e7e483323d2ec178f2d2e6c0fc041c1" }
tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" }
tree-sitter-dockerfile = { git = "https://github.com/camdencheek/tree-sitter-dockerfile", rev = "33e22c33bcdbfc33d42806ee84cfd0b1248cc392" }
tree-sitter-dart = { git = "https://github.com/agent3bood/tree-sitter-dart", rev = "48934e3bf757a9b78f17bdfaa3e2b4284656fdc7" }
tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "a2861e88a730287a60c11ea9299c033c7d076e30" }
tree-sitter-elm = { git = "https://github.com/elm-tooling/tree-sitter-elm", rev = "692c50c0b961364c40299e73c1306aecb5d20f40" }

View File

@ -44,7 +44,6 @@ tree-sitter-clojure.workspace = true
tree-sitter-cpp.workspace = true
tree-sitter-css.workspace = true
tree-sitter-dart.workspace = true
tree-sitter-dockerfile.workspace = true
tree-sitter-elixir.workspace = true
tree-sitter-elm.workspace = true
tree-sitter-embedded-template.workspace = true

View File

@ -1,124 +0,0 @@
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use futures::StreamExt;
use language::{LanguageServerName, LspAdapter, LspAdapterDelegate};
use lsp::LanguageServerBinary;
use node_runtime::NodeRuntime;
use smol::fs;
use std::{
any::Any,
ffi::OsString,
path::{Path, PathBuf},
sync::Arc,
};
use util::{maybe, ResultExt};
const SERVER_PATH: &str = "node_modules/dockerfile-language-server-nodejs/bin/docker-langserver";
fn server_binary_arguments(server_path: &Path) -> Vec<OsString> {
vec![server_path.into(), "--stdio".into()]
}
pub struct DockerfileLspAdapter {
node: Arc<dyn NodeRuntime>,
}
impl DockerfileLspAdapter {
pub fn new(node: Arc<dyn NodeRuntime>) -> Self {
Self { node }
}
}
#[async_trait(?Send)]
impl LspAdapter for DockerfileLspAdapter {
fn name(&self) -> LanguageServerName {
LanguageServerName("docker-langserver".into())
}
async fn fetch_latest_server_version(
&self,
_: &dyn LspAdapterDelegate,
) -> Result<Box<dyn 'static + Send + Any>> {
Ok(Box::new(
self.node
.npm_package_latest_version("dockerfile-language-server-nodejs")
.await?,
) as Box<_>)
}
async fn fetch_server_binary(
&self,
latest_version: Box<dyn 'static + Send + Any>,
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Result<LanguageServerBinary> {
let latest_version = latest_version.downcast::<String>().unwrap();
let server_path = container_dir.join(SERVER_PATH);
let package_name = "dockerfile-language-server-nodejs";
let should_install_language_server = self
.node
.should_install_npm_package(package_name, &server_path, &container_dir, &latest_version)
.await;
if should_install_language_server {
self.node
.npm_install_packages(&container_dir, &[(package_name, latest_version.as_str())])
.await?;
}
Ok(LanguageServerBinary {
path: self.node.binary_path().await?,
env: None,
arguments: server_binary_arguments(&server_path),
})
}
async fn cached_server_binary(
&self,
container_dir: PathBuf,
_: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &*self.node).await
}
async fn installation_test_binary(
&self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
get_cached_server_binary(container_dir, &*self.node).await
}
}
async fn get_cached_server_binary(
container_dir: PathBuf,
node: &dyn NodeRuntime,
) -> Option<LanguageServerBinary> {
maybe!(async {
let mut last_version_dir = None;
let mut entries = fs::read_dir(&container_dir).await?;
while let Some(entry) = entries.next().await {
let entry = entry?;
if entry.file_type().await?.is_dir() {
last_version_dir = Some(entry.path());
}
}
let last_version_dir = last_version_dir.ok_or_else(|| anyhow!("no cached binary"))?;
let server_path = last_version_dir.join(SERVER_PATH);
if server_path.exists() {
Ok(LanguageServerBinary {
path: node.binary_path().await?,
env: None,
arguments: server_binary_arguments(&server_path),
})
} else {
Err(anyhow!(
"missing executable in directory {:?}",
last_version_dir
))
}
})
.await
.log_err()
}

View File

@ -1,9 +0,0 @@
name = "Dockerfile"
grammar = "dockerfile"
path_suffixes = ["Dockerfile"]
line_comments = ["# "]
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
]

View File

@ -1,63 +0,0 @@
; Dockerfile instructions set taken from:
; https://docs.docker.com/engine/reference/builder/#overview
; https://github.com/helix-editor/helix/blob/78c34194b5c83beb26ca04f12bf9d53fd5aba801/runtime/queries/dockerfile/highlights.scm
[
"ADD"
"ARG"
"CMD"
"COPY"
"ENTRYPOINT"
"ENV"
"EXPOSE"
"FROM"
"HEALTHCHECK"
"LABEL"
"MAINTAINER"
"ONBUILD"
"RUN"
"SHELL"
"STOPSIGNAL"
"USER"
"VOLUME"
"WORKDIR"
; "as" for multi-stage builds
"AS"
] @keyword
[
":"
"@"
] @operator
(comment) @comment
(image_spec
(image_tag
":" @punctuation.special)
(image_digest
"@" @punctuation.special))
[
(double_quoted_string)
(single_quoted_string)
(json_string)
] @string
[
(env_pair)
(label_pair)
] @constant
[
(param)
(mount_param)
] @function
(expansion
[
"$"
"{"
"}"
] @punctuation.special
) @constant

View File

@ -1,6 +0,0 @@
; We need impl this
; ((comment) @injection.content
; (#set! injection.language "comment"))
((shell_command) @content
(#set! "language" "bash"))

View File

@ -18,7 +18,6 @@ mod csharp;
mod css;
mod dart;
mod deno;
mod dockerfile;
mod elixir;
mod elm;
mod erlang;
@ -70,7 +69,6 @@ pub fn init(
("clojure", tree_sitter_clojure::language()),
("cpp", tree_sitter_cpp::language()),
("css", tree_sitter_css::language()),
("dockerfile", tree_sitter_dockerfile::language()),
("elixir", tree_sitter_elixir::language()),
("elm", tree_sitter_elm::language()),
(
@ -190,13 +188,6 @@ pub fn init(
]
);
language!(
"dockerfile",
vec![Arc::new(dockerfile::DockerfileLspAdapter::new(
node_runtime.clone(),
))]
);
match &ElixirSettings::get(None, cx).lsp {
elixir::ElixirLspSetting::ElixirLs => {
language!(