diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/display/navigation_target.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/extend_selection.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide/src/runnables.rs | 35 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/highlighting.html | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/rainbow_highlighting.html | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 29 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tags.rs | 2 |
9 files changed, 86 insertions, 30 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 55f75b15a..2189cef65 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -156,6 +156,12 @@ impl Completions { | |||
156 | name: Option<String>, | 156 | name: Option<String>, |
157 | macro_: hir::MacroDef, | 157 | macro_: hir::MacroDef, |
158 | ) { | 158 | ) { |
159 | // FIXME: Currently proc-macro do not have ast-node, | ||
160 | // such that it does not have source | ||
161 | if macro_.is_proc_macro() { | ||
162 | return; | ||
163 | } | ||
164 | |||
159 | let name = match name { | 165 | let name = match name { |
160 | Some(it) => it, | 166 | Some(it) => it, |
161 | None => return, | 167 | None => return, |
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 6289f53f3..67bc9c31b 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs | |||
@@ -176,7 +176,7 @@ impl ToNav for FileSymbol { | |||
176 | file_id: self.file_id, | 176 | file_id: self.file_id, |
177 | name: self.name.clone(), | 177 | name: self.name.clone(), |
178 | kind: self.kind, | 178 | kind: self.kind, |
179 | full_range: self.ptr.range(), | 179 | full_range: self.range, |
180 | focus_range: self.name_range, | 180 | focus_range: self.name_range, |
181 | container_name: self.container_name.clone(), | 181 | container_name: self.container_name.clone(), |
182 | description: description_from_symbol(db, self), | 182 | description: description_from_symbol(db, self), |
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 | ||
63 | impl ReferenceResult { | 63 | impl 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/runnables.rs b/crates/ra_ide/src/runnables.rs index 9433f3a24..05a66e03c 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs | |||
@@ -34,7 +34,7 @@ impl Display for TestId { | |||
34 | 34 | ||
35 | #[derive(Debug)] | 35 | #[derive(Debug)] |
36 | pub enum RunnableKind { | 36 | pub enum RunnableKind { |
37 | Test { test_id: TestId }, | 37 | Test { test_id: TestId, attr: TestAttr }, |
38 | TestMod { path: String }, | 38 | TestMod { path: String }, |
39 | Bench { test_id: TestId }, | 39 | Bench { test_id: TestId }, |
40 | Bin, | 40 | Bin, |
@@ -77,7 +77,8 @@ fn runnable_fn(sema: &Semantics<RootDatabase>, fn_def: ast::FnDef) -> Option<Run | |||
77 | }; | 77 | }; |
78 | 78 | ||
79 | if has_test_related_attribute(&fn_def) { | 79 | if has_test_related_attribute(&fn_def) { |
80 | RunnableKind::Test { test_id } | 80 | let attr = TestAttr::from_fn(&fn_def); |
81 | RunnableKind::Test { test_id, attr } | ||
81 | } else if fn_def.has_atom_attr("bench") { | 82 | } else if fn_def.has_atom_attr("bench") { |
82 | RunnableKind::Bench { test_id } | 83 | RunnableKind::Bench { test_id } |
83 | } else { | 84 | } else { |
@@ -87,6 +88,21 @@ fn runnable_fn(sema: &Semantics<RootDatabase>, fn_def: ast::FnDef) -> Option<Run | |||
87 | Some(Runnable { range: fn_def.syntax().text_range(), kind }) | 88 | Some(Runnable { range: fn_def.syntax().text_range(), kind }) |
88 | } | 89 | } |
89 | 90 | ||
91 | #[derive(Debug)] | ||
92 | pub struct TestAttr { | ||
93 | pub ignore: bool, | ||
94 | } | ||
95 | |||
96 | impl TestAttr { | ||
97 | fn from_fn(fn_def: &ast::FnDef) -> TestAttr { | ||
98 | let ignore = fn_def | ||
99 | .attrs() | ||
100 | .filter_map(|attr| attr.simple_name()) | ||
101 | .any(|attribute_text| attribute_text == "ignore"); | ||
102 | TestAttr { ignore } | ||
103 | } | ||
104 | } | ||
105 | |||
90 | /// This is a method with a heuristics to support test methods annotated with custom test annotations, such as | 106 | /// This is a method with a heuristics to support test methods annotated with custom test annotations, such as |
91 | /// `#[test_case(...)]`, `#[tokio::test]` and similar. | 107 | /// `#[test_case(...)]`, `#[tokio::test]` and similar. |
92 | /// Also a regular `#[test]` annotation is supported. | 108 | /// Also a regular `#[test]` annotation is supported. |
@@ -157,6 +173,9 @@ mod tests { | |||
157 | test_id: Path( | 173 | test_id: Path( |
158 | "test_foo", | 174 | "test_foo", |
159 | ), | 175 | ), |
176 | attr: TestAttr { | ||
177 | ignore: false, | ||
178 | }, | ||
160 | }, | 179 | }, |
161 | }, | 180 | }, |
162 | Runnable { | 181 | Runnable { |
@@ -165,6 +184,9 @@ mod tests { | |||
165 | test_id: Path( | 184 | test_id: Path( |
166 | "test_foo", | 185 | "test_foo", |
167 | ), | 186 | ), |
187 | attr: TestAttr { | ||
188 | ignore: true, | ||
189 | }, | ||
168 | }, | 190 | }, |
169 | }, | 191 | }, |
170 | ] | 192 | ] |
@@ -200,6 +222,9 @@ mod tests { | |||
200 | test_id: Path( | 222 | test_id: Path( |
201 | "test_mod::test_foo1", | 223 | "test_mod::test_foo1", |
202 | ), | 224 | ), |
225 | attr: TestAttr { | ||
226 | ignore: false, | ||
227 | }, | ||
203 | }, | 228 | }, |
204 | }, | 229 | }, |
205 | ] | 230 | ] |
@@ -237,6 +262,9 @@ mod tests { | |||
237 | test_id: Path( | 262 | test_id: Path( |
238 | "foo::test_mod::test_foo1", | 263 | "foo::test_mod::test_foo1", |
239 | ), | 264 | ), |
265 | attr: TestAttr { | ||
266 | ignore: false, | ||
267 | }, | ||
240 | }, | 268 | }, |
241 | }, | 269 | }, |
242 | ] | 270 | ] |
@@ -276,6 +304,9 @@ mod tests { | |||
276 | test_id: Path( | 304 | test_id: Path( |
277 | "foo::bar::test_mod::test_foo1", | 305 | "foo::bar::test_mod::test_foo1", |
278 | ), | 306 | ), |
307 | attr: TestAttr { | ||
308 | ignore: false, | ||
309 | }, | ||
279 | }, | 310 | }, |
280 | }, | 311 | }, |
281 | ] | 312 | ] |
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 | } |