diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index f04e9109c..77aeca669 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | use std::fmt::Write; | 2 | use std::fmt::Write; |
3 | 3 | ||
4 | use ra_db::{SourceDatabase, salsa::Database}; | 4 | use ra_db::{SourceDatabase, salsa::Database, FilePosition}; |
5 | use ra_syntax::ast::{self, AstNode}; | 5 | use ra_syntax::{algo, ast::{self, AstNode}}; |
6 | use test_utils::covers; | 6 | use test_utils::covers; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
@@ -946,6 +946,43 @@ fn test<R>(query_response: Canonical<QueryResponse<R>>) { | |||
946 | ); | 946 | ); |
947 | } | 947 | } |
948 | 948 | ||
949 | #[test] | ||
950 | fn cross_crate_associated_method_call() { | ||
951 | let (mut db, pos) = MockDatabase::with_position( | ||
952 | r#" | ||
953 | //- /main.rs | ||
954 | fn test() { | ||
955 | let x = other_crate::foo::S::thing(); | ||
956 | x<|>; | ||
957 | } | ||
958 | |||
959 | //- /lib.rs | ||
960 | mod foo { | ||
961 | struct S; | ||
962 | impl S { | ||
963 | fn thing() -> i128 {} | ||
964 | } | ||
965 | } | ||
966 | "#, | ||
967 | ); | ||
968 | db.set_crate_graph_from_fixture(crate_graph! { | ||
969 | "main": ("/main.rs", ["other_crate"]), | ||
970 | "other_crate": ("/lib.rs", []), | ||
971 | }); | ||
972 | assert_eq!("i128", type_at_pos(&db, pos)); | ||
973 | } | ||
974 | |||
975 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | ||
976 | let func = source_binder::function_from_position(db, pos).unwrap(); | ||
977 | let body_syntax_mapping = func.body_syntax_mapping(db); | ||
978 | let inference_result = func.infer(db); | ||
979 | let (_, syntax) = func.source(db); | ||
980 | let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap(); | ||
981 | let expr = body_syntax_mapping.node_expr(node).unwrap(); | ||
982 | let ty = &inference_result[expr]; | ||
983 | ty.to_string() | ||
984 | } | ||
985 | |||
949 | fn infer(content: &str) -> String { | 986 | fn infer(content: &str) -> String { |
950 | let (db, _, file_id) = MockDatabase::with_single_file(content); | 987 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
951 | let source_file = db.parse(file_id); | 988 | let source_file = db.parse(file_id); |