Closes #21822 ## Context Exposes `preferred_line_length` from `AllLanguageSettings` to the Extension API's `LanguageSettings` struct. Currently only `tab_size` is available to extensions, which prevents language extensions (e.g. Dart) from reading the user's preferred line length and forwarding it to their language server (e.g. as `dart.lineLength`). Related: https://github.com/zed-extensions/dart/issues/2 ## How to Review Small change — follow how `tab_size` is plumbed through: 1. WIT definition (`language-settings` record) 2. `extension_api` Rust struct 3. Host-side bridge conversion The new field follows the exact same pattern. ## Self-Review Checklist <!-- Check before requesting review: --> - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - Compile-time verified via WIT bindings; no runtime behavior change - [x] Performance impact has been considered and is acceptable Release Notes: - N/A
57 lines
1.8 KiB
Rust
57 lines
1.8 KiB
Rust
//! Provides access to Zed settings.
|
|
|
|
#[path = "../wit/since_v0.8.0/settings.rs"]
|
|
mod types;
|
|
|
|
use crate::{Project, Result, SettingsLocation, Worktree, wit};
|
|
use serde_json;
|
|
pub use types::*;
|
|
|
|
impl LanguageSettings {
|
|
/// Returns the [`LanguageSettings`] for the given language.
|
|
pub fn for_worktree(language: Option<&str>, worktree: &Worktree) -> Result<Self> {
|
|
get_settings("language", language, Some(worktree.id()))
|
|
}
|
|
}
|
|
|
|
impl LspSettings {
|
|
/// Returns the [`LspSettings`] for the given language server.
|
|
pub fn for_worktree(language_server_name: &str, worktree: &Worktree) -> Result<Self> {
|
|
get_settings("lsp", Some(language_server_name), Some(worktree.id()))
|
|
}
|
|
}
|
|
|
|
impl ContextServerSettings {
|
|
/// Returns the [`ContextServerSettings`] for the given context server.
|
|
pub fn for_project(context_server_id: &str, project: &Project) -> Result<Self> {
|
|
let global_setting: Self = get_settings("context_servers", Some(context_server_id), None)?;
|
|
|
|
for worktree_id in project.worktree_ids() {
|
|
let settings = get_settings(
|
|
"context_servers",
|
|
Some(context_server_id),
|
|
Some(worktree_id),
|
|
)?;
|
|
if settings != global_setting {
|
|
return Ok(settings);
|
|
}
|
|
}
|
|
|
|
Ok(global_setting)
|
|
}
|
|
}
|
|
|
|
fn get_settings<T: serde::de::DeserializeOwned>(
|
|
settings_type: &str,
|
|
settings_name: Option<&str>,
|
|
worktree_id: Option<u64>,
|
|
) -> Result<T> {
|
|
let location = worktree_id.map(|worktree_id| SettingsLocation {
|
|
worktree_id,
|
|
path: String::new(),
|
|
});
|
|
let settings_json = wit::get_settings(location.as_ref(), settings_type, settings_name)?;
|
|
let settings: T = serde_json::from_str(&settings_json).map_err(|err| err.to_string())?;
|
|
Ok(settings)
|
|
}
|