aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-10 08:46:43 +0100
committerAleksey Kladov <[email protected]>2019-04-10 08:48:15 +0100
commit10726fdb65fda9144a5f9201272d065a268fc1b7 (patch)
treef5640991cbf0db2bfdad29b911435827cadfb4a8 /crates/ra_ide_api/src
parent1cd184d6539478c7e54c92835902921976dce5d1 (diff)
type-safer source-map for bindings
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs8
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs1
-rw-r--r--crates/ra_ide_api/src/references.rs11
3 files changed, 11 insertions, 9 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index e54fe7b7e..7e47fa6bd 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -1,4 +1,4 @@
1use hir::Resolution; 1use hir::{Resolution, Either};
2use ra_syntax::AstNode; 2use ra_syntax::AstNode;
3use test_utils::tested_by; 3use test_utils::tested_by;
4 4
@@ -19,10 +19,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
19 for (name, res) in module_scope.entries() { 19 for (name, res) in module_scope.entries() {
20 if Some(module) == ctx.module { 20 if Some(module) == ctx.module {
21 if let Some(import) = res.import { 21 if let Some(import) = res.import {
22 if let hir::ImportSource::UseTree(tree) = 22 if let Either::A(use_tree) = module.import_source(ctx.db, import) {
23 module.import_source(ctx.db, import) 23 if use_tree.syntax().range().contains_inclusive(ctx.offset) {
24 {
25 if tree.syntax().range().contains_inclusive(ctx.offset) {
26 // for `use self::foo<|>`, don't suggest `foo` as a completion 24 // for `use self::foo<|>`, don't suggest `foo` as a completion
27 tested_by!(dont_complete_current_use); 25 tested_by!(dont_complete_current_use);
28 continue; 26 continue;
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 660b43cfa..60c1f5085 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -113,6 +113,7 @@ pub(crate) fn reference_definition(
113 let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping"); 113 let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping");
114 let name = 114 let name =
115 path.as_ident().cloned().expect("local binding from a multi-segment path"); 115 path.as_ident().cloned().expect("local binding from a multi-segment path");
116 let ptr = ptr.either(|it| it.into(), |it| it.into());
116 let nav = NavigationTarget::from_scope_entry(file_id, name, ptr); 117 let nav = NavigationTarget::from_scope_entry(file_id, name, ptr);
117 return Exact(nav); 118 return Exact(nav);
118 } 119 }
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index 20bbf11a3..3e30e047c 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -1,5 +1,5 @@
1use relative_path::{RelativePath, RelativePathBuf}; 1use relative_path::{RelativePath, RelativePathBuf};
2use hir::{ModuleSource, source_binder}; 2use hir::{ModuleSource, source_binder, Either};
3use ra_db::{SourceDatabase}; 3use ra_db::{SourceDatabase};
4use ra_syntax::{ 4use ra_syntax::{
5 AstNode, SyntaxNode, SourceFile, 5 AstNode, SyntaxNode, SourceFile,
@@ -89,9 +89,12 @@ pub(crate) fn find_all_refs(
89 source_binder::function_from_child_node(db, position.file_id, name_ref.syntax())?; 89 source_binder::function_from_child_node(db, position.file_id, name_ref.syntax())?;
90 let scope = descr.scopes(db); 90 let scope = descr.scopes(db);
91 let resolved = scope.resolve_local_name(name_ref)?; 91 let resolved = scope.resolve_local_name(name_ref)?;
92 let resolved = resolved.ptr().to_node(source_file); 92 if let Either::A(ptr) = resolved.ptr() {
93 let binding = find_node_at_offset::<ast::BindPat>(syntax, resolved.range().end())?; 93 if let ast::PatKind::BindPat(binding) = ptr.to_node(source_file).kind() {
94 Some((binding, descr)) 94 return Some((binding, descr));
95 }
96 }
97 None
95 } 98 }
96} 99}
97 100