Skip to content

Commit 6df969f

Browse files
committed
the offset used for the completion cursor should always be relative to the original file and not to the marco file
1 parent fbf8e12 commit 6df969f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

crates/hir/src/source_analyzer.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ impl SourceAnalyzer {
6767
let scopes = db.expr_scopes(def);
6868
let scope = match offset {
6969
None => scope_for(&scopes, &source_map, node),
70-
Some(offset) => scope_for_offset(db, &scopes, &source_map, node.with_value(offset)),
70+
Some(offset) => {
71+
let file_id = node.file_id.original_file(db.upcast());
72+
scope_for_offset(db, &scopes, &source_map, InFile::new(file_id.into(), offset))
73+
}
7174
};
7275
let resolver = resolver_for_scope(db.upcast(), def, scope);
7376
SourceAnalyzer {
@@ -88,7 +91,10 @@ impl SourceAnalyzer {
8891
let scopes = db.expr_scopes(def);
8992
let scope = match offset {
9093
None => scope_for(&scopes, &source_map, node),
91-
Some(offset) => scope_for_offset(db, &scopes, &source_map, node.with_value(offset)),
94+
Some(offset) => {
95+
let file_id = node.file_id.original_file(db.upcast());
96+
scope_for_offset(db, &scopes, &source_map, InFile::new(file_id.into(), offset))
97+
}
9298
};
9399
let resolver = resolver_for_scope(db.upcast(), def, scope);
94100
SourceAnalyzer { resolver, def: Some((def, body, source_map)), infer: None, file_id }

crates/ide-completion/src/tests/expression.rs

+1
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ fn quux(x: i32) {
513513
",
514514
expect![[r#"
515515
fn quux(…) fn(i32)
516+
lc x i32
516517
ma m!(…) macro_rules! m
517518
bt u32
518519
kw crate::

crates/ide-completion/src/tests/type_pos.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ fn x<'lt, T, const C: usize>() -> $0
9090
}
9191

9292
#[test]
93-
fn fn_return_type2() {
93+
fn fn_return_type_no_local_items() {
9494
check(
9595
r#"
9696
fn foo() -> B$0 {
9797
struct Bar;
98+
enum Baz {}
99+
union Bax {
100+
i: i32,
101+
f: f32
102+
}
98103
}
99104
"#,
100105
expect![[r#"

0 commit comments

Comments
 (0)