the offset used for the completion cursor should always be relative to the original file and not to the marco file

This commit is contained in:
XFFXFF 2022-06-16 16:43:08 +08:00
parent fbf8e12234
commit 6df969f5f4
3 changed files with 15 additions and 3 deletions

View file

@ -67,7 +67,10 @@ impl SourceAnalyzer {
let scopes = db.expr_scopes(def); let scopes = db.expr_scopes(def);
let scope = match offset { let scope = match offset {
None => scope_for(&scopes, &source_map, node), None => scope_for(&scopes, &source_map, node),
Some(offset) => scope_for_offset(db, &scopes, &source_map, node.with_value(offset)), Some(offset) => {
let file_id = node.file_id.original_file(db.upcast());
scope_for_offset(db, &scopes, &source_map, InFile::new(file_id.into(), offset))
}
}; };
let resolver = resolver_for_scope(db.upcast(), def, scope); let resolver = resolver_for_scope(db.upcast(), def, scope);
SourceAnalyzer { SourceAnalyzer {
@ -88,7 +91,10 @@ impl SourceAnalyzer {
let scopes = db.expr_scopes(def); let scopes = db.expr_scopes(def);
let scope = match offset { let scope = match offset {
None => scope_for(&scopes, &source_map, node), None => scope_for(&scopes, &source_map, node),
Some(offset) => scope_for_offset(db, &scopes, &source_map, node.with_value(offset)), Some(offset) => {
let file_id = node.file_id.original_file(db.upcast());
scope_for_offset(db, &scopes, &source_map, InFile::new(file_id.into(), offset))
}
}; };
let resolver = resolver_for_scope(db.upcast(), def, scope); let resolver = resolver_for_scope(db.upcast(), def, scope);
SourceAnalyzer { resolver, def: Some((def, body, source_map)), infer: None, file_id } SourceAnalyzer { resolver, def: Some((def, body, source_map)), infer: None, file_id }

View file

@ -513,6 +513,7 @@ fn quux(x: i32) {
", ",
expect![[r#" expect![[r#"
fn quux() fn(i32) fn quux() fn(i32)
lc x i32
ma m!() macro_rules! m ma m!() macro_rules! m
bt u32 bt u32
kw crate:: kw crate::

View file

@ -90,11 +90,16 @@ fn x<'lt, T, const C: usize>() -> $0
} }
#[test] #[test]
fn fn_return_type2() { fn fn_return_type_no_local_items() {
check( check(
r#" r#"
fn foo() -> B$0 { fn foo() -> B$0 {
struct Bar; struct Bar;
enum Baz {}
union Bax {
i: i32,
f: f32
}
} }
"#, "#,
expect![[r#" expect![[r#"