diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-18 21:32:34 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-18 21:32:34 +0000 |
commit | 48d6324a3f8a48efe3275424584a753c4e60d762 (patch) | |
tree | cda6b85e9f08457f016490c551158fc5b59d8cb6 /crates/ide/src | |
parent | 5e82d3172282e159e539569b80b3135c17b972f0 (diff) | |
parent | 8c0f454d115a5ce5fa4a9a0aa7116eac99a292f9 (diff) |
Merge #8086
8086: Use a highlight modifier for intra doc links r=Veykril a=Veykril
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide/src')
12 files changed, 53 insertions, 29 deletions
diff --git a/crates/ide/src/syntax_highlighting/html.rs b/crates/ide/src/syntax_highlighting/html.rs index 1d34731ab..5327af845 100644 --- a/crates/ide/src/syntax_highlighting/html.rs +++ b/crates/ide/src/syntax_highlighting/html.rs | |||
@@ -59,7 +59,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
59 | .label { color: #DFAF8F; font-style: italic; } | 59 | .label { color: #DFAF8F; font-style: italic; } |
60 | .comment { color: #7F9F7F; } | 60 | .comment { color: #7F9F7F; } |
61 | .documentation { color: #629755; } | 61 | .documentation { color: #629755; } |
62 | .intra_doc_link { color: #A9C577; } | 62 | .intra_doc_link { font-style: italic; } |
63 | .injected { opacity: 0.65 ; } | 63 | .injected { opacity: 0.65 ; } |
64 | .struct, .enum { color: #7CB8BB; } | 64 | .struct, .enum { color: #7CB8BB; } |
65 | .enum_variant { color: #BDE0F3; } | 65 | .enum_variant { color: #BDE0F3; } |
diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index e6dbd307e..f359eacf2 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs | |||
@@ -4,7 +4,7 @@ use std::{mem, ops::Range}; | |||
4 | 4 | ||
5 | use either::Either; | 5 | use either::Either; |
6 | use hir::{HasAttrs, InFile, Semantics}; | 6 | use hir::{HasAttrs, InFile, Semantics}; |
7 | use ide_db::{call_info::ActiveParameter, defs::Definition}; | 7 | use ide_db::{call_info::ActiveParameter, defs::Definition, SymbolKind}; |
8 | use syntax::{ | 8 | use syntax::{ |
9 | ast::{self, AstNode, AttrsOwner, DocCommentsOwner}, | 9 | ast::{self, AstNode, AttrsOwner, DocCommentsOwner}, |
10 | match_ast, AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize, | 10 | match_ast, AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize, |
@@ -225,13 +225,16 @@ pub(super) fn doc_comment( | |||
225 | intra_doc_links.extend( | 225 | intra_doc_links.extend( |
226 | extract_definitions_from_markdown(line) | 226 | extract_definitions_from_markdown(line) |
227 | .into_iter() | 227 | .into_iter() |
228 | .filter(|(link, ns, _)| { | 228 | .filter_map(|(link, ns, range)| { |
229 | validate_intra_doc_link(sema.db, &def, link, *ns) | 229 | validate_intra_doc_link(sema.db, &def, &link, ns).zip(Some(range)) |
230 | }) | 230 | }) |
231 | .map(|(.., Range { start, end })| { | 231 | .map(|(def, Range { start, end })| { |
232 | TextRange::at( | 232 | ( |
233 | prev_range_start + TextSize::from(start as u32), | 233 | def, |
234 | TextSize::from((end - start) as u32), | 234 | TextRange::at( |
235 | prev_range_start + TextSize::from(start as u32), | ||
236 | TextSize::from((end - start) as u32), | ||
237 | ), | ||
235 | ) | 238 | ) |
236 | }), | 239 | }), |
237 | ); | 240 | ); |
@@ -255,10 +258,13 @@ pub(super) fn doc_comment( | |||
255 | } | 258 | } |
256 | } | 259 | } |
257 | 260 | ||
258 | for range in intra_doc_links { | 261 | for (def, range) in intra_doc_links { |
259 | hl.add(HlRange { | 262 | hl.add(HlRange { |
260 | range, | 263 | range, |
261 | highlight: HlTag::IntraDocLink | HlMod::Documentation, | 264 | highlight: module_def_to_hl_tag(def) |
265 | | HlMod::Documentation | ||
266 | | HlMod::Injected | ||
267 | | HlMod::IntraDocLink, | ||
262 | binding_hash: None, | 268 | binding_hash: None, |
263 | }); | 269 | }); |
264 | } | 270 | } |
@@ -317,7 +323,7 @@ fn validate_intra_doc_link( | |||
317 | def: &Definition, | 323 | def: &Definition, |
318 | link: &str, | 324 | link: &str, |
319 | ns: Option<hir::Namespace>, | 325 | ns: Option<hir::Namespace>, |
320 | ) -> bool { | 326 | ) -> Option<hir::ModuleDef> { |
321 | match def { | 327 | match def { |
322 | Definition::ModuleDef(def) => match def { | 328 | Definition::ModuleDef(def) => match def { |
323 | hir::ModuleDef::Module(it) => it.resolve_doc_path(db, &link, ns), | 329 | hir::ModuleDef::Module(it) => it.resolve_doc_path(db, &link, ns), |
@@ -337,5 +343,21 @@ fn validate_intra_doc_link( | |||
337 | | Definition::GenericParam(_) | 343 | | Definition::GenericParam(_) |
338 | | Definition::Label(_) => None, | 344 | | Definition::Label(_) => None, |
339 | } | 345 | } |
340 | .is_some() | 346 | } |
347 | |||
348 | fn module_def_to_hl_tag(def: hir::ModuleDef) -> HlTag { | ||
349 | let symbol = match def { | ||
350 | hir::ModuleDef::Module(_) => SymbolKind::Module, | ||
351 | hir::ModuleDef::Function(_) => SymbolKind::Function, | ||
352 | hir::ModuleDef::Adt(hir::Adt::Struct(_)) => SymbolKind::Struct, | ||
353 | hir::ModuleDef::Adt(hir::Adt::Enum(_)) => SymbolKind::Enum, | ||
354 | hir::ModuleDef::Adt(hir::Adt::Union(_)) => SymbolKind::Union, | ||
355 | hir::ModuleDef::Variant(_) => SymbolKind::Variant, | ||
356 | hir::ModuleDef::Const(_) => SymbolKind::Const, | ||
357 | hir::ModuleDef::Static(_) => SymbolKind::Static, | ||
358 | hir::ModuleDef::Trait(_) => SymbolKind::Trait, | ||
359 | hir::ModuleDef::TypeAlias(_) => SymbolKind::TypeAlias, | ||
360 | hir::ModuleDef::BuiltinType(_) => return HlTag::BuiltinType, | ||
361 | }; | ||
362 | HlTag::Symbol(symbol) | ||
341 | } | 363 | } |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index ce46e5127..93db79b89 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -26,7 +26,6 @@ pub enum HlTag { | |||
26 | Comment, | 26 | Comment, |
27 | EscapeSequence, | 27 | EscapeSequence, |
28 | FormatSpecifier, | 28 | FormatSpecifier, |
29 | IntraDocLink, | ||
30 | Keyword, | 29 | Keyword, |
31 | NumericLiteral, | 30 | NumericLiteral, |
32 | Operator, | 31 | Operator, |
@@ -57,6 +56,8 @@ pub enum HlMod { | |||
57 | Static, | 56 | Static, |
58 | /// Used for items in impls&traits. | 57 | /// Used for items in impls&traits. |
59 | Associated, | 58 | Associated, |
59 | /// Used for intra doc links in doc injection. | ||
60 | IntraDocLink, | ||
60 | 61 | ||
61 | /// Keep this last! | 62 | /// Keep this last! |
62 | Unsafe, | 63 | Unsafe, |
@@ -117,7 +118,6 @@ impl HlTag { | |||
117 | HlTag::Comment => "comment", | 118 | HlTag::Comment => "comment", |
118 | HlTag::EscapeSequence => "escape_sequence", | 119 | HlTag::EscapeSequence => "escape_sequence", |
119 | HlTag::FormatSpecifier => "format_specifier", | 120 | HlTag::FormatSpecifier => "format_specifier", |
120 | HlTag::IntraDocLink => "intra_doc_link", | ||
121 | HlTag::Keyword => "keyword", | 121 | HlTag::Keyword => "keyword", |
122 | HlTag::Punctuation(punct) => match punct { | 122 | HlTag::Punctuation(punct) => match punct { |
123 | HlPunct::Bracket => "bracket", | 123 | HlPunct::Bracket => "bracket", |
@@ -151,6 +151,7 @@ impl HlMod { | |||
151 | HlMod::ControlFlow, | 151 | HlMod::ControlFlow, |
152 | HlMod::Definition, | 152 | HlMod::Definition, |
153 | HlMod::Documentation, | 153 | HlMod::Documentation, |
154 | HlMod::IntraDocLink, | ||
154 | HlMod::Injected, | 155 | HlMod::Injected, |
155 | HlMod::Mutable, | 156 | HlMod::Mutable, |
156 | HlMod::Consuming, | 157 | HlMod::Consuming, |
@@ -162,17 +163,18 @@ impl HlMod { | |||
162 | 163 | ||
163 | fn as_str(self) -> &'static str { | 164 | fn as_str(self) -> &'static str { |
164 | match self { | 165 | match self { |
166 | HlMod::Associated => "associated", | ||
165 | HlMod::Attribute => "attribute", | 167 | HlMod::Attribute => "attribute", |
168 | HlMod::Callable => "callable", | ||
169 | HlMod::Consuming => "consuming", | ||
166 | HlMod::ControlFlow => "control", | 170 | HlMod::ControlFlow => "control", |
167 | HlMod::Definition => "declaration", | 171 | HlMod::Definition => "declaration", |
168 | HlMod::Documentation => "documentation", | 172 | HlMod::Documentation => "documentation", |
169 | HlMod::Injected => "injected", | 173 | HlMod::Injected => "injected", |
174 | HlMod::IntraDocLink => "intra_doc_link", | ||
170 | HlMod::Mutable => "mutable", | 175 | HlMod::Mutable => "mutable", |
171 | HlMod::Consuming => "consuming", | ||
172 | HlMod::Unsafe => "unsafe", | ||
173 | HlMod::Callable => "callable", | ||
174 | HlMod::Static => "static", | 176 | HlMod::Static => "static", |
175 | HlMod::Associated => "associated", | 177 | HlMod::Unsafe => "unsafe", |
176 | } | 178 | } |
177 | } | 179 | } |
178 | 180 | ||
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html index 60c7518af..4635ea927 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index 5d802a647..045162eb8 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |
@@ -99,8 +99,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
99 | <span class="brace">}</span> | 99 | <span class="brace">}</span> |
100 | <span class="brace">}</span> | 100 | <span class="brace">}</span> |
101 | 101 | ||
102 | <span class="comment documentation">/// </span><span class="intra_doc_link documentation">[`Foo`](Foo)</span><span class="comment documentation"> is a struct</span> | 102 | <span class="comment documentation">/// </span><span class="struct documentation intra_doc_link injected">[`Foo`](Foo)</span><span class="comment documentation"> is a struct</span> |
103 | <span class="comment documentation">/// </span><span class="intra_doc_link documentation">[`all_the_links`](all_the_links)</span><span class="comment documentation"> is this function</span> | 103 | <span class="comment documentation">/// </span><span class="function documentation intra_doc_link injected">[`all_the_links`](all_the_links)</span><span class="comment documentation"> is this function</span> |
104 | <span class="comment documentation">/// [`noop`](noop) is a macro below</span> | 104 | <span class="comment documentation">/// [`noop`](noop) is a macro below</span> |
105 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration">all_the_links</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 105 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration">all_the_links</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
106 | 106 | ||
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html index 4e312765c..ca9bb1e7d 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html index 57dfe7509..9215ddd9e 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index 75dbd0f14..e860d713e 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html index 423256a20..6a6555208 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index fffe8c0f5..8b2dd3b70 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/injection.html b/crates/ide/src/syntax_highlighting/test_data/injection.html index 34d8deb68..9ab46d05c 100644 --- a/crates/ide/src/syntax_highlighting/test_data/injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/injection.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html b/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html index d9ca3a4c4..666b0b228 100644 --- a/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html | |||
@@ -7,7 +7,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
7 | .label { color: #DFAF8F; font-style: italic; } | 7 | .label { color: #DFAF8F; font-style: italic; } |
8 | .comment { color: #7F9F7F; } | 8 | .comment { color: #7F9F7F; } |
9 | .documentation { color: #629755; } | 9 | .documentation { color: #629755; } |
10 | .intra_doc_link { color: #A9C577; } | 10 | .intra_doc_link { font-style: italic; } |
11 | .injected { opacity: 0.65 ; } | 11 | .injected { opacity: 0.65 ; } |
12 | .struct, .enum { color: #7CB8BB; } | 12 | .struct, .enum { color: #7CB8BB; } |
13 | .enum_variant { color: #BDE0F3; } | 13 | .enum_variant { color: #BDE0F3; } |