diff --git a/crates/collab/src/tests/remote_editing_collaboration_tests.rs b/crates/collab/src/tests/remote_editing_collaboration_tests.rs index c4410fd776be7d..83aa341226af5d 100644 --- a/crates/collab/src/tests/remote_editing_collaboration_tests.rs +++ b/crates/collab/src/tests/remote_editing_collaboration_tests.rs @@ -100,7 +100,7 @@ async fn test_sharing_an_ssh_remote_project( let file = buffer_b.read(cx).file(); assert_eq!( all_language_settings(file, cx) - .language(Some(&("Rust".into()))) + .language(None, Some(&("Rust".into())), cx) .language_servers, ["override-rust-analyzer".into()] ) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 5bacf8248caca3..e50bfcf2671210 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -10776,9 +10776,7 @@ impl Editor { settings::SoftWrap::PreferredLineLength => { SoftWrap::Column(settings.preferred_line_length) } - language_settings::SoftWrap::Bounded => { - SoftWrap::Bounded(settings.preferred_line_length) - } + settings::SoftWrap::Bounded => SoftWrap::Bounded(settings.preferred_line_length), } } @@ -10816,7 +10814,9 @@ impl Editor { } else { let soft_wrap = match self.soft_wrap_mode(cx) { SoftWrap::None | SoftWrap::PreferLine => settings::SoftWrap::EditorWidth, - SoftWrap::EditorWidth | SoftWrap::Column(_) | SoftWrap::Bounded(_) => settings::SoftWrap::PreferLine, + SoftWrap::EditorWidth | SoftWrap::Column(_) | SoftWrap::Bounded(_) => { + settings::SoftWrap::PreferLine + } }; self.soft_wrap_mode_override = Some(soft_wrap); } @@ -12658,7 +12658,7 @@ fn inlay_hint_settings( let settings = all_language_settings(file, cx); settings .language( - file.and_then(|file| Some((file.worktree_id(), file.abs_path_in_worktree(cx).ok()?))), + file.and_then(|file| Some((file.worktree_id(cx), file.abs_path_in_worktree(cx).ok()?))), language.map(|l| l.name()).as_ref(), cx, ) diff --git a/crates/extension/src/wasm_host/wit/since_v0_2_0.rs b/crates/extension/src/wasm_host/wit/since_v0_2_0.rs index 7fa79c2544475b..9115a3ca5022d1 100644 --- a/crates/extension/src/wasm_host/wit/since_v0_2_0.rs +++ b/crates/extension/src/wasm_host/wit/since_v0_2_0.rs @@ -402,7 +402,8 @@ impl ExtensionImports for WasmState { "language" => { let key = key.map(|k| LanguageName::new(&k)); let settings = - AllLanguageSettings::get(location, cx).language(key.as_ref()); + // TODO kb use `location` instead of `None` + AllLanguageSettings::get(location, cx).language(None, key.as_ref(), cx); Ok(serde_json::to_string(&settings::LanguageSettings { tab_size: settings.tab_size, })?) diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index 2770160c6d5d30..33d97ec3a0c451 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -18,7 +18,7 @@ use serde::{ use serde_json::Value; use settings::{ add_references_to_properties, EditorConfigContent, Settings, SettingsLocation, SettingsSources, - SettingsStore, SoftWrap, + SettingsStore, SoftWrap, WorktreeId, }; use std::{ borrow::Cow, @@ -41,7 +41,7 @@ pub fn language_settings<'a>( ) -> Cow<'a, LanguageSettings> { let language_name = language.map(|l| l.name()); all_language_settings(file, cx).language( - file.and_then(|file| Some((file.worktree_id(), file.abs_path_in_worktree(cx).ok()?))), + file.and_then(|file| Some((file.worktree_id(cx), file.abs_path_in_worktree(cx).ok()?))), language_name.as_ref(), cx, ) @@ -789,7 +789,8 @@ impl AllLanguageSettings { /// Returns the [`LanguageSettings`] for the language with the specified name. pub fn language<'a>( &'a self, - abs_path_in_worktree: Option<(usize, PathBuf)>, + // TODO kb wrong API, store the previous file in the `AllLanguageSettings` instead of requiring it here + abs_path_in_worktree: Option<(WorktreeId, PathBuf)>, language_name: Option<&LanguageName>, cx: &'a AppContext, ) -> Cow<'a, LanguageSettings> { @@ -801,7 +802,7 @@ impl AllLanguageSettings { abs_path_in_worktree.and_then(|(worktree_id, file_abs_path)| { cx.global::().editorconfig_settings( worktree_id, - language_name.map(ToOwned::to_owned), + language_name.map(|name| name.0.to_string()), &file_abs_path, ) }); @@ -837,7 +838,7 @@ impl AllLanguageSettings { } self.language( - file.and_then(|file| Some((file.worktree_id(), file.abs_path_in_worktree(cx).ok()?))), + file.and_then(|file| Some((file.worktree_id(cx), file.abs_path_in_worktree(cx).ok()?))), language.map(|l| l.name()).as_ref(), cx, ) diff --git a/crates/languages/src/rust.rs b/crates/languages/src/rust.rs index 309407efdbfe55..ebae4dd4642189 100644 --- a/crates/languages/src/rust.rs +++ b/crates/languages/src/rust.rs @@ -448,7 +448,7 @@ impl ContextProvider for RustContextProvider { ) -> Option { const DEFAULT_RUN_NAME_STR: &str = "RUST_DEFAULT_PACKAGE_RUN"; let language_settings = all_language_settings(file.as_ref(), cx).language( - file.and_then(|file| Some((file.worktree_id(), file.abs_path_in_worktree(cx).ok()?))), + file.and_then(|file| Some((file.worktree_id(cx), file.abs_path_in_worktree(cx).ok()?))), Some(&"Rust".into()), cx, ); diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index ee02492dd8cfda..acb6938a31dc8e 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -58,6 +58,7 @@ use smol::channel::Sender; use snippet::Snippet; use std::{ any::Any, + borrow::Cow, cmp::Ordering, convert::TryInto, ffi::OsStr, @@ -1071,9 +1072,14 @@ impl LspStore { .filter(|_| { maybe!({ let language_name = buffer.read(cx).language_at(position)?.name(); + let abs_path_in_a_worktree = buffer.read(cx).file().and_then(|file| { + let worktree_id = file.worktree_id(cx); + let abs_path = file.abs_path_in_worktree(cx).ok()?; + Some((worktree_id, abs_path)) + }); Some( AllLanguageSettings::get_global(cx) - .language(Some(&language_name)) + .language(abs_path_in_a_worktree, Some(&language_name), cx) .linked_edits, ) }) == Some(true) @@ -1172,7 +1178,7 @@ impl LspStore { cx: &mut ModelContext, ) -> Task>> { let options = buffer.update(cx, |buffer, cx| { - lsp_command::lsp_formatting_options(language_settings( + lsp_command::lsp_formatting_options(&language_settings( buffer.language_at(position).as_ref(), buffer.file(), cx, @@ -4450,9 +4456,17 @@ impl LspStore { worktree: &'a Model, language: &LanguageName, cx: &'a mut ModelContext, - ) -> &'a LanguageSettings { + ) -> Cow<'a, LanguageSettings> { let root_file = worktree.update(cx, |tree, cx| tree.root_file(cx)); - all_language_settings(root_file.map(|f| f as _).as_ref(), cx).language(Some(language)) + let abs_path_in_worktree = root_file.as_ref().and_then(|f| { + let worktree = worktree.read(cx); + Some((worktree.id(), f.abs_path_in_worktree(cx).ok()?)) + }); + all_language_settings(root_file.map(|f| f as _).as_ref(), cx).language( + abs_path_in_worktree, + Some(language), + cx, + ) } pub fn start_language_servers( diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 43f1a1f999ae6d..9bdf94c9da2d82 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2171,7 +2171,7 @@ impl Project { }; let buffer_file = buffer.read(cx).file().cloned(); let settings = - language_settings(Some(new_language), buffer_file.as_ref(), cx).clone(); + language_settings(Some(new_language), buffer_file.as_ref(), cx).into_owned(); let buffer_file = File::from_dyn(buffer_file.as_ref()); let worktree = buffer_file.as_ref().map(|f| f.worktree_id(cx)); if let Some(prettier_plugins) = diff --git a/crates/remote_server/src/remote_editing_tests.rs b/crates/remote_server/src/remote_editing_tests.rs index b7fc56d3c60262..42e5e93475f454 100644 --- a/crates/remote_server/src/remote_editing_tests.rs +++ b/crates/remote_server/src/remote_editing_tests.rs @@ -203,7 +203,7 @@ async fn test_remote_settings(cx: &mut TestAppContext, server_cx: &mut TestAppCo server_cx.read(|cx| { assert_eq!( AllLanguageSettings::get_global(cx) - .language(Some(&"Rust".into())) + .language(None, Some(&"Rust".into()), cx) .language_servers, ["custom-rust-analyzer".into()] ) @@ -262,7 +262,7 @@ async fn test_remote_settings(cx: &mut TestAppContext, server_cx: &mut TestAppCo }), cx ) - .language(Some(&"Rust".into())) + .language(None, Some(&"Rust".into()), cx) .language_servers, ["override-rust-analyzer".into()] ) @@ -272,7 +272,7 @@ async fn test_remote_settings(cx: &mut TestAppContext, server_cx: &mut TestAppCo let file = buffer.read(cx).file(); assert_eq!( all_language_settings(file, cx) - .language(Some(&"Rust".into())) + .language(None, Some(&"Rust".into()), cx) .language_servers, ["override-rust-analyzer".into()] ) @@ -355,7 +355,7 @@ async fn test_remote_lsp(cx: &mut TestAppContext, server_cx: &mut TestAppContext let file = buffer.read(cx).file(); assert_eq!( all_language_settings(file, cx) - .language(Some(&"Rust".into())) + .language(None, Some(&"Rust".into()), cx) .language_servers, ["rust-analyzer".into()] ) diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs index 1e57b4fc422dd0..5337a94c8e5a17 100644 --- a/crates/settings/src/settings_store.rs +++ b/crates/settings/src/settings_store.rs @@ -184,6 +184,8 @@ pub enum SoftWrap { EditorWidth, /// Soft wrap lines at the preferred line length PreferredLineLength, + /// Soft wrap line at the preferred line length or the editor width (whichever is smaller) + Bounded, } /// A set of strongly-typed setting values defined via multiple JSON files. @@ -208,7 +210,7 @@ pub struct SettingsStore { #[derive(Debug, Eq, PartialEq, Hash)] struct EditorConfigKey { language_name: Option, - worktree_id: usize, + worktree_id: WorktreeId, editorconfig_chain: SmallVec<[PathBuf; 3]>, } @@ -838,7 +840,7 @@ impl SettingsStore { pub fn editorconfig_settings( &self, - worktree_id: usize, + worktree_id: WorktreeId, language_name: Option, file_abs_path: &Path, ) -> Option {