Remove documentation query
This commit is contained in:
parent
03b886de53
commit
b3652ef288
@ -38,7 +38,7 @@ macro_rules! impl_has_attrs {
|
|||||||
}
|
}
|
||||||
fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> {
|
fn docs(self, db: &dyn HirDatabase) -> Option<Documentation> {
|
||||||
let def = AttrDefId::$def_id(self.into());
|
let def = AttrDefId::$def_id(self.into());
|
||||||
db.documentation(def)
|
db.attrs(def).docs()
|
||||||
}
|
}
|
||||||
fn resolve_doc_path(self, db: &dyn HirDatabase, link: &str, ns: Option<Namespace>) -> Option<ModuleDef> {
|
fn resolve_doc_path(self, db: &dyn HirDatabase, link: &str, ns: Option<Namespace>) -> Option<ModuleDef> {
|
||||||
let def = AttrDefId::$def_id(self.into());
|
let def = AttrDefId::$def_id(self.into());
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
pub use hir_def::db::{
|
pub use hir_def::db::{
|
||||||
AttrsQuery, BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQueryQuery,
|
AttrsQuery, BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQueryQuery,
|
||||||
CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery,
|
CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, EnumDataQuery, ExprScopesQuery,
|
||||||
ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery,
|
FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery, InternConstQuery,
|
||||||
InternConstQuery, InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery,
|
InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery, InternImplQuery,
|
||||||
InternImplQuery, InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery,
|
InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery, InternUnionQuery,
|
||||||
InternUnionQuery, ItemTreeQuery, LangItemQuery, ModuleLangItemsQuery, StaticDataQuery,
|
ItemTreeQuery, LangItemQuery, ModuleLangItemsQuery, StaticDataQuery, StructDataQuery,
|
||||||
StructDataQuery, TraitDataQuery, TypeAliasDataQuery, UnionDataQuery,
|
TraitDataQuery, TypeAliasDataQuery, UnionDataQuery,
|
||||||
};
|
};
|
||||||
pub use hir_expand::db::{
|
pub use hir_expand::db::{
|
||||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
|
AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
|
||||||
|
@ -5,6 +5,7 @@ use std::{ops, sync::Arc};
|
|||||||
use cfg::{CfgExpr, CfgOptions};
|
use cfg::{CfgExpr, CfgOptions};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{hygiene::Hygiene, AstId, InFile};
|
use hir_expand::{hygiene::Hygiene, AstId, InFile};
|
||||||
|
use itertools::Itertools;
|
||||||
use mbe::ast_to_token_tree;
|
use mbe::ast_to_token_tree;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, AttrsOwner},
|
ast::{self, AstNode, AttrsOwner},
|
||||||
@ -14,6 +15,7 @@ use tt::Subtree;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
|
docs::Documentation,
|
||||||
item_tree::{ItemTreeId, ItemTreeNode},
|
item_tree::{ItemTreeId, ItemTreeNode},
|
||||||
nameres::ModuleSource,
|
nameres::ModuleSource,
|
||||||
path::ModPath,
|
path::ModPath,
|
||||||
@ -140,6 +142,20 @@ impl Attrs {
|
|||||||
Some(cfg) => cfg_options.check(&cfg) != Some(false),
|
Some(cfg) => cfg_options.check(&cfg) != Some(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn docs(&self) -> Option<Documentation> {
|
||||||
|
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<SmolStr> 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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
@ -10,7 +10,6 @@ use crate::{
|
|||||||
attr::Attrs,
|
attr::Attrs,
|
||||||
body::{scope::ExprScopes, Body, BodySourceMap},
|
body::{scope::ExprScopes, Body, BodySourceMap},
|
||||||
data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData},
|
data::{ConstData, FunctionData, ImplData, StaticData, TraitData, TypeAliasData},
|
||||||
docs::Documentation,
|
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
import_map::ImportMap,
|
import_map::ImportMap,
|
||||||
item_tree::ItemTree,
|
item_tree::ItemTree,
|
||||||
@ -105,11 +104,6 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
|||||||
#[salsa::invoke(LangItems::lang_item_query)]
|
#[salsa::invoke(LangItems::lang_item_query)]
|
||||||
fn lang_item(&self, start_crate: CrateId, item: SmolStr) -> Option<LangItemTarget>;
|
fn lang_item(&self, start_crate: CrateId, item: SmolStr) -> Option<LangItemTarget>;
|
||||||
|
|
||||||
// FIXME(https://github.com/rust-analyzer/rust-analyzer/issues/2148#issuecomment-550519102)
|
|
||||||
// Remove this query completely, in favor of `Attrs::docs` method
|
|
||||||
#[salsa::invoke(Documentation::documentation_query)]
|
|
||||||
fn documentation(&self, def: AttrDefId) -> Option<Documentation>;
|
|
||||||
|
|
||||||
#[salsa::invoke(ImportMap::import_map_query)]
|
#[salsa::invoke(ImportMap::import_map_query)]
|
||||||
fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
|
fn import_map(&self, krate: CrateId) -> Arc<ImportMap>;
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,9 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use either::Either;
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{ast, SmolStr};
|
use syntax::{ast, SmolStr};
|
||||||
|
|
||||||
use crate::{
|
|
||||||
db::DefDatabase,
|
|
||||||
src::{HasChildSource, HasSource},
|
|
||||||
AdtId, AttrDefId, Lookup,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Holds documentation
|
/// Holds documentation
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Documentation(Arc<str>);
|
pub struct Documentation(Arc<str>);
|
||||||
@ -26,7 +19,7 @@ impl Into<String> for Documentation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Documentation {
|
impl Documentation {
|
||||||
fn new(s: &str) -> Documentation {
|
pub fn new(s: &str) -> Documentation {
|
||||||
Documentation(s.into())
|
Documentation(s.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,42 +33,6 @@ impl Documentation {
|
|||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
&*self.0
|
&*self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn documentation_query(
|
|
||||||
db: &dyn DefDatabase,
|
|
||||||
def: AttrDefId,
|
|
||||||
) -> Option<Documentation> {
|
|
||||||
match def {
|
|
||||||
AttrDefId::ModuleId(module) => {
|
|
||||||
let def_map = db.crate_def_map(module.krate);
|
|
||||||
let src = def_map[module.local_id].declaration_source(db)?;
|
|
||||||
docs_from_ast(&src.value)
|
|
||||||
}
|
|
||||||
AttrDefId::FieldId(it) => {
|
|
||||||
let src = it.parent.child_source(db);
|
|
||||||
match &src.value[it.local_id] {
|
|
||||||
Either::Left(_tuple) => None,
|
|
||||||
Either::Right(record) => docs_from_ast(record),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AttrDefId::AdtId(it) => match it {
|
|
||||||
AdtId::StructId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
|
||||||
AdtId::EnumId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
|
||||||
AdtId::UnionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
|
||||||
},
|
|
||||||
AttrDefId::EnumVariantId(it) => {
|
|
||||||
let src = it.parent.child_source(db);
|
|
||||||
docs_from_ast(&src.value[it.local_id])
|
|
||||||
}
|
|
||||||
AttrDefId::TraitId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
|
||||||
AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id?.to_node(db.upcast())),
|
|
||||||
AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
|
||||||
AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
|
||||||
AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
|
||||||
AttrDefId::TypeAliasId(it) => docs_from_ast(&it.lookup(db).source(db).value),
|
|
||||||
AttrDefId::ImplId(_) => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn docs_from_ast<N>(node: &N) -> Option<Documentation>
|
pub(crate) fn docs_from_ast<N>(node: &N) -> Option<Documentation>
|
||||||
@ -94,7 +51,8 @@ fn merge_doc_comments_and_attrs(
|
|||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
match (doc_comment_text, doc_attr_text) {
|
match (doc_comment_text, doc_attr_text) {
|
||||||
(Some(mut comment_text), Some(attr_text)) => {
|
(Some(mut comment_text), Some(attr_text)) => {
|
||||||
comment_text.push_str("\n");
|
comment_text.reserve(attr_text.len() + 1);
|
||||||
|
comment_text.push('\n');
|
||||||
comment_text.push_str(&attr_text);
|
comment_text.push_str(&attr_text);
|
||||||
Some(comment_text)
|
Some(comment_text)
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,6 @@ impl RootDatabase {
|
|||||||
hir::db::ModuleLangItemsQuery
|
hir::db::ModuleLangItemsQuery
|
||||||
hir::db::CrateLangItemsQuery
|
hir::db::CrateLangItemsQuery
|
||||||
hir::db::LangItemQuery
|
hir::db::LangItemQuery
|
||||||
hir::db::DocumentationQuery
|
|
||||||
hir::db::ImportMapQuery
|
hir::db::ImportMapQuery
|
||||||
|
|
||||||
// HirDatabase
|
// HirDatabase
|
||||||
|
Loading…
x
Reference in New Issue
Block a user