From 5dc27898959d2330b0822d95a9ee2488e687895a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jun 2019 13:51:18 +0300 Subject: Move docs to dedicated module --- crates/ra_hir/src/code_model.rs | 68 --------------------------------------- crates/ra_hir/src/docs.rs | 71 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 6ee6bd627..59d7d589a 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -319,12 +319,6 @@ impl Module { } } -impl Docs for Module { - fn docs(&self, db: &impl HirDatabase) -> Option { - self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1)) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct StructField { pub(crate) parent: VariantDef, @@ -355,15 +349,6 @@ impl StructField { } } -impl Docs for StructField { - fn docs(&self, db: &impl HirDatabase) -> Option { - match self.source(db).1 { - FieldSource::Named(named) => docs_from_ast(&*named), - FieldSource::Pos(..) => return None, - } - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Struct { pub(crate) id: StructId, @@ -425,12 +410,6 @@ impl Struct { } } -impl Docs for Struct { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Union { pub(crate) id: StructId, @@ -464,12 +443,6 @@ impl Union { } } -impl Docs for Union { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Enum { pub(crate) id: EnumId, @@ -519,12 +492,6 @@ impl Enum { } } -impl Docs for Enum { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct EnumVariant { pub(crate) parent: Enum, @@ -568,12 +535,6 @@ impl EnumVariant { } } -impl Docs for EnumVariant { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - /// The defs which have a body. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum DefWithBody { @@ -757,12 +718,6 @@ impl Function { } } -impl Docs for Function { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Const { pub(crate) id: ConstId, @@ -806,12 +761,6 @@ impl Const { } } -impl Docs for Const { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - /// The declared signature of a const. #[derive(Debug, Clone, PartialEq, Eq)] pub struct ConstSignature { @@ -884,12 +833,6 @@ impl Static { } } -impl Docs for Static { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Trait { pub(crate) id: TraitId, @@ -936,12 +879,6 @@ impl Trait { } } -impl Docs for Trait { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct TypeAlias { pub(crate) id: TypeAliasId, @@ -998,11 +935,6 @@ impl TypeAlias { } } -impl Docs for TypeAlias { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct MacroDef { pub(crate) id: MacroDefId, diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index 5db72c08a..c2279fe95 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs @@ -1,6 +1,6 @@ use ra_syntax::ast; -use crate::HirDatabase; +use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union}; /// Holds documentation #[derive(Debug, Clone)] @@ -29,3 +29,72 @@ pub trait Docs { pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option { node.doc_comment_text().map(|it| Documentation::new(&it)) } + +impl Docs for Module { + fn docs(&self, db: &impl HirDatabase) -> Option { + self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1)) + } +} + +impl Docs for StructField { + fn docs(&self, db: &impl HirDatabase) -> Option { + match self.source(db).1 { + FieldSource::Named(named) => docs_from_ast(&*named), + FieldSource::Pos(..) => return None, + } + } +} + +impl Docs for Struct { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Union { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Enum { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for EnumVariant { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Function { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Const { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Static { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for Trait { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} + +impl Docs for TypeAlias { + fn docs(&self, db: &impl HirDatabase) -> Option { + docs_from_ast(&*self.source(db).1) + } +} -- cgit v1.2.3 From 33026c654e3a667e25ea27004c22be138ed83d33 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jun 2019 14:16:05 +0300 Subject: make Docs handing more ideomatic --- crates/ra_hir/src/code_model.rs | 1 - crates/ra_hir/src/docs.rs | 10 +++++----- crates/ra_lsp_server/src/conv.rs | 2 +- crates/ra_lsp_server/src/markdown.rs | 23 +++++++---------------- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 59d7d589a..861d6aefe 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -12,7 +12,6 @@ use crate::{ ty::{TraitRef, InferenceResult, primitive::{IntTy, FloatTy, Signedness, IntBitness, FloatBitness}}, adt::{EnumVariantId, StructFieldId, VariantDef}, generics::HasGenericParams, - docs::{Documentation, Docs, docs_from_ast}, ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeAliasId, MacroDefId}, impl_block::ImplBlock, resolve::Resolver, diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index c2279fe95..38c0922eb 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs @@ -1,24 +1,24 @@ use ra_syntax::ast; -use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union}; +use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource}; /// Holds documentation #[derive(Debug, Clone)] pub struct Documentation(String); impl Documentation { - pub fn new(s: &str) -> Self { - Self(s.into()) + fn new(s: &str) -> Documentation { + Documentation(s.into()) } - pub fn contents(&self) -> &str { + pub fn as_str(&self) -> &str { &self.0 } } impl Into for Documentation { fn into(self) -> String { - self.contents().into() + self.0.clone() } } diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 88d29b256..257492589 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -171,7 +171,7 @@ impl Conv for ra_ide_api::Documentation { fn conv(self) -> Documentation { Documentation::MarkupContent(MarkupContent { kind: MarkupKind::Markdown, - value: crate::markdown::sanitize_markdown(self).into(), + value: crate::markdown::mark_fenced_blocks_as_rust(self.as_str()).into(), }) } } diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs index f505755e8..e382eee90 100644 --- a/crates/ra_lsp_server/src/markdown.rs +++ b/crates/ra_lsp_server/src/markdown.rs @@ -1,26 +1,20 @@ -use ra_ide_api::Documentation; - -pub(crate) fn sanitize_markdown(docs: Documentation) -> Documentation { - let docs: String = docs.into(); - - // Massage markdown +pub(crate) fn mark_fenced_blocks_as_rust(src: &str) -> String { let mut processed_lines = Vec::new(); let mut in_code_block = false; - for line in docs.lines() { + for line in src.lines() { if line.starts_with("```") { - in_code_block = !in_code_block; + in_code_block ^= true } let line = if in_code_block && line.starts_with("```") && !line.contains("rust") { - "```rust".into() + "```rust" } else { - line.to_string() + line }; processed_lines.push(line); } - - Documentation::new(&processed_lines.join("\n")) + processed_lines.join("\n") } #[cfg(test)] @@ -30,9 +24,6 @@ mod tests { #[test] fn test_codeblock_adds_rust() { let comment = "```\nfn some_rust() {}\n```"; - assert_eq!( - sanitize_markdown(Documentation::new(comment)).contents(), - "```rust\nfn some_rust() {}\n```" - ); + assert_eq!(mark_fenced_blocks_as_rust(comment), "```rust\nfn some_rust() {}\n```"); } } -- cgit v1.2.3 From 2c28f5245dd8ede715d99b55fdad0ceb3de9dbe7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jun 2019 14:36:39 +0300 Subject: make documenation a query --- crates/ra_hir/src/code_model.rs | 2 +- crates/ra_hir/src/db.rs | 3 + crates/ra_hir/src/docs.rs | 123 +++++++++++++++++++--------------------- 3 files changed, 62 insertions(+), 66 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 861d6aefe..cf16ed94d 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -196,7 +196,7 @@ impl Module { /// `None` for the crate root. pub fn declaration_source( self, - db: &impl HirDatabase, + db: &(impl DefDatabase + AstDatabase), ) -> Option<(HirFileId, TreeArc)> { let def_map = db.crate_def_map(self.krate); let decl = def_map[self.module_id].declaration?; diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 3afd0994c..d2a372f3b 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -127,6 +127,9 @@ pub trait DefDatabase: SourceDatabase { #[salsa::invoke(crate::lang_item::LangItems::lang_item_query)] fn lang_item(&self, start_crate: Crate, item: SmolStr) -> Option; + + #[salsa::invoke(crate::docs::documentation_query)] + fn documentation(&self, def: crate::docs::DocDef) -> Option; } #[salsa::query_group(HirDatabaseStorage)] diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index 38c0922eb..900fd2aa8 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs @@ -1,10 +1,44 @@ +use std::sync::Arc; + use ra_syntax::ast; -use crate::{HirDatabase, Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource}; +use crate::{ + HirDatabase, DefDatabase, AstDatabase, + Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource +}; + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum DocDef { + Module(Module), + StructField(StructField), + Struct(Struct), + Enum(Enum), + EnumVariant(EnumVariant), + Static(Static), + Const(Const), + Function(Function), + Union(Union), + Trait(Trait), + TypeAlias(TypeAlias), +} + +impl_froms!( + DocDef: Module, + StructField, + Struct, + Enum, + EnumVariant, + Static, + Const, + Function, + Union, + Trait, + TypeAlias +); /// Holds documentation -#[derive(Debug, Clone)] -pub struct Documentation(String); +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Documentation(Arc); impl Documentation { fn new(s: &str) -> Documentation { @@ -12,13 +46,13 @@ impl Documentation { } pub fn as_str(&self) -> &str { - &self.0 + &*self.0 } } impl Into for Documentation { fn into(self) -> String { - self.0.clone() + self.as_str().to_owned() } } @@ -30,71 +64,30 @@ pub(crate) fn docs_from_ast(node: &impl ast::DocCommentsOwner) -> Option Option { - self.declaration_source(db).and_then(|it| docs_from_ast(&*it.1)) - } -} - -impl Docs for StructField { - fn docs(&self, db: &impl HirDatabase) -> Option { - match self.source(db).1 { +pub(crate) fn documentation_query( + db: &(impl DefDatabase + AstDatabase), + def: DocDef, +) -> Option { + match def { + DocDef::Module(it) => docs_from_ast(&*it.declaration_source(db)?.1), + DocDef::StructField(it) => match it.source(db).1 { FieldSource::Named(named) => docs_from_ast(&*named), FieldSource::Pos(..) => return None, - } - } -} - -impl Docs for Struct { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - -impl Docs for Union { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - -impl Docs for Enum { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - -impl Docs for EnumVariant { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - -impl Docs for Function { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - -impl Docs for Const { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - -impl Docs for Static { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - -impl Docs for Trait { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) + }, + DocDef::Struct(it) => docs_from_ast(&*it.source(db).1), + DocDef::Enum(it) => docs_from_ast(&*it.source(db).1), + DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).1), + DocDef::Static(it) => docs_from_ast(&*it.source(db).1), + DocDef::Const(it) => docs_from_ast(&*it.source(db).1), + DocDef::Function(it) => docs_from_ast(&*it.source(db).1), + DocDef::Union(it) => docs_from_ast(&*it.source(db).1), + DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), + DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1), } } -impl Docs for TypeAlias { +impl + Copy> Docs for T { fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) + db.documentation((*self).into()) } } -- cgit v1.2.3 From 1b783e33e953f2c63c96c1d7fa54d2e64fbd2d9a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jun 2019 14:48:56 +0300 Subject: one macro def should be enough --- crates/ra_hir/src/code_model.rs | 9 +++++++ crates/ra_hir/src/docs.rs | 7 +++-- crates/ra_hir/src/lib.rs | 2 +- crates/ra_hir/src/source_binder.rs | 30 +++++----------------- crates/ra_ide_api/src/display/navigation_target.rs | 5 +--- crates/ra_ide_api/src/name_ref_kind.rs | 5 ++-- 6 files changed, 25 insertions(+), 33 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index cf16ed94d..27850028b 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -939,6 +939,15 @@ pub struct MacroDef { pub(crate) id: MacroDefId, } +impl MacroDef { + pub fn source( + &self, + db: &(impl DefDatabase + AstDatabase), + ) -> (HirFileId, TreeArc) { + (self.id.0.file_id(), self.id.0.to_node(db)) + } +} + pub enum Container { Trait(Trait), ImplBlock(ImplBlock), diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index 900fd2aa8..1b0f84de5 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs @@ -4,7 +4,7 @@ use ra_syntax::ast; use crate::{ HirDatabase, DefDatabase, AstDatabase, - Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource + Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource, MacroDef, }; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -20,6 +20,7 @@ pub enum DocDef { Union(Union), Trait(Trait), TypeAlias(TypeAlias), + MacroDef(MacroDef), } impl_froms!( @@ -33,7 +34,8 @@ impl_froms!( Function, Union, Trait, - TypeAlias + TypeAlias, + MacroDef ); /// Holds documentation @@ -83,6 +85,7 @@ pub(crate) fn documentation_query( DocDef::Union(it) => docs_from_ast(&*it.source(db).1), DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1), + DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1), } } diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 18dea5f17..0e4aaf678 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -69,7 +69,7 @@ pub use self::{ expr::ExprScopes, resolve::Resolution, generics::{GenericParams, GenericParam, HasGenericParams}, - source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax,MacroByExampleDef}, + source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax}, }; pub use self::code_model::{ diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 6a5799622..410064d45 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use rustc_hash::{FxHashSet, FxHashMap}; use ra_db::{FileId, FilePosition}; use ra_syntax::{ - SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange,TreeArc, + SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange, ast::{self, AstNode, NameOwner}, algo::find_node_at_offset, SyntaxKind::*, @@ -18,10 +18,9 @@ use ra_syntax::{ use crate::{ HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, - AsName, Module, HirFileId, Crate, Trait, Resolver, Ty,Path, + AsName, Module, HirFileId, Crate, Trait, Resolver, Ty, Path, MacroDef, expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, - ids::{LocationCtx, MacroDefId}, - docs::{docs_from_ast,Documentation}, + ids::LocationCtx, expr, AstId, }; @@ -182,27 +181,10 @@ pub enum PathResolution { /// A generic parameter GenericParam(u32), SelfType(crate::ImplBlock), - Macro(MacroByExampleDef), + Macro(MacroDef), AssocItem(crate::ImplItem), } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct MacroByExampleDef { - pub(crate) id: MacroDefId, -} - -impl MacroByExampleDef { - pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { - (self.id.0.file_id(), self.id.0.to_node(db)) - } -} - -impl crate::Docs for MacroByExampleDef { - fn docs(&self, db: &impl HirDatabase) -> Option { - docs_from_ast(&*self.source(db).1) - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub struct ScopeEntryWithSyntax { pub(crate) name: Name, @@ -284,10 +266,10 @@ impl SourceAnalyzer { &self, db: &impl HirDatabase, macro_call: &ast::MacroCall, - ) -> Option { + ) -> Option { let id = self.resolver.resolve_macro_call(db, macro_call.path().and_then(Path::from_ast))?; - Some(MacroByExampleDef { id }) + Some(MacroDef { id }) } pub fn resolve_hir_path( diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index e19c071b0..45002d098 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -238,10 +238,7 @@ impl NavigationTarget { } } - pub(crate) fn from_macro_def( - db: &RootDatabase, - macro_call: hir::MacroByExampleDef, - ) -> NavigationTarget { + pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget { let (file_id, node) = macro_call.source(db); log::debug!("nav target {}", node.syntax().debug_dump()); NavigationTarget::from_named(file_id.original_file(db), &*node) diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs index 90972bc58..000036db4 100644 --- a/crates/ra_ide_api/src/name_ref_kind.rs +++ b/crates/ra_ide_api/src/name_ref_kind.rs @@ -1,11 +1,12 @@ use ra_syntax::{AstNode, AstPtr, ast}; use hir::Either; -use crate::db::RootDatabase; use test_utils::tested_by; +use crate::db::RootDatabase; + pub enum NameRefKind { Method(hir::Function), - Macro(hir::MacroByExampleDef), + Macro(hir::MacroDef), FieldAccess(hir::StructField), AssocItem(hir::ImplItem), Def(hir::ModuleDef), -- cgit v1.2.3 From ac64967872507bb921ad69fc50ac3475c1fc26f8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jun 2019 14:55:25 +0300 Subject: add a fixme --- crates/ra_hir/src/nameres.rs | 2 ++ crates/ra_hir/src/resolve.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 8b798d6c9..dc0dd23c9 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -323,6 +323,8 @@ impl CrateDefMap { (res.resolved_def, res.segment_index) } + // FIXME: This seems to do the same work as `resolve_path_with_macro`, but + // using a completely different code path. Seems bad, huh? pub(crate) fn find_macro( &self, db: &impl DefDatabase, diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 0f6ee7f47..d6956f45e 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -148,8 +148,8 @@ impl Resolver { PathResult::from_resolution(self.resolve_name(db, &Name::self_param())) } else { let (item_map, module) = match self.module() { - Some(m) => m, - _ => return PathResult::empty(), + Some(it) => it, + None => return PathResult::empty(), }; let (module_res, segment_index) = item_map.resolve_path(db, module, path); -- cgit v1.2.3