Remove indent_size
parameter from Buffer::edit_with_autoindent
Instead, compute the indent size by reading the settings inside that method. Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
b1b252ee45
commit
cdf6ae25bb
8 changed files with 77 additions and 104 deletions
|
@ -249,34 +249,37 @@ impl super::LspAdapter for CLspAdapter {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpui::MutableAppContext;
|
||||
use language::{Buffer, IndentSize};
|
||||
use language::Buffer;
|
||||
use settings::Settings;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[gpui::test]
|
||||
fn test_c_autoindent(cx: &mut MutableAppContext) {
|
||||
cx.foreground().set_block_on_ticks(usize::MAX..=usize::MAX);
|
||||
let mut settings = Settings::test(cx);
|
||||
settings.editor_overrides.tab_size = Some(2.try_into().unwrap());
|
||||
cx.set_global(settings);
|
||||
let language = crate::languages::language("c", tree_sitter_c::language(), None);
|
||||
|
||||
cx.add_model(|cx| {
|
||||
let mut buffer = Buffer::new(0, "", cx).with_language(Arc::new(language), cx);
|
||||
let size = IndentSize::spaces(2);
|
||||
|
||||
// empty function
|
||||
buffer.edit_with_autoindent([(0..0, "int main() {}")], size, cx);
|
||||
buffer.edit_with_autoindent([(0..0, "int main() {}")], cx);
|
||||
|
||||
// indent inside braces
|
||||
let ix = buffer.len() - 1;
|
||||
buffer.edit_with_autoindent([(ix..ix, "\n\n")], size, cx);
|
||||
buffer.edit_with_autoindent([(ix..ix, "\n\n")], cx);
|
||||
assert_eq!(buffer.text(), "int main() {\n \n}");
|
||||
|
||||
// indent body of single-statement if statement
|
||||
let ix = buffer.len() - 2;
|
||||
buffer.edit_with_autoindent([(ix..ix, "if (a)\nb;")], size, cx);
|
||||
buffer.edit_with_autoindent([(ix..ix, "if (a)\nb;")], cx);
|
||||
assert_eq!(buffer.text(), "int main() {\n if (a)\n b;\n}");
|
||||
|
||||
// indent inside field expression
|
||||
let ix = buffer.len() - 3;
|
||||
buffer.edit_with_autoindent([(ix..ix, "\n.c")], size, cx);
|
||||
buffer.edit_with_autoindent([(ix..ix, "\n.c")], cx);
|
||||
assert_eq!(buffer.text(), "int main() {\n if (a)\n b\n .c;\n}");
|
||||
|
||||
buffer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue