Tease apart orthogonal concerns in markdown link rewriting

`hir` should know nothing about URLs, markdown and html. It should
only be able to:

* resolve stringy path from documentation
* generate canonical stringy path for a def

In contrast, link rewriting should not care about semantics of paths
and names resolution, and should be concern only with text mangling
bits.
This commit is contained in:
Aleksey Kladov 2020-08-26 18:56:41 +02:00
parent 3d6c4c143b
commit f8a59adf5e
9 changed files with 297 additions and 337 deletions

View file

@ -196,6 +196,16 @@ impl ModuleDef {
}
}
pub fn canonical_path(&self, db: &dyn HirDatabase) -> Option<String> {
let mut segments = Vec::new();
segments.push(self.name(db)?.to_string());
for m in self.module(db)?.path_to_root(db) {
segments.extend(m.name(db).map(|it| it.to_string()))
}
segments.reverse();
Some(segments.join("::"))
}
pub fn definition_visibility(&self, db: &dyn HirDatabase) -> Option<Visibility> {
let module = match self {
ModuleDef::Module(it) => it.parent(db)?,