From 6b8358d4d9317c13593ae15e6065d67eecb85296 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 29 Mar 2021 20:11:28 +0200 Subject: Remove code duplication in highlight injection --- crates/ide/src/syntax_highlighting/inject.rs | 32 +++------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) (limited to 'crates/ide/src/syntax_highlighting') diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 963c3fb59..b62d43256 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -11,7 +11,8 @@ use syntax::{ }; use crate::{ - doc_links::extract_definitions_from_markdown, Analysis, HlMod, HlRange, HlTag, RootDatabase, + doc_links::{extract_definitions_from_markdown, resolve_doc_path_for_def}, + Analysis, HlMod, HlRange, HlTag, RootDatabase, }; use super::{highlights::Highlights, injector::Injector}; @@ -190,7 +191,7 @@ pub(super) fn doc_comment( extract_definitions_from_markdown(line) .into_iter() .filter_map(|(range, link, ns)| { - Some(range).zip(validate_intra_doc_link(sema.db, &def, &link, ns)) + Some(range).zip(resolve_doc_path_for_def(sema.db, def, &link, ns)) }) .map(|(Range { start, end }, def)| { ( @@ -283,33 +284,6 @@ fn find_doc_string_in_attr(attr: &hir::Attr, it: &ast::Attr) -> Option, -) -> Option { - match def { - Definition::ModuleDef(def) => match def { - hir::ModuleDef::Module(it) => it.resolve_doc_path(db, &link, ns), - hir::ModuleDef::Function(it) => it.resolve_doc_path(db, &link, ns), - hir::ModuleDef::Adt(it) => it.resolve_doc_path(db, &link, ns), - hir::ModuleDef::Variant(it) => it.resolve_doc_path(db, &link, ns), - hir::ModuleDef::Const(it) => it.resolve_doc_path(db, &link, ns), - hir::ModuleDef::Static(it) => it.resolve_doc_path(db, &link, ns), - hir::ModuleDef::Trait(it) => it.resolve_doc_path(db, &link, ns), - hir::ModuleDef::TypeAlias(it) => it.resolve_doc_path(db, &link, ns), - hir::ModuleDef::BuiltinType(_) => None, - }, - Definition::Macro(it) => it.resolve_doc_path(db, &link, ns), - Definition::Field(it) => it.resolve_doc_path(db, &link, ns), - Definition::SelfType(_) - | Definition::Local(_) - | Definition::GenericParam(_) - | Definition::Label(_) => None, - } -} - fn module_def_to_hl_tag(def: hir::ModuleDef) -> HlTag { let symbol = match def { hir::ModuleDef::Module(_) => SymbolKind::Module, -- cgit v1.2.3