Add support for using a language server with multiple languages (#10293)

This PR updates the `extension.toml` to allow specifying multiple
languages for a language server to work with.

The `languages` field takes precedence over `language`. In the future
the `language` field will be removed.

As part of this, the Emmet extension has been extended with support for
PHP and ERB.

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Marshall Bowers 2024-04-08 14:24:56 -04:00 committed by GitHub
parent 5e44748677
commit d009d84ead
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 15 deletions

View file

@ -98,11 +98,34 @@ pub struct GrammarManifestEntry {
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct LanguageServerManifestEntry {
pub language: Arc<str>,
/// Deprecated in favor of `languages`.
#[serde(default)]
language: Option<Arc<str>>,
/// The list of languages this language server should work with.
#[serde(default)]
languages: Vec<Arc<str>>,
#[serde(default)]
pub language_ids: HashMap<String, String>,
}
impl LanguageServerManifestEntry {
/// Returns the list of languages for the language server.
///
/// Prefer this over accessing the `language` or `languages` fields directly,
/// as we currently support both.
///
/// We can replace this with just field access for the `languages` field once
/// we have removed `language`.
pub fn languages(&self) -> impl IntoIterator<Item = Arc<str>> + '_ {
let language = if self.languages.is_empty() {
self.language.clone()
} else {
None
};
self.languages.iter().cloned().chain(language)
}
}
impl ExtensionManifest {
pub async fn load(fs: Arc<dyn Fs>, extension_dir: &Path) -> Result<Self> {
let extension_name = extension_dir