Add language icons to the language selector (#21298)
Closes https://github.com/zed-industries/zed/issues/21290 This is a first attempt to show the language icons to the selector. Ideally, I wouldn't like to have yet another place mapping extensions to icons, as we already have the `file_types.json` file doing that, but I'm not so sure how to pull from it yet. Maybe in a future pass we'll improve this and make it more solid. <img width="700" alt="Screenshot 2024-11-28 at 16 10 27" src="https://github.com/user-attachments/assets/683c3bef-5389-470f-a41e-3d510b927b61"> Release Notes: - N/A --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev> Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
parent
995b40f149
commit
f795ce9623
16 changed files with 119 additions and 18 deletions
|
@ -129,6 +129,10 @@ pub static PLAIN_TEXT: LazyLock<Arc<Language>> = LazyLock::new(|| {
|
|||
LanguageConfig {
|
||||
name: "Plain Text".into(),
|
||||
soft_wrap: Some(SoftWrap::EditorWidth),
|
||||
matcher: LanguageMatcher {
|
||||
path_suffixes: vec!["txt".to_owned()],
|
||||
first_line_pattern: None,
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
None,
|
||||
|
@ -1418,6 +1422,10 @@ impl Language {
|
|||
pub fn prettier_parser_name(&self) -> Option<&str> {
|
||||
self.config.prettier_parser_name.as_deref()
|
||||
}
|
||||
|
||||
pub fn config(&self) -> &LanguageConfig {
|
||||
&self.config
|
||||
}
|
||||
}
|
||||
|
||||
impl LanguageScope {
|
||||
|
|
|
@ -130,6 +130,7 @@ pub struct AvailableLanguage {
|
|||
name: LanguageName,
|
||||
grammar: Option<Arc<str>>,
|
||||
matcher: LanguageMatcher,
|
||||
hidden: bool,
|
||||
load: Arc<dyn Fn() -> Result<LoadedLanguage> + 'static + Send + Sync>,
|
||||
loaded: bool,
|
||||
}
|
||||
|
@ -142,6 +143,9 @@ impl AvailableLanguage {
|
|||
pub fn matcher(&self) -> &LanguageMatcher {
|
||||
&self.matcher
|
||||
}
|
||||
pub fn hidden(&self) -> bool {
|
||||
self.hidden
|
||||
}
|
||||
}
|
||||
|
||||
enum AvailableGrammar {
|
||||
|
@ -288,6 +292,7 @@ impl LanguageRegistry {
|
|||
config.name.clone(),
|
||||
config.grammar.clone(),
|
||||
config.matcher.clone(),
|
||||
config.hidden,
|
||||
Arc::new(move || {
|
||||
Ok(LoadedLanguage {
|
||||
config: config.clone(),
|
||||
|
@ -436,6 +441,7 @@ impl LanguageRegistry {
|
|||
name: LanguageName,
|
||||
grammar_name: Option<Arc<str>>,
|
||||
matcher: LanguageMatcher,
|
||||
hidden: bool,
|
||||
load: Arc<dyn Fn() -> Result<LoadedLanguage> + 'static + Send + Sync>,
|
||||
) {
|
||||
let state = &mut *self.state.write();
|
||||
|
@ -455,6 +461,7 @@ impl LanguageRegistry {
|
|||
grammar: grammar_name,
|
||||
matcher,
|
||||
load,
|
||||
hidden,
|
||||
loaded: false,
|
||||
});
|
||||
state.version += 1;
|
||||
|
@ -522,6 +529,7 @@ impl LanguageRegistry {
|
|||
name: language.name(),
|
||||
grammar: language.config.grammar.clone(),
|
||||
matcher: language.config.matcher.clone(),
|
||||
hidden: language.config.hidden,
|
||||
load: Arc::new(|| Err(anyhow!("already loaded"))),
|
||||
loaded: true,
|
||||
});
|
||||
|
@ -590,15 +598,12 @@ impl LanguageRegistry {
|
|||
async move { rx.await? }
|
||||
}
|
||||
|
||||
pub fn available_language_for_name(
|
||||
self: &Arc<Self>,
|
||||
name: &LanguageName,
|
||||
) -> Option<AvailableLanguage> {
|
||||
pub fn available_language_for_name(self: &Arc<Self>, name: &str) -> Option<AvailableLanguage> {
|
||||
let state = self.state.read();
|
||||
state
|
||||
.available_languages
|
||||
.iter()
|
||||
.find(|l| &l.name == name)
|
||||
.find(|l| l.name.0.as_ref() == name)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue