mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
extensions_ui: Sync suggested extensions with the live registry (#63211)
# Objective The suggested-extension prompt only fires for a hand-picked list of file types. Many rows had drifted from what their extensions actually register today (`toml` didn't know `uv.lock`, `dockerfile` ignored Compose files, …), entries were no longer sorted by ID, and the table had no tests locking its invariants. ## Solution - Synced every existing row against its extension's current `path_suffixes`. - Added 15 popular languages: asciidoc, csv, env, gdscript, groovy, ini, json5, julia, just, nginx, odin, perl, python-requirements, scala, solidity. - Re-sorted by ID. - Excluded despite appearing in manifests: erb compounds and elixir `html.eex` (dead keys under exact-match), haskell `x`, asciidoc `asc` (PGP clash), env/ini generic words (`conf`, `local`, systemd units…), gdscript `import`, ruby `Berksfile.lock` (JSON). `gradle`/`gradle.kts` stay with the groovy/kotlin rows. - Behavior change: git-firefly is no longer suggested for `COMMIT_EDITMSG` etc., mirroring upstream's own manifest — only `COMMIT_EDITMSG` has built-in core coverage. ## Testing - New tests lock suffix uniqueness across the table, ID sortedness, and representative lookups for every row — including dotfiles (`.envrc`, `.gitattributes`) and name-over-extension priority (`uv.lock`, `compose.yaml`, `nginx.conf`). - All 69 extension IDs were verified against [zed-industries/extensions](https://github.com/zed-industries/extensions); every kept suffix appears in that extension's live language config. - Best exercised by checking out this branch, uninstalling e.g. the `csv` extension, and opening a `.csv` file. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable <details> <summary>Showcase</summary> Before: opening `hello.sol` shows nothing — Zed silently moves on. After: *"Do you want to install the recommended 'solidity' extension for 'sol' files?"* </details> --- Release Notes: - Added extension installation suggestions for many more languages when opening unsupported files --------- Co-authored-by: MrSubidubi <finn@zed.dev>
This commit is contained in:
+1
-1
@@ -11,8 +11,8 @@ extend-exclude = [
|
||||
".mailmap",
|
||||
|
||||
# File suffixes aren't typos.
|
||||
"crates/extension_suggest/src/extension_suggest.rs",
|
||||
"crates/theme/src/icon_theme.rs",
|
||||
"crates/extensions_ui/src/extension_suggest.rs",
|
||||
|
||||
# Some mock data is flagged as typos.
|
||||
"crates/assistant_tools/src/web_search_tool.rs",
|
||||
|
||||
Generated
+8
@@ -6241,6 +6241,13 @@ dependencies = [
|
||||
"ztracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "extension_suggest"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"path",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "extensions_ui"
|
||||
version = "0.1.0"
|
||||
@@ -6254,6 +6261,7 @@ dependencies = [
|
||||
"editor",
|
||||
"extension",
|
||||
"extension_host",
|
||||
"extension_suggest",
|
||||
"fs",
|
||||
"fuzzy",
|
||||
"git",
|
||||
|
||||
@@ -73,6 +73,7 @@ members = [
|
||||
"crates/extension_api",
|
||||
"crates/extension_cli",
|
||||
"crates/extension_host",
|
||||
"crates/extension_suggest",
|
||||
"crates/extensions_ui",
|
||||
"crates/feature_flags",
|
||||
"crates/feature_flags_macros",
|
||||
@@ -342,6 +343,7 @@ etw_tracing = { path = "crates/etw_tracing" }
|
||||
eval_utils = { path = "crates/eval_utils" }
|
||||
extension = { path = "crates/extension" }
|
||||
extension_host = { path = "crates/extension_host" }
|
||||
extension_suggest = { path = "crates/extension_suggest" }
|
||||
extensions_ui = { path = "crates/extensions_ui" }
|
||||
feature_flags = { path = "crates/feature_flags" }
|
||||
feature_flags_macros = { path = "crates/feature_flags_macros" }
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "extension_suggest"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
publish.workspace = true
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/extension_suggest.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
path.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
path = { workspace = true, features = ["test-support"] }
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../LICENSE-GPL
|
||||
@@ -0,0 +1,435 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, OnceLock},
|
||||
};
|
||||
|
||||
use path::rel_path::RelPath;
|
||||
|
||||
const SUGGESTIONS_BY_EXTENSION_ID: &[(&str, &[&str])] = &[
|
||||
("asciidoc", &["adoc", "asciidoc"]),
|
||||
("astro", &["astro"]),
|
||||
("beancount", &["bean", "beancount"]),
|
||||
("clojure", &["bb", "clj", "cljc", "cljd", "cljs", "edn"]),
|
||||
(
|
||||
"csharp",
|
||||
&["cs", "csproj", "proj", "props", "slnx", "targets"],
|
||||
),
|
||||
("csv", &["csv"]),
|
||||
("cython", &["pyx", "pxd", "pxi"]),
|
||||
("dart", &["dart"]),
|
||||
(
|
||||
"dockerfile",
|
||||
&[
|
||||
"Containerfile",
|
||||
"Dockerfile",
|
||||
"compose.yaml",
|
||||
"compose.yml",
|
||||
"docker-compose.yaml",
|
||||
"docker-compose.yml",
|
||||
"dockerfile",
|
||||
],
|
||||
),
|
||||
("elisp", &["el"]),
|
||||
(
|
||||
"elixir",
|
||||
&["eex", "ex", "exs", "heex", "leex", "mix.lock", "neex"],
|
||||
),
|
||||
("elm", &["elm"]),
|
||||
("env", &[".env", ".envrc", "env", "envrc"]),
|
||||
(
|
||||
"erlang",
|
||||
&[
|
||||
"app.src",
|
||||
"Emakefile",
|
||||
"erl",
|
||||
"erlang",
|
||||
"escript",
|
||||
"hrl",
|
||||
"rebar.config",
|
||||
"xrl",
|
||||
"yrl",
|
||||
],
|
||||
),
|
||||
("fish", &["fish"]),
|
||||
(
|
||||
"gdscript",
|
||||
&[
|
||||
"gd",
|
||||
"gdextension",
|
||||
"gdshader",
|
||||
"gdshaderinc",
|
||||
"godot",
|
||||
"tres",
|
||||
"tscn",
|
||||
],
|
||||
),
|
||||
(
|
||||
"git-firefly",
|
||||
&[
|
||||
".containerignore",
|
||||
".cursorignore",
|
||||
".dockerignore",
|
||||
".eslintignore",
|
||||
".fdignore",
|
||||
".git-blame-ignore-revs",
|
||||
".gitattributes",
|
||||
".gitconfig",
|
||||
".gitignore",
|
||||
".gitignore_global",
|
||||
".gitmodules",
|
||||
".ignore",
|
||||
".lfsconfig",
|
||||
".npmignore",
|
||||
".prettierignore",
|
||||
".rgignore",
|
||||
".vscodeignore",
|
||||
"config.worktree",
|
||||
"git-rebase-todo",
|
||||
"gitattributes",
|
||||
],
|
||||
),
|
||||
("gleam", &["gleam"]),
|
||||
(
|
||||
"glsl",
|
||||
&[
|
||||
"comp", "frag", "geom", "glsl", "mesh", "rcall", "rgen", "rahit", "rchit", "rmiss",
|
||||
"rint", "task", "tesc", "tese", "vert",
|
||||
],
|
||||
),
|
||||
("graphql", &["gql", "graphql", "graphqls"]),
|
||||
(
|
||||
"groovy",
|
||||
&["Jenkinsfile", "JenkinsFile", "gradle", "groovy"],
|
||||
),
|
||||
("haskell", &["cabal", "hs", "lhs"]),
|
||||
("html", &["htm", "html", "shtml"]),
|
||||
("ini", &["inf", "ini"]),
|
||||
("java", &["java", "properties"]),
|
||||
("json5", &["json5"]),
|
||||
("julia", &["jl"]),
|
||||
("just", &["JUSTFILE", "Justfile", "just", "justfile"]),
|
||||
("kotlin", &["kt", "kts"]),
|
||||
(
|
||||
"latex",
|
||||
&[
|
||||
"bib", "biblatex", "bibtex", "cls", "dtx", "ins", "latex", "sty", "tex",
|
||||
],
|
||||
),
|
||||
("log", &["log"]),
|
||||
("lua", &["lua"]),
|
||||
(
|
||||
"make",
|
||||
&[
|
||||
"GNUmakefile",
|
||||
"mak",
|
||||
"Makefile",
|
||||
"makefile",
|
||||
"mk",
|
||||
"OCamlMakefile",
|
||||
],
|
||||
),
|
||||
("neocmake", &["CMakeLists.txt", "cmake"]),
|
||||
("nginx", &["nginx.conf"]),
|
||||
("nim", &["nim", "nim_format_string", "nimble", "nims"]),
|
||||
("nix", &["nix"]),
|
||||
("nu", &["nu", "nuon"]),
|
||||
(
|
||||
"ocaml",
|
||||
&[
|
||||
"dune",
|
||||
"dune-project",
|
||||
"dune-workspace",
|
||||
"ml",
|
||||
"mld",
|
||||
"mli",
|
||||
"mll",
|
||||
"mlx",
|
||||
"mly",
|
||||
"re",
|
||||
"rei",
|
||||
],
|
||||
),
|
||||
("odin", &["odin"]),
|
||||
("perl", &["pl", "pm", "pod", "t"]),
|
||||
("php", &["php", "phpt", "phtml"]),
|
||||
("powershell", &["ps1", "psm1"]),
|
||||
("prisma", &["prisma"]),
|
||||
("proto", &["proto"]),
|
||||
("purescript", &["purs"]),
|
||||
(
|
||||
"python-requirements",
|
||||
&["constraints.txt", "requirements.txt"],
|
||||
),
|
||||
("r", &["R", "Rmd", "qmd", "r", "rmd"]),
|
||||
("racket", &["rkt"]),
|
||||
("rescript", &["res", "resi"]),
|
||||
("rst", &["rst"]),
|
||||
(
|
||||
"ruby",
|
||||
&[
|
||||
"Appfile",
|
||||
"Appraisals",
|
||||
"Berksfile",
|
||||
"Brewfile",
|
||||
"builder",
|
||||
"cap",
|
||||
"Capfile",
|
||||
"capfile",
|
||||
"Cheffile",
|
||||
"Dangerfile",
|
||||
"Deliverfile",
|
||||
"erb",
|
||||
"Fastfile",
|
||||
"Gemfile",
|
||||
"gemspec",
|
||||
"Guardfile",
|
||||
"Gymfile",
|
||||
"Hobofile",
|
||||
"irbrc",
|
||||
"jbuilder",
|
||||
"Matchfile",
|
||||
"Podfile",
|
||||
"pryrc",
|
||||
"Puppetfile",
|
||||
"rabl",
|
||||
"rake",
|
||||
"Rakefile",
|
||||
"Rantfile",
|
||||
"rb",
|
||||
"rbs",
|
||||
"ru",
|
||||
"rxml",
|
||||
"Scanfile",
|
||||
"simplecov",
|
||||
"Snapfile",
|
||||
"Steepfile",
|
||||
"thor",
|
||||
"Thorfile",
|
||||
"Vagrantfile",
|
||||
],
|
||||
),
|
||||
("scala", &["mill", "scala", "sbt", "sc"]),
|
||||
("scheme", &["scm", "ss"]),
|
||||
("scss", &["sass", "scss"]),
|
||||
("solidity", &["sol", "yul"]),
|
||||
("sql", &["sql"]),
|
||||
("svelte", &["svelte"]),
|
||||
("swift", &["swift", "swiftinterface"]),
|
||||
("templ", &["templ"]),
|
||||
("terraform", &["hcl", "tf", "tfvars", "tofu"]),
|
||||
("toml", &["Cargo.lock", "Pipfile", "toml", "uv.lock"]),
|
||||
("typst", &["typ", "typst"]),
|
||||
("vue", &["vue"]),
|
||||
("wgsl", &["wgsl"]),
|
||||
("windows-batch", &["bat", "cmd"]),
|
||||
("wit", &["wit"]),
|
||||
("xml", &["xml"]),
|
||||
("zig", &["zig", "zon"]),
|
||||
];
|
||||
|
||||
pub struct LanguageAdditionSuggestion {
|
||||
pub extension_id: &'static str,
|
||||
pub languages: &'static [&'static str],
|
||||
pub title: &'static str,
|
||||
pub description: &'static str,
|
||||
pub docs_url: &'static str,
|
||||
pub install_message: &'static str,
|
||||
}
|
||||
|
||||
const SUGGESTIONS_BY_LANGUAGE: &[LanguageAdditionSuggestion] = &[LanguageAdditionSuggestion {
|
||||
extension_id: "emmet",
|
||||
languages: &[
|
||||
"Angular",
|
||||
"Blade",
|
||||
"CSS",
|
||||
"Django",
|
||||
"ERB",
|
||||
"Elixir",
|
||||
"HEEx",
|
||||
"HTML",
|
||||
"HTML+ERB",
|
||||
"JavaScript",
|
||||
"Jinja2",
|
||||
"LESS",
|
||||
"Liquid",
|
||||
"Nunjucks",
|
||||
"PHP",
|
||||
"SCSS",
|
||||
"Statamic Antlers",
|
||||
"TSX",
|
||||
"Twig",
|
||||
"Vue.js",
|
||||
],
|
||||
title: "Emmet is available for this file",
|
||||
description: "Emmet expands abbreviations such as `ul>li*3` into HTML and `m10` into CSS.",
|
||||
docs_url: "https://zed.dev/docs/languages/emmet",
|
||||
install_message: "Install Emmet",
|
||||
}];
|
||||
|
||||
fn suggested_extensions() -> &'static HashMap<&'static str, Arc<str>> {
|
||||
static SUGGESTIONS_BY_PATH_SUFFIX: OnceLock<HashMap<&str, Arc<str>>> = OnceLock::new();
|
||||
SUGGESTIONS_BY_PATH_SUFFIX.get_or_init(|| {
|
||||
SUGGESTIONS_BY_EXTENSION_ID
|
||||
.iter()
|
||||
.flat_map(|(name, path_suffixes)| {
|
||||
let name = Arc::<str>::from(*name);
|
||||
path_suffixes
|
||||
.iter()
|
||||
.map(move |suffix| (*suffix, name.clone()))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct SuggestedExtension {
|
||||
pub extension_id: Arc<str>,
|
||||
pub file_name_or_extension: Arc<str>,
|
||||
}
|
||||
|
||||
/// Returns the suggested extension for the given [`Path`].
|
||||
pub fn suggest_extension(path: &RelPath) -> Option<SuggestedExtension> {
|
||||
let (file_name_or_extension, extension_id) = path
|
||||
.file_name()
|
||||
.and_then(|file_name| {
|
||||
// We suggest against file names first, as these suggestions will be more
|
||||
// specific than ones based on the file extension.
|
||||
suggested_extensions()
|
||||
.get(file_name)
|
||||
.map(|suggestion| (Arc::from(file_name), suggestion))
|
||||
})
|
||||
.or_else(|| {
|
||||
path.extension().and_then(|file_extension| {
|
||||
suggested_extensions()
|
||||
.get(file_extension)
|
||||
.map(|suggestion| (Arc::from(file_extension), suggestion))
|
||||
})
|
||||
})?;
|
||||
|
||||
Some(SuggestedExtension {
|
||||
extension_id: extension_id.clone(),
|
||||
file_name_or_extension,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn additional_suggestion_for_language(
|
||||
language_name: &str,
|
||||
) -> Option<&LanguageAdditionSuggestion> {
|
||||
SUGGESTIONS_BY_LANGUAGE
|
||||
.iter()
|
||||
.find(|suggestion| suggestion.languages.contains(&language_name))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use path::rel_path::rel_path;
|
||||
|
||||
#[test]
|
||||
pub fn test_suggested_extension() {
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("Cargo.toml")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "toml".into(),
|
||||
file_name_or_extension: "toml".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("Cargo.lock")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "toml".into(),
|
||||
file_name_or_extension: "Cargo.lock".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("Dockerfile")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "dockerfile".into(),
|
||||
file_name_or_extension: "Dockerfile".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("a/b/c/d/.gitignore")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "git-firefly".into(),
|
||||
file_name_or_extension: ".gitignore".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("a/b/c/d/test.gleam")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "gleam".into(),
|
||||
file_name_or_extension: "gleam".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("a/b/c/d/test.sol")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "solidity".into(),
|
||||
file_name_or_extension: "sol".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("a/b/c/d/test.jl")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "julia".into(),
|
||||
file_name_or_extension: "jl".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("script.pl")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "perl".into(),
|
||||
file_name_or_extension: "pl".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path("app/uv.lock")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "toml".into(),
|
||||
file_name_or_extension: "uv.lock".into()
|
||||
})
|
||||
);
|
||||
// Dotfiles have no `Path::extension`, so they match by name.
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path(".envrc")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "env".into(),
|
||||
file_name_or_extension: ".envrc".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggest_extension(rel_path(".gitattributes")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "git-firefly".into(),
|
||||
file_name_or_extension: ".gitattributes".into()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn suggested_path_suffixes_are_unique() {
|
||||
let mut claims: HashMap<&str, &str> = HashMap::new();
|
||||
for (extension_id, path_suffixes) in SUGGESTIONS_BY_EXTENSION_ID {
|
||||
for suffix in *path_suffixes {
|
||||
let previous = claims.insert(suffix, extension_id);
|
||||
assert!(
|
||||
previous.is_none(),
|
||||
"duplicate suffix `{suffix}` is claimed by both `{}` and `{extension_id}`",
|
||||
previous.unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn table_is_sorted_by_extension_id() {
|
||||
assert!(
|
||||
SUGGESTIONS_BY_EXTENSION_ID
|
||||
.iter()
|
||||
.map(|(extension_id, _)| *extension_id)
|
||||
.is_sorted(),
|
||||
"suggested extensions must be sorted by id"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ db.workspace = true
|
||||
editor.workspace = true
|
||||
extension.workspace = true
|
||||
extension_host.workspace = true
|
||||
extension_suggest.workspace = true
|
||||
fs.workspace = true
|
||||
fuzzy.workspace = true
|
||||
git.workspace = true
|
||||
|
||||
+5
-204
@@ -1,9 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
use std::sync::Arc;
|
||||
|
||||
use db::kvp::KeyValueStore;
|
||||
use editor::Editor;
|
||||
use extension_host::{ExtensionSettings, ExtensionStore};
|
||||
use extension_suggest::SuggestedExtension;
|
||||
use gpui::{App, AppContext as _, Context, Entity, SharedString};
|
||||
use language::{Buffer, PLAIN_TEXT};
|
||||
use markdown::{Markdown, MarkdownElement};
|
||||
@@ -11,120 +11,11 @@ use project::lsp_store::LspStoreEvent;
|
||||
use settings::Settings as _;
|
||||
use ui::prelude::*;
|
||||
use util::ResultExt;
|
||||
use util::rel_path::RelPath;
|
||||
use workspace::notifications::{
|
||||
NotificationId, markdown_style, simple_message_notification::MessageNotification,
|
||||
};
|
||||
use workspace::{AppState, Event as WorkspaceEvent, Workspace};
|
||||
|
||||
const SUGGESTIONS_BY_EXTENSION_ID: &[(&str, &[&str])] = &[
|
||||
("astro", &["astro"]),
|
||||
("beancount", &["beancount"]),
|
||||
("clojure", &["bb", "clj", "cljc", "cljs", "edn"]),
|
||||
("neocmake", &["CMakeLists.txt", "cmake"]),
|
||||
("csharp", &["cs"]),
|
||||
("cython", &["pyx", "pxd", "pxi"]),
|
||||
("dart", &["dart"]),
|
||||
("dockerfile", &["Dockerfile"]),
|
||||
("elisp", &["el"]),
|
||||
("elixir", &["eex", "ex", "exs", "heex", "leex", "neex"]),
|
||||
("elm", &["elm"]),
|
||||
("erlang", &["erl", "hrl"]),
|
||||
("fish", &["fish"]),
|
||||
(
|
||||
"git-firefly",
|
||||
&[
|
||||
".gitconfig",
|
||||
".gitignore",
|
||||
"COMMIT_EDITMSG",
|
||||
"EDIT_DESCRIPTION",
|
||||
"MERGE_MSG",
|
||||
"NOTES_EDITMSG",
|
||||
"TAG_EDITMSG",
|
||||
"git-rebase-todo",
|
||||
],
|
||||
),
|
||||
("gleam", &["gleam"]),
|
||||
("glsl", &["vert", "frag"]),
|
||||
("graphql", &["gql", "graphql"]),
|
||||
("haskell", &["hs"]),
|
||||
("html", &["htm", "html", "shtml"]),
|
||||
("java", &["java"]),
|
||||
("kotlin", &["kt"]),
|
||||
("latex", &["tex"]),
|
||||
("log", &["log"]),
|
||||
("lua", &["lua"]),
|
||||
("make", &["Makefile"]),
|
||||
("nim", &["nim"]),
|
||||
("nix", &["nix"]),
|
||||
("nu", &["nu"]),
|
||||
("ocaml", &["ml", "mli"]),
|
||||
("php", &["php"]),
|
||||
("powershell", &["ps1", "psm1"]),
|
||||
("prisma", &["prisma"]),
|
||||
("proto", &["proto"]),
|
||||
("purescript", &["purs"]),
|
||||
("r", &["r", "R"]),
|
||||
("racket", &["rkt"]),
|
||||
("rescript", &["res", "resi"]),
|
||||
("rst", &["rst"]),
|
||||
("ruby", &["rb", "erb"]),
|
||||
("scheme", &["scm"]),
|
||||
("scss", &["scss"]),
|
||||
("sql", &["sql"]),
|
||||
("svelte", &["svelte"]),
|
||||
("swift", &["swift"]),
|
||||
("templ", &["templ"]),
|
||||
("terraform", &["tf", "tfvars", "hcl"]),
|
||||
("toml", &["Cargo.lock", "toml"]),
|
||||
("typst", &["typ"]),
|
||||
("vue", &["vue"]),
|
||||
("wgsl", &["wgsl"]),
|
||||
("windows-batch", &["bat", "cmd"]),
|
||||
("wit", &["wit"]),
|
||||
("xml", &["xml"]),
|
||||
("zig", &["zig"]),
|
||||
];
|
||||
|
||||
struct LanguageSuggestion {
|
||||
extension_id: &'static str,
|
||||
languages: &'static [&'static str],
|
||||
title: &'static str,
|
||||
description: &'static str,
|
||||
docs_url: &'static str,
|
||||
install_message: &'static str,
|
||||
}
|
||||
|
||||
const SUGGESTIONS_BY_LANGUAGE: &[LanguageSuggestion] = &[LanguageSuggestion {
|
||||
extension_id: "emmet",
|
||||
languages: &[
|
||||
"Angular",
|
||||
"Blade",
|
||||
"CSS",
|
||||
"Django",
|
||||
"ERB",
|
||||
"Elixir",
|
||||
"HEEx",
|
||||
"HTML",
|
||||
"HTML+ERB",
|
||||
"JavaScript",
|
||||
"Jinja2",
|
||||
"LESS",
|
||||
"Liquid",
|
||||
"Nunjucks",
|
||||
"PHP",
|
||||
"SCSS",
|
||||
"Statamic Antlers",
|
||||
"TSX",
|
||||
"Twig",
|
||||
"Vue.js",
|
||||
],
|
||||
title: "Emmet is available for this file",
|
||||
description: "Emmet expands abbreviations such as `ul>li*3` into HTML and `m10` into CSS.",
|
||||
docs_url: "https://zed.dev/docs/languages/emmet",
|
||||
install_message: "Install Emmet",
|
||||
}];
|
||||
|
||||
struct ExtensionSuggestionNotification;
|
||||
|
||||
pub(crate) fn init(cx: &mut App) {
|
||||
@@ -169,56 +60,6 @@ pub(crate) fn init(cx: &mut App) {
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn suggested_extensions() -> &'static HashMap<&'static str, Arc<str>> {
|
||||
static SUGGESTIONS_BY_PATH_SUFFIX: OnceLock<HashMap<&str, Arc<str>>> = OnceLock::new();
|
||||
SUGGESTIONS_BY_PATH_SUFFIX.get_or_init(|| {
|
||||
SUGGESTIONS_BY_EXTENSION_ID
|
||||
.iter()
|
||||
.flat_map(|(name, path_suffixes)| {
|
||||
let name = Arc::<str>::from(*name);
|
||||
path_suffixes
|
||||
.iter()
|
||||
.map(move |suffix| (*suffix, name.clone()))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
struct SuggestedExtension {
|
||||
pub extension_id: Arc<str>,
|
||||
pub file_name_or_extension: Arc<str>,
|
||||
}
|
||||
|
||||
/// Returns the suggested extension for the given [`Path`].
|
||||
fn suggested_extension(path: &RelPath) -> Option<SuggestedExtension> {
|
||||
let file_extension: Option<Arc<str>> = path.extension().map(|extension| extension.into());
|
||||
let file_name: Option<Arc<str>> = path.file_name().map(|name| name.into());
|
||||
|
||||
let (file_name_or_extension, extension_id) = None
|
||||
// We suggest against file names first, as these suggestions will be more
|
||||
// specific than ones based on the file extension.
|
||||
.or_else(|| {
|
||||
file_name.clone().zip(
|
||||
file_name
|
||||
.as_deref()
|
||||
.and_then(|file_name| suggested_extensions().get(file_name)),
|
||||
)
|
||||
})
|
||||
.or_else(|| {
|
||||
file_extension.clone().zip(
|
||||
file_extension
|
||||
.as_deref()
|
||||
.and_then(|file_extension| suggested_extensions().get(file_extension)),
|
||||
)
|
||||
})?;
|
||||
|
||||
Some(SuggestedExtension {
|
||||
extension_id: extension_id.clone(),
|
||||
file_name_or_extension,
|
||||
})
|
||||
}
|
||||
|
||||
fn language_extension_key(extension_id: &str) -> String {
|
||||
format!("{extension_id}_extension_suggest")
|
||||
}
|
||||
@@ -277,9 +118,8 @@ fn suggest_for_buffer(
|
||||
|
||||
match language_name {
|
||||
Some(language_name) => {
|
||||
let Some(suggestion) = SUGGESTIONS_BY_LANGUAGE
|
||||
.iter()
|
||||
.find(|suggestion| suggestion.languages.contains(&language_name.as_ref()))
|
||||
let Some(suggestion) =
|
||||
extension_suggest::additional_suggestion_for_language(language_name.as_ref())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
@@ -317,7 +157,7 @@ fn suggest_for_buffer(
|
||||
let Some(SuggestedExtension {
|
||||
extension_id,
|
||||
file_name_or_extension,
|
||||
}) = suggested_extension(file.path())
|
||||
}) = extension_suggest::suggest_extension(file.path())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
@@ -413,45 +253,6 @@ mod tests {
|
||||
|
||||
const EMMET_EXTENSION_ID: &str = "emmet";
|
||||
|
||||
#[test]
|
||||
pub fn test_suggested_extension() {
|
||||
assert_eq!(
|
||||
suggested_extension(rel_path("Cargo.toml")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "toml".into(),
|
||||
file_name_or_extension: "toml".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggested_extension(rel_path("Cargo.lock")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "toml".into(),
|
||||
file_name_or_extension: "Cargo.lock".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggested_extension(rel_path("Dockerfile")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "dockerfile".into(),
|
||||
file_name_or_extension: "Dockerfile".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggested_extension(rel_path("a/b/c/d/.gitignore")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "git-firefly".into(),
|
||||
file_name_or_extension: ".gitignore".into()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
suggested_extension(rel_path("a/b/c/d/test.gleam")),
|
||||
Some(SuggestedExtension {
|
||||
extension_id: "gleam".into(),
|
||||
file_name_or_extension: "gleam".into()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_language_suggestion_for_supported_language(cx: &mut TestAppContext) {
|
||||
let app_state = init_test(cx);
|
||||
@@ -1,5 +1,5 @@
|
||||
mod components;
|
||||
mod extension_suggest;
|
||||
mod extension_suggestions;
|
||||
mod extension_version_selector;
|
||||
|
||||
use std::sync::OnceLock;
|
||||
@@ -109,7 +109,7 @@ pub fn init(cx: &mut App) {
|
||||
update_rebuild_dev_extension_visibility(&store, cx);
|
||||
})
|
||||
.detach();
|
||||
extension_suggest::init(cx);
|
||||
extension_suggestions::init(cx);
|
||||
|
||||
cx.observe_new(move |workspace: &mut Workspace, window, _cx| {
|
||||
if window.is_none() {
|
||||
|
||||
Reference in New Issue
Block a user