Use language settings' prettier parsers as a fallback for files with no path (#12273)

Follow-up of
https://github.com/zed-industries/zed/pull/12095#issuecomment-2123230762
reverting back part of https://github.com/zed-industries/zed/pull/11558
that was related to `language.toml` parsing.

Now all extensions that define `prettier_parser_name` in their language
configs, will enable formatting untitled buffers without any extra
language settings like

```json
{
  "languages": {
    "JSON": {
      "prettier": {
        "allowed": true,
        "parser": "json"
      }
    }
  }
}
```



Release Notes:

- Improved ergonomics of untitled buffer formatting with prettier, no
extra language settings are needed by default.
This commit is contained in:
Kirill Bulatov 2024-05-25 10:50:53 +03:00 committed by GitHub
parent d5fe2c85d8
commit 32f11dfa00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 24 additions and 6 deletions

View file

@ -610,6 +610,10 @@ pub struct LanguageConfig {
/// How to soft-wrap long lines of text.
#[serde(default)]
pub soft_wrap: Option<SoftWrap>,
/// The name of a Prettier parser that will be used for this language when no file path is available.
/// If there's a parser name in the language settings, that will be used instead.
#[serde(default)]
pub prettier_parser_name: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default, JsonSchema)]
@ -692,9 +696,10 @@ impl Default for LanguageConfig {
overrides: Default::default(),
word_characters: Default::default(),
collapsed_placeholder: Default::default(),
hard_tabs: Default::default(),
tab_size: Default::default(),
soft_wrap: Default::default(),
hard_tabs: None,
tab_size: None,
soft_wrap: None,
prettier_parser_name: None,
}
}
}
@ -1372,6 +1377,10 @@ impl Language {
language_name => language_name.to_lowercase(),
}
}
pub fn prettier_parser_name(&self) -> Option<&str> {
self.config.prettier_parser_name.as_deref()
}
}
impl LanguageScope {