aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-28 15:49:46 +0000
committerAleksey Kladov <[email protected]>2020-02-28 15:53:12 +0000
commit56ce34c6a7ec0b4426d4cb25e10512c7efaf6f06 (patch)
treeeec2d0d619cba2989313e66a87207b1641264a74 /crates/ra_ide
parent5ebfcb9cb757ece936f631cf69136e1d38cb6afc (diff)
Correctly flag 'lifetime definitions as definitions
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html41
-rw-r--r--crates/ra_ide/src/snapshots/rainbow_highlighting.html18
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs9
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs2
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs8
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs9
6 files changed, 47 insertions, 40 deletions
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
index cb4097e05..495b07f69 100644
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ b/crates/ra_ide/src/snapshots/highlighting.html
@@ -3,7 +3,7 @@
3body { margin: 0; } 3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } 4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5 5
6 6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; } 7.comment { color: #7F9F7F; }
8.struct, .enum { color: #7CB8BB; } 8.struct, .enum { color: #7CB8BB; }
9.enum_variant { color: #BDE0F3; } 9.enum_variant { color: #BDE0F3; }
@@ -27,14 +27,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
27.control { font-style: italic; } 27.control { font-style: italic; }
28</style> 28</style>
29<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span> 29<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
30<span class="keyword">struct</span> <span class="struct">Foo</span> { 30<span class="keyword">struct</span> <span class="struct declaration">Foo</span> {
31 <span class="keyword">pub</span> <span class="field">x</span>: <span class="builtin_type">i32</span>, 31 <span class="keyword">pub</span> <span class="field declaration">x</span>: <span class="builtin_type">i32</span>,
32 <span class="keyword">pub</span> <span class="field">y</span>: <span class="builtin_type">i32</span>, 32 <span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>,
33} 33}
34 34
35<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type_param">T</span>&gt;() -&gt; <span class="type_param">T</span> { 35<span class="keyword">fn</span> <span class="function declaration">foo</span>&lt;<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>&gt;() -&gt; <span class="type_param">T</span> {
36 <span class="macro">unimplemented</span><span class="macro">!</span>(); 36 <span class="function">foo</span>::&lt;<span class="lifetime">'a</span>, <span class="builtin_type">i32</span>&gt;()
37 <span class="function">foo</span>::&lt;<span class="builtin_type">i32</span>&gt;();
38} 37}
39 38
40<span class="macro">macro_rules</span><span class="macro">!</span> def_fn { 39<span class="macro">macro_rules</span><span class="macro">!</span> def_fn {
@@ -42,40 +41,40 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
42} 41}
43 42
44<span class="macro">def_fn</span><span class="macro">!</span> { 43<span class="macro">def_fn</span><span class="macro">!</span> {
45 <span class="keyword">fn</span> <span class="function">bar</span>() -&gt; <span class="builtin_type">u32</span> { 44 <span class="keyword">fn</span> <span class="function declaration">bar</span>() -&gt; <span class="builtin_type">u32</span> {
46 <span class="numeric_literal">100</span> 45 <span class="numeric_literal">100</span>
47 } 46 }
48} 47}
49 48
50<span class="comment">// comment</span> 49<span class="comment">// comment</span>
51<span class="keyword">fn</span> <span class="function">main</span>() { 50<span class="keyword">fn</span> <span class="function declaration">main</span>() {
52 <span class="macro">println</span><span class="macro">!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>); 51 <span class="macro">println</span><span class="macro">!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
53 52
54 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">vec</span> = Vec::new(); 53 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">vec</span> = Vec::new();
55 <span class="keyword control">if</span> <span class="keyword">true</span> { 54 <span class="keyword control">if</span> <span class="keyword">true</span> {
56 <span class="keyword">let</span> <span class="variable">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>;
57 <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>.push(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
58 } 57 }
59 <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>.set_len(<span class="numeric_literal">0</span>); }
60 59
61 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable 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>;
62 <span class="keyword">let</span> <span class="variable 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>;
63 <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable mutable">y</span>; 62 <span class="keyword">let</span> <span class="variable declaration">z</span> = &<span class="variable mutable">y</span>;
64 63
65 <span class="variable mutable">y</span>; 64 <span class="variable mutable">y</span>;
66} 65}
67 66
68<span class="keyword">enum</span> <span class="enum">Option</span>&lt;<span class="type_param">T</span>&gt; { 67<span class="keyword">enum</span> <span class="enum declaration">Option</span>&lt;<span class="type_param declaration">T</span>&gt; {
69 <span class="enum_variant">Some</span>(<span class="type_param">T</span>), 68 <span class="enum_variant declaration">Some</span>(<span class="type_param">T</span>),
70 <span class="enum_variant">None</span>, 69 <span class="enum_variant declaration">None</span>,
71} 70}
72<span class="keyword">use</span> <span class="enum">Option</span>::*; 71<span class="keyword">use</span> <span class="enum">Option</span>::*;
73 72
74<span class="keyword">impl</span>&lt;<span class="type_param">T</span>&gt; <span class="enum">Option</span>&lt;<span class="type_param">T</span>&gt; { 73<span class="keyword">impl</span>&lt;<span class="type_param declaration">T</span>&gt; <span class="enum">Option</span>&lt;<span class="type_param">T</span>&gt; {
75 <span class="keyword">fn</span> <span class="function">and</span>&lt;<span class="type_param">U</span>&gt;(<span class="keyword">self</span>, <span class="variable">other</span>: <span class="enum">Option</span>&lt;<span class="type_param">U</span>&gt;) -&gt; <span class="enum">Option</span>&lt;(<span class="type_param">T</span>, <span class="type_param">U</span>)&gt; { 74 <span class="keyword">fn</span> <span class="function declaration">and</span>&lt;<span class="type_param declaration">U</span>&gt;(<span class="keyword">self</span>, <span class="variable declaration">other</span>: <span class="enum">Option</span>&lt;<span class="type_param">U</span>&gt;) -&gt; <span class="enum">Option</span>&lt;(<span class="type_param">T</span>, <span class="type_param">U</span>)&gt; {
76 <span class="keyword control">match</span> <span class="variable">other</span> { 75 <span class="keyword control">match</span> <span class="variable">other</span> {
77 <span class="enum_variant">None</span> =&gt; <span class="macro">todo</span><span class="macro">!</span>(), 76 <span class="enum_variant">None</span> =&gt; <span class="macro">unimplemented</span><span class="macro">!</span>(),
78 <span class="variable">Nope</span> =&gt; <span class="variable">Nope</span>, 77 <span class="variable declaration">Nope</span> =&gt; <span class="variable">Nope</span>,
79 } 78 }
80 } 79 }
81}</code></pre> \ No newline at end of file 80}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
index f63e64b6d..dddbfc0dd 100644
--- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html
+++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
@@ -3,7 +3,7 @@
3body { margin: 0; } 3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } 4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5 5
6 6.lifetime { color: #DFAF8F; font-style: italic; }
7.comment { color: #7F9F7F; } 7.comment { color: #7F9F7F; }
8.struct, .enum { color: #7CB8BB; } 8.struct, .enum { color: #7CB8BB; }
9.enum_variant { color: #BDE0F3; } 9.enum_variant { color: #BDE0F3; }
@@ -26,15 +26,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
26.keyword.unsafe { color: #BC8383; font-weight: bold; } 26.keyword.unsafe { color: #BC8383; font-weight: bold; }
27.control { font-style: italic; } 27.control { font-style: italic; }
28</style> 28</style>
29<pre><code><span class="keyword">fn</span> <span class="function">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" 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" 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>.to_string();
32 <span class="keyword">let</span> <span class="variable" 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>.to_string();
33 33
34 <span class="keyword">let</span> <span class="variable" 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" 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>.to_string();
36} 36}
37 37
38<span class="keyword">fn</span> <span class="function">bar</span>() { 38<span class="keyword">fn</span> <span class="function declaration">bar</span>() {
39 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>; 39 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
40}</code></pre> \ No newline at end of file 40}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 6312bcb83..b94b6a022 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -214,8 +214,13 @@ fn highlight_element(
214 INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), 214 INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(),
215 BYTE => HighlightTag::ByteLiteral.into(), 215 BYTE => HighlightTag::ByteLiteral.into(),
216 CHAR => HighlightTag::CharLiteral.into(), 216 CHAR => HighlightTag::CharLiteral.into(),
217 // FIXME: set Declaration for decls 217 LIFETIME => {
218 LIFETIME => HighlightTag::Lifetime.into(), 218 let h = Highlight::new(HighlightTag::Lifetime);
219 dbg!(match element.parent().map(|it| it.kind()) {
220 Some(LIFETIME_PARAM) | Some(LABEL) => h | HighlightModifier::Definition,
221 _ => h,
222 })
223 }
219 224
220 k if k.is_keyword() => { 225 k if k.is_keyword() => {
221 let h = Highlight::new(HighlightTag::Keyword); 226 let h = Highlight::new(HighlightTag::Keyword);
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 54678c278..e13766c9d 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -80,7 +80,7 @@ const STYLE: &str = "
80body { margin: 0; } 80body { margin: 0; }
81pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } 81pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
82 82
83 83.lifetime { color: #DFAF8F; font-style: italic; }
84.comment { color: #7F9F7F; } 84.comment { color: #7F9F7F; }
85.struct, .enum { color: #7CB8BB; } 85.struct, .enum { color: #7CB8BB; }
86.enum_variant { color: #BDE0F3; } 86.enum_variant { color: #BDE0F3; }
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index 9da80823c..8835a5de2 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -90,8 +90,12 @@ impl fmt::Display for HighlightTag {
90} 90}
91 91
92impl HighlightModifier { 92impl HighlightModifier {
93 const ALL: &'static [HighlightModifier] = 93 const ALL: &'static [HighlightModifier] = &[
94 &[HighlightModifier::Mutable, HighlightModifier::Unsafe, HighlightModifier::Control]; 94 HighlightModifier::Control,
95 HighlightModifier::Definition,
96 HighlightModifier::Mutable,
97 HighlightModifier::Unsafe,
98 ];
95 99
96 fn as_str(self) -> &'static str { 100 fn as_str(self) -> &'static str {
97 match self { 101 match self {
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index 21c4dd818..98c030791 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -17,9 +17,8 @@ struct Foo {
17 pub y: i32, 17 pub y: i32,
18} 18}
19 19
20fn foo<T>() -> T { 20fn foo<'a, T>() -> T {
21 unimplemented!(); 21 foo::<'a, i32>()
22 foo::<i32>();
23} 22}
24 23
25macro_rules! def_fn { 24macro_rules! def_fn {
@@ -59,7 +58,7 @@ use Option::*;
59impl<T> Option<T> { 58impl<T> Option<T> {
60 fn and<U>(self, other: Option<U>) -> Option<(T, U)> { 59 fn and<U>(self, other: Option<U>) -> Option<(T, U)> {
61 match other { 60 match other {
62 None => todo!(), 61 None => unimplemented!(),
63 Nope => Nope, 62 Nope => Nope,
64 } 63 }
65 } 64 }
@@ -130,5 +129,5 @@ fn test_ranges() {
130 .highlight_range(FileRange { file_id, range: TextRange::offset_len(82.into(), 1.into()) }) 129 .highlight_range(FileRange { file_id, range: TextRange::offset_len(82.into(), 1.into()) })
131 .unwrap(); 130 .unwrap();
132 131
133 assert_eq!(&highlights[0].highlight.to_string(), "field"); 132 assert_eq!(&highlights[0].highlight.to_string(), "field.declaration");
134} 133}