Skip to content

Commit

Permalink
Post-rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneToIgnore committed Sep 17, 2024
1 parent ae9b3df commit ff97c84
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
)
Expand Down
10 changes: 5 additions & 5 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
)
Expand Down
3 changes: 2 additions & 1 deletion crates/extension/src/wasm_host/wit/since_v0_2_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})?)
Expand Down
11 changes: 6 additions & 5 deletions crates/language/src/language_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down Expand Up @@ -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> {
Expand All @@ -801,7 +802,7 @@ impl AllLanguageSettings {
abs_path_in_worktree.and_then(|(worktree_id, file_abs_path)| {
cx.global::<SettingsStore>().editorconfig_settings(
worktree_id,
language_name.map(ToOwned::to_owned),
language_name.map(|name| name.0.to_string()),
&file_abs_path,
)
});
Expand Down Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/languages/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl ContextProvider for RustContextProvider {
) -> Option<TaskTemplates> {
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,
);
Expand Down
22 changes: 18 additions & 4 deletions crates/project/src/lsp_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use smol::channel::Sender;
use snippet::Snippet;
use std::{
any::Any,
borrow::Cow,
cmp::Ordering,
convert::TryInto,
ffi::OsStr,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1172,7 +1178,7 @@ impl LspStore {
cx: &mut ModelContext<Self>,
) -> Task<Result<Option<Transaction>>> {
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,
Expand Down Expand Up @@ -4450,9 +4456,17 @@ impl LspStore {
worktree: &'a Model<Worktree>,
language: &LanguageName,
cx: &'a mut ModelContext<Self>,
) -> &'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(
Expand Down
2 changes: 1 addition & 1 deletion crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
8 changes: 4 additions & 4 deletions crates/remote_server/src/remote_editing_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
)
Expand Down Expand Up @@ -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()]
)
Expand All @@ -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()]
)
Expand Down Expand Up @@ -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()]
)
Expand Down
6 changes: 4 additions & 2 deletions crates/settings/src/settings_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -208,7 +210,7 @@ pub struct SettingsStore {
#[derive(Debug, Eq, PartialEq, Hash)]
struct EditorConfigKey {
language_name: Option<String>,
worktree_id: usize,
worktree_id: WorktreeId,
editorconfig_chain: SmallVec<[PathBuf; 3]>,
}

Expand Down Expand Up @@ -838,7 +840,7 @@ impl SettingsStore {

pub fn editorconfig_settings(
&self,
worktree_id: usize,
worktree_id: WorktreeId,
language_name: Option<String>,
file_abs_path: &Path,
) -> Option<EditorConfigContent> {
Expand Down

0 comments on commit ff97c84

Please sign in to comment.