diff options
author | Aleksey Kladov <[email protected]> | 2020-08-26 17:56:41 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-08-26 19:24:00 +0100 |
commit | f8a59adf5e9633aa5d10efcdbf70b408d280ef01 (patch) | |
tree | d088d683f75bbd2bed837f1ca0aca61fdba5c11b /crates/hir/src/code_model.rs | |
parent | 3d6c4c143b4b4c74810318eca1b5493e43535fff (diff) |
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.
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r-- | crates/hir/src/code_model.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index c2ee20dbb..c2fc819e7 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -196,6 +196,16 @@ impl ModuleDef { | |||
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | pub fn canonical_path(&self, db: &dyn HirDatabase) -> Option<String> { | ||
200 | let mut segments = Vec::new(); | ||
201 | segments.push(self.name(db)?.to_string()); | ||
202 | for m in self.module(db)?.path_to_root(db) { | ||
203 | segments.extend(m.name(db).map(|it| it.to_string())) | ||
204 | } | ||
205 | segments.reverse(); | ||
206 | Some(segments.join("::")) | ||
207 | } | ||
208 | |||
199 | pub fn definition_visibility(&self, db: &dyn HirDatabase) -> Option<Visibility> { | 209 | pub fn definition_visibility(&self, db: &dyn HirDatabase) -> Option<Visibility> { |
200 | let module = match self { | 210 | let module = match self { |
201 | ModuleDef::Module(it) => it.parent(db)?, | 211 | ModuleDef::Module(it) => it.parent(db)?, |