diff options
author | Lukas Wirth <[email protected]> | 2020-12-07 17:06:46 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-12-07 18:58:17 +0000 |
commit | b3652ef2886e01f772559aa90df4c45e7c7fb1fd (patch) | |
tree | 91f2a10f146d17fba626a4125d3a1fe1956e7f00 /crates/hir_def/src/attr.rs | |
parent | 03b886de53834168dd52b5e504a649292f129ae6 (diff) |
Remove documentation query
Diffstat (limited to 'crates/hir_def/src/attr.rs')
-rw-r--r-- | crates/hir_def/src/attr.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index b2ce7ca3c..7825290e6 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs | |||
@@ -5,6 +5,7 @@ use std::{ops, sync::Arc}; | |||
5 | use cfg::{CfgExpr, CfgOptions}; | 5 | use cfg::{CfgExpr, CfgOptions}; |
6 | use either::Either; | 6 | use either::Either; |
7 | use hir_expand::{hygiene::Hygiene, AstId, InFile}; | 7 | use hir_expand::{hygiene::Hygiene, AstId, InFile}; |
8 | use itertools::Itertools; | ||
8 | use mbe::ast_to_token_tree; | 9 | use mbe::ast_to_token_tree; |
9 | use syntax::{ | 10 | use syntax::{ |
10 | ast::{self, AstNode, AttrsOwner}, | 11 | ast::{self, AstNode, AttrsOwner}, |
@@ -14,6 +15,7 @@ use tt::Subtree; | |||
14 | 15 | ||
15 | use crate::{ | 16 | use crate::{ |
16 | db::DefDatabase, | 17 | db::DefDatabase, |
18 | docs::Documentation, | ||
17 | item_tree::{ItemTreeId, ItemTreeNode}, | 19 | item_tree::{ItemTreeId, ItemTreeNode}, |
18 | nameres::ModuleSource, | 20 | nameres::ModuleSource, |
19 | path::ModPath, | 21 | path::ModPath, |
@@ -140,6 +142,20 @@ impl Attrs { | |||
140 | Some(cfg) => cfg_options.check(&cfg) != Some(false), | 142 | Some(cfg) => cfg_options.check(&cfg) != Some(false), |
141 | } | 143 | } |
142 | } | 144 | } |
145 | |||
146 | pub fn docs(&self) -> Option<Documentation> { | ||
147 | let mut docs = String::new(); | ||
148 | self.by_key("doc") | ||
149 | .attrs() | ||
150 | .flat_map(|attr| match attr.input.as_ref()? { | ||
151 | AttrInput::Literal(s) => Some(s), | ||
152 | AttrInput::TokenTree(_) => None, | ||
153 | }) | ||
154 | .intersperse(&SmolStr::new_inline("\n")) | ||
155 | // No FromIterator<SmolStr> for String | ||
156 | .for_each(|s| docs.push_str(s.as_str())); | ||
157 | if docs.is_empty() { None } else { Some(docs) }.map(|it| Documentation::new(&it)) | ||
158 | } | ||
143 | } | 159 | } |
144 | 160 | ||
145 | #[derive(Debug, Clone, PartialEq, Eq)] | 161 | #[derive(Debug, Clone, PartialEq, Eq)] |