1use std::sync::{Arc, LazyLock};
2
3use collections::HashMap;
4use gpui::SharedString;
5
6use crate::Appearance;
7
8/// A family of icon themes.
9pub struct IconThemeFamily {
10 /// The unique ID for the icon theme family.
11 pub id: String,
12 /// The name of the icon theme family.
13 pub name: SharedString,
14 /// The author of the icon theme family.
15 pub author: SharedString,
16 /// The list of icon themes in the family.
17 pub themes: Vec<IconTheme>,
18}
19
20/// An icon theme.
21#[derive(Debug, PartialEq)]
22pub struct IconTheme {
23 /// The unique ID for the icon theme.
24 pub id: String,
25 /// The name of the icon theme.
26 pub name: SharedString,
27 /// The appearance of the icon theme (e.g., light or dark).
28 pub appearance: Appearance,
29 /// The icons used for directories.
30 pub directory_icons: DirectoryIcons,
31 /// The icons used for named directories.
32 pub named_directory_icons: HashMap<String, DirectoryIcons>,
33 /// The icons used for chevrons.
34 pub chevron_icons: ChevronIcons,
35 /// The mapping of file stems to their associated icon keys.
36 pub file_stems: HashMap<String, String>,
37 /// The mapping of file suffixes to their associated icon keys.
38 pub file_suffixes: HashMap<String, String>,
39 /// The mapping of icon keys to icon definitions.
40 pub file_icons: HashMap<String, IconDefinition>,
41}
42
43/// The icons used for directories.
44#[derive(Debug, PartialEq, Clone)]
45pub struct DirectoryIcons {
46 /// The path to the icon to use for a collapsed directory.
47 pub collapsed: Option<SharedString>,
48 /// The path to the icon to use for an expanded directory.
49 pub expanded: Option<SharedString>,
50}
51
52/// The icons used for chevrons.
53#[derive(Debug, PartialEq)]
54pub struct ChevronIcons {
55 /// The path to the icon to use for a collapsed chevron.
56 pub collapsed: Option<SharedString>,
57 /// The path to the icon to use for an expanded chevron.
58 pub expanded: Option<SharedString>,
59}
60
61/// An icon definition.
62#[derive(Debug, PartialEq)]
63pub struct IconDefinition {
64 /// The path to the icon file.
65 pub path: SharedString,
66}
67
68const FILE_STEMS_BY_ICON_KEY: &[(&str, &[&str])] = &[
69 ("docker", &["Containerfile", "Dockerfile"]),
70 ("ruby", &["Podfile"]),
71 ("heroku", &["Procfile"]),
72];
73
74const FILE_SUFFIXES_BY_ICON_KEY: &[(&str, &[&str])] = &[
75 ("astro", &["astro"]),
76 (
77 "audio",
78 &[
79 "aac", "flac", "m4a", "mka", "mp3", "ogg", "opus", "wav", "wma", "wv",
80 ],
81 ),
82 ("backup", &["bak"]),
83 ("bicep", &["bicep"]),
84 ("bun", &["lockb"]),
85 ("c", &["c", "h"]),
86 ("cairo", &["cairo"]),
87 ("code", &["handlebars", "metadata", "rkt", "scm"]),
88 ("coffeescript", &["coffee"]),
89 (
90 "cpp",
91 &[
92 "c++", "h++", "cc", "cpp", "cppm", "cxx", "hh", "hpp", "hxx", "inl", "ixx",
93 ],
94 ),
95 ("crystal", &["cr", "ecr"]),
96 ("csharp", &["cs"]),
97 ("csproj", &["csproj"]),
98 ("css", &["css", "pcss", "postcss"]),
99 ("cue", &["cue"]),
100 ("dart", &["dart"]),
101 ("diff", &["diff"]),
102 (
103 "docker",
104 &[
105 "docker-compose.yml",
106 "docker-compose.yaml",
107 "compose.yml",
108 "compose.yaml",
109 ],
110 ),
111 (
112 "document",
113 &[
114 "doc", "docx", "mdx", "odp", "ods", "odt", "pdf", "ppt", "pptx", "rtf", "txt", "xls",
115 "xlsx",
116 ],
117 ),
118 ("elixir", &["eex", "ex", "exs", "heex"]),
119 ("elm", &["elm"]),
120 (
121 "erlang",
122 &[
123 "Emakefile",
124 "app.src",
125 "erl",
126 "escript",
127 "hrl",
128 "rebar.config",
129 "xrl",
130 "yrl",
131 ],
132 ),
133 (
134 "eslint",
135 &[
136 "eslint.config.cjs",
137 "eslint.config.cts",
138 "eslint.config.js",
139 "eslint.config.mjs",
140 "eslint.config.mts",
141 "eslint.config.ts",
142 "eslintrc",
143 "eslintrc.js",
144 "eslintrc.json",
145 ],
146 ),
147 ("font", &["otf", "ttf", "woff", "woff2"]),
148 ("fsharp", &["fs"]),
149 ("fsproj", &["fsproj"]),
150 ("gitlab", &["gitlab-ci.yml", "gitlab-ci.yaml"]),
151 ("gleam", &["gleam"]),
152 ("go", &["go", "mod", "work"]),
153 ("graphql", &["gql", "graphql", "graphqls"]),
154 ("haskell", &["hs"]),
155 ("hcl", &["hcl"]),
156 (
157 "helm",
158 &[
159 "helmfile.yaml",
160 "helmfile.yml",
161 "Chart.yaml",
162 "Chart.yml",
163 "Chart.lock",
164 "values.yaml",
165 "values.yml",
166 "requirements.yaml",
167 "requirements.yml",
168 "tpl",
169 ],
170 ),
171 ("html", &["htm", "html"]),
172 (
173 "image",
174 &[
175 "avif", "bmp", "gif", "heic", "heif", "ico", "j2k", "jfif", "jp2", "jpeg", "jpg",
176 "jxl", "png", "psd", "qoi", "svg", "tiff", "webp",
177 ],
178 ),
179 ("ipynb", &["ipynb"]),
180 ("java", &["java"]),
181 ("javascript", &["cjs", "js", "mjs"]),
182 ("json", &["json", "jsonc"]),
183 ("julia", &["jl"]),
184 ("kdl", &["kdl"]),
185 ("kotlin", &["kt"]),
186 ("lock", &["lock"]),
187 ("log", &["log"]),
188 ("lua", &["lua"]),
189 ("luau", &["luau"]),
190 ("markdown", &["markdown", "md"]),
191 ("metal", &["metal"]),
192 ("nim", &["nim", "nims", "nimble"]),
193 ("nix", &["nix"]),
194 ("ocaml", &["ml", "mli"]),
195 ("odin", &["odin"]),
196 ("php", &["php"]),
197 (
198 "prettier",
199 &[
200 "prettier.config.cjs",
201 "prettier.config.js",
202 "prettier.config.mjs",
203 "prettierignore",
204 "prettierrc",
205 "prettierrc.cjs",
206 "prettierrc.js",
207 "prettierrc.json",
208 "prettierrc.json5",
209 "prettierrc.mjs",
210 "prettierrc.toml",
211 "prettierrc.yaml",
212 "prettierrc.yml",
213 ],
214 ),
215 ("prisma", &["prisma"]),
216 ("puppet", &["pp"]),
217 ("python", &["py"]),
218 ("r", &["r", "R"]),
219 ("react", &["cjsx", "ctsx", "jsx", "mjsx", "mtsx", "tsx"]),
220 ("roc", &["roc"]),
221 ("ruby", &["rb"]),
222 ("rust", &["rs"]),
223 ("sass", &["sass", "scss"]),
224 ("scala", &["scala", "sc"]),
225 ("settings", &["conf", "ini"]),
226 ("solidity", &["sol"]),
227 (
228 "storage",
229 &[
230 "accdb", "csv", "dat", "db", "dbf", "dll", "fmp", "fp7", "frm", "gdb", "ib", "ldf",
231 "mdb", "mdf", "myd", "myi", "pdb", "RData", "rdata", "sav", "sdf", "sql", "sqlite",
232 "tsv",
233 ],
234 ),
235 (
236 "stylelint",
237 &[
238 "stylelint.config.cjs",
239 "stylelint.config.js",
240 "stylelint.config.mjs",
241 "stylelintignore",
242 "stylelintrc",
243 "stylelintrc.cjs",
244 "stylelintrc.js",
245 "stylelintrc.json",
246 "stylelintrc.mjs",
247 "stylelintrc.yaml",
248 "stylelintrc.yml",
249 ],
250 ),
251 ("surrealql", &["surql"]),
252 ("svelte", &["svelte"]),
253 ("swift", &["swift"]),
254 ("tcl", &["tcl"]),
255 ("template", &["hbs", "plist", "xml"]),
256 (
257 "terminal",
258 &[
259 "bash",
260 "bash_aliases",
261 "bash_login",
262 "bash_logout",
263 "bash_profile",
264 "bashrc",
265 "fish",
266 "nu",
267 "profile",
268 "ps1",
269 "sh",
270 "zlogin",
271 "zlogout",
272 "zprofile",
273 "zsh",
274 "zsh_aliases",
275 "zsh_histfile",
276 "zsh_history",
277 "zshenv",
278 "zshrc",
279 ],
280 ),
281 ("terraform", &["tf", "tfvars"]),
282 ("toml", &["toml"]),
283 ("typescript", &["cts", "mts", "ts"]),
284 ("v", &["v", "vsh", "vv"]),
285 (
286 "vcs",
287 &[
288 "COMMIT_EDITMSG",
289 "EDIT_DESCRIPTION",
290 "MERGE_MSG",
291 "NOTES_EDITMSG",
292 "TAG_EDITMSG",
293 "gitattributes",
294 "gitignore",
295 "gitkeep",
296 "gitmodules",
297 ],
298 ),
299 ("vbproj", &["vbproj"]),
300 ("video", &["avi", "m4v", "mkv", "mov", "mp4", "webm", "wmv"]),
301 ("vs_sln", &["sln"]),
302 ("vs_suo", &["suo"]),
303 ("vue", &["vue"]),
304 ("vyper", &["vy", "vyi"]),
305 ("wgsl", &["wgsl"]),
306 ("yaml", &["yaml", "yml"]),
307 ("zig", &["zig"]),
308];
309
310/// A mapping of a file type identifier to its corresponding icon.
311const FILE_ICONS: &[(&str, &str)] = &[
312 ("astro", "icons/file_icons/astro.svg"),
313 ("audio", "icons/file_icons/audio.svg"),
314 ("bicep", "icons/file_icons/file.svg"),
315 ("bun", "icons/file_icons/bun.svg"),
316 ("c", "icons/file_icons/c.svg"),
317 ("cairo", "icons/file_icons/cairo.svg"),
318 ("code", "icons/file_icons/code.svg"),
319 ("coffeescript", "icons/file_icons/coffeescript.svg"),
320 ("cpp", "icons/file_icons/cpp.svg"),
321 ("crystal", "icons/file_icons/file.svg"),
322 ("csharp", "icons/file_icons/file.svg"),
323 ("csproj", "icons/file_icons/file.svg"),
324 ("css", "icons/file_icons/css.svg"),
325 ("cue", "icons/file_icons/file.svg"),
326 ("dart", "icons/file_icons/dart.svg"),
327 ("default", "icons/file_icons/file.svg"),
328 ("diff", "icons/file_icons/diff.svg"),
329 ("docker", "icons/file_icons/docker.svg"),
330 ("document", "icons/file_icons/book.svg"),
331 ("elixir", "icons/file_icons/elixir.svg"),
332 ("elm", "icons/file_icons/elm.svg"),
333 ("erlang", "icons/file_icons/erlang.svg"),
334 ("eslint", "icons/file_icons/eslint.svg"),
335 ("font", "icons/file_icons/font.svg"),
336 ("fsharp", "icons/file_icons/fsharp.svg"),
337 ("fsproj", "icons/file_icons/file.svg"),
338 ("gitlab", "icons/file_icons/gitlab.svg"),
339 ("gleam", "icons/file_icons/gleam.svg"),
340 ("go", "icons/file_icons/go.svg"),
341 ("graphql", "icons/file_icons/graphql.svg"),
342 ("haskell", "icons/file_icons/haskell.svg"),
343 ("hcl", "icons/file_icons/hcl.svg"),
344 ("helm", "icons/file_icons/helm.svg"),
345 ("heroku", "icons/file_icons/heroku.svg"),
346 ("html", "icons/file_icons/html.svg"),
347 ("image", "icons/file_icons/image.svg"),
348 ("ipynb", "icons/file_icons/jupyter.svg"),
349 ("java", "icons/file_icons/java.svg"),
350 ("javascript", "icons/file_icons/javascript.svg"),
351 ("json", "icons/file_icons/code.svg"),
352 ("julia", "icons/file_icons/julia.svg"),
353 ("kdl", "icons/file_icons/kdl.svg"),
354 ("kotlin", "icons/file_icons/kotlin.svg"),
355 ("lock", "icons/file_icons/lock.svg"),
356 ("log", "icons/file_icons/info.svg"),
357 ("lua", "icons/file_icons/lua.svg"),
358 ("luau", "icons/file_icons/luau.svg"),
359 ("markdown", "icons/file_icons/book.svg"),
360 ("metal", "icons/file_icons/metal.svg"),
361 ("nim", "icons/file_icons/nim.svg"),
362 ("nix", "icons/file_icons/nix.svg"),
363 ("ocaml", "icons/file_icons/ocaml.svg"),
364 ("odin", "icons/file_icons/odin.svg"),
365 ("phoenix", "icons/file_icons/phoenix.svg"),
366 ("php", "icons/file_icons/php.svg"),
367 ("prettier", "icons/file_icons/prettier.svg"),
368 ("prisma", "icons/file_icons/prisma.svg"),
369 ("puppet", "icons/file_icons/puppet.svg"),
370 ("python", "icons/file_icons/python.svg"),
371 ("r", "icons/file_icons/r.svg"),
372 ("react", "icons/file_icons/react.svg"),
373 ("roc", "icons/file_icons/roc.svg"),
374 ("ruby", "icons/file_icons/ruby.svg"),
375 ("rust", "icons/file_icons/rust.svg"),
376 ("sass", "icons/file_icons/sass.svg"),
377 ("scala", "icons/file_icons/scala.svg"),
378 ("settings", "icons/file_icons/settings.svg"),
379 ("solidity", "icons/file_icons/file.svg"),
380 ("storage", "icons/file_icons/database.svg"),
381 ("stylelint", "icons/file_icons/javascript.svg"),
382 ("surrealql", "icons/file_icons/surrealql.svg"),
383 ("svelte", "icons/file_icons/html.svg"),
384 ("swift", "icons/file_icons/swift.svg"),
385 ("tcl", "icons/file_icons/tcl.svg"),
386 ("template", "icons/file_icons/html.svg"),
387 ("terminal", "icons/file_icons/terminal.svg"),
388 ("terraform", "icons/file_icons/terraform.svg"),
389 ("toml", "icons/file_icons/toml.svg"),
390 ("typescript", "icons/file_icons/typescript.svg"),
391 ("v", "icons/file_icons/v.svg"),
392 ("vbproj", "icons/file_icons/file.svg"),
393 ("vcs", "icons/file_icons/git.svg"),
394 ("video", "icons/file_icons/video.svg"),
395 ("vs_sln", "icons/file_icons/file.svg"),
396 ("vs_suo", "icons/file_icons/file.svg"),
397 ("vue", "icons/file_icons/vue.svg"),
398 ("vyper", "icons/file_icons/vyper.svg"),
399 ("wgsl", "icons/file_icons/wgsl.svg"),
400 ("yaml", "icons/file_icons/yaml.svg"),
401 ("zig", "icons/file_icons/zig.svg"),
402];
403
404/// Returns a mapping of file associations to icon keys.
405fn icon_keys_by_association(
406 associations_by_icon_key: &[(&str, &[&str])],
407) -> HashMap<String, String> {
408 let mut icon_keys_by_association = HashMap::default();
409 for (icon_key, associations) in associations_by_icon_key {
410 for association in *associations {
411 icon_keys_by_association.insert(association.to_string(), icon_key.to_string());
412 }
413 }
414
415 icon_keys_by_association
416}
417
418/// The name of the default icon theme.
419pub(crate) const DEFAULT_ICON_THEME_NAME: &str = "Zed (Default)";
420
421static DEFAULT_ICON_THEME: LazyLock<Arc<IconTheme>> = LazyLock::new(|| {
422 Arc::new(IconTheme {
423 id: "zed".into(),
424 name: DEFAULT_ICON_THEME_NAME.into(),
425 appearance: Appearance::Dark,
426 directory_icons: DirectoryIcons {
427 collapsed: Some("icons/file_icons/folder.svg".into()),
428 expanded: Some("icons/file_icons/folder_open.svg".into()),
429 },
430 named_directory_icons: HashMap::default(),
431 chevron_icons: ChevronIcons {
432 collapsed: Some("icons/file_icons/chevron_right.svg".into()),
433 expanded: Some("icons/file_icons/chevron_down.svg".into()),
434 },
435 file_stems: icon_keys_by_association(FILE_STEMS_BY_ICON_KEY),
436 file_suffixes: icon_keys_by_association(FILE_SUFFIXES_BY_ICON_KEY),
437 file_icons: HashMap::from_iter(FILE_ICONS.iter().map(|(ty, path)| {
438 (
439 ty.to_string(),
440 IconDefinition {
441 path: (*path).into(),
442 },
443 )
444 })),
445 })
446});
447
448/// Returns the default icon theme.
449pub fn default_icon_theme() -> Arc<IconTheme> {
450 DEFAULT_ICON_THEME.clone()
451}