mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Replace Range<usize> usage with TextRange
This commit is contained in:
parent
c43359b64e
commit
8d786dc4c3
2 changed files with 27 additions and 32 deletions
|
@ -1,6 +1,9 @@
|
|||
//! Extracts, resolves and rewrites links and intra-doc links in markdown documentation.
|
||||
|
||||
use std::{convert::TryFrom, iter::once, ops::Range};
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
iter::once,
|
||||
};
|
||||
|
||||
use itertools::Itertools;
|
||||
use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag};
|
||||
|
@ -15,7 +18,9 @@ use ide_db::{
|
|||
defs::{Definition, NameClass, NameRefClass},
|
||||
RootDatabase,
|
||||
};
|
||||
use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, TokenAtOffset, T};
|
||||
use syntax::{
|
||||
ast, match_ast, AstNode, SyntaxKind::*, SyntaxNode, SyntaxToken, TextRange, TokenAtOffset, T,
|
||||
};
|
||||
|
||||
use crate::{FilePosition, Semantics};
|
||||
|
||||
|
@ -115,7 +120,7 @@ pub(crate) fn external_docs(
|
|||
/// Extracts all links from a given markdown text.
|
||||
pub(crate) fn extract_definitions_from_markdown(
|
||||
markdown: &str,
|
||||
) -> Vec<(Range<usize>, String, Option<hir::Namespace>)> {
|
||||
) -> Vec<(TextRange, String, Option<hir::Namespace>)> {
|
||||
Parser::new_with_broken_link_callback(
|
||||
markdown,
|
||||
Options::empty(),
|
||||
|
@ -126,7 +131,11 @@ pub(crate) fn extract_definitions_from_markdown(
|
|||
if let Event::Start(Tag::Link(_, target, title)) = event {
|
||||
let link = if target.is_empty() { title } else { target };
|
||||
let (link, ns) = parse_intra_doc_link(&link);
|
||||
Some((range, link.to_string(), ns))
|
||||
Some((
|
||||
TextRange::new(range.start.try_into().ok()?, range.end.try_into().ok()?),
|
||||
link.to_string(),
|
||||
ns,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue