aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/doc_links.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index 9a9a41113..2edd551cb 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -1,6 +1,9 @@
1//! Extracts, resolves and rewrites links and intra-doc links in markdown documentation. 1//! Extracts, resolves and rewrites links and intra-doc links in markdown documentation.
2 2
3use std::{convert::TryFrom, iter::once, ops::Range}; 3use std::{
4 convert::{TryFrom, TryInto},
5 iter::once,
6};
4 7
5use itertools::Itertools; 8use itertools::Itertools;
6use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag}; 9use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag};
@@ -15,7 +18,9 @@ use ide_db::{
15 defs::{Definition, NameClass, NameRefClass}, 18 defs::{Definition, NameClass, NameRefClass},
16 RootDatabase, 19 RootDatabase,
17}; 20};
18use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, TokenAtOffset, T}; 21use syntax::{
22 ast, match_ast, AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, TextRange, TokenAtOffset, T,
23};
19 24
20use crate::{FilePosition, Semantics}; 25use crate::{FilePosition, Semantics};
21 26
@@ -115,7 +120,7 @@ pub(crate) fn external_docs(
115/// Extracts all links from a given markdown text. 120/// Extracts all links from a given markdown text.
116pub(crate) fn extract_definitions_from_markdown( 121pub(crate) fn extract_definitions_from_markdown(
117 markdown: &str, 122 markdown: &str,
118) -> Vec<(Range<usize>, String, Option<hir::Namespace>)> { 123) -> Vec<(TextRange, String, Option<hir::Namespace>)> {
119 Parser::new_with_broken_link_callback( 124 Parser::new_with_broken_link_callback(
120 markdown, 125 markdown,
121 Options::empty(), 126 Options::empty(),
@@ -126,7 +131,11 @@ pub(crate) fn extract_definitions_from_markdown(
126 if let Event::Start(Tag::Link(_, target, title)) = event { 131 if let Event::Start(Tag::Link(_, target, title)) = event {
127 let link = if target.is_empty() { title } else { target }; 132 let link = if target.is_empty() { title } else { target };
128 let (link, ns) = parse_intra_doc_link(&link); 133 let (link, ns) = parse_intra_doc_link(&link);
129 Some((range, link.to_string(), ns)) 134 Some((
135 TextRange::new(range.start.try_into().ok()?, range.end.try_into().ok()?),
136 link.to_string(),
137 ns,
138 ))
130 } else { 139 } else {
131 None 140 None
132 } 141 }