aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/completion/presentation.rs6
-rw-r--r--crates/ra_ide/src/extend_selection.rs2
-rw-r--r--crates/ra_ide/src/goto_definition.rs28
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html6
-rw-r--r--crates/ra_ide/src/snapshots/rainbow_highlighting.html6
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs29
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs2
7 files changed, 52 insertions, 27 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index bb12a1bdc..f8dac1d54 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -161,6 +161,12 @@ impl Completions {
161 name: Option<String>, 161 name: Option<String>,
162 macro_: hir::MacroDef, 162 macro_: hir::MacroDef,
163 ) { 163 ) {
164 // FIXME: Currently proc-macro do not have ast-node,
165 // such that it does not have source
166 if macro_.is_proc_macro() {
167 return;
168 }
169
164 let name = match name { 170 let name = match name {
165 Some(it) => it, 171 Some(it) => it,
166 None => return, 172 None => return,
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index f5a063351..753d2ef6a 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -96,7 +96,7 @@ fn try_extend_selection(
96 return Some(node.text_range()); 96 return Some(node.text_range());
97 } 97 }
98 98
99 let node = shallowest_node(&node.into()); 99 let node = shallowest_node(&node);
100 100
101 if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) { 101 if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) {
102 if let Some(range) = extend_list_item(&node) { 102 if let Some(range) = extend_list_item(&node) {
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index 8aed94d16..9998ca5a3 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -62,10 +62,9 @@ pub(crate) enum ReferenceResult {
62 62
63impl ReferenceResult { 63impl ReferenceResult {
64 fn to_vec(self) -> Vec<NavigationTarget> { 64 fn to_vec(self) -> Vec<NavigationTarget> {
65 use self::ReferenceResult::*;
66 match self { 65 match self {
67 Exact(target) => vec![target], 66 ReferenceResult::Exact(target) => vec![target],
68 Approximate(vec) => vec, 67 ReferenceResult::Approximate(vec) => vec,
69 } 68 }
70 } 69 }
71} 70}
@@ -74,8 +73,6 @@ pub(crate) fn reference_definition(
74 sema: &Semantics<RootDatabase>, 73 sema: &Semantics<RootDatabase>,
75 name_ref: &ast::NameRef, 74 name_ref: &ast::NameRef,
76) -> ReferenceResult { 75) -> ReferenceResult {
77 use self::ReferenceResult::*;
78
79 let name_kind = classify_name_ref(sema, name_ref); 76 let name_kind = classify_name_ref(sema, name_ref);
80 if let Some(def) = name_kind { 77 if let Some(def) = name_kind {
81 let def = def.definition(); 78 let def = def.definition();
@@ -91,7 +88,7 @@ pub(crate) fn reference_definition(
91 .into_iter() 88 .into_iter()
92 .map(|s| s.to_nav(sema.db)) 89 .map(|s| s.to_nav(sema.db))
93 .collect(); 90 .collect();
94 Approximate(navs) 91 ReferenceResult::Approximate(navs)
95} 92}
96 93
97#[cfg(test)] 94#[cfg(test)]
@@ -399,6 +396,25 @@ mod tests {
399 } 396 }
400 397
401 #[test] 398 #[test]
399 fn goto_def_for_record_pat_fields() {
400 covers!(ra_ide_db::goto_def_for_record_field_pats);
401 check_goto(
402 r"
403 //- /lib.rs
404 struct Foo {
405 spam: u32,
406 }
407
408 fn bar(foo: Foo) -> Foo {
409 let Foo { spam<|>: _, } = foo
410 }
411 ",
412 "spam RECORD_FIELD_DEF FileId(1) [17; 26) [17; 21)",
413 "spam: u32|spam",
414 );
415 }
416
417 #[test]
402 fn goto_def_for_record_fields_macros() { 418 fn goto_def_for_record_fields_macros() {
403 check_goto( 419 check_goto(
404 r" 420 r"
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
index 214dcbb62..ccb1fc751 100644
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ b/crates/ra_ide/src/snapshots/highlighting.html
@@ -50,12 +50,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
50<span class="keyword">fn</span> <span class="function declaration">main</span>() { 50<span class="keyword">fn</span> <span class="function declaration">main</span>() {
51 <span class="macro">println!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>); 51 <span class="macro">println!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
52 52
53 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">vec</span> = Vec::new(); 53 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">vec</span> = <span class="unresolved_reference">Vec</span>::<span class="unresolved_reference">new</span>();
54 <span class="keyword control">if</span> <span class="keyword">true</span> { 54 <span class="keyword control">if</span> <span class="keyword">true</span> {
55 <span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>; 55 <span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>;
56 <span class="variable mutable">vec</span>.push(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> }); 56 <span class="variable mutable">vec</span>.<span class="unresolved_reference">push</span>(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
57 } 57 }
58 <span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.set_len(<span class="numeric_literal">0</span>); } 58 <span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.<span class="unresolved_reference">set_len</span>(<span class="numeric_literal">0</span>); }
59 59
60 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>; 60 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>;
61 <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>; 61 <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
index dddbfc0dd..3df82c45f 100644
--- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html
+++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
@@ -28,11 +28,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
28</style> 28</style>
29<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span>() { 29<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span>() {
30 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>; 30 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
31 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string(); 31 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.<span class="unresolved_reference">to_string</span>();
32 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string(); 32 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.<span class="unresolved_reference">to_string</span>();
33 33
34 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string_literal">"other color please!"</span>; 34 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string_literal">"other color please!"</span>;
35 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> = <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span>.to_string(); 35 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> = <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span>.<span class="unresolved_reference">to_string</span>();
36} 36}
37 37
38<span class="keyword">fn</span> <span class="function declaration">bar</span>() { 38<span class="keyword">fn</span> <span class="function declaration">bar</span>() {
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 7b15b82bd..93d502875 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -239,20 +239,21 @@ fn highlight_element(
239 NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => return None, 239 NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => return None,
240 NAME_REF => { 240 NAME_REF => {
241 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); 241 let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
242 let name_kind = classify_name_ref(sema, &name_ref)?; 242 match classify_name_ref(sema, &name_ref) {
243 243 Some(name_kind) => match name_kind {
244 match name_kind { 244 NameRefClass::Definition(def) => {
245 NameRefClass::Definition(def) => { 245 if let Definition::Local(local) = &def {
246 if let Definition::Local(local) = &def { 246 if let Some(name) = local.name(db) {
247 if let Some(name) = local.name(db) { 247 let shadow_count =
248 let shadow_count = 248 bindings_shadow_count.entry(name.clone()).or_default();
249 bindings_shadow_count.entry(name.clone()).or_default(); 249 binding_hash = Some(calc_binding_hash(&name, *shadow_count))
250 binding_hash = Some(calc_binding_hash(&name, *shadow_count)) 250 }
251 } 251 };
252 }; 252 highlight_name(db, def)
253 highlight_name(db, def) 253 }
254 } 254 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
255 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), 255 },
256 None => HighlightTag::UnresolvedReference.into(),
256 } 257 }
257 } 258 }
258 259
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index e8b138e1a..f2c421654 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -38,6 +38,7 @@ pub enum HighlightTag {
38 TypeParam, 38 TypeParam,
39 Union, 39 Union,
40 Local, 40 Local,
41 UnresolvedReference,
41} 42}
42 43
43#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 44#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -79,6 +80,7 @@ impl HighlightTag {
79 HighlightTag::TypeParam => "type_param", 80 HighlightTag::TypeParam => "type_param",
80 HighlightTag::Union => "union", 81 HighlightTag::Union => "union",
81 HighlightTag::Local => "variable", 82 HighlightTag::Local => "variable",
83 HighlightTag::UnresolvedReference => "unresolved_reference",
82 } 84 }
83 } 85 }
84} 86}