Skip to content

Commit

Permalink
Remove optional path argument when getting settings
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed May 17, 2023
1 parent 1f0e79e commit 2d5f03e
Show file tree
Hide file tree
Showing 35 changed files with 84 additions and 113 deletions.
6 changes: 3 additions & 3 deletions crates/auto_update/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ pub fn init(http_client: Arc<dyn HttpClient>, server_url: String, cx: &mut AppCo
let auto_updater = cx.add_model(|cx| {
let updater = AutoUpdater::new(version, http_client, server_url);

let mut update_subscription = settings::get_setting::<AutoUpdateSetting>(None, cx)
let mut update_subscription = settings::get::<AutoUpdateSetting>(cx)
.0
.then(|| updater.start_polling(cx));

cx.observe_global::<SettingsStore, _>(move |updater, cx| {
if settings::get_setting::<AutoUpdateSetting>(None, cx).0 {
if settings::get::<AutoUpdateSetting>(cx).0 {
if update_subscription.is_none() {
update_subscription = Some(updater.start_polling(cx))
}
Expand Down Expand Up @@ -281,7 +281,7 @@ impl AutoUpdater {
let release_channel = cx
.has_global::<ReleaseChannel>()
.then(|| cx.global::<ReleaseChannel>().display_name());
let telemetry = settings::get_setting::<TelemetrySettings>(None, cx).metrics;
let telemetry = settings::get::<TelemetrySettings>(cx).metrics;

(installation_id, release_channel, telemetry)
});
Expand Down
5 changes: 2 additions & 3 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ impl Client {
self.telemetry().report_mixpanel_event(
"read credentials from keychain",
Default::default(),
*settings::get_setting::<TelemetrySettings>(None, cx),
*settings::get::<TelemetrySettings>(cx),
);
});
}
Expand Down Expand Up @@ -1075,8 +1075,7 @@ impl Client {
let telemetry = self.telemetry.clone();
let http = self.http.clone();

let telemetry_settings =
cx.read(|cx| *settings::get_setting::<TelemetrySettings>(None, cx));
let telemetry_settings = cx.read(|cx| *settings::get::<TelemetrySettings>(cx));

executor.clone().spawn(async move {
// Generate a pair of asymmetric encryption keys. The public key will be used by the
Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Telemetry {
is_staff: bool,
cx: &AppContext,
) {
if !settings::get_setting::<TelemetrySettings>(None, cx).metrics {
if !settings::get::<TelemetrySettings>(cx).metrics {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/collab_ui/src/sharing_status_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn init(cx: &mut AppContext) {
if let Some(room) = call.read(cx).room() {
if room.read(cx).is_screen_sharing() {
if status_indicator.is_none()
&& settings::get_setting::<WorkspaceSettings>(None, cx).show_call_status_icon
&& settings::get::<WorkspaceSettings>(cx).show_call_status_icon
{
status_indicator = Some(cx.add_status_bar_item(|_| SharingStatusIndicator));
}
Expand Down
3 changes: 1 addition & 2 deletions crates/copilot/src/copilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl Copilot {
fn enable_or_disable_copilot(&mut self, cx: &mut ModelContext<Copilot>) {
let http = self.http.clone();
let node_runtime = self.node_runtime.clone();
if all_language_settings(None, cx).copilot_enabled(None, None) {
if all_language_settings(cx).copilot_enabled(None, None) {
if matches!(self.server, CopilotServer::Disabled) {
let start_task = cx
.spawn({
Expand Down Expand Up @@ -786,7 +786,6 @@ impl Copilot {
let uri = registered_buffer.uri.clone();
let position = position.to_point_utf16(buffer);
let settings = language_settings(
None,
buffer.language_at(position).map(|l| l.name()).as_deref(),
cx,
);
Expand Down
13 changes: 6 additions & 7 deletions crates/copilot_button/src/copilot_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl View for CopilotButton {
}

fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let all_language_settings = &all_language_settings(None, cx);
let all_language_settings = &all_language_settings(cx);
if !all_language_settings.copilot.feature_enabled {
return Empty::new().into_any();
}
Expand Down Expand Up @@ -198,7 +198,7 @@ impl CopilotButton {
if let Some(language) = self.language.clone() {
let fs = fs.clone();
let language_enabled =
language_settings::language_settings(None, Some(language.as_ref()), cx)
language_settings::language_settings(Some(language.as_ref()), cx)
.show_copilot_suggestions;
menu_options.push(ContextMenuItem::handler(
format!(
Expand All @@ -210,7 +210,7 @@ impl CopilotButton {
));
}

let settings = settings::get_setting::<AllLanguageSettings>(None, cx);
let settings = settings::get::<AllLanguageSettings>(cx);

if let Some(path) = self.path.as_ref() {
let path_enabled = settings.copilot_enabled_for_path(path);
Expand Down Expand Up @@ -282,7 +282,7 @@ impl CopilotButton {
let path = snapshot.file_at(suggestion_anchor).map(|file| file.path());

self.editor_enabled = Some(
all_language_settings(None, cx)
all_language_settings(cx)
.copilot_enabled(language_name.as_deref(), path.map(|p| p.as_ref())),
);
self.language = language_name;
Expand Down Expand Up @@ -364,15 +364,14 @@ async fn configure_disabled_globs(
}

fn toggle_copilot_globally(fs: Arc<dyn Fs>, cx: &mut AppContext) {
let show_copilot_suggestions = all_language_settings(None, cx).copilot_enabled(None, None);
let show_copilot_suggestions = all_language_settings(cx).copilot_enabled(None, None);
update_settings_file::<AllLanguageSettings>(fs, cx, move |file| {
file.defaults.show_copilot_suggestions = Some((!show_copilot_suggestions).into())
});
}

fn toggle_copilot_for_language(language: Arc<str>, fs: Arc<dyn Fs>, cx: &mut AppContext) {
let show_copilot_suggestions =
all_language_settings(None, cx).copilot_enabled(Some(&language), None);
let show_copilot_suggestions = all_language_settings(cx).copilot_enabled(Some(&language), None);
update_settings_file::<AllLanguageSettings>(fs, cx, move |file| {
file.languages
.entry(language)
Expand Down
2 changes: 1 addition & 1 deletion crates/diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl Item for ProjectDiagnosticsEditor {
fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
let (message, highlights) = highlight_diagnostic_message(Vec::new(), &diagnostic.message);
Arc::new(move |cx| {
let settings = settings::get_setting::<ThemeSettings>(None, cx);
let settings = settings::get::<ThemeSettings>(cx);
let theme = &settings.theme.editor;
let style = theme.diagnostic_header.clone();
let font_size = (style.text_scale_factor
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/blink_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl BlinkManager {
}

fn blink_cursors(&mut self, epoch: usize, cx: &mut ModelContext<Self>) {
if settings::get_setting::<EditorSettings>(None, cx).cursor_blink {
if settings::get::<EditorSettings>(cx).cursor_blink {
if epoch == self.blink_epoch && self.enabled && !self.blinking_paused {
self.visible = !self.visible;
cx.notify();
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/display_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl DisplayMap {
.as_singleton()
.and_then(|buffer| buffer.read(cx).language())
.map(|language| language.name());
language_settings(None, language_name.as_deref(), cx).tab_size
language_settings(language_name.as_deref(), cx).tab_size
}

#[cfg(test)]
Expand Down
16 changes: 8 additions & 8 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ impl Editor {
) -> Self {
let editor_view_id = cx.view_id();
let display_map = cx.add_model(|cx| {
let settings = settings::get_setting::<ThemeSettings>(None, cx);
let settings = settings::get::<ThemeSettings>(cx);
let style = build_style(settings, get_field_editor_theme.as_deref(), None, cx);
DisplayMap::new(
buffer.clone(),
Expand Down Expand Up @@ -1427,7 +1427,7 @@ impl Editor {

fn style(&self, cx: &AppContext) -> EditorStyle {
build_style(
settings::get_setting::<ThemeSettings>(None, cx),
settings::get::<ThemeSettings>(cx),
self.get_field_editor_theme.as_deref(),
self.override_text_style.as_deref(),
cx,
Expand Down Expand Up @@ -2385,7 +2385,7 @@ impl Editor {
}

fn trigger_completion_on_input(&mut self, text: &str, cx: &mut ViewContext<Self>) {
if !settings::get_setting::<EditorSettings>(None, cx).show_completions_on_input {
if !settings::get::<EditorSettings>(cx).show_completions_on_input {
return;
}

Expand Down Expand Up @@ -3156,7 +3156,7 @@ impl Editor {
let language_name = snapshot
.language_at(location)
.map(|language| language.name());
let settings = all_language_settings(None, cx);
let settings = all_language_settings(cx);
settings.copilot_enabled(language_name.as_deref(), path)
}

Expand Down Expand Up @@ -6902,7 +6902,7 @@ impl Editor {
.map(|a| a.to_string());

let telemetry = project.read(cx).client().telemetry().clone();
let telemetry_settings = *settings::get_setting::<TelemetrySettings>(None, cx);
let telemetry_settings = *settings::get::<TelemetrySettings>(cx);

let event = ClickhouseEvent::Copilot {
suggestion_id,
Expand Down Expand Up @@ -6937,8 +6937,8 @@ impl Editor {
.untyped_user_settings()
.get("vim_mode")
== Some(&serde_json::Value::Bool(true));
let telemetry_settings = *settings::get_setting::<TelemetrySettings>(None, cx);
let copilot_enabled = all_language_settings(None, cx).copilot_enabled(None, None);
let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
let copilot_enabled = all_language_settings(cx).copilot_enabled(None, None);
let copilot_enabled_for_language = self
.buffer
.read(cx)
Expand Down Expand Up @@ -7616,7 +7616,7 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
}

Arc::new(move |cx: &mut BlockContext| {
let settings = settings::get_setting::<ThemeSettings>(None, cx);
let settings = settings::get::<ThemeSettings>(cx);
let theme = &settings.theme.editor;
let style = diagnostic_style(diagnostic.severity, is_valid, theme);
let font_size = (style.text_scale_factor
Expand Down
19 changes: 9 additions & 10 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl EditorElement {
let scroll_top = scroll_position.y() * line_height;

let show_gutter = matches!(
settings::get_setting::<WorkspaceSettings>(None, cx)
settings::get::<WorkspaceSettings>(cx)
.git
.git_gutter
.unwrap_or_default(),
Expand Down Expand Up @@ -2060,15 +2060,14 @@ impl Element<Editor> for EditorElement {
));
}

let show_scrollbars =
match settings::get_setting::<EditorSettings>(None, cx).show_scrollbars {
ShowScrollbars::Auto => {
snapshot.has_scrollbar_info() || editor.scroll_manager.scrollbars_visible()
}
ShowScrollbars::System => editor.scroll_manager.scrollbars_visible(),
ShowScrollbars::Always => true,
ShowScrollbars::Never => false,
};
let show_scrollbars = match settings::get::<EditorSettings>(cx).show_scrollbars {
ShowScrollbars::Auto => {
snapshot.has_scrollbar_info() || editor.scroll_manager.scrollbars_visible()
}
ShowScrollbars::System => editor.scroll_manager.scrollbars_visible(),
ShowScrollbars::Always => true,
ShowScrollbars::Never => false,
};

let include_root = editor
.project
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/hover_popover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn hover(editor: &mut Editor, _: &Hover, cx: &mut ViewContext<Editor>) {
/// The internal hover action dispatches between `show_hover` or `hide_hover`
/// depending on whether a point to hover over is provided.
pub fn hover_at(editor: &mut Editor, point: Option<DisplayPoint>, cx: &mut ViewContext<Editor>) {
if settings::get_setting::<EditorSettings>(None, cx).hover_popover_enabled {
if settings::get::<EditorSettings>(cx).hover_popover_enabled {
if let Some(point) = point {
show_hover(editor, point, false, cx);
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/editor/src/multi_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ impl MultiBuffer {
cx: &'a AppContext,
) -> &'a LanguageSettings {
let language = self.language_at(point, cx);
language_settings(None, language.map(|l| l.name()).as_deref(), cx)
language_settings(language.map(|l| l.name()).as_deref(), cx)
}

pub fn for_each_buffer(&self, mut f: impl FnMut(&ModelHandle<Buffer>)) {
Expand Down Expand Up @@ -2782,7 +2782,7 @@ impl MultiBufferSnapshot {
) -> &'a LanguageSettings {
self.point_to_buffer_offset(point)
.map(|(buffer, offset)| buffer.settings_at(offset, cx))
.unwrap_or_else(|| language_settings(None, None, cx))
.unwrap_or_else(|| language_settings(None, cx))
}

pub fn language_scope_at<'a, T: ToOffset>(&'a self, point: T) -> Option<LanguageScope> {
Expand Down
2 changes: 1 addition & 1 deletion crates/journal/src/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
}

pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut AppContext) {
let settings = settings::get_setting::<JournalSettings>(None, cx);
let settings = settings::get::<JournalSettings>(cx);
let journal_dir = match journal_dir(settings.path.as_ref().unwrap()) {
Some(journal_dir) => journal_dir,
None => {
Expand Down
4 changes: 2 additions & 2 deletions crates/language/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ impl BufferSnapshot {

pub fn language_indent_size_at<T: ToOffset>(&self, position: T, cx: &AppContext) -> IndentSize {
let language_name = self.language_at(position).map(|language| language.name());
let settings = language_settings(None, language_name.as_deref(), cx);
let settings = language_settings(language_name.as_deref(), cx);
if settings.hard_tabs {
IndentSize::tab()
} else {
Expand Down Expand Up @@ -2152,7 +2152,7 @@ impl BufferSnapshot {
cx: &'a AppContext,
) -> &'a LanguageSettings {
let language = self.language_at(position);
language_settings(None, language.map(|l| l.name()).as_deref(), cx)
language_settings(language.map(|l| l.name()).as_deref(), cx)
}

pub fn language_scope_at<D: ToOffset>(&self, position: D) -> Option<LanguageScope> {
Expand Down
15 changes: 4 additions & 11 deletions crates/language/src/language_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@ pub fn init(cx: &mut AppContext) {
settings::register_setting::<AllLanguageSettings>(cx);
}

pub fn language_settings<'a>(
path: Option<&Path>,
language: Option<&str>,
cx: &'a AppContext,
) -> &'a LanguageSettings {
settings::get_setting::<AllLanguageSettings>(path, cx).language(language)
pub fn language_settings<'a>(language: Option<&str>, cx: &'a AppContext) -> &'a LanguageSettings {
settings::get::<AllLanguageSettings>(cx).language(language)
}

pub fn all_language_settings<'a>(
path: Option<&Path>,
cx: &'a AppContext,
) -> &'a AllLanguageSettings {
settings::get_setting::<AllLanguageSettings>(path, cx)
pub fn all_language_settings<'a>(cx: &'a AppContext) -> &'a AllLanguageSettings {
settings::get::<AllLanguageSettings>(cx)
}

#[derive(Debug, Clone)]
Expand Down
9 changes: 4 additions & 5 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl Project {
}

fn on_settings_changed(&mut self, cx: &mut ModelContext<Self>) {
let settings = all_language_settings(None, cx);
let settings = all_language_settings(cx);

let mut language_servers_to_start = Vec::new();
for buffer in self.opened_buffers.values() {
Expand Down Expand Up @@ -2208,7 +2208,7 @@ impl Project {
language: Arc<Language>,
cx: &mut ModelContext<Self>,
) {
if !language_settings(None, Some(&language.name()), cx).enable_language_server {
if !language_settings(Some(&language.name()), cx).enable_language_server {
return;
}

Expand All @@ -2229,7 +2229,7 @@ impl Project {
None => continue,
};

let lsp = settings::get_setting::<ProjectSettings>(None, cx)
let lsp = settings::get::<ProjectSettings>(cx)
.lsp
.get(&adapter.name.0);
let override_options = lsp.map(|s| s.initialization_options.clone()).flatten();
Expand Down Expand Up @@ -3259,8 +3259,7 @@ impl Project {
for (buffer, buffer_abs_path, language_server) in &buffers_with_paths_and_servers {
let settings = buffer.read_with(&cx, |buffer, cx| {
let language_name = buffer.language().map(|language| language.name());
language_settings(buffer_abs_path.as_deref(), language_name.as_deref(), cx)
.clone()
language_settings(language_name.as_deref(), cx).clone()
});

let remove_trailing_whitespace = settings.remove_trailing_whitespace_on_save;
Expand Down
2 changes: 1 addition & 1 deletion crates/project/src/terminals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Project {
"creating terminals as a guest is not supported yet"
));
} else {
let settings = settings::get_setting::<TerminalSettings>(None, cx);
let settings = settings::get::<TerminalSettings>(cx);

let terminal = TerminalBuilder::new(
working_directory.clone(),
Expand Down
Loading

0 comments on commit 2d5f03e

Please sign in to comment.