mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Add a test for self field completion
Needed to add a default crate graph in the analysis for that.
This commit is contained in:
parent
6ab0e292d2
commit
0ad13b9477
3 changed files with 25 additions and 5 deletions
|
@ -72,6 +72,21 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_struct_field_completion_self() {
|
||||||
|
check_ref_completion(
|
||||||
|
r"
|
||||||
|
struct A { the_field: u32 }
|
||||||
|
impl A {
|
||||||
|
fn foo(self) {
|
||||||
|
self.<|>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r#"the_field"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_struct_field_completion_for_method_call() {
|
fn test_no_struct_field_completion_for_method_call() {
|
||||||
check_ref_completion(
|
check_ref_completion(
|
||||||
|
|
|
@ -4,7 +4,7 @@ use relative_path::RelativePathBuf;
|
||||||
use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER};
|
use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER};
|
||||||
use ra_db::mock::FileMap;
|
use ra_db::mock::FileMap;
|
||||||
|
|
||||||
use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, FileRange, SourceRootId};
|
use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId};
|
||||||
|
|
||||||
/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
|
/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
|
||||||
/// from a set of in-memory files.
|
/// from a set of in-memory files.
|
||||||
|
@ -87,12 +87,17 @@ impl MockAnalysis {
|
||||||
let source_root = SourceRootId(0);
|
let source_root = SourceRootId(0);
|
||||||
let mut change = AnalysisChange::new();
|
let mut change = AnalysisChange::new();
|
||||||
change.add_root(source_root, true);
|
change.add_root(source_root, true);
|
||||||
|
let mut crate_graph = CrateGraph::default();
|
||||||
for (path, contents) in self.files.into_iter() {
|
for (path, contents) in self.files.into_iter() {
|
||||||
assert!(path.starts_with('/'));
|
assert!(path.starts_with('/'));
|
||||||
let path = RelativePathBuf::from_path(&path[1..]).unwrap();
|
let path = RelativePathBuf::from_path(&path[1..]).unwrap();
|
||||||
let file_id = file_map.add(path.clone());
|
let file_id = file_map.add(path.clone());
|
||||||
|
if path == "/lib.rs" || path == "/main.rs" {
|
||||||
|
crate_graph.add_crate_root(file_id);
|
||||||
|
}
|
||||||
change.add_file(source_root, file_id, path, Arc::new(contents));
|
change.add_file(source_root, file_id, path, Arc::new(contents));
|
||||||
}
|
}
|
||||||
|
change.set_crate_graph(crate_graph);
|
||||||
// change.set_file_resolver(Arc::new(file_map));
|
// change.set_file_resolver(Arc::new(file_map));
|
||||||
host.apply_change(change);
|
host.apply_change(change);
|
||||||
host
|
host
|
||||||
|
|
|
@ -138,14 +138,14 @@ fn test_resolve_parent_module_for_inline() {
|
||||||
fn test_resolve_crate_root() {
|
fn test_resolve_crate_root() {
|
||||||
let mock = MockAnalysis::with_files(
|
let mock = MockAnalysis::with_files(
|
||||||
"
|
"
|
||||||
//- /lib.rs
|
//- /bar.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
//- /foo.rs
|
//- /bar/foo.rs
|
||||||
// emtpy <|>
|
// emtpy <|>
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
let root_file = mock.id_of("/lib.rs");
|
let root_file = mock.id_of("/bar.rs");
|
||||||
let mod_file = mock.id_of("/foo.rs");
|
let mod_file = mock.id_of("/bar/foo.rs");
|
||||||
let mut host = mock.analysis_host();
|
let mut host = mock.analysis_host();
|
||||||
assert!(host.analysis().crate_for(mod_file).unwrap().is_empty());
|
assert!(host.analysis().crate_for(mod_file).unwrap().is_empty());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue