Allow extensions to provide data for language_ids (#10053)

This PR makes it so extensions can provide values for the `language_ids`
method on the `LspAdapter` trait.

These are provided as data in the `language_servers` section of the
`extension.toml`, like so:

```toml
[language_servers.intelephense]
name = "Intelephense"
language = "PHP"
language_ids = { PHP = "php"}
```

Release Notes:

- N/A

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Marshall Bowers 2024-04-01 17:01:11 -04:00 committed by GitHub
parent 65f0712713
commit 39cc3c0778
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View file

@ -113,14 +113,22 @@ impl LspAdapter for ExtensionLspAdapter {
}
fn language_ids(&self) -> HashMap<String, String> {
// TODO: Eventually we'll want to expose an extension API for doing this, but for
// now we just manually language ID mappings for extensions that we know need it.
// TODO: The language IDs can be provided via the language server options
// in `extension.toml now but we're leaving these existing usages in place temporarily
// to avoid any compatibility issues between Zed and the extension versions.
//
// We can remove once the following extension versions no longer see any use:
// - php@0.0.1
if self.extension.manifest.id.as_ref() == "php" {
return HashMap::from_iter([("PHP".into(), "php".into())]);
}
Default::default()
self.extension
.manifest
.language_servers
.get(&LanguageServerName(self.config.name.clone().into()))
.map(|server| server.language_ids.clone())
.unwrap_or_default()
}
async fn initialization_options(