aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/syntax_highlighting/inject.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/syntax_highlighting/inject.rs')
-rw-r--r--crates/ide/src/syntax_highlighting/inject.rs55
1 files changed, 23 insertions, 32 deletions
diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs
index b62d43256..504783f31 100644
--- a/crates/ide/src/syntax_highlighting/inject.rs
+++ b/crates/ide/src/syntax_highlighting/inject.rs
@@ -1,6 +1,6 @@
1//! "Recursive" Syntax highlighting for code in doctests and fixtures. 1//! "Recursive" Syntax highlighting for code in doctests and fixtures.
2 2
3use std::{mem, ops::Range}; 3use std::mem;
4 4
5use either::Either; 5use either::Either;
6use hir::{HasAttrs, InFile, Semantics}; 6use hir::{HasAttrs, InFile, Semantics};
@@ -139,8 +139,28 @@ pub(super) fn doc_comment(
139 // Replace the original, line-spanning comment ranges by new, only comment-prefix 139 // Replace the original, line-spanning comment ranges by new, only comment-prefix
140 // spanning comment ranges. 140 // spanning comment ranges.
141 let mut new_comments = Vec::new(); 141 let mut new_comments = Vec::new();
142 let mut intra_doc_links = Vec::new();
143 let mut string; 142 let mut string;
143
144 if let Some((docs, doc_mapping)) = attributes.docs_with_rangemap(sema.db) {
145 extract_definitions_from_markdown(docs.as_str())
146 .into_iter()
147 .filter_map(|(range, link, ns)| {
148 let def = resolve_doc_path_for_def(sema.db, def, &link, ns)?;
149 let InFile { file_id, value: range } = doc_mapping.map(range)?;
150 (file_id == node.file_id).then(|| (range, def))
151 })
152 .for_each(|(range, def)| {
153 hl.add(HlRange {
154 range,
155 highlight: module_def_to_hl_tag(def)
156 | HlMod::Documentation
157 | HlMod::Injected
158 | HlMod::IntraDocLink,
159 binding_hash: None,
160 })
161 });
162 }
163
144 for attr in attributes.by_key("doc").attrs() { 164 for attr in attributes.by_key("doc").attrs() {
145 let InFile { file_id, value: src } = attrs_source_map.source_of(&attr); 165 let InFile { file_id, value: src } = attrs_source_map.source_of(&attr);
146 if file_id != node.file_id { 166 if file_id != node.file_id {
@@ -186,25 +206,7 @@ pub(super) fn doc_comment(
186 is_doctest = is_codeblock && is_rust; 206 is_doctest = is_codeblock && is_rust;
187 continue; 207 continue;
188 } 208 }
189 None if !is_doctest => { 209 None if !is_doctest => continue,
190 intra_doc_links.extend(
191 extract_definitions_from_markdown(line)
192 .into_iter()
193 .filter_map(|(range, link, ns)| {
194 Some(range).zip(resolve_doc_path_for_def(sema.db, def, &link, ns))
195 })
196 .map(|(Range { start, end }, def)| {
197 (
198 def,
199 TextRange::at(
200 prev_range_start + TextSize::from(start as u32),
201 TextSize::from((end - start) as u32),
202 ),
203 )
204 }),
205 );
206 continue;
207 }
208 None => (), 210 None => (),
209 } 211 }
210 212
@@ -223,17 +225,6 @@ pub(super) fn doc_comment(
223 } 225 }
224 } 226 }
225 227
226 for (def, range) in intra_doc_links {
227 hl.add(HlRange {
228 range,
229 highlight: module_def_to_hl_tag(def)
230 | HlMod::Documentation
231 | HlMod::Injected
232 | HlMod::IntraDocLink,
233 binding_hash: None,
234 });
235 }
236
237 if new_comments.is_empty() { 228 if new_comments.is_empty() {
238 return; // no need to run an analysis on an empty file 229 return; // no need to run an analysis on an empty file
239 } 230 }