Skip to content

Commit

Permalink
fix small indentation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri committed Nov 22, 2024
1 parent f102da2 commit 79b8c31
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler-core/src/language_server/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,7 @@ impl<'a> TurnIntoUse<'a> {
// want to move the entire body of the anonymous function to this level.
let use_nesting_level = self
.line_numbers
.src_span_to_lsp_range(called_function_span)
.src_span_to_lsp_range(call_span)
.start
.character;
let indentation = " ".repeat(use_nesting_level as usize);
Expand Down
22 changes: 21 additions & 1 deletion compiler-core/src/language_server/tests/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3568,7 +3568,9 @@ fn turn_call_into_use_starts_from_innermost_function() {
let src = r#"
pub fn main() {
wibble(10, 20, fn(a) {
wibble(30, 40, fn(b) { a + b })
wibble(30, 40, fn(b) {
a + b
})
})
}
Expand Down Expand Up @@ -3603,3 +3605,21 @@ fn wibble(m, n, f) {
find_position_of("use").to_selection(),
);
}

#[test]
fn turn_call_into_use_with_module_function() {
let src = r#"
import other
pub fn main() {
other.wibble(10, 20, fn(a) {
todo
a + b
})
}
"#;
assert_code_action!(
TURN_INTO_USE_EXPRESSION,
TestProject::for_source(src).add_module("other", "pub fn wibble(n, m, f) { todo }"),
find_position_of("wibble").to_selection(),
);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
source: compiler-core/src/language_server/tests/action.rs
expression: "\npub fn main() {\n wibble(10, 20, fn(a) {\n wibble(30, 40, fn(b) { a + b })\n })\n}\n\nfn wibble(m, n, f) {\n f(1)\n}\n"
expression: "\npub fn main() {\n wibble(10, 20, fn(a) {\n wibble(30, 40, fn(b) {\n a + b\n })\n })\n}\n\nfn wibble(m, n, f) {\n f(1)\n}\n"
---
----- BEFORE ACTION

pub fn main() {
wibble(10, 20, fn(a) {
wibble(30, 40, fn(b) { a + b })
▔▔▔▔↑
wibble(30, 40, fn(b) {
▔▔▔▔↑
a + b
})
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: compiler-core/src/language_server/tests/action.rs
expression: "\nimport other\npub fn main() {\n other.wibble(10, 20, fn(a) {\n todo\n a + b\n })\n}\n"
---
----- BEFORE ACTION

import other
pub fn main() {
other.wibble(10, 20, fn(a) {
todo
a + b
})
}


----- AFTER ACTION

import other
pub fn main() {
use a <- other.wibble(10, 20)
todo
a + b
}

0 comments on commit 79b8c31

Please sign in to comment.