aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/display/navigation_target.rs8
-rw-r--r--crates/ide/src/extend_selection.rs7
-rw-r--r--crates/ide/src/goto_definition.rs17
-rw-r--r--crates/ide/src/hover.rs14
-rw-r--r--crates/ide/src/syntax_highlighting.rs16
-rw-r--r--crates/ide/src/syntax_highlighting/html.rs2
-rw-r--r--crates/ide/src/syntax_highlighting/inject.rs132
-rw-r--r--crates/ide/src/syntax_highlighting/tags.rs14
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html2
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html6
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html2
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlight_injection.html2
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlight_strings.html2
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html2
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/highlighting.html2
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/injection.html2
-rw-r--r--crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html2
17 files changed, 133 insertions, 99 deletions
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index c086de163..364be260c 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -339,10 +339,14 @@ impl TryToNav for hir::Field {
339impl TryToNav for hir::MacroDef { 339impl TryToNav for hir::MacroDef {
340 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> { 340 fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
341 let src = self.source(db)?; 341 let src = self.source(db)?;
342 log::debug!("nav target {:#?}", src.value.syntax()); 342 let name_owner: &dyn ast::NameOwner = match &src.value {
343 Either::Left(it) => it,
344 Either::Right(it) => it,
345 };
346 log::debug!("nav target {:#?}", name_owner.syntax());
343 let mut res = NavigationTarget::from_named( 347 let mut res = NavigationTarget::from_named(
344 db, 348 db,
345 src.as_ref().map(|it| it as &dyn ast::NameOwner), 349 src.as_ref().with_value(name_owner),
346 SymbolKind::Macro, 350 SymbolKind::Macro,
347 ); 351 );
348 res.docs = self.docs(db); 352 res.docs = self.docs(db);
diff --git a/crates/ide/src/extend_selection.rs b/crates/ide/src/extend_selection.rs
index e187243cb..5201ce587 100644
--- a/crates/ide/src/extend_selection.rs
+++ b/crates/ide/src/extend_selection.rs
@@ -263,11 +263,10 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
263 ) -> Option<SyntaxToken> { 263 ) -> Option<SyntaxToken> {
264 node.siblings_with_tokens(dir) 264 node.siblings_with_tokens(dir)
265 .skip(1) 265 .skip(1)
266 .skip_while(|node| match node { 266 .find(|node| match node {
267 NodeOrToken::Node(_) => false, 267 NodeOrToken::Node(_) => true,
268 NodeOrToken::Token(it) => is_single_line_ws(it), 268 NodeOrToken::Token(it) => !is_single_line_ws(it),
269 }) 269 })
270 .next()
271 .and_then(|it| it.into_token()) 270 .and_then(|it| it.into_token())
272 .filter(|node| node.kind() == delimiter_kind) 271 .filter(|node| node.kind() == delimiter_kind)
273 } 272 }
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index 598b47e41..473d48c2f 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -1176,4 +1176,21 @@ fn foo() { A { a$0: }; }
1176"#, 1176"#,
1177 ) 1177 )
1178 } 1178 }
1179
1180 #[test]
1181 fn goto_proc_macro() {
1182 check(
1183 r#"
1184//- /main.rs crate:main deps:mac
1185use mac::fn_macro;
1186
1187fn_macro$0!();
1188
1189//- /mac.rs crate:mac
1190#[proc_macro]
1191fn fn_macro() {}
1192 //^^^^^^^^
1193 "#,
1194 )
1195 }
1179} 1196}
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 15d309d7d..a3fb17c0a 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -331,10 +331,16 @@ fn hover_for_definition(
331) -> Option<Markup> { 331) -> Option<Markup> {
332 let mod_path = definition_mod_path(db, &def); 332 let mod_path = definition_mod_path(db, &def);
333 return match def { 333 return match def {
334 Definition::Macro(it) => { 334 Definition::Macro(it) => match &it.source(db)?.value {
335 let label = macro_label(&it.source(db)?.value); 335 Either::Left(mac) => {
336 from_def_source_labeled(db, it, Some(label), mod_path) 336 let label = macro_label(&mac);
337 } 337 from_def_source_labeled(db, it, Some(label), mod_path)
338 }
339 Either::Right(_) => {
340 // FIXME
341 None
342 }
343 },
338 Definition::Field(def) => from_hir_fmt(db, def, mod_path), 344 Definition::Field(def) => from_hir_fmt(db, def, mod_path),
339 Definition::ModuleDef(it) => match it { 345 Definition::ModuleDef(it) => match it {
340 ModuleDef::Module(it) => from_hir_fmt(db, it, mod_path), 346 ModuleDef::Module(it) => from_hir_fmt(db, it, mod_path),
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index ba3447b3a..e25b698e0 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -12,7 +12,7 @@ mod html;
12#[cfg(test)] 12#[cfg(test)]
13mod tests; 13mod tests;
14 14
15use hir::{Name, Semantics}; 15use hir::{InFile, Name, Semantics};
16use ide_db::{RootDatabase, SymbolKind}; 16use ide_db::{RootDatabase, SymbolKind};
17use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
18use syntax::{ 18use syntax::{
@@ -73,14 +73,20 @@ pub(crate) fn highlight(
73 }; 73 };
74 74
75 let mut hl = highlights::Highlights::new(root.text_range()); 75 let mut hl = highlights::Highlights::new(root.text_range());
76 traverse(&mut hl, &sema, &root, range_to_highlight, syntactic_name_ref_highlighting); 76 traverse(
77 &mut hl,
78 &sema,
79 InFile::new(file_id.into(), &root),
80 range_to_highlight,
81 syntactic_name_ref_highlighting,
82 );
77 hl.to_vec() 83 hl.to_vec()
78} 84}
79 85
80fn traverse( 86fn traverse(
81 hl: &mut Highlights, 87 hl: &mut Highlights,
82 sema: &Semantics<RootDatabase>, 88 sema: &Semantics<RootDatabase>,
83 root: &SyntaxNode, 89 root: InFile<&SyntaxNode>,
84 range_to_highlight: TextRange, 90 range_to_highlight: TextRange,
85 syntactic_name_ref_highlighting: bool, 91 syntactic_name_ref_highlighting: bool,
86) { 92) {
@@ -93,7 +99,7 @@ fn traverse(
93 99
94 // Walk all nodes, keeping track of whether we are inside a macro or not. 100 // Walk all nodes, keeping track of whether we are inside a macro or not.
95 // If in macro, expand it first and highlight the expanded code. 101 // If in macro, expand it first and highlight the expanded code.
96 for event in root.preorder_with_tokens() { 102 for event in root.value.preorder_with_tokens() {
97 let event_range = match &event { 103 let event_range = match &event {
98 WalkEvent::Enter(it) | WalkEvent::Leave(it) => it.text_range(), 104 WalkEvent::Enter(it) | WalkEvent::Leave(it) => it.text_range(),
99 }; 105 };
@@ -150,7 +156,7 @@ fn traverse(
150 WalkEvent::Enter(it) => it, 156 WalkEvent::Enter(it) => it,
151 WalkEvent::Leave(it) => { 157 WalkEvent::Leave(it) => {
152 if let Some(node) = it.as_node() { 158 if let Some(node) = it.as_node() {
153 inject::doc_comment(hl, sema, node); 159 inject::doc_comment(hl, sema, root.with_value(node));
154 } 160 }
155 continue; 161 continue;
156 } 162 }
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 947cc974c..8e0940184 100644
--- a/crates/ide/src/syntax_highlighting/inject.rs
+++ b/crates/ide/src/syntax_highlighting/inject.rs
@@ -3,10 +3,10 @@
3use std::{mem, ops::Range}; 3use std::{mem, ops::Range};
4 4
5use either::Either; 5use either::Either;
6use hir::{HasAttrs, Semantics}; 6use hir::{HasAttrs, InFile, Semantics};
7use ide_db::{call_info::ActiveParameter, defs::Definition}; 7use ide_db::{call_info::ActiveParameter, defs::Definition, SymbolKind};
8use syntax::{ 8use syntax::{
9 ast::{self, AstNode, AttrsOwner, DocCommentsOwner}, 9 ast::{self, AstNode},
10 match_ast, AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize, 10 match_ast, AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize,
11}; 11};
12 12
@@ -23,7 +23,7 @@ pub(super) fn ra_fixture(
23 expanded: SyntaxToken, 23 expanded: SyntaxToken,
24) -> Option<()> { 24) -> Option<()> {
25 let active_parameter = ActiveParameter::at_token(&sema, expanded)?; 25 let active_parameter = ActiveParameter::at_token(&sema, expanded)?;
26 if !active_parameter.name.starts_with("ra_fixture") { 26 if !active_parameter.ident().map_or(false, |name| name.text().starts_with("ra_fixture")) {
27 return None; 27 return None;
28 } 28 }
29 let value = literal.value()?; 29 let value = literal.value()?;
@@ -89,57 +89,27 @@ const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
89 "edition2021", 89 "edition2021",
90]; 90];
91 91
92// Basically an owned dyn AttrsOwner without extra Boxing
93struct AttrsOwnerNode {
94 node: SyntaxNode,
95}
96
97impl AttrsOwnerNode {
98 fn new<N: DocCommentsOwner>(node: N) -> Self {
99 AttrsOwnerNode { node: node.syntax().clone() }
100 }
101}
102
103impl AttrsOwner for AttrsOwnerNode {}
104impl AstNode for AttrsOwnerNode {
105 fn can_cast(_: syntax::SyntaxKind) -> bool
106 where
107 Self: Sized,
108 {
109 false
110 }
111 fn cast(_: SyntaxNode) -> Option<Self>
112 where
113 Self: Sized,
114 {
115 None
116 }
117 fn syntax(&self) -> &SyntaxNode {
118 &self.node
119 }
120}
121
122fn doc_attributes<'node>( 92fn doc_attributes<'node>(
123 sema: &Semantics<RootDatabase>, 93 sema: &Semantics<RootDatabase>,
124 node: &'node SyntaxNode, 94 node: &'node SyntaxNode,
125) -> Option<(AttrsOwnerNode, hir::Attrs, Definition)> { 95) -> Option<(hir::AttrsWithOwner, Definition)> {
126 match_ast! { 96 match_ast! {
127 match node { 97 match node {
128 ast::SourceFile(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Module(def)))), 98 ast::SourceFile(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Module(def)))),
129 ast::Module(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Module(def)))), 99 ast::Module(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Module(def)))),
130 ast::Fn(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Function(def)))), 100 ast::Fn(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Function(def)))),
131 ast::Struct(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Struct(def))))), 101 ast::Struct(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Struct(def))))),
132 ast::Union(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Union(def))))), 102 ast::Union(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Union(def))))),
133 ast::Enum(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(def))))), 103 ast::Enum(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(def))))),
134 ast::Variant(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Variant(def)))), 104 ast::Variant(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Variant(def)))),
135 ast::Trait(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Trait(def)))), 105 ast::Trait(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Trait(def)))),
136 ast::Static(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Static(def)))), 106 ast::Static(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Static(def)))),
137 ast::Const(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Const(def)))), 107 ast::Const(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Const(def)))),
138 ast::TypeAlias(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::TypeAlias(def)))), 108 ast::TypeAlias(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::TypeAlias(def)))),
139 ast::Impl(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::SelfType(def))), 109 ast::Impl(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::SelfType(def))),
140 ast::RecordField(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::Field(def))), 110 ast::RecordField(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Field(def))),
141 ast::TupleField(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::Field(def))), 111 ast::TupleField(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Field(def))),
142 ast::MacroRules(it) => sema.to_def(&it).map(|def| (AttrsOwnerNode::new(it), def.attrs(sema.db), Definition::Macro(def))), 112 ast::MacroRules(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Macro(def))),
143 // ast::MacroDef(it) => sema.to_def(&it).map(|def| (Box::new(it) as _, def.attrs(sema.db))), 113 // ast::MacroDef(it) => sema.to_def(&it).map(|def| (Box::new(it) as _, def.attrs(sema.db))),
144 // ast::Use(it) => sema.to_def(&it).map(|def| (Box::new(it) as _, def.attrs(sema.db))), 114 // ast::Use(it) => sema.to_def(&it).map(|def| (Box::new(it) as _, def.attrs(sema.db))),
145 _ => return None 115 _ => return None
@@ -148,8 +118,12 @@ fn doc_attributes<'node>(
148} 118}
149 119
150/// Injection of syntax highlighting of doctests. 120/// Injection of syntax highlighting of doctests.
151pub(super) fn doc_comment(hl: &mut Highlights, sema: &Semantics<RootDatabase>, node: &SyntaxNode) { 121pub(super) fn doc_comment(
152 let (owner, attributes, def) = match doc_attributes(sema, node) { 122 hl: &mut Highlights,
123 sema: &Semantics<RootDatabase>,
124 node: InFile<&SyntaxNode>,
125) {
126 let (attributes, def) = match doc_attributes(sema, node.value) {
153 Some(it) => it, 127 Some(it) => it,
154 None => return, 128 None => return,
155 }; 129 };
@@ -157,7 +131,7 @@ pub(super) fn doc_comment(hl: &mut Highlights, sema: &Semantics<RootDatabase>, n
157 let mut inj = Injector::default(); 131 let mut inj = Injector::default();
158 inj.add_unmapped("fn doctest() {\n"); 132 inj.add_unmapped("fn doctest() {\n");
159 133
160 let attrs_source_map = attributes.source_map(&owner); 134 let attrs_source_map = attributes.source_map(sema.db);
161 135
162 let mut is_codeblock = false; 136 let mut is_codeblock = false;
163 let mut is_doctest = false; 137 let mut is_doctest = false;
@@ -168,7 +142,10 @@ pub(super) fn doc_comment(hl: &mut Highlights, sema: &Semantics<RootDatabase>, n
168 let mut intra_doc_links = Vec::new(); 142 let mut intra_doc_links = Vec::new();
169 let mut string; 143 let mut string;
170 for attr in attributes.by_key("doc").attrs() { 144 for attr in attributes.by_key("doc").attrs() {
171 let src = attrs_source_map.source_of(&attr); 145 let InFile { file_id, value: src } = attrs_source_map.source_of(&attr);
146 if file_id != node.file_id {
147 continue;
148 }
172 let (line, range, prefix) = match &src { 149 let (line, range, prefix) = match &src {
173 Either::Left(it) => { 150 Either::Left(it) => {
174 string = match find_doc_string_in_attr(attr, it) { 151 string = match find_doc_string_in_attr(attr, it) {
@@ -213,13 +190,16 @@ pub(super) fn doc_comment(hl: &mut Highlights, sema: &Semantics<RootDatabase>, n
213 intra_doc_links.extend( 190 intra_doc_links.extend(
214 extract_definitions_from_markdown(line) 191 extract_definitions_from_markdown(line)
215 .into_iter() 192 .into_iter()
216 .filter(|(link, ns, _)| { 193 .filter_map(|(link, ns, range)| {
217 validate_intra_doc_link(sema.db, &def, link, *ns) 194 validate_intra_doc_link(sema.db, &def, &link, ns).zip(Some(range))
218 }) 195 })
219 .map(|(.., Range { start, end })| { 196 .map(|(def, Range { start, end })| {
220 TextRange::at( 197 (
221 prev_range_start + TextSize::from(start as u32), 198 def,
222 TextSize::from((end - start) as u32), 199 TextRange::at(
200 prev_range_start + TextSize::from(start as u32),
201 TextSize::from((end - start) as u32),
202 ),
223 ) 203 )
224 }), 204 }),
225 ); 205 );
@@ -243,10 +223,13 @@ pub(super) fn doc_comment(hl: &mut Highlights, sema: &Semantics<RootDatabase>, n
243 } 223 }
244 } 224 }
245 225
246 for range in intra_doc_links { 226 for (def, range) in intra_doc_links {
247 hl.add(HlRange { 227 hl.add(HlRange {
248 range, 228 range,
249 highlight: HlTag::IntraDocLink | HlMod::Documentation, 229 highlight: module_def_to_hl_tag(def)
230 | HlMod::Documentation
231 | HlMod::Injected
232 | HlMod::IntraDocLink,
250 binding_hash: None, 233 binding_hash: None,
251 }); 234 });
252 } 235 }
@@ -277,9 +260,9 @@ pub(super) fn doc_comment(hl: &mut Highlights, sema: &Semantics<RootDatabase>, n
277} 260}
278 261
279fn find_doc_string_in_attr(attr: &hir::Attr, it: &ast::Attr) -> Option<ast::String> { 262fn find_doc_string_in_attr(attr: &hir::Attr, it: &ast::Attr) -> Option<ast::String> {
280 match it.literal() { 263 match it.expr() {
281 // #[doc = lit] 264 // #[doc = lit]
282 Some(lit) => match lit.kind() { 265 Some(ast::Expr::Literal(lit)) => match lit.kind() {
283 ast::LiteralKind::String(it) => Some(it), 266 ast::LiteralKind::String(it) => Some(it),
284 _ => None, 267 _ => None,
285 }, 268 },
@@ -297,6 +280,7 @@ fn find_doc_string_in_attr(attr: &hir::Attr, it: &ast::Attr) -> Option<ast::Stri
297 string.text().get(1..string.text().len() - 1).map_or(false, |it| it == text) 280 string.text().get(1..string.text().len() - 1).map_or(false, |it| it == text)
298 }) 281 })
299 } 282 }
283 _ => return None,
300 } 284 }
301} 285}
302 286
@@ -305,7 +289,7 @@ fn validate_intra_doc_link(
305 def: &Definition, 289 def: &Definition,
306 link: &str, 290 link: &str,
307 ns: Option<hir::Namespace>, 291 ns: Option<hir::Namespace>,
308) -> bool { 292) -> Option<hir::ModuleDef> {
309 match def { 293 match def {
310 Definition::ModuleDef(def) => match def { 294 Definition::ModuleDef(def) => match def {
311 hir::ModuleDef::Module(it) => it.resolve_doc_path(db, &link, ns), 295 hir::ModuleDef::Module(it) => it.resolve_doc_path(db, &link, ns),
@@ -325,5 +309,21 @@ fn validate_intra_doc_link(
325 | Definition::GenericParam(_) 309 | Definition::GenericParam(_)
326 | Definition::Label(_) => None, 310 | Definition::Label(_) => None,
327 } 311 }
328 .is_some() 312}
313
314fn module_def_to_hl_tag(def: hir::ModuleDef) -> HlTag {
315 let symbol = match def {
316 hir::ModuleDef::Module(_) => SymbolKind::Module,
317 hir::ModuleDef::Function(_) => SymbolKind::Function,
318 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => SymbolKind::Struct,
319 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => SymbolKind::Enum,
320 hir::ModuleDef::Adt(hir::Adt::Union(_)) => SymbolKind::Union,
321 hir::ModuleDef::Variant(_) => SymbolKind::Variant,
322 hir::ModuleDef::Const(_) => SymbolKind::Const,
323 hir::ModuleDef::Static(_) => SymbolKind::Static,
324 hir::ModuleDef::Trait(_) => SymbolKind::Trait,
325 hir::ModuleDef::TypeAlias(_) => SymbolKind::TypeAlias,
326 hir::ModuleDef::BuiltinType(_) => return HlTag::BuiltinType,
327 };
328 HlTag::Symbol(symbol)
329} 329}
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; }