Define project settings in project crate
This commit is contained in:
parent
65e3713d4d
commit
cbd4771f10
17 changed files with 59 additions and 27 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4852,6 +4852,7 @@ dependencies = [
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"regex",
|
"regex",
|
||||||
"rpc",
|
"rpc",
|
||||||
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
@ -94,6 +94,7 @@ smol = { version = "1.2" }
|
||||||
tempdir = { version = "0.3.7" }
|
tempdir = { version = "0.3.7" }
|
||||||
thiserror = { version = "1.0.29" }
|
thiserror = { version = "1.0.29" }
|
||||||
time = { version = "0.3", features = ["serde", "serde-well-known"] }
|
time = { version = "0.3", features = ["serde", "serde-well-known"] }
|
||||||
|
toml = { version = "0.5" }
|
||||||
unindent = { version = "0.1.7" }
|
unindent = { version = "0.1.7" }
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|
|
@ -51,7 +51,7 @@ tokio = { version = "1", features = ["full"] }
|
||||||
tokio-tungstenite = "0.17"
|
tokio-tungstenite = "0.17"
|
||||||
tonic = "0.6"
|
tonic = "0.6"
|
||||||
tower = "0.4"
|
tower = "0.4"
|
||||||
toml = "0.5.8"
|
toml.workspace = true
|
||||||
tracing = "0.1.34"
|
tracing = "0.1.34"
|
||||||
tracing-log = "0.1.3"
|
tracing-log = "0.1.3"
|
||||||
tracing-subscriber = { version = "0.3.11", features = ["env-filter", "json"] }
|
tracing-subscriber = { version = "0.3.11", features = ["env-filter", "json"] }
|
||||||
|
|
|
@ -201,7 +201,7 @@ impl TestServer {
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
Project::init(&client);
|
Project::init(&client, cx);
|
||||||
client::init(&client, cx);
|
client::init(&client, cx);
|
||||||
language::init(cx);
|
language::init(cx);
|
||||||
editor::init_settings(cx);
|
editor::init_settings(cx);
|
||||||
|
|
|
@ -25,10 +25,7 @@ impl Setting for EditorSettings {
|
||||||
default_value: &Self::FileContent,
|
default_value: &Self::FileContent,
|
||||||
user_values: &[&Self::FileContent],
|
user_values: &[&Self::FileContent],
|
||||||
_: &gpui::AppContext,
|
_: &gpui::AppContext,
|
||||||
) -> anyhow::Result<Self>
|
) -> anyhow::Result<Self> {
|
||||||
where
|
|
||||||
Self: Sized,
|
|
||||||
{
|
|
||||||
Self::load_via_json_merge(default_value, user_values)
|
Self::load_via_json_merge(default_value, user_values)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6684,6 +6684,7 @@ pub(crate) fn init_test(cx: &mut TestAppContext, f: fn(&mut AllLanguageSettingsC
|
||||||
cx.set_global(Settings::test(cx));
|
cx.set_global(Settings::test(cx));
|
||||||
language::init(cx);
|
language::init(cx);
|
||||||
crate::init(cx);
|
crate::init(cx);
|
||||||
|
Project::init_settings(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
update_test_settings(cx, f);
|
update_test_settings(cx, f);
|
||||||
|
|
|
@ -40,6 +40,7 @@ impl<'a> EditorLspTestContext<'a> {
|
||||||
language::init(cx);
|
language::init(cx);
|
||||||
crate::init(cx);
|
crate::init(cx);
|
||||||
pane::init(cx);
|
pane::init(cx);
|
||||||
|
Project::init_settings(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
let file_name = format!(
|
let file_name = format!(
|
||||||
|
|
|
@ -50,6 +50,7 @@ parking_lot.workspace = true
|
||||||
postage.workspace = true
|
postage.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
|
schemars.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
serde_derive.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
@ -57,7 +58,7 @@ sha2 = "0.10"
|
||||||
similar = "1.3"
|
similar = "1.3"
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
toml = "0.5"
|
toml.workspace = true
|
||||||
itertools = "0.10"
|
itertools = "0.10"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
mod ignore;
|
mod ignore;
|
||||||
mod lsp_command;
|
mod lsp_command;
|
||||||
mod lsp_glob_set;
|
mod lsp_glob_set;
|
||||||
|
mod project_settings;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod terminals;
|
pub mod terminals;
|
||||||
pub mod worktree;
|
pub mod worktree;
|
||||||
|
@ -42,6 +43,7 @@ use lsp::{
|
||||||
use lsp_command::*;
|
use lsp_command::*;
|
||||||
use lsp_glob_set::LspGlobSet;
|
use lsp_glob_set::LspGlobSet;
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
|
use project_settings::ProjectSettings;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use search::SearchQuery;
|
use search::SearchQuery;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
@ -385,7 +387,13 @@ impl FormatTrigger {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Project {
|
impl Project {
|
||||||
pub fn init(client: &Arc<Client>) {
|
pub fn init_settings(cx: &mut AppContext) {
|
||||||
|
settings::register_setting::<ProjectSettings>(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(client: &Arc<Client>, cx: &mut AppContext) {
|
||||||
|
Self::init_settings(cx);
|
||||||
|
|
||||||
client.add_model_message_handler(Self::handle_add_collaborator);
|
client.add_model_message_handler(Self::handle_add_collaborator);
|
||||||
client.add_model_message_handler(Self::handle_update_project_collaborator);
|
client.add_model_message_handler(Self::handle_update_project_collaborator);
|
||||||
client.add_model_message_handler(Self::handle_remove_collaborator);
|
client.add_model_message_handler(Self::handle_remove_collaborator);
|
||||||
|
@ -2206,7 +2214,9 @@ impl Project {
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
let lsp = &cx.global::<Settings>().lsp.get(&adapter.name.0);
|
let lsp = settings::get_setting::<ProjectSettings>(None, cx)
|
||||||
|
.lsp
|
||||||
|
.get(&adapter.name.0);
|
||||||
let override_options = lsp.map(|s| s.initialization_options.clone()).flatten();
|
let override_options = lsp.map(|s| s.initialization_options.clone()).flatten();
|
||||||
|
|
||||||
let mut initialization_options = adapter.initialization_options.clone();
|
let mut initialization_options = adapter.initialization_options.clone();
|
||||||
|
|
31
crates/project/src/project_settings.rs
Normal file
31
crates/project/src/project_settings.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
use collections::HashMap;
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use settings::Setting;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
|
||||||
|
pub struct ProjectSettings {
|
||||||
|
#[serde(default)]
|
||||||
|
pub lsp: HashMap<Arc<str>, LspSettings>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub struct LspSettings {
|
||||||
|
pub initialization_options: Option<serde_json::Value>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Setting for ProjectSettings {
|
||||||
|
const KEY: Option<&'static str> = None;
|
||||||
|
|
||||||
|
type FileContent = Self;
|
||||||
|
|
||||||
|
fn load(
|
||||||
|
default_value: &Self::FileContent,
|
||||||
|
user_values: &[&Self::FileContent],
|
||||||
|
_: &gpui::AppContext,
|
||||||
|
) -> anyhow::Result<Self> {
|
||||||
|
Self::load_via_json_merge(default_value, user_values)
|
||||||
|
}
|
||||||
|
}
|
|
@ -3723,5 +3723,6 @@ fn init_test(cx: &mut gpui::TestAppContext) {
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
cx.set_global(SettingsStore::test(cx));
|
cx.set_global(SettingsStore::test(cx));
|
||||||
language::init(cx);
|
language::init(cx);
|
||||||
|
Project::init_settings(cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,6 +374,7 @@ mod tests {
|
||||||
cx.set_global(Settings::test(cx));
|
cx.set_global(Settings::test(cx));
|
||||||
cx.set_global(SettingsStore::test(cx));
|
cx.set_global(SettingsStore::test(cx));
|
||||||
language::init(cx);
|
language::init(cx);
|
||||||
|
Project::init_settings(cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ serde.workspace = true
|
||||||
serde_derive.workspace = true
|
serde_derive.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
toml = "0.5"
|
toml.workspace = true
|
||||||
tree-sitter = "*"
|
tree-sitter = "*"
|
||||||
tree-sitter-json = "*"
|
tree-sitter-json = "*"
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ use sqlez::{
|
||||||
bindable::{Bind, Column, StaticColumnCount},
|
bindable::{Bind, Column, StaticColumnCount},
|
||||||
statement::Statement,
|
statement::Statement,
|
||||||
};
|
};
|
||||||
use std::{borrow::Cow, collections::HashMap, str, sync::Arc};
|
use std::{borrow::Cow, str, sync::Arc};
|
||||||
use theme::{Theme, ThemeRegistry};
|
use theme::{Theme, ThemeRegistry};
|
||||||
use util::ResultExt as _;
|
use util::ResultExt as _;
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ pub struct Settings {
|
||||||
pub default_dock_anchor: DockAnchor,
|
pub default_dock_anchor: DockAnchor,
|
||||||
pub git: GitSettings,
|
pub git: GitSettings,
|
||||||
pub git_overrides: GitSettings,
|
pub git_overrides: GitSettings,
|
||||||
pub lsp: HashMap<Arc<str>, LspSettings>,
|
|
||||||
pub theme: Arc<Theme>,
|
pub theme: Arc<Theme>,
|
||||||
pub base_keymap: BaseKeymap,
|
pub base_keymap: BaseKeymap,
|
||||||
}
|
}
|
||||||
|
@ -80,7 +79,6 @@ impl Setting for Settings {
|
||||||
default_dock_anchor: defaults.default_dock_anchor.unwrap(),
|
default_dock_anchor: defaults.default_dock_anchor.unwrap(),
|
||||||
git: defaults.git.unwrap(),
|
git: defaults.git.unwrap(),
|
||||||
git_overrides: Default::default(),
|
git_overrides: Default::default(),
|
||||||
lsp: defaults.lsp.clone(),
|
|
||||||
theme: themes.get(defaults.theme.as_ref().unwrap()).unwrap(),
|
theme: themes.get(defaults.theme.as_ref().unwrap()).unwrap(),
|
||||||
base_keymap: Default::default(),
|
base_keymap: Default::default(),
|
||||||
};
|
};
|
||||||
|
@ -290,19 +288,11 @@ pub struct SettingsFileContent {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub git: Option<GitSettings>,
|
pub git: Option<GitSettings>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub lsp: HashMap<Arc<str>, LspSettings>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub theme: Option<String>,
|
pub theme: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub base_keymap: Option<BaseKeymap>,
|
pub base_keymap: Option<BaseKeymap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
|
||||||
#[serde(rename_all = "snake_case")]
|
|
||||||
pub struct LspSettings {
|
|
||||||
pub initialization_options: Option<Value>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
pub fn initial_user_settings_content(assets: &'static impl AssetSource) -> Cow<'static, str> {
|
pub fn initial_user_settings_content(assets: &'static impl AssetSource) -> Cow<'static, str> {
|
||||||
match assets.load(INITIAL_USER_SETTINGS_ASSET_PATH).unwrap() {
|
match assets.load(INITIAL_USER_SETTINGS_ASSET_PATH).unwrap() {
|
||||||
|
@ -340,7 +330,6 @@ impl Settings {
|
||||||
default_dock_anchor: defaults.default_dock_anchor.unwrap(),
|
default_dock_anchor: defaults.default_dock_anchor.unwrap(),
|
||||||
git: defaults.git.unwrap(),
|
git: defaults.git.unwrap(),
|
||||||
git_overrides: Default::default(),
|
git_overrides: Default::default(),
|
||||||
lsp: defaults.lsp.clone(),
|
|
||||||
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
|
theme: themes.get(&defaults.theme.unwrap()).unwrap(),
|
||||||
base_keymap: Default::default(),
|
base_keymap: Default::default(),
|
||||||
}
|
}
|
||||||
|
@ -388,7 +377,6 @@ impl Settings {
|
||||||
merge(&mut self.base_keymap, data.base_keymap);
|
merge(&mut self.base_keymap, data.base_keymap);
|
||||||
|
|
||||||
self.git_overrides = data.git.unwrap_or_default();
|
self.git_overrides = data.git.unwrap_or_default();
|
||||||
self.lsp = data.lsp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn git_gutter(&self) -> GitGutter {
|
pub fn git_gutter(&self) -> GitGutter {
|
||||||
|
@ -416,7 +404,6 @@ impl Settings {
|
||||||
default_dock_anchor: DockAnchor::Bottom,
|
default_dock_anchor: DockAnchor::Bottom,
|
||||||
git: Default::default(),
|
git: Default::default(),
|
||||||
git_overrides: Default::default(),
|
git_overrides: Default::default(),
|
||||||
lsp: Default::default(),
|
|
||||||
theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), Default::default),
|
theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), Default::default),
|
||||||
base_keymap: Default::default(),
|
base_keymap: Default::default(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,4 @@ parking_lot.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
serde_derive.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
toml = "0.5"
|
toml.workspace = true
|
||||||
|
|
|
@ -101,7 +101,7 @@ smol.workspace = true
|
||||||
tempdir.workspace = true
|
tempdir.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
tiny_http = "0.8"
|
tiny_http = "0.8"
|
||||||
toml = "0.5"
|
toml.workspace = true
|
||||||
tree-sitter = "0.20"
|
tree-sitter = "0.20"
|
||||||
tree-sitter-c = "0.20.1"
|
tree-sitter-c = "0.20.1"
|
||||||
tree-sitter-cpp = "0.20.0"
|
tree-sitter-cpp = "0.20.0"
|
||||||
|
|
|
@ -157,7 +157,7 @@ fn main() {
|
||||||
cx.set_global(client.clone());
|
cx.set_global(client.clone());
|
||||||
|
|
||||||
context_menu::init(cx);
|
context_menu::init(cx);
|
||||||
project::Project::init(&client);
|
project::Project::init(&client, cx);
|
||||||
client::init(&client, cx);
|
client::init(&client, cx);
|
||||||
command_palette::init(cx);
|
command_palette::init(cx);
|
||||||
editor::init(cx);
|
editor::init(cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue