Add the ability for extensions to provide language settings (#10296)
This PR adds the ability for extensions to provide certain language settings via the language `config.toml`. These settings are then merged in with the rest of the settings when the language is loaded from the extension. The language settings that are available are: - `tab_size` - `hard_tabs` - `soft_wrap` Additionally, for bundled languages we moved these settings out of the `settings/default.json` and into their respective `config.toml`s . For languages currently provided by extensions, we are leaving the values in the `settings/default.json` temporarily until all released versions of Zed are able to load these settings from the extension. --- Along the way we ended up refactoring the `Settings::load` method slightly, introducing a new `SettingsSources` struct to better convey where the settings are being loaded from. This makes it easier to load settings from specific locations/sets of locations in an explicit way. Release Notes: - N/A --------- Co-authored-by: Max <max@zed.dev> Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
parent
4a3032c5e5
commit
7c5bc3c26f
42 changed files with 349 additions and 338 deletions
|
@ -1,11 +1,12 @@
|
|||
use anyhow::Context;
|
||||
use gpui::AppContext;
|
||||
use gpui::{AppContext, BorrowAppContext};
|
||||
pub use language::*;
|
||||
use node_runtime::NodeRuntime;
|
||||
use rust_embed::RustEmbed;
|
||||
use settings::Settings;
|
||||
use settings::{Settings, SettingsStore};
|
||||
use smol::stream::StreamExt;
|
||||
use std::{str, sync::Arc};
|
||||
use util::asset_str;
|
||||
use util::{asset_str, ResultExt};
|
||||
|
||||
use crate::{elixir::elixir_task_context, rust::RustContextProvider};
|
||||
|
||||
|
@ -327,6 +328,27 @@ pub fn init(
|
|||
"Svelte".into(),
|
||||
Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
|
||||
);
|
||||
|
||||
let mut subscription = languages.subscribe();
|
||||
let mut prev_language_settings = languages.language_settings();
|
||||
|
||||
cx.spawn(|cx| async move {
|
||||
while subscription.next().await.is_some() {
|
||||
let language_settings = languages.language_settings();
|
||||
if language_settings != prev_language_settings {
|
||||
cx.update(|cx| {
|
||||
cx.update_global(|settings: &mut SettingsStore, cx| {
|
||||
settings
|
||||
.set_extension_settings(language_settings.clone(), cx)
|
||||
.log_err();
|
||||
});
|
||||
})?;
|
||||
prev_language_settings = language_settings;
|
||||
}
|
||||
}
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue