mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-28 21:32:39 +00:00
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:
parent
5e44748677
commit
d009d84ead
3 changed files with 43 additions and 15 deletions
|
@ -98,11 +98,34 @@ pub struct GrammarManifestEntry {
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
|
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
|
||||||
pub struct LanguageServerManifestEntry {
|
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)]
|
#[serde(default)]
|
||||||
pub language_ids: HashMap<String, String>,
|
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 {
|
impl ExtensionManifest {
|
||||||
pub async fn load(fs: Arc<dyn Fs>, extension_dir: &Path) -> Result<Self> {
|
pub async fn load(fs: Arc<dyn Fs>, extension_dir: &Path) -> Result<Self> {
|
||||||
let extension_name = extension_dir
|
let extension_name = extension_dir
|
||||||
|
|
|
@ -962,8 +962,10 @@ impl ExtensionStore {
|
||||||
};
|
};
|
||||||
grammars_to_remove.extend(extension.manifest.grammars.keys().cloned());
|
grammars_to_remove.extend(extension.manifest.grammars.keys().cloned());
|
||||||
for (language_server_name, config) in extension.manifest.language_servers.iter() {
|
for (language_server_name, config) in extension.manifest.language_servers.iter() {
|
||||||
self.language_registry
|
for language in config.languages() {
|
||||||
.remove_lsp_adapter(config.language.as_ref(), language_server_name);
|
self.language_registry
|
||||||
|
.remove_lsp_adapter(&language, language_server_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1103,18 +1105,20 @@ impl ExtensionStore {
|
||||||
|
|
||||||
for (manifest, wasm_extension) in &wasm_extensions {
|
for (manifest, wasm_extension) in &wasm_extensions {
|
||||||
for (language_server_id, language_server_config) in &manifest.language_servers {
|
for (language_server_id, language_server_config) in &manifest.language_servers {
|
||||||
this.language_registry.register_lsp_adapter(
|
for language in language_server_config.languages() {
|
||||||
language_server_config.language.clone(),
|
this.language_registry.register_lsp_adapter(
|
||||||
Arc::new(ExtensionLspAdapter {
|
language.clone(),
|
||||||
extension: wasm_extension.clone(),
|
Arc::new(ExtensionLspAdapter {
|
||||||
host: this.wasm_host.clone(),
|
extension: wasm_extension.clone(),
|
||||||
language_server_id: language_server_id.clone(),
|
host: this.wasm_host.clone(),
|
||||||
config: wit::LanguageServerConfig {
|
language_server_id: language_server_id.clone(),
|
||||||
name: language_server_id.0.to_string(),
|
config: wit::LanguageServerConfig {
|
||||||
language_name: language_server_config.language.to_string(),
|
name: language_server_id.0.to_string(),
|
||||||
},
|
language_name: language.to_string(),
|
||||||
}),
|
},
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.wasm_extensions.extend(wasm_extensions);
|
this.wasm_extensions.extend(wasm_extensions);
|
||||||
|
|
|
@ -9,3 +9,4 @@ repository = "https://github.com/zed-industries/zed"
|
||||||
[language_servers.emmet-language-server]
|
[language_servers.emmet-language-server]
|
||||||
name = "Emmet Language Server"
|
name = "Emmet Language Server"
|
||||||
language = "HTML"
|
language = "HTML"
|
||||||
|
languages = ["HTML", "PHP", "ERB"]
|
||||||
|
|
Loading…
Reference in a new issue