Stream: t-compiler/rust-analyzer

Topic: How to get position from ast::Comment

sasurau4 (Dec 21 2020 at 09:32, on Zulip):

I'm working on
If the doc comment has multiple link, we need to determine which link is pointed from position.offset. In basic source code, it can be easily done by file.token_at_offset method but comment has only non-structured &str. What is the best way to get position from doc comment?

/// Blah, .. [`foo`]<|> is [`bar`] ...
Joshua Nelson (Dec 21 2020 at 14:21, on Zulip):

@sasurau4 couldn't you do doc_comment[start..end]?

Joshua Nelson (Dec 21 2020 at 14:22, on Zulip):

or hmm I don't know if offset is a number or a range

sasurau4 (Dec 21 2020 at 14:46, on Zulip):

Yeah, I could do doc_comment[start..end] if I knew where infra link the FilePosition indicates. But FilePosition has only the offset of the file, so I have to determine where the offset is included by intra link range.
I tried parsing doc comment by pulldown_cmark, it emit only Event that doesn't contain any position infos.
The change of intra link to ast seems very difficult.

Joshua Nelson (Dec 21 2020 at 15:19, on Zulip):

Pulldown_cmark will give you the span if you call into_offset_iter

sasurau4 (Dec 22 2020 at 11:47, on Zulip):

It seems great! Thanks

Last update: Jul 28 2021 at 04:00UTC