Skip to content

Commit b9ed09d

Browse files
giacomocavalierilpil
authored andcommitted
only suggest the "inline variable" code action when hovering the variable
Previously the language server would suggest it even if someone was selecting multiple lines including variables.
1 parent d1c7cca commit b9ed09d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696

9797
([Giacomo Cavalieri](https://github.com/giacomocavalieri))
9898

99+
- The "inline variable" code action is now only suggested when hovering over the
100+
relevant variable.
101+
([Giacomo Cavalieri](https://github.com/giacomocavalieri))
102+
99103
### Formatter
100104

101105
### Bug fixes

compiler-core/src/language_server/code_action.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5983,7 +5983,7 @@ impl<'ast> ast::visit::Visit<'ast> for InlineVariable<'ast> {
59835983
) {
59845984
let range = self.edits.src_span_to_lsp_range(*location);
59855985

5986-
if !overlaps(self.params.range, range) {
5986+
if !within(self.params.range, range) {
59875987
return;
59885988
}
59895989

@@ -6025,7 +6025,7 @@ impl<'ast> ast::visit::Visit<'ast> for InlineVariable<'ast> {
60256025

60266026
let range = self.edits.src_span_to_lsp_range(*location);
60276027

6028-
if !overlaps(self.params.range, range) {
6028+
if !within(self.params.range, range) {
60296029
return;
60306030
}
60316031

compiler-core/src/language_server/tests/action.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8933,6 +8933,23 @@ pub fn main() {
89338933
);
89348934
}
89358935

8936+
#[test]
8937+
fn no_inline_variable_action_when_spanning_multiple_items() {
8938+
assert_no_code_actions!(
8939+
INLINE_VARIABLE,
8940+
"
8941+
pub fn main(x: Int, y: Int) {
8942+
let a = 1
8943+
let b = 2
8944+
main(a, b)
8945+
}
8946+
",
8947+
find_position_of("main")
8948+
.nth_occurrence(2)
8949+
.select_until(find_position_of(")").nth_occurrence(2))
8950+
);
8951+
}
8952+
89368953
#[test]
89378954
fn no_inline_variable_action_for_use_pattern() {
89388955
assert_no_code_actions!(

0 commit comments

Comments
 (0)