Skip to content

Commit 598bd2d

Browse files
committed
go to def and find all references support for import/export declarations
1 parent 2eb1cc8 commit 598bd2d

File tree

4 files changed

+81
-8
lines changed

4 files changed

+81
-8
lines changed

source/language_service/src/definition/tests.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,44 @@ fn notebook_local_from_later_cell() {
680680
("cell2", "let z = ↘x + 2;"),
681681
]);
682682
}
683+
684+
#[test]
685+
fn item_export() {
686+
assert_definition(
687+
r#"
688+
namespace Test {
689+
operation ◉Foo◉() : Unit {
690+
}
691+
export Fo↘o;
692+
}
693+
"#,
694+
);
695+
}
696+
697+
#[test]
698+
fn item_export_with_alias() {
699+
assert_definition(
700+
r#"
701+
namespace Test {
702+
operation ◉Foo◉() : Unit {
703+
}
704+
export Fo↘o as Bar;
705+
}
706+
"#,
707+
);
708+
}
709+
710+
#[test]
711+
fn item_import() {
712+
assert_definition(
713+
r#"
714+
namespace Test {
715+
operation ◉Foo◉() : Unit {
716+
}
717+
}
718+
namespace Other {
719+
import X, Test.Fo↘o;
720+
}
721+
"#,
722+
);
723+
}

source/language_service/src/name_locator.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::rc::Rc;
66

77
use crate::compilation::Compilation;
88
use qsc::ast::visit::{
9-
Visitor, walk_attr, walk_expr, walk_namespace, walk_pat, walk_ty, walk_ty_def,
9+
Visitor, walk_attr, walk_expr, walk_item, walk_namespace, walk_pat, walk_ty, walk_ty_def,
1010
};
1111
use qsc::ast::{FieldAccess, Idents, PathKind};
1212
use qsc::display::Lookup;
@@ -267,7 +267,7 @@ impl<'package, T: Handler<'package>> Visitor<'package> for Locator<'_, 'package,
267267
self.context.current_item_name = context_curr_item_name;
268268
}
269269
}
270-
_ => {}
270+
_ => walk_item(self, item),
271271
}
272272
self.context.current_item_doc = context;
273273
}
@@ -447,12 +447,13 @@ impl<'package, T: Handler<'package>> Visitor<'package> for Locator<'_, 'package,
447447
}
448448
}
449449
}
450-
// The path is a namespace path.
450+
// The path is not a field accessor.
451451
None => match self.compilation.get_res(path.id) {
452-
Some(resolve::Res::Item(item_id, _)) => {
452+
Some(res) if res.item_id().is_some() => {
453+
let item_id = res.item_id().expect("should have item id");
453454
let (item, _, resolved_item_id) = self
454455
.compilation
455-
.resolve_item_relative_to_user_package(item_id);
456+
.resolve_item_relative_to_user_package(&item_id);
456457
match &item.kind {
457458
hir::ItemKind::Callable(decl) => {
458459
self.inner.at_callable_ref(path, &resolved_item_id, decl);

source/language_service/src/references.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,11 @@ struct FindItemRefs<'a> {
343343
impl Visitor<'_> for FindItemRefs<'_> {
344344
fn visit_path(&mut self, path: &ast::Path) {
345345
let res = self.compilation.get_res(path.id);
346-
if let Some(resolve::Res::Item(item_id, _)) = res {
347-
if self.eq(item_id) {
348-
self.locations.push(path.name.span);
346+
if let Some(res) = res {
347+
if let Some(item_id) = res.item_id() {
348+
if self.eq(&item_id) {
349+
self.locations.push(path.name.span);
350+
}
349351
}
350352
}
351353
}

source/language_service/src/references/tests.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,3 +928,32 @@ fn notebook_local_reference() {
928928
("cell2", "let z = ◉↘x◉ + 2;"),
929929
]);
930930
}
931+
932+
#[test]
933+
fn export() {
934+
check_include_decl(
935+
r#"
936+
namespace Test {
937+
operation ◉Fo↘o◉() : Unit {
938+
}
939+
export ◉Foo◉ as Bar;
940+
}
941+
"#,
942+
);
943+
}
944+
945+
#[test]
946+
fn import() {
947+
check_include_decl(
948+
r#"
949+
namespace Test {
950+
operation ◉Fo↘o◉() : Unit {
951+
}
952+
}
953+
namespace Other {
954+
import X, Test.◉Foo◉;
955+
import ◉Foo◉ as Bar;
956+
}
957+
"#,
958+
);
959+
}

0 commit comments

Comments
 (0)