diff options
Diffstat (limited to 'crates/ide/src/syntax_highlighting')
-rw-r--r-- | crates/ide/src/syntax_highlighting/html.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/injection.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 3 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlighting.html | 19 | ||||
-rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 19 |
5 files changed, 43 insertions, 2 deletions
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 57e2d2923..abcc5cccc 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! Renders a bit of code as HTML. | 1 | //! Renders a bit of code as HTML. |
2 | 2 | ||
3 | use base_db::SourceDatabase; | 3 | use ide_db::base_db::SourceDatabase; |
4 | use oorandom::Rand32; | 4 | use oorandom::Rand32; |
5 | use stdx::format_to; | 5 | use stdx::format_to; |
6 | use syntax::{AstNode, TextRange, TextSize}; | 6 | use syntax::{AstNode, TextRange, TextSize}; |
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs index acd91b26c..59a74bc02 100644 --- a/crates/ide/src/syntax_highlighting/injection.rs +++ b/crates/ide/src/syntax_highlighting/injection.rs | |||
@@ -3,8 +3,8 @@ | |||
3 | use std::{collections::BTreeMap, convert::TryFrom}; | 3 | use std::{collections::BTreeMap, convert::TryFrom}; |
4 | 4 | ||
5 | use ast::{HasQuotes, HasStringValue}; | 5 | use ast::{HasQuotes, HasStringValue}; |
6 | use call_info::ActiveParameter; | ||
7 | use hir::Semantics; | 6 | use hir::Semantics; |
7 | use ide_db::call_info::ActiveParameter; | ||
8 | use itertools::Itertools; | 8 | use itertools::Itertools; |
9 | use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; | 9 | use syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; |
10 | 10 | ||
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index c1b817f06..e8f78ad52 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -64,6 +64,7 @@ pub enum HighlightModifier { | |||
64 | Mutable, | 64 | Mutable, |
65 | Consuming, | 65 | Consuming, |
66 | Unsafe, | 66 | Unsafe, |
67 | Callable, | ||
67 | } | 68 | } |
68 | 69 | ||
69 | impl HighlightTag { | 70 | impl HighlightTag { |
@@ -122,6 +123,7 @@ impl HighlightModifier { | |||
122 | HighlightModifier::Mutable, | 123 | HighlightModifier::Mutable, |
123 | HighlightModifier::Consuming, | 124 | HighlightModifier::Consuming, |
124 | HighlightModifier::Unsafe, | 125 | HighlightModifier::Unsafe, |
126 | HighlightModifier::Callable, | ||
125 | ]; | 127 | ]; |
126 | 128 | ||
127 | fn as_str(self) -> &'static str { | 129 | fn as_str(self) -> &'static str { |
@@ -134,6 +136,7 @@ impl HighlightModifier { | |||
134 | HighlightModifier::Mutable => "mutable", | 136 | HighlightModifier::Mutable => "mutable", |
135 | HighlightModifier::Consuming => "consuming", | 137 | HighlightModifier::Consuming => "consuming", |
136 | HighlightModifier::Unsafe => "unsafe", | 138 | HighlightModifier::Unsafe => "unsafe", |
139 | HighlightModifier::Callable => "callable", | ||
137 | } | 140 | } |
138 | } | 141 | } |
139 | 142 | ||
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 0bb0928e4..0cb84866d 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html | |||
@@ -44,6 +44,17 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
44 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">Copy</span> <span class="punctuation">{</span><span class="punctuation">}</span> | 44 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">Copy</span> <span class="punctuation">{</span><span class="punctuation">}</span> |
45 | <span class="punctuation">}</span> | 45 | <span class="punctuation">}</span> |
46 | 46 | ||
47 | <span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration">ops</span> <span class="punctuation">{</span> | ||
48 | <span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">lang</span><span class="attribute"> </span><span class="operator">=</span><span class="attribute"> </span><span class="string_literal">"fn_once"</span><span class="attribute">]</span> | ||
49 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">FnOnce</span><span class="punctuation"><</span><span class="type_param declaration">Args</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">}</span> | ||
50 | |||
51 | <span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">lang</span><span class="attribute"> </span><span class="operator">=</span><span class="attribute"> </span><span class="string_literal">"fn_mut"</span><span class="attribute">]</span> | ||
52 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">FnMut</span><span class="punctuation"><</span><span class="type_param declaration">Args</span><span class="punctuation">></span><span class="punctuation">:</span> <span class="trait">FnOnce</span><span class="punctuation"><</span><span class="type_param">Args</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">}</span> | ||
53 | |||
54 | <span class="attribute">#</span><span class="attribute">[</span><span class="function attribute">lang</span><span class="attribute"> </span><span class="operator">=</span><span class="attribute"> </span><span class="string_literal">"fn"</span><span class="attribute">]</span> | ||
55 | <span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration">Fn</span><span class="punctuation"><</span><span class="type_param declaration">Args</span><span class="punctuation">></span><span class="punctuation">:</span> <span class="trait">FnMut</span><span class="punctuation"><</span><span class="type_param">Args</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">}</span> | ||
56 | <span class="punctuation">}</span> | ||
57 | |||
47 | 58 | ||
48 | <span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span> | 59 | <span class="keyword">struct</span> <span class="struct declaration">Foo</span> <span class="punctuation">{</span> |
49 | <span class="keyword">pub</span> <span class="field declaration">x</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span> | 60 | <span class="keyword">pub</span> <span class="field declaration">x</span><span class="punctuation">:</span> <span class="builtin_type">i32</span><span class="punctuation">,</span> |
@@ -99,6 +110,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
99 | <span class="function">foo</span><span class="operator">::</span><span class="punctuation"><</span><span class="lifetime">'a</span><span class="punctuation">,</span> <span class="builtin_type">i32</span><span class="punctuation">></span><span class="punctuation">(</span><span class="punctuation">)</span> | 110 | <span class="function">foo</span><span class="operator">::</span><span class="punctuation"><</span><span class="lifetime">'a</span><span class="punctuation">,</span> <span class="builtin_type">i32</span><span class="punctuation">></span><span class="punctuation">(</span><span class="punctuation">)</span> |
100 | <span class="punctuation">}</span> | 111 | <span class="punctuation">}</span> |
101 | 112 | ||
113 | <span class="keyword">use</span> <span class="module">ops</span><span class="operator">::</span><span class="trait">Fn</span><span class="punctuation">;</span> | ||
114 | <span class="keyword">fn</span> <span class="function declaration">baz</span><span class="punctuation"><</span><span class="type_param declaration">F</span><span class="punctuation">:</span> <span class="trait">Fn</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">-></span> <span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">></span><span class="punctuation">(</span><span class="value_param declaration callable">f</span><span class="punctuation">:</span> <span class="type_param">F</span><span class="punctuation">)</span> <span class="punctuation">{</span> | ||
115 | <span class="value_param callable">f</span><span class="punctuation">(</span><span class="punctuation">)</span> | ||
116 | <span class="punctuation">}</span> | ||
117 | |||
102 | <span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> <span class="punctuation">{</span> | 118 | <span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> <span class="punctuation">{</span> |
103 | <span class="punctuation">(</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">:</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">)</span> <span class="operator">=</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">}</span> | 119 | <span class="punctuation">(</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">:</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">)</span> <span class="operator">=</span><span class="punctuation">></span> <span class="punctuation">{</span><span class="punctuation">$</span><span class="punctuation">(</span><span class="punctuation">$</span>tt<span class="punctuation">)</span><span class="punctuation">*</span><span class="punctuation">}</span> |
104 | <span class="punctuation">}</span> | 120 | <span class="punctuation">}</span> |
@@ -157,6 +173,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
157 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function">quop</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 173 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function">quop</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
158 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function mutable">qux</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | 174 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function mutable">qux</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> |
159 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function">baz</span><span class="punctuation">(</span><span class="variable mutable">copy</span><span class="punctuation">)</span><span class="punctuation">;</span> | 175 | <span class="variable mutable">copy</span><span class="punctuation">.</span><span class="function">baz</span><span class="punctuation">(</span><span class="variable mutable">copy</span><span class="punctuation">)</span><span class="punctuation">;</span> |
176 | |||
177 | <span class="keyword">let</span> <span class="variable declaration callable">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="punctuation">;</span> | ||
178 | <span class="keyword">let</span> <span class="variable declaration callable">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function">baz</span><span class="punctuation">;</span> | ||
160 | <span class="punctuation">}</span> | 179 | <span class="punctuation">}</span> |
161 | 180 | ||
162 | <span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation"><</span><span class="type_param declaration">T</span><span class="punctuation">></span> <span class="punctuation">{</span> | 181 | <span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation"><</span><span class="type_param declaration">T</span><span class="punctuation">></span> <span class="punctuation">{</span> |
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 126363b8b..da20c300e 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -18,6 +18,17 @@ pub mod marker { | |||
18 | pub trait Copy {} | 18 | pub trait Copy {} |
19 | } | 19 | } |
20 | 20 | ||
21 | pub mod ops { | ||
22 | #[lang = "fn_once"] | ||
23 | pub trait FnOnce<Args> {} | ||
24 | |||
25 | #[lang = "fn_mut"] | ||
26 | pub trait FnMut<Args>: FnOnce<Args> {} | ||
27 | |||
28 | #[lang = "fn"] | ||
29 | pub trait Fn<Args>: FnMut<Args> {} | ||
30 | } | ||
31 | |||
21 | 32 | ||
22 | struct Foo { | 33 | struct Foo { |
23 | pub x: i32, | 34 | pub x: i32, |
@@ -73,6 +84,11 @@ fn foo<'a, T>() -> T { | |||
73 | foo::<'a, i32>() | 84 | foo::<'a, i32>() |
74 | } | 85 | } |
75 | 86 | ||
87 | use ops::Fn; | ||
88 | fn baz<F: Fn() -> ()>(f: F) { | ||
89 | f() | ||
90 | } | ||
91 | |||
76 | macro_rules! def_fn { | 92 | macro_rules! def_fn { |
77 | ($($tt:tt)*) => {$($tt)*} | 93 | ($($tt:tt)*) => {$($tt)*} |
78 | } | 94 | } |
@@ -131,6 +147,9 @@ fn main() { | |||
131 | copy.quop(); | 147 | copy.quop(); |
132 | copy.qux(); | 148 | copy.qux(); |
133 | copy.baz(copy); | 149 | copy.baz(copy); |
150 | |||
151 | let a = |x| x; | ||
152 | let bar = Foo::baz; | ||
134 | } | 153 | } |
135 | 154 | ||
136 | enum Option<T> { | 155 | enum Option<T> { |