From b3652ef2886e01f772559aa90df4c45e7c7fb1fd Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 7 Dec 2020 18:06:46 +0100 Subject: Remove documentation query --- crates/hir_def/src/attr.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/hir_def/src/attr.rs') 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}; use cfg::{CfgExpr, CfgOptions}; use either::Either; use hir_expand::{hygiene::Hygiene, AstId, InFile}; +use itertools::Itertools; use mbe::ast_to_token_tree; use syntax::{ ast::{self, AstNode, AttrsOwner}, @@ -14,6 +15,7 @@ use tt::Subtree; use crate::{ db::DefDatabase, + docs::Documentation, item_tree::{ItemTreeId, ItemTreeNode}, nameres::ModuleSource, path::ModPath, @@ -140,6 +142,20 @@ impl Attrs { Some(cfg) => cfg_options.check(&cfg) != Some(false), } } + + pub fn docs(&self) -> Option { + let mut docs = String::new(); + self.by_key("doc") + .attrs() + .flat_map(|attr| match attr.input.as_ref()? { + AttrInput::Literal(s) => Some(s), + AttrInput::TokenTree(_) => None, + }) + .intersperse(&SmolStr::new_inline("\n")) + // No FromIterator for String + .for_each(|s| docs.push_str(s.as_str())); + if docs.is_empty() { None } else { Some(docs) }.map(|it| Documentation::new(&it)) + } } #[derive(Debug, Clone, PartialEq, Eq)] -- cgit v1.2.3