From 3a9934e2c3280864877a90c5ced777bad898d73a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 10 Feb 2019 22:34:29 +0100 Subject: Keep track of crate edition --- crates/ra_ide_api/src/lib.rs | 3 ++- crates/ra_ide_api/src/mock_analysis.rs | 6 +++--- crates/ra_ide_api/tests/test/main.rs | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index de3ec4e0a..d77a56ce8 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -62,7 +62,8 @@ pub use ra_ide_api_light::{ LineIndex, LineCol, translate_offset_with_edit, }; pub use ra_db::{ - Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId + Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, + Edition }; pub use hir::Documentation; diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs index 017ac5de3..550d69641 100644 --- a/crates/ra_ide_api/src/mock_analysis.rs +++ b/crates/ra_ide_api/src/mock_analysis.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use relative_path::RelativePathBuf; use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; -use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId}; +use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId, Edition::Edition2018}; /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis /// from a set of in-memory files. @@ -89,9 +89,9 @@ impl MockAnalysis { let path = RelativePathBuf::from_path(&path[1..]).unwrap(); let file_id = FileId(i as u32 + 1); if path == "/lib.rs" || path == "/main.rs" { - root_crate = Some(crate_graph.add_crate_root(file_id)); + root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018)); } else if path.ends_with("/lib.rs") { - let other_crate = crate_graph.add_crate_root(file_id); + let other_crate = crate_graph.add_crate_root(file_id, Edition2018); let crate_name = path.parent().unwrap().file_name().unwrap(); if let Some(root_crate) = root_crate { crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap(); diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs index 4cf842452..0526f7584 100644 --- a/crates/ra_ide_api/tests/test/main.rs +++ b/crates/ra_ide_api/tests/test/main.rs @@ -1,7 +1,7 @@ use insta::assert_debug_snapshot_matches; use ra_ide_api::{ mock_analysis::{single_file, single_file_with_position, MockAnalysis}, - AnalysisChange, CrateGraph, FileId, Query, NavigationTarget, + AnalysisChange, CrateGraph, Edition::Edition2018, FileId, Query, NavigationTarget }; use ra_syntax::{TextRange, SmolStr}; @@ -36,7 +36,7 @@ fn test_resolve_crate_root() { assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); let mut crate_graph = CrateGraph::default(); - let crate_id = crate_graph.add_crate_root(root_file); + let crate_id = crate_graph.add_crate_root(root_file, Edition2018); let mut change = AnalysisChange::new(); change.set_crate_graph(crate_graph); host.apply_change(change); -- cgit v1.2.3 From 911e32bca9b73e66eceb6bbee3768c82e94597d5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 13 Feb 2019 20:53:42 +0100 Subject: Complete names from prelude --- crates/ra_ide_api/src/completion/complete_scope.rs | 21 ++++++++- .../completion_item__completes_prelude.snap | 54 ++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__completes_prelude.snap (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 445788407..eeaf26d93 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -4,7 +4,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_trivial_path { return; } - let names = ctx.resolver.all_names(); + let names = ctx.resolver.all_names(ctx.db); names.into_iter().for_each(|(name, res)| { CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) @@ -165,4 +165,23 @@ mod tests { fn completes_self_in_methods() { check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }") } + + #[test] + fn completes_prelude() { + check_reference_completion( + "completes_prelude", + " + //- /main.rs + fn foo() { let x: <|> } + + //- /std/lib.rs + #[prelude_import] + use prelude::*; + + mod prelude { + struct Option; + } + ", + ); + } } diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__completes_prelude.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__completes_prelude.snap new file mode 100644 index 000000000..2b5a1a8ea --- /dev/null +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__completes_prelude.snap @@ -0,0 +1,54 @@ +--- +created: "2019-02-13T19:52:43.734834624Z" +creator: insta@0.6.2 +source: crates/ra_ide_api/src/completion/completion_item.rs +expression: kind_completions +--- +[ + CompletionItem { + completion_kind: Reference, + label: "Option", + kind: Some( + Struct + ), + detail: None, + documentation: None, + lookup: None, + insert_text: None, + insert_text_format: PlainText, + source_range: [18; 18), + text_edit: None + }, + CompletionItem { + completion_kind: Reference, + label: "foo", + kind: Some( + Function + ), + detail: Some( + "fn foo()" + ), + documentation: None, + lookup: None, + insert_text: Some( + "foo()$0" + ), + insert_text_format: Snippet, + source_range: [18; 18), + text_edit: None + }, + CompletionItem { + completion_kind: Reference, + label: "std", + kind: Some( + Module + ), + detail: None, + documentation: None, + lookup: None, + insert_text: None, + insert_text_format: PlainText, + source_range: [18; 18), + text_edit: None + } +] -- cgit v1.2.3